grovepi/docs/site/api/interrupt/index.html
2025-03-21 16:04:17 +01:00

914 lines
No EOL
35 KiB
HTML

<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="Python documentation for the GrovePi">
<link rel="canonical" href="https://dexterind.github.io/GrovePi/api/interrupt/">
<meta name="author" content="DexterInd Team">
<meta name="lang:clipboard.copy" content="Copy to clipboard">
<meta name="lang:clipboard.copied" content="Copied to clipboard">
<meta name="lang:search.language" content="en">
<meta name="lang:search.pipeline.stopwords" content="True">
<meta name="lang:search.pipeline.trimmer" content="True">
<meta name="lang:search.result.none" content="No matching documents">
<meta name="lang:search.result.one" content="1 matching document">
<meta name="lang:search.result.other" content="# matching documents">
<meta name="lang:search.tokenizer" content="[\s\-]+">
<link rel="shortcut icon" href="../../img/favicon.ico">
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.1.2">
<title>Interrupt-Based Devices - GrovePi Documentation</title>
<link rel="stylesheet" href="../../assets/stylesheets/application.3020aac5.css">
<script src="../../assets/javascripts/modernizr.01ccdecf.js"></script>
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
<link rel="stylesheet" href="../../assets/fonts/material-icons.css">
</head>
<body dir="ltr">
<svg class="md-svg">
<defs>
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
viewBox="0 0 416 448" id="__github">
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
99.5z" />
</svg>
</defs>
</svg>
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
<a href="#api-interrupt-based-devices" tabindex="1" class="md-skip">
Skip to content
</a>
<header class="md-header" data-md-component="header">
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="https://dexterind.github.io/GrovePi" title="GrovePi Documentation" class="md-header-nav__button md-logo">
<i class="md-icon"></i>
</a>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
</div>
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
GrovePi Documentation
</span>
<span class="md-header-nav__topic">
Interrupt-Based Devices
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
<label class="md-icon md-search__icon" for="__search"></label>
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
&#xE5CD;
</button>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" data-md-scrollfix>
<div class="md-search-result" data-md-component="result">
<div class="md-search-result__meta">
Type to start searching
</div>
<ol class="md-search-result__list"></ol>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<div class="md-header-nav__source">
<a href="https://github.com/DexterInd/GrovePi/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
DexterInd/GrovePi
</div>
</a>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container">
<main class="md-main">
<div class="md-main__inner md-grid" data-md-component="container">
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" data-md-level="0">
<label class="md-nav__title md-nav__title--site" for="__drawer">
<a href="https://dexterind.github.io/GrovePi" title="GrovePi Documentation" class="md-nav__button md-logo">
<i class="md-icon"></i>
</a>
GrovePi Documentation
</label>
<div class="md-nav__source">
<a href="https://github.com/DexterInd/GrovePi/" title="Go to repository" class="md-source" data-md-source="github">
<div class="md-source__icon">
<svg viewBox="0 0 24 24" width="24" height="24">
<use xlink:href="#__github" width="24" height="24"></use>
</svg>
</div>
<div class="md-source__repository">
DexterInd/GrovePi
</div>
</a>
</div>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../.." title="About" class="md-nav__link">
About
</a>
</li>
<li class="md-nav__item">
<a href="../../quickstart/" title="Getting Started" class="md-nav__link">
Getting Started
</a>
</li>
<li class="md-nav__item">
<a href="../../fw/" title="Firmware Stuff" class="md-nav__link">
Firmware Stuff
</a>
</li>
<li class="md-nav__item">
<a href="../../hw/" title="Hardware Ports" class="md-nav__link">
Hardware Ports
</a>
</li>
<li class="md-nav__item md-nav__item--active md-nav__item--nested">
<input class="md-toggle md-nav__toggle" data-md-toggle="nav-5" type="checkbox" id="nav-5" checked>
<label class="md-nav__link" for="nav-5">
API Reference
</label>
<nav class="md-nav" data-md-component="collapsible" data-md-level="1">
<label class="md-nav__title" for="nav-5">
API Reference
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../gpio/" title="GPIO Functions" class="md-nav__link">
GPIO Functions
</a>
</li>
<li class="md-nav__item">
<a href="../general/" title="General Sensors" class="md-nav__link">
General Sensors
</a>
</li>
<li class="md-nav__item">
<a href="../complex/" title="Complex Devices" class="md-nav__link">
Complex Devices
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
Interrupt-Based Devices
</label>
<a href="./" title="Interrupt-Based Devices" class="md-nav__link md-nav__link--active">
Interrupt-Based Devices
</a>
<nav class="md-nav md-nav--secondary">
<label class="md-nav__title" for="__toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#grovepiset_pin_interruptpin-ftype-interrupt_mode-period" title="grovepi.set_pin_interrupt(pin, ftype, interrupt_mode, period)" class="md-nav__link">
grovepi.set_pin_interrupt(pin, ftype, interrupt_mode, period)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiunset_pin_interruptpin" title="grovepi.unset_pin_interrupt(pin)" class="md-nav__link">
grovepi.unset_pin_interrupt(pin)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiunset_all_interrupts" title="grovepi.unset_all_interrupts()" class="md-nav__link">
grovepi.unset_all_interrupts()
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiis_interrupt_activepin" title="grovepi.is_interrupt_active(pin)" class="md-nav__link">
grovepi.is_interrupt_active(pin)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiget_active_interrupts" title="grovepi.get_active_interrupts()" class="md-nav__link">
grovepi.get_active_interrupts()
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiread_interrupt_statepin" title="grovepi.read_interrupt_state(pin)" class="md-nav__link">
grovepi.read_interrupt_state(pin)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepidust_sensor_enpin-2-period-30000" title="grovepi.dust_sensor_en(pin = 2, period = 30000)" class="md-nav__link">
grovepi.dust_sensor_en(pin = 2, period = 30000)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepidust_sensor_dispin-2" title="grovepi.dust_sensor_dis(pin = 2)" class="md-nav__link">
grovepi.dust_sensor_dis(pin = 2)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepidust_sensor_readpin-2-period-30000" title="grovepi.dust_sensor_read(pin = 2, period = 30000)" class="md-nav__link">
grovepi.dust_sensor_read(pin = 2, period = 30000)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiencoder_enpin-2-steps-32" title="grovepi.encoder_en(pin = 2, steps = 32)" class="md-nav__link">
grovepi.encoder_en(pin = 2, steps = 32)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiencoder_dispin-2" title="grovepi.encoder_dis(pin = 2)" class="md-nav__link">
grovepi.encoder_dis(pin = 2)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiencoderreadpin-2" title="grovepi.encoderRead(pin = 2)" class="md-nav__link">
grovepi.encoderRead(pin = 2)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiflowenablepin-2-period-2000" title="grovepi.flowEnable(pin = 2, period = 2000)" class="md-nav__link">
grovepi.flowEnable(pin = 2, period = 2000)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiflowdisablepin-2" title="grovepi.flowDisable(pin = 2)" class="md-nav__link">
grovepi.flowDisable(pin = 2)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiflowreadpin-2" title="grovepi.flowRead(pin = 2)" class="md-nav__link">
grovepi.flowRead(pin = 2)
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../../supported/" title="Supported Modules" class="md-nav__link">
Supported Modules
</a>
</li>
<li class="md-nav__item">
<a href="../../release-notes/" title="Release Notes" class="md-nav__link">
Release Notes
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary">
<label class="md-nav__title" for="__toc">Table of contents</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="#grovepiset_pin_interruptpin-ftype-interrupt_mode-period" title="grovepi.set_pin_interrupt(pin, ftype, interrupt_mode, period)" class="md-nav__link">
grovepi.set_pin_interrupt(pin, ftype, interrupt_mode, period)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiunset_pin_interruptpin" title="grovepi.unset_pin_interrupt(pin)" class="md-nav__link">
grovepi.unset_pin_interrupt(pin)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiunset_all_interrupts" title="grovepi.unset_all_interrupts()" class="md-nav__link">
grovepi.unset_all_interrupts()
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiis_interrupt_activepin" title="grovepi.is_interrupt_active(pin)" class="md-nav__link">
grovepi.is_interrupt_active(pin)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiget_active_interrupts" title="grovepi.get_active_interrupts()" class="md-nav__link">
grovepi.get_active_interrupts()
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiread_interrupt_statepin" title="grovepi.read_interrupt_state(pin)" class="md-nav__link">
grovepi.read_interrupt_state(pin)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepidust_sensor_enpin-2-period-30000" title="grovepi.dust_sensor_en(pin = 2, period = 30000)" class="md-nav__link">
grovepi.dust_sensor_en(pin = 2, period = 30000)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepidust_sensor_dispin-2" title="grovepi.dust_sensor_dis(pin = 2)" class="md-nav__link">
grovepi.dust_sensor_dis(pin = 2)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepidust_sensor_readpin-2-period-30000" title="grovepi.dust_sensor_read(pin = 2, period = 30000)" class="md-nav__link">
grovepi.dust_sensor_read(pin = 2, period = 30000)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiencoder_enpin-2-steps-32" title="grovepi.encoder_en(pin = 2, steps = 32)" class="md-nav__link">
grovepi.encoder_en(pin = 2, steps = 32)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiencoder_dispin-2" title="grovepi.encoder_dis(pin = 2)" class="md-nav__link">
grovepi.encoder_dis(pin = 2)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiencoderreadpin-2" title="grovepi.encoderRead(pin = 2)" class="md-nav__link">
grovepi.encoderRead(pin = 2)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiflowenablepin-2-period-2000" title="grovepi.flowEnable(pin = 2, period = 2000)" class="md-nav__link">
grovepi.flowEnable(pin = 2, period = 2000)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiflowdisablepin-2" title="grovepi.flowDisable(pin = 2)" class="md-nav__link">
grovepi.flowDisable(pin = 2)
</a>
</li>
<li class="md-nav__item">
<a href="#grovepiflowreadpin-2" title="grovepi.flowRead(pin = 2)" class="md-nav__link">
grovepi.flowRead(pin = 2)
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content">
<article class="md-content__inner md-typeset">
<a href="https://github.com/DexterInd/GrovePi/edit/master/docs/api/interrupt.md" title="Edit this page" class="md-icon md-content__icon">&#xE3C9;</a>
<h1 id="api-interrupt-based-devices">API - Interrupt-Based Devices<a class="headerlink" href="#api-interrupt-based-devices" title="Permanent link">&para;</a></h1>
<p>In this section the Python API reference for interrupt-based devices is described. This library is supported on both major versions
of Python: 2.x and 3.x.</p>
<p>The API for the following sensors is described in this section:</p>
<ul>
<li><a href="https://www.seeedstudio.com/Grove-Dust-Sensor%EF%BC%88PPD42NS%EF%BC%89-p-1050.html">Grove Dust Sensor</a></li>
<li><a href="https://www.seeedstudio.com/Grove-Encoder-p-1352.html">Grove Encoder</a></li>
<li><a href="https://www.seeedstudio.com/M11%2A1.25-Water-Flow-Sensor-p-1345.html">Grove Water Flow Sensor</a> of whose functionality can be used in other applications too</li>
</ul>
<p>Apart from describing the API for the above sensors, there is also described a set of functions used to set interrupt events on the GrovePi. These functions are like the building blocks of the API of the above sensors and can be used for your own implementation, should it be applicable to your device.</p>
<hr />
<p><strong>IMPORTANT</strong></p>
<p>This library and the other ones too are not thread-safe. You cannot call the GrovePi from multiple threads or processes
as that will put the GrovePi into a broken state.</p>
<p>In case you need to reset the GrovePi from your Raspberry Pi, <a href="../../fw/#resetting-the-grovepi">check this section</a>.</p>
<p>The functions don't verify if the input parameters are valid and therefore the parameters have to be verified/validated before that.
Calling a function with improper parameters can result in an undefined behavior for the GrovePi.</p>
<hr />
<h2 id="grovepiset_pin_interruptpin-ftype-interrupt_mode-period"><code>grovepi.set_pin_interrupt(pin, ftype, interrupt_mode, period)</code><a class="headerlink" href="#grovepiset_pin_interruptpin-ftype-interrupt_mode-period" title="Permanent link">&para;</a></h2>
<p>Attach an interrupt event to a port.</p>
<p>Can be used to count pulses, duration of pulses, set different kinds of trigger modes (on change, rising or falling edges) all done within a given time period.</p>
<p>If there are subsequent calls to this set function without detaching the interrupt event first from a given pin, then it will overwrite the old setting and update it to reflect the latest one.</p>
<p>Also, setting this up disables the OUTPUT functionality on the selected pin. If the selected pin has to drive the output, then detach the interrupt event with <a href="#grovepiunset_pin_interruptpin">grovepi.unset_pin_interrupt</a>.</p>
<p><strong>Parameters</strong></p>
<ul>
<li><code>pin {Integer}</code> can be pins D2-D8 to which the device is connected to</li>
<li><code>ftype {Integer}</code> the type of event/operation associated for the given pin. Can take values <code>grovepi.COUNT_CHANGES</code> (for counting the number of triggers) or <code>grovepi.COUNT_LOW_DURATION</code> (which measures how much time the signal stays low in a given period).</li>
<li><code>interrupt_mode {Integer}</code> triggering mode of the interrupt. It can be <code>grovepi.CHANGE</code>, <code>grovepi.FALLING</code> or <code>grovepi.RISING</code>, just like on the Arduino.</li>
<li><code>period {Integer}</code> specifying after how long the recorded value should be stored on the GrovePi to be subsequently read on the master device (Raspberry Pi). Measured in milliseconds. Minimum value shouldn't be too small (say under <em>5 ms</em>) and the maximum value is <em>65535 ms</em>.</li>
</ul>
<p><strong>Returns</strong>: None</p>
<hr />
<h2 id="grovepiunset_pin_interruptpin"><code>grovepi.unset_pin_interrupt(pin)</code><a class="headerlink" href="#grovepiunset_pin_interruptpin" title="Permanent link">&para;</a></h2>
<p>Detach an interrupt event from a given pin.</p>
<p>Necessary if you want to set output values to this pin with <a href="../gpio/#grovepidigitalwritepin-value">grovepi.digitalWrite</a> function.</p>
<p><strong>Parameters</strong></p>
<ul>
<li><code>pin {Integer}</code> pins D2-D8 from which the interrupt is released from</li>
</ul>
<p><strong>Returns</strong>: None</p>
<hr />
<h2 id="grovepiunset_all_interrupts"><code>grovepi.unset_all_interrupts()</code><a class="headerlink" href="#grovepiunset_all_interrupts" title="Permanent link">&para;</a></h2>
<p>Detach all active interrupt events on all pins.</p>
<p><strong>Parameters</strong>: None</p>
<p><strong>Returns</strong>: None</p>
<hr />
<h2 id="grovepiis_interrupt_activepin"><code>grovepi.is_interrupt_active(pin)</code><a class="headerlink" href="#grovepiis_interrupt_activepin" title="Permanent link">&para;</a></h2>
<p>Check if a pin has an interrupt event associated.</p>
<p><strong>Parameters</strong></p>
<ul>
<li><code>pin {Integer}</code> pin to check (D2-D8) if there's an associated interrupt event</li>
</ul>
<p><strong>Returns</strong>: <code>{Bool}</code> - <code>True</code> if it has an interrupt event associated and <code>False</code> if otherwise.</p>
<hr />
<h2 id="grovepiget_active_interrupts"><code>grovepi.get_active_interrupts()</code><a class="headerlink" href="#grovepiget_active_interrupts" title="Permanent link">&para;</a></h2>
<p>Get a list of all pins that have associated interrupt events.</p>
<p><strong>Parameters</strong>: None</p>
<p><strong>Returns</strong>: A list of integers representing the active pins that have interrupt events.</p>
<hr />
<h2 id="grovepiread_interrupt_statepin"><code>grovepi.read_interrupt_state(pin)</code><a class="headerlink" href="#grovepiread_interrupt_statepin" title="Permanent link">&para;</a></h2>
<p>Get the recorded value by the interrupt event on the given pin.</p>
<p>If an interrupt is set on pin D2 (D2 is taken as an example, it can be any other digital pin) with the type of operation set to <code>grovepi.COUNT_CHANGES</code> and mode of interrupt set to <code>grovepi.RISING</code> with a period set to <em>1000 ms</em>, then say if 567 rising edges are detected, then at the end of this period of <em>1000 ms</em>, this function will return for pin D2 value 567. And the returned value of this function on D2 pin will update every <em>1000 ms</em>, because that's the period that has been set for it. And the outcome varies depending on how the interrupt event is initially set.</p>
<p><strong>Parameters</strong></p>
<ul>
<li><code>pin {Integer}</code> pin to check the recorded value for the associated interrupt event</li>
</ul>
<p><strong>Returns</strong>: <code>{Bool}</code> - <code>True</code> if it has an interrupt event associated and <code>False</code> if otherwise.</p>
<hr />
<h2 id="grovepidust_sensor_enpin-2-period-30000"><code>grovepi.dust_sensor_en(pin = 2, period = 30000)</code><a class="headerlink" href="#grovepidust_sensor_enpin-2-period-30000" title="Permanent link">&para;</a></h2>
<p>Enables the <a href="https://www.seeedstudio.com/Grove-Dust-Sensor%EF%BC%88PPD42NS%EF%BC%89-p-1050.html">Grove Dust Sensor</a>.</p>
<p>If there is another interrupt event set on this pin, calling this method will overwrite the previous setting. Check <a href="#grovepiset_pin_interruptpin-ftype-interrupt_mode-period">grovepi.set_pin_interrupt</a> to find out more. It's the same effect as with calling this after calling <a href="#grovepiencoder_enpin-2-steps-32">grovepi.encoder_en</a> or <a href="#grovepiflowenablepin-2-period-2000">grovepi.flowEnable</a>. </p>
<p>This function is the same as calling <code>set_pin_interrupt(pin, ftype=COUNT_LOW_DURATION, interrupt_mode=CHANGE, period=period)</code>.</p>
<p><strong>Parameters</strong></p>
<ul>
<li><code>pin {Integer}</code> the pin (D2-D8) to which the dust sensor is assigned to</li>
<li><code>period {Integer}</code> refresh time frame for the dust sensor. Maximum value for this parameter is <em>65535</em> ms.</li>
</ul>
<p><strong>Returns</strong>: None</p>
<hr />
<h2 id="grovepidust_sensor_dispin-2"><code>grovepi.dust_sensor_dis(pin = 2)</code><a class="headerlink" href="#grovepidust_sensor_dispin-2" title="Permanent link">&para;</a></h2>
<p>Disables the <a href="https://www.seeedstudio.com/Grove-Dust-Sensor%EF%BC%88PPD42NS%EF%BC%89-p-1050.html">Grove Dust Sensor</a>.</p>
<p>To disable the dust sensor that sits on the given pin. It's the same as calling <a href="#grovepiunset_pin_interruptpin">unset_pin_interrupt</a> function. </p>
<p><em>This function will be removed from future versions and it's only kept for making the API backwards-compatible.</em></p>
<p><strong>Parameters</strong>:</p>
<ul>
<li><code>pin {Integer}</code> the pin (D2-D8) to which the dust sensor is connected to</li>
</ul>
<p><strong>Returns</strong>: None</p>
<hr />
<h2 id="grovepidust_sensor_readpin-2-period-30000"><code>grovepi.dust_sensor_read(pin = 2, period = 30000)</code><a class="headerlink" href="#grovepidust_sensor_readpin-2-period-30000" title="Permanent link">&para;</a></h2>
<p>Reads the low pulse occupancy of the <a href="https://www.seeedstudio.com/Grove-Dust-Sensor%EF%BC%88PPD42NS%EF%BC%89-p-1050.html">Grove Dust Sensor</a> in the given period of time as set with <a href="#grovepiset_pin_interruptpin-ftype-interrupt_mode-period">grovepi.set_pin_interrupt</a> function.</p>
<p><strong>Parameters</strong>: None</p>
<ul>
<li><code>pin {Integer}</code> - the pin (D2-D8) to which the dust sensor is connected to</li>
<li><code>period {Integer}</code> - refresh time frame for the dust sensor as set with <a href="#grovepiset_pin_interruptpin-ftype-interrupt_mode-period">grovepi.set_pin_interrupt</a> function. Maximum value for this parameter is <em>65535</em> ms.</li>
</ul>
<p><strong>Returns</strong>: <code>{(Integer, Float, Float)}</code> list</p>
<ul>
<li>1st element is the LPO time</li>
<li>the 2nd one is the percentage (LPO time divided by total period)</li>
<li>the 3rd is the concentration as measured in <em>pcs/283ml=0.01cf</em> where the particle size is over <em>1um</em></li>
</ul>
<p>The dust sensor's characteristics can be seen in the following graph.</p>
<p><img alt="Grove Dust Sensor Characteristics" src="../../img/dust_sensor_characteristics.jpg" /></p>
<hr />
<h2 id="grovepiencoder_enpin-2-steps-32"><code>grovepi.encoder_en(pin = 2, steps = 32)</code><a class="headerlink" href="#grovepiencoder_enpin-2-steps-32" title="Permanent link">&para;</a></h2>
<p>Enable the <a href="https://www.seeedstudio.com/Grove-Encoder-p-1352.html">Grove Encoder</a>.</p>
<p>If the pin already has an associated interrupt event, calling this method will overwrite the setting with the new change for the given pin.</p>
<p>Since the encoder needs two interrupt-enabled pins, when calling this function for a <em>pin</em>, it also attaches the next pin in line <em>pin + 1</em>. To see which pins have been attached, call <a href="#grovepiget_active_interrupts">get_active_interrupts</a> function.</p>
<p><strong>Parameters</strong>: </p>
<ul>
<li>
<p><code>pin {Integer}</code> the pin to which the encoder is connected to. It also attaches the pin right next up in its line <em>pin + 1</em>. Can be set for D2-D7 pins. Notice how the last one can't be used because there would have to be another pin available after it, but there isn't because it's the last one in the chain.</p>
</li>
<li>
<p><code>steps {Integer}</code> specifies the number of steps for the encoder</p>
</li>
</ul>
<p><strong>Returns</strong>: None</p>
<hr />
<h2 id="grovepiencoder_dispin-2"><code>grovepi.encoder_dis(pin = 2)</code><a class="headerlink" href="#grovepiencoder_dispin-2" title="Permanent link">&para;</a></h2>
<p>Disable the <a href="https://www.seeedstudio.com/Grove-Encoder-p-1352.html">Grove Encoder</a>.</p>
<p>Necessary if you want to set output values to this pin with <a href="../gpio/#grovepidigitalwritepin-value">grovepi.digitalWrite</a> function. It's the same as calling <a href="#grovepiunset_pin_interruptpin">unset_pin_interrupt</a> function for <em>pin</em> and <em>pin + 1</em>. </p>
<p><strong>Parameters</strong>:</p>
<ul>
<li><code>pin {Integer}</code> the pin (D2-D8) to which the flow sensor is connected to</li>
</ul>
<p><strong>Returns</strong>: None</p>
<hr />
<h2 id="grovepiencoderreadpin-2"><code>grovepi.encoderRead(pin = 2)</code><a class="headerlink" href="#grovepiencoderreadpin-2" title="Permanent link">&para;</a></h2>
<p>Read the data off of the <a href="https://www.seeedstudio.com/Grove-Encoder-p-1352.html">Grove Encoder</a>.</p>
<p><strong>Parameters</strong>:</p>
<ul>
<li><code>pin {Integer}</code> - the pin (D2-D7) to which the encoder is attached to.</li>
</ul>
<p><strong>Returns</strong>: <code>{Integer}</code> the current position of the encoder</p>
<hr />
<h2 id="grovepiflowenablepin-2-period-2000"><code>grovepi.flowEnable(pin = 2, period = 2000)</code><a class="headerlink" href="#grovepiflowenablepin-2-period-2000" title="Permanent link">&para;</a></h2>
<p>Enables the <a href="https://www.seeedstudio.com/M11%2A1.25-Water-Flow-Sensor-p-1345.html">Grove Water Flow Sensor</a>.</p>
<p>This function literally counts the number of rising pulses in the given time period. Because of that, calling this is the same as calling <code>set_pin_interrupt(pin, ftype=COUNT_CHANGES, interrupt_mode=RISING, period=period)</code> for <em>pin</em>.</p>
<p>If the pin already has an associated interrupt event, calling this method will overwrite the setting with the new change for the given pin.</p>
<p><em>This function will be removed from future versions and it's only kept for making the API backwards-compatible.</em></p>
<p><strong>Parameters</strong></p>
<ul>
<li><code>pin {Integer}</code> the pin (D2-D8) to which the dust sensor is assigned to</li>
<li><code>period {Integer}</code> refresh time frame for the dust sensor. Maximum value for this parameter is <em>65535</em> ms.</li>
</ul>
<p><strong>Returns</strong>: None</p>
<hr />
<h2 id="grovepiflowdisablepin-2"><code>grovepi.flowDisable(pin = 2)</code><a class="headerlink" href="#grovepiflowdisablepin-2" title="Permanent link">&para;</a></h2>
<p>Disables the <a href="https://www.seeedstudio.com/M11%2A1.25-Water-Flow-Sensor-p-1345.html">Grove Water Flow Sensor</a>.</p>
<p>Necessary if you want to set output values to this pin with <a href="../gpio/#grovepidigitalwritepin-value">grovepi.digitalWrite</a> function. It's the same as calling <a href="#grovepiunset_pin_interruptpin">unset_pin_interrupt</a> function.</p>
<p><em>This function will be removed from future versions and it's only kept for making the API backwards-compatible.</em></p>
<p><strong>Parameters</strong>: </p>
<ul>
<li><code>pin {Integer}</code> the pin (D2-D8) to which the flow sensor is connected to</li>
</ul>
<p><strong>Returns</strong>: None</p>
<hr />
<h2 id="grovepiflowreadpin-2"><code>grovepi.flowRead(pin = 2)</code><a class="headerlink" href="#grovepiflowreadpin-2" title="Permanent link">&para;</a></h2>
<p>Enables the <a href="https://www.seeedstudio.com/M11%2A1.25-Water-Flow-Sensor-p-1345.html">Grove Water Flow Sensor</a>.</p>
<p>This function counts the number of rising pulses in the time period set with <a href="#grovepiflowenablepin-2-period-2000">grovepi.flowEnable</a>.</p>
<p>It's the same as calling <a href="#grovepiread_interrupt_statepin">grovepi.read_interrupt_state</a> for the given pin.</p>
<p><strong>Parameters</strong>:</p>
<ul>
<li><code>pin {Integer}</code> the pin (D2-D8) to which the flow sensor is connected to</li>
</ul>
<p><strong>Returns</strong>: <code>{Integer}</code> number of rising pulses that occurred within the given time frame</p>
</article>
</div>
</div>
</main>
<footer class="md-footer">
<div class="md-footer-nav">
<nav class="md-footer-nav__inner md-grid">
<a href="../complex/" title="Complex Devices" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
<div class="md-flex__cell md-flex__cell--shrink">
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
</div>
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
<span class="md-flex__ellipsis">
<span class="md-footer-nav__direction">
Previous
</span>
Complex Devices
</span>
</div>
</a>
<a href="../../supported/" title="Supported Modules" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
<span class="md-flex__ellipsis">
<span class="md-footer-nav__direction">
Next
</span>
Supported Modules
</span>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i>
</div>
</a>
</nav>
</div>
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-footer-copyright">
<div class="md-footer-copyright__highlight">
Maintained by the <a href="/release-notes/#maintenance-team">DexterInd Team</a>.
</div>
powered by
<a href="https://www.mkdocs.org">MkDocs</a>
and
<a href="https://squidfunk.github.io/mkdocs-material/">
Material for MkDocs</a>
</div>
<div class="md-footer-social">
<link rel="stylesheet" href="../../assets/fonts/font-awesome.css">
<a href="https://github.com/DexterInd" class="md-footer-social__link fa fa-github"></a>
<a href="https://twitter.com/dexterind" class="md-footer-social__link fa fa-twitter"></a>
</div>
</div>
</div>
</footer>
</div>
<script src="../../assets/javascripts/application.267712eb.js"></script>
<script>app.initialize({version:"1.0.4",url:{base:"../.."}})</script>
</body>
</html>