# pigpio

file_name: index
menu_title: pigpio
page_title: The pigpio library
pic1: rpi.jpg
pic2: servo.jpg
pic3: motor.jpg
body:
pigpio is a library for the Raspberry which allows control of the
General Purpose Input Outputs (GPIO).&nbsp; pigpio works on all
versions of the Pi.
<p><a href="download.html">Download</a><br></p>
<h3>Features<br></h3>
<ul>
<li>
<p>hardware timed sampling and time-stamping of GPIO 0-31 every 5
us<br></p>
</li>
<li>
<p>hardware timed PWM on all of GPIO 0-31<br></p>
</li>
<li>
<p>hardware timed servo pulses on all of GPIO 0-31</p>
</li>
<li>
<p>callbacks on GPIO 0-31 level change (time accurate to a few
us)</p>
</li>
<li>
<p>notifications via pipe on GPIO 0-31 level change<br></p>
</li>
<li>
<p>callbacks at timed intervals</p>
</li>
<li>
<p>reading/writing all of the GPIO in a bank (0-31, 32-53) as a
single operation</p>
</li>
<li>
<p>GPIO reading, writing, modes, and internal pulls<br></p>
</li>
<li>
<p>socket and pipe interfaces for the bulk of the functionality</p>
</li>
<li>
<p>waveforms to generate GPIO level changes (time accurate to a few
us)</p>
</li>
<li>
<p>software serial links using any user GPIO</p>
</li>
<li>
<p>rudimentary permission control through the socket and pipe
interfaces<br></p>
</li>
<li>creating and running scripts on the pigpio daemon</li>
</ul>
<h3>General</h3>
The pigpio <a href="cif.html">library</a> is written in the C
programming language.<br>
<br>
The <a href="pigpiod.html">pigpio daemon</a> offers a <a href=
"sif.html">socket</a> and <a href="pif.html">pipe</a> interface to
the underlying C library.<br>
<br>
A <a href="pdif2.html">C library</a> and a <a href=
"python.html">Python module</a> allow control of the GPIO via the
pigpio daemon.<br>
<br>
There is third party support for a number of <a href=
"index.html#Other_Languages">other languages</a>.&nbsp;
<h3>piscope</h3>
<p><a href="piscope.html">piscope</a> is a logic analyser (digital
waveform viewer).<br></p>
piscope is a GTK+3 application and uses pigpio to provide raw GPIO
level data.&nbsp; piscope may be run on a Pi or on any machine
capable of compiling a GTK+3 application.
<h3><a name="GPIO" id="GPIO"></a>GPIO</h3>
<p><span style="font-weight: bold;">ALL GPIO</span> are identified
by their <span style="font-weight: bold;">Broadcom
number</span>.&nbsp; See <a href=
"http://elinux.org/RPi_Low-level_peripherals#General_Purpose_Input.2FOutput_.28GPIO.29">
elinux.org</a><br></p>
There are 54 GPIO in total, arranged in two banks.<br>
<p>Bank 1 contains GPIO 0-31.&nbsp; Bank 2 contains GPIO
32-53.<br></p>
For all types of Pi it is safe to read all the GPIO. If you try to
write a system GPIO or change its mode you can crash the Pi or
corrupt the data on the SD card.<br>
<br>
There are several types of board, each with different expansion
headers, giving physical access to different GPIO.&nbsp;
<ul>
<li><a href="#Type_1">Type 1</a> - Model B (original model)</li>
<li><a href="#Type_2">Type 2</a> - Model A, B (revision 2)</li>
<li><a href="#Type_3">Type 3</a> - Model A+, B+, Pi Zero, Pi2B,
Pi3B</li>
<li><a href="#CM">Compute Module</a> - Compute Module</li>
</ul>
<h4><a name="Type_1" id="Type_1"></a>Type 1 - Model B (original
model)</h4>
<ul>
<li>26 pin header (P1).</li>
</ul>
<ul>
<li>Hardware revision numbers of 2 and 3.</li>
</ul>
<ul>
<li>User GPIO 0-1, 4, 7-11, 14-15, 17-18, 21-25.</li>
</ul>
<table summary="" style="width: 60%; text-align: left;"
cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
<br></td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">3V3</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">5V</td>
</tr>
<tr>
<td style="text-align: center;">SDA</td>
<td style="text-align: center;">0<br></td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">5V</td>
</tr>
<tr>
<td style="text-align: center;">SCL</td>
<td style="text-align: center;">1<br></td>
<td style="text-align: center;">5</td>
<td style="text-align: center;">6</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">14</td>
<td style="text-align: center;">TXD</td>
</tr>
<tr>
<td style="text-align: center;">Ground</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">9</td>
<td style="text-align: center;">10</td>
<td style="text-align: center;">15</td>
<td style="text-align: center;">RXD</td>
</tr>
<tr>
<td style="text-align: center;">ce1</td>
<td style="text-align: center;">17</td>
<td style="text-align: center;">11</td>
<td style="text-align: center;">12</td>
<td style="text-align: center;">18</td>
<td style="text-align: center;">ce0</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">21</td>
<td style="text-align: center;">13</td>
<td style="text-align: center;">14</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">22</td>
<td style="text-align: center;">15</td>
<td style="text-align: center;">16</td>
<td style="text-align: center;">23</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">3V3</td>
<td style="text-align: center;">-<br></td>
<td style="text-align: center;">17</td>
<td style="text-align: center;">18</td>
<td style="text-align: center;">24</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">MOSI</td>
<td style="text-align: center;">10</td>
<td style="text-align: center;">19</td>
<td style="text-align: center;">20</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;">MISO</td>
<td style="text-align: center;">9</td>
<td style="text-align: center;">21</td>
<td style="text-align: center;">22</td>
<td style="text-align: center;">25</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">SCLK</td>
<td style="text-align: center;">11</td>
<td style="text-align: center;">23</td>
<td style="text-align: center;">24</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">CE0</td>
</tr>
<tr>
<td style="text-align: center;">Ground</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">25</td>
<td style="text-align: center;">26</td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">CE1</td>
</tr>
</tbody>
</table>
<br>
<h4><a name="Type_2" id="Type_2"></a>Type 2 - Model A, B (revision
2)</h4>
26 pin header (P1) and an additional 8 pin header (P5).
<ul>
<li>Hardware revision numbers of 4, 5, 6 (B), 7, 8, 9 (A), and 13,
14, 15 (B).</li>
</ul>
<ul>
<li>User GPIO 2-4, 7-11, 14-15, 17-18, 22-25, 27-31.<br></li>
</ul>
<table summary="" style="width: 60%; text-align: left;"
cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
<br></td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">3V3</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">5V</td>
</tr>
<tr>
<td style="text-align: center;">SDA</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">5V</td>
</tr>
<tr>
<td style="text-align: center;">SCL</td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">5</td>
<td style="text-align: center;">6</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">14</td>
<td style="text-align: center;">TXD</td>
</tr>
<tr>
<td style="text-align: center;">Ground</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">9</td>
<td style="text-align: center;">10</td>
<td style="text-align: center;">15</td>
<td style="text-align: center;">RXD</td>
</tr>
<tr>
<td style="text-align: center;">ce1</td>
<td style="text-align: center;">17</td>
<td style="text-align: center;">11</td>
<td style="text-align: center;">12</td>
<td style="text-align: center;">18</td>
<td style="text-align: center;">ce0</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">27</td>
<td style="text-align: center;">13</td>
<td style="text-align: center;">14</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">22</td>
<td style="text-align: center;">15</td>
<td style="text-align: center;">16</td>
<td style="text-align: center;">23</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">3V3</td>
<td style="text-align: center;">-<br></td>
<td style="text-align: center;">17</td>
<td style="text-align: center;">18</td>
<td style="text-align: center;">24</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">MOSI</td>
<td style="text-align: center;">10</td>
<td style="text-align: center;">19</td>
<td style="text-align: center;">20</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;">MISO</td>
<td style="text-align: center;">9</td>
<td style="text-align: center;">21</td>
<td style="text-align: center;">22</td>
<td style="text-align: center;">25</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">SCLK</td>
<td style="text-align: center;">11</td>
<td style="text-align: center;">23</td>
<td style="text-align: center;">24</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">CE0</td>
</tr>
<tr>
<td style="text-align: center;">Ground</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">25</td>
<td style="text-align: center;">26</td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">CE1</td>
</tr>
</tbody>
</table>
<br>
<table summary="" style="width: 60%; text-align: left;"
cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
<br></td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">5V<br></td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">3V3</td>
</tr>
<tr>
<td style="text-align: center;">SDA<br></td>
<td style="text-align: center;">28</td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">29</td>
<td style="text-align: center;">SCL</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">30</td>
<td style="text-align: center;">5</td>
<td style="text-align: center;">6</td>
<td style="text-align: center;">31</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">Ground<br></td>
<td style="text-align: center;">-<br></td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">-<br></td>
<td style="text-align: center;">Ground</td>
</tr>
</tbody>
</table>
<br>
<h4><a name="Type_3" id="Type_3"></a>Type 3 - Model A+, B+, Pi
Zero, Pi Zero W, Pi2B, Pi3B, Pi4B<br></h4>
<ul>
<li>40 pin expansion header (J8).</li>
</ul>
<ul>
<li>Hardware revision numbers of 16 or greater.</li>
</ul>
<ul>
<li>User GPIO 2-27 (0 and 1 are reserved).<br></li>
</ul>
<table summary="" style="width: 60%; text-align: left;"
cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
<br></td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">3V3</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">5V</td>
</tr>
<tr>
<td style="text-align: center;">SDA</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">5V</td>
</tr>
<tr>
<td style="text-align: center;">SCL</td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">5</td>
<td style="text-align: center;">6</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">14</td>
<td style="text-align: center;">TXD</td>
</tr>
<tr>
<td style="text-align: center;">Ground</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">9</td>
<td style="text-align: center;">10</td>
<td style="text-align: center;">15</td>
<td style="text-align: center;">RXD</td>
</tr>
<tr>
<td style="text-align: center;">ce1</td>
<td style="text-align: center;">17</td>
<td style="text-align: center;">11</td>
<td style="text-align: center;">12</td>
<td style="text-align: center;">18</td>
<td style="text-align: center;">ce0</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">27</td>
<td style="text-align: center;">13</td>
<td style="text-align: center;">14</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">22</td>
<td style="text-align: center;">15</td>
<td style="text-align: center;">16</td>
<td style="text-align: center;">23</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">3V3</td>
<td style="text-align: center;">-<br></td>
<td style="text-align: center;">17</td>
<td style="text-align: center;">18</td>
<td style="text-align: center;">24</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">MOSI</td>
<td style="text-align: center;">10</td>
<td style="text-align: center;">19</td>
<td style="text-align: center;">20</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;">MISO</td>
<td style="text-align: center;">9</td>
<td style="text-align: center;">21</td>
<td style="text-align: center;">22</td>
<td style="text-align: center;">25</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">SCLK</td>
<td style="text-align: center;">11</td>
<td style="text-align: center;">23</td>
<td style="text-align: center;">24</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">CE0</td>
</tr>
<tr>
<td style="text-align: center;">Ground</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">25</td>
<td style="text-align: center;">26</td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">CE1</td>
</tr>
<tr>
<td style="text-align: center;">ID_SD</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">27</td>
<td style="text-align: center;">28</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">ID_SC</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">5</td>
<td style="text-align: center;">29</td>
<td style="text-align: center;">30</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">6</td>
<td style="text-align: center;">31</td>
<td style="text-align: center;">32</td>
<td style="text-align: center;">12</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">13</td>
<td style="text-align: center;">33</td>
<td style="text-align: center;">34</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;">miso</td>
<td style="text-align: center;">19</td>
<td style="text-align: center;">35</td>
<td style="text-align: center;">36</td>
<td style="text-align: center;">16</td>
<td style="text-align: center;">ce2</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">26</td>
<td style="text-align: center;">37</td>
<td style="text-align: center;">38</td>
<td style="text-align: center;">20</td>
<td style="text-align: center;">mosi</td>
</tr>
<tr>
<td style="text-align: center;">Ground</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">39</td>
<td style="text-align: center;">40</td>
<td style="text-align: center;">21</td>
<td style="text-align: center;">sclk</td>
</tr>
</tbody>
</table>
<br>
<h4><a name="CM" id="CM"></a>Compute Module</h4>
<p>All 54 GPIO may be physically accessed.&nbsp; Some are reserved
for system use - refer to the Compute Module documentation.<br></p>
<p>Only GPIO 0-31 are supported for hardware timed sampling, PWM,
servo pulses, alert callbacks, waves, and software serial
links.<br></p>
<h3><a name="Other_Languages" id="Other_Languages"></a>Other
Languages</h3>
<p>There are several third party projects which provide wrappers
for pigpio.<br></p>
<p>Some are listed here:<br></p>
<ul>
<li><a href="https://github.com/skvamme/pigpio">Erlang</a>
(skvamme)</li>
<li><a href="https://github.com/mattjlewis/pigpioj">Java</a> JNI
wrapper around the pigpio C library (mattlewis)</li>
<li><a href="https://github.com/mattjlewis/diozero">Java</a> via
diozero, a high level wrapper around pigpio, Pi4J, wiringPi etc
(mattlewis)</li>
<li><a href="https://github.com/nkolban/jpigpio">Java</a>
(nkolban)</li>
<li><a href=
"https://github.com/unosquare/pigpio-dotnet">.NET/mono</a>
(unosquare)</li>
<li><a href="https://github.com/fivdi/pigpio">Node.js</a>
A wrapper for the pigpio C library (fivdi)</li>
<li><a href="https://github.com/guymcswain/pigpio-client">Node.js</a>
A client for pigpio socket interface (guymcswain)</li>
<li><a href="https://metacpan.org/pod/RPi::PIGPIO">Perl</a> (Gligan
Calin Horea)</li>
<li><a href=
"https://github.com/nak1114/ruby-extension-pigpio">Ruby</a>
(Nak)</li>
<li><a href=
"https://github.com/vasmalltalk/pigpio-vast">Smalltalk</a>(Instantiations)</li>
<li><a href=
"https://github.com/UBogun/Xojo-pigpio">Xojo</a>(UBogun)</li>
<li><a href=
"https://github.com/eugenedakin/pigpio-GPIO">Xojo</a>(Eugene Dakin)</li>
</ul>
<hr style="width: 100%; height: 2px;">
<p><font size="-2">The PWM and servo pulses are timed using the DMA
and PWM/PCM peripherals.&nbsp; This use was inspired by Richard
Hirst's <a href="https://github.com/richardghirst/PiBits" target=
"_blank">servoblaster</a> kernel module.</font></p>


file_name: pigpiod
menu_title: pigpiod
page_title: pigpio Daemon
pic1: breadboard.jpg
pic2: caps.jpg
pic3: driver.jpg
body:
pigpiod is a utility which launches the pigpio library as a daemon.<br>
<br>
Once launched the pigpio library runs in the background accepting commands from the pipe and socket interfaces.<br>
<br>
The pigpiod utility requires sudo privileges to launch the library but thereafter the pipe and socket commands may be issued by normal users.<br>
<br>
pigpiod accepts the following configuration options<br>
<br>
<table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td><b>-a value</b></td><td>DMA memory allocation mode</td><td>0=AUTO, 1=PMAP, 2=MBOX</td><td>Default AUTO
</td></tr><tr><td><b>-b value</b></td><td>GPIO sample buffer size in milliseconds</td><td>100-10000</td><td>Default 120
</td></tr><tr><td><b>-c value</b></td><td>Library internal settings</td><td></td><td>Default 0
</td></tr><tr><td><b>-d value</b></td><td>Primary DMA channel</td><td>0-14</td><td>Default 14
</td></tr><tr><td><b>-e value</b></td><td>Secondary DMA channel</td><td>0-14</td><td>Default 6.  Preferably use one of DMA channels 0 to 6 for the secondary channel
</td></tr><tr><td><b>-f</b></td><td>Disable fifo interface</td><td></td><td>Default enabled
</td></tr><tr><td><b>-g</b></td><td>Run in foreground (do not fork)</td><td></td><td>Default disabled
</td></tr><tr><td><b>-k</b></td><td>Disable local and remote socket interface</td><td></td><td>Default enabled
</td></tr><tr><td><b>-l</b></td><td>Disable remote socket interface</td><td></td><td>Default enabled
</td></tr><tr><td><b>-m</b></td><td>Disable alerts (sampling)</td><td></td><td>Default enabled
</td></tr><tr><td><b>-n IP address</b></td><td>Allow IP address to use the socket interface</td><td>Name (e.g. paul) or dotted quad (e.g. 192.168.1.66)</td><td>If the -n option is not used all addresses are allowed (unless overridden by the -k or -l options).  Multiple -n options are allowed.  If -k has been used -n has no effect.  If -l has been used only -n localhost has any effect
</td></tr><tr><td><b>-p value</b></td><td>Socket port</td><td>1024-32000</td><td>Default 8888
</td></tr><tr><td><b>-s value</b></td><td>Sample rate</td><td>1, 2, 4, 5, 8, or 10 microseconds</td><td>Default 5
</td></tr><tr><td><b>-t value</b></td><td>Clock peripheral</td><td>0=PWM 1=PCM</td><td>Default PCM.  pigpio uses one or both of PCM and PWM.  If PCM is used then PWM is available for audio.  If PWM is used then PCM is available for audio.  If waves or hardware PWM are used neither PWM nor PCM will be available for audio.
</td></tr><tr><td><b>-v -V</b></td><td>Display pigpio version and exit</td><td></td><td>
</td></tr><tr><td><b>-x mask</b></td><td>GPIO which may be updated</td><td>A 54 bit mask with (1&lt;&lt;n) set if the user may update GPIO #n</td><td>Default is the set of user GPIO for the board revision.  Use -x -1 to allow all GPIO
</td></tr></tbody></table><h3>Example</h3><code>sudo&nbsp;pigpiod&nbsp;-s&nbsp;2&nbsp;-b&nbsp;200&nbsp;-f<br></code><br><br>Launch the pigpio library with a sample rate of 2 microseconds and a 200 millisecond buffer.  Disable the fifo interface.
<h3>Permissions</h3>pigpio provides a rudimentary permissions system for commands issued via the socket and pipe interfaces.
<br><br>All GPIO may be read.
<br><br>Only the user GPIO for the board type or those specified by the -x option may be updated.
<br><br><code>Type&nbsp;1&nbsp;boards&nbsp;0x03E6CF93&nbsp;(26&nbsp;pin&nbsp;header)<br>Type&nbsp;2&nbsp;boards&nbsp;0xFBC6CF9C&nbsp;(26&nbsp;pin&nbsp;+&nbsp;8&nbsp;pin&nbsp;header)<br>Type&nbsp;3&nbsp;boards&nbsp;0x0FFFFFFC&nbsp;(40&nbsp;pin&nbsp;header)<br></code><br><br>In this context an update includes the following:
<br><br>GPIO mode set<br>
GPIO pull/up down<br>
GPIO write<br>
GPIO set PWM (including range and frequency)<br>
GPIO set servo
<br><br>In addition the bank clear and set commands, and the wave commands will only
affect updateable GPIO.
<h3>Exceptions</h3>The following exceptions are made for particular models.
<br><br><b>Models A and B</b><br><br>The green activity LED (GPIO 16) may be written.<br>
<br><b>Models A+ and B+</b><br><br>The green activity LED (GPIO 47) may be written.<br>
The red power LED (GPIO 35) may be written.<br>
The high USB power mode (GPIO 38) may be written.<br>
<br><b>Pi Zero</b><br><br>The green activity LED (GPIO 47) may be written.<br>
<br><b>Pi2B</b><br><br>The green activity LED (GPIO 47) may be written.<br>
The red power LED (GPIO 35) may be written.<br>
The high USB power mode (GPIO 38) may be written.<br>
<br><b>Pi3B</b><br><br>The green activity LED and the red power LED are not writable.<br>
The USB power mode is fixed at 1.2 amps (high power).<br>
<h3>DMA Channels</h3>The secondary channel is only used for the transmission of waves.
<br><br>If possible use one of channels 0 to 6 for the secondary channel (a full channel).
<br><br>A full channel only requires one DMA control block regardless of the length of a pulse delay.  Channels 7 to 14 (lite channels) require one DMA control block for each 16383 microseconds of delay.  I.e. a 10 second pulse delay requires one control block on a full channel and 611 control blocks on a lite channel.
<br><br>


file_name: cif
menu_title: pigpio C I/F
page_title: pigpio C Interface
pic1: imu-1.jpg
pic2: lcd.jpg
pic3: psu.jpg
body:
<br><br>pigpio is a C library for the Raspberry which allows control of the GPIO.
<h3>Features</h3>o hardware timed PWM on any of GPIO 0-31
<br><br>o hardware timed servo pulses on any of GPIO 0-31
<br><br>o callbacks when any of GPIO 0-31 change state
<br><br>o callbacks at timed intervals
<br><br>o reading/writing all of the GPIO in a bank as one operation
<br><br>o individually setting GPIO modes, reading and writing
<br><br>o notifications when any of GPIO 0-31 change state
<br><br>o the construction of output waveforms with microsecond timing
<br><br>o rudimentary permission control over GPIO
<br><br>o a simple interface to start and stop new threads
<br><br>o I2C, SPI, and serial link wrappers
<br><br>o creating and running scripts
<h3>GPIO</h3>ALL GPIO are identified by their Broadcom number.
<h3>Credits</h3>The PWM and servo pulses are timed using the DMA and PWM peripherals.
<br><br>This use was inspired by Richard Hirst's servoblaster kernel module.
<h3>Usage</h3>Include &lt;pigpio.h&gt; in your source files.
<br><br>Assuming your source is in prog.c use the following command to build and
run the executable.
<br><br><code>gcc&nbsp;-Wall&nbsp;-pthread&nbsp;-o&nbsp;prog&nbsp;prog.c&nbsp;-lpigpio&nbsp;-lrt<br>sudo&nbsp;./prog<br></code><br><br>For examples of usage see the C programs within the pigpio archive file.
<h3>Notes</h3>All the functions which return an int return &lt; 0 on error.
<br><br><a href="#gpioInitialise">gpioInitialise</a> must be called before all other library functions
with the following exceptions:
<br><br><code><a href="#gpioCfg*">gpioCfg*</a><br><a href="#gpioVersion">gpioVersion</a><br><a href="#gpioHardwareRevision">gpioHardwareRevision</a><br></code><br><br>If the library is not initialised all but the <a href="#gpioCfg*">gpioCfg*</a>,
<a href="#gpioVersion">gpioVersion</a>, and <a href="#gpioHardwareRevision">gpioHardwareRevision</a> functions will
return error PI_NOT_INITIALISED.
<br><br>If the library is initialised the <a href="#gpioCfg*">gpioCfg*</a> functions will return
error PI_INITIALISED.
<br><br>If you intend to rely on signals sent to your application, you should
turn off the internal signal handling as shown in this example:
<br><br><code>int&nbsp;cfg&nbsp;=&nbsp;gpioCfgGetInternals();<br>cfg&nbsp;|=&nbsp;PI_CFG_NOSIGHANDLER;&nbsp;&nbsp;//&nbsp;(1&lt;&lt;10)<br>gpioCfgSetInternals(cfg);<br>int&nbsp;status&nbsp;=&nbsp;gpioInitialise();<br></code><h2>OVERVIEW</h2><table border="0" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td></td></tr><tr><td><b>ESSENTIAL
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioInitialise">gpioInitialise</a></td><td>            Initialise library
</td></tr><tr><td><a href="#gpioTerminate">gpioTerminate</a></td><td>             Stop library
</td></tr><tr><td></td><td></td></tr><tr><td><b>BASIC
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioSetMode">gpioSetMode</a></td><td>               Set a GPIO mode
</td></tr><tr><td><a href="#gpioGetMode">gpioGetMode</a></td><td>               Get a GPIO mode
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioSetPullUpDown">gpioSetPullUpDown</a></td><td>         Set/clear GPIO pull up/down resistor
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioRead">gpioRead</a></td><td>                  Read a GPIO
</td></tr><tr><td><a href="#gpioWrite">gpioWrite</a></td><td>                 Write a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><b>PWM (overrides servo commands on same GPIO)
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioPWM">gpioPWM</a></td><td>                   Start/stop PWM pulses on a GPIO
</td></tr><tr><td><a href="#gpioSetPWMfrequency">gpioSetPWMfrequency</a></td><td>       Configure PWM frequency for a GPIO
</td></tr><tr><td><a href="#gpioSetPWMrange">gpioSetPWMrange</a></td><td>           Configure PWM range for a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioGetPWMdutycycle">gpioGetPWMdutycycle</a></td><td>       Get dutycycle setting on a GPIO
</td></tr><tr><td><a href="#gpioGetPWMfrequency">gpioGetPWMfrequency</a></td><td>       Get configured PWM frequency for a GPIO
</td></tr><tr><td><a href="#gpioGetPWMrange">gpioGetPWMrange</a></td><td>           Get configured PWM range for a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioGetPWMrealRange">gpioGetPWMrealRange</a></td><td>       Get underlying PWM range for a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><b>Servo (overrides PWM commands on same GPIO)
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioServo">gpioServo</a></td><td>                 Start/stop servo pulses on a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioGetServoPulsewidth">gpioGetServoPulsewidth</a></td><td>    Get pulsewidth setting on a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><b>INTERMEDIATE
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioTrigger">gpioTrigger</a></td><td>               Send a trigger pulse to a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioSetWatchdog">gpioSetWatchdog</a></td><td>           Set a watchdog on a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioRead_Bits_0_31">gpioRead_Bits_0_31</a></td><td>        Read all GPIO in bank 1
</td></tr><tr><td><a href="#gpioRead_Bits_32_53">gpioRead_Bits_32_53</a></td><td>       Read all GPIO in bank 2
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioWrite_Bits_0_31_Clear">gpioWrite_Bits_0_31_Clear</a></td><td> Clear selected GPIO in bank 1
</td></tr><tr><td><a href="#gpioWrite_Bits_32_53_Clear">gpioWrite_Bits_32_53_Clear</a></td><td>Clear selected GPIO in bank 2
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioWrite_Bits_0_31_Set">gpioWrite_Bits_0_31_Set</a></td><td>   Set selected GPIO in bank 1
</td></tr><tr><td><a href="#gpioWrite_Bits_32_53_Set">gpioWrite_Bits_32_53_Set</a></td><td>  Set selected GPIO in bank 2
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioSetAlertFunc">gpioSetAlertFunc</a></td><td>          Request a GPIO level change callback
</td></tr><tr><td><a href="#gpioSetAlertFuncEx">gpioSetAlertFuncEx</a></td><td>        Request a GPIO change callback, extended
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioSetTimerFunc">gpioSetTimerFunc</a></td><td>          Request a regular timed callback
</td></tr><tr><td><a href="#gpioSetTimerFuncEx">gpioSetTimerFuncEx</a></td><td>        Request a regular timed callback, extended
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioStartThread">gpioStartThread</a></td><td>           Start a new thread
</td></tr><tr><td><a href="#gpioStopThread">gpioStopThread</a></td><td>            Stop a previously started thread
</td></tr><tr><td></td><td></td></tr><tr><td><b>ADVANCED
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioNotifyOpen">gpioNotifyOpen</a></td><td>            Request a notification handle
</td></tr><tr><td><a href="#gpioNotifyClose">gpioNotifyClose</a></td><td>           Close a notification
</td></tr><tr><td><a href="#gpioNotifyOpenWithSize">gpioNotifyOpenWithSize</a></td><td>    Request a notification with sized pipe
</td></tr><tr><td><a href="#gpioNotifyBegin">gpioNotifyBegin</a></td><td>           Start notifications for selected GPIO
</td></tr><tr><td><a href="#gpioNotifyPause">gpioNotifyPause</a></td><td>           Pause notifications
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioHardwareClock">gpioHardwareClock</a></td><td>         Start hardware clock on supported GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioHardwarePWM">gpioHardwarePWM</a></td><td>           Start hardware PWM on supported GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioGlitchFilter">gpioGlitchFilter</a></td><td>          Set a glitch filter on a GPIO
</td></tr><tr><td><a href="#gpioNoiseFilter">gpioNoiseFilter</a></td><td>           Set a noise filter on a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioSetPad">gpioSetPad</a></td><td>                Sets a pads drive strength
</td></tr><tr><td><a href="#gpioGetPad">gpioGetPad</a></td><td>                Gets a pads drive strength
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#shell">shell</a></td><td>                     Executes a shell command
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioSetISRFunc">gpioSetISRFunc</a></td><td>            Request a GPIO interrupt callback
</td></tr><tr><td><a href="#gpioSetISRFuncEx">gpioSetISRFuncEx</a></td><td>          Request a GPIO interrupt callback, extended
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioSetSignalFunc">gpioSetSignalFunc</a></td><td>         Request a signal callback
</td></tr><tr><td><a href="#gpioSetSignalFuncEx">gpioSetSignalFuncEx</a></td><td>       Request a signal callback, extended
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioSetGetSamplesFunc">gpioSetGetSamplesFunc</a></td><td>     Requests a GPIO samples callback
</td></tr><tr><td><a href="#gpioSetGetSamplesFuncEx">gpioSetGetSamplesFuncEx</a></td><td>   Requests a GPIO samples callback, extended
</td></tr><tr><td></td><td></td></tr><tr><td><b>Custom
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioCustom1">gpioCustom1</a></td><td>               User custom function 1
</td></tr><tr><td><a href="#gpioCustom2">gpioCustom2</a></td><td>               User custom function 2
</td></tr><tr><td></td><td></td></tr><tr><td><b>Events
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#eventMonitor">eventMonitor</a></td><td>              Sets the events to monitor
</td></tr><tr><td><a href="#eventSetFunc">eventSetFunc</a></td><td>              Request an event callback
</td></tr><tr><td><a href="#eventSetFuncEx">eventSetFuncEx</a></td><td>            Request an event callback, extended
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#eventTrigger">eventTrigger</a></td><td>              Trigger an event
</td></tr><tr><td></td><td></td></tr><tr><td><b>Scripts
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioStoreScript">gpioStoreScript</a></td><td>           Store a script
</td></tr><tr><td><a href="#gpioRunScript">gpioRunScript</a></td><td>             Run a stored script
</td></tr><tr><td><a href="#gpioUpdateScript">gpioUpdateScript</a></td><td>          Set a scripts parameters
</td></tr><tr><td><a href="#gpioScriptStatus">gpioScriptStatus</a></td><td>          Get script status and parameters
</td></tr><tr><td><a href="#gpioStopScript">gpioStopScript</a></td><td>            Stop a running script
</td></tr><tr><td><a href="#gpioDeleteScript">gpioDeleteScript</a></td><td>          Delete a stored script
</td></tr><tr><td></td><td></td></tr><tr><td><b>I2C
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2cOpen">i2cOpen</a></td><td>                   Opens an I2C device
</td></tr><tr><td><a href="#i2cClose">i2cClose</a></td><td>                  Closes an I2C device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2cWriteQuick">i2cWriteQuick</a></td><td>             SMBus write quick
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2cReadByte">i2cReadByte</a></td><td>               SMBus read byte
</td></tr><tr><td><a href="#i2cWriteByte">i2cWriteByte</a></td><td>              SMBus write byte
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2cReadByteData">i2cReadByteData</a></td><td>           SMBus read byte data
</td></tr><tr><td><a href="#i2cWriteByteData">i2cWriteByteData</a></td><td>          SMBus write byte data
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2cReadWordData">i2cReadWordData</a></td><td>           SMBus read word data
</td></tr><tr><td><a href="#i2cWriteWordData">i2cWriteWordData</a></td><td>          SMBus write word data
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2cReadBlockData">i2cReadBlockData</a></td><td>          SMBus read block data
</td></tr><tr><td><a href="#i2cWriteBlockData">i2cWriteBlockData</a></td><td>         SMBus write block data
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2cReadI2CBlockData">i2cReadI2CBlockData</a></td><td>       SMBus read I2C block data
</td></tr><tr><td><a href="#i2cWriteI2CBlockData">i2cWriteI2CBlockData</a></td><td>      SMBus write I2C block data
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2cReadDevice">i2cReadDevice</a></td><td>             Reads the raw I2C device
</td></tr><tr><td><a href="#i2cWriteDevice">i2cWriteDevice</a></td><td>            Writes the raw I2C device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2cProcessCall">i2cProcessCall</a></td><td>            SMBus process call
</td></tr><tr><td><a href="#i2cBlockProcessCall">i2cBlockProcessCall</a></td><td>       SMBus block process call
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2cSwitchCombined">i2cSwitchCombined</a></td><td>         Sets or clears the combined flag
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2cSegments">i2cSegments</a></td><td>               Performs multiple I2C transactions
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2cZip">i2cZip</a></td><td>                    Performs multiple I2C transactions
</td></tr><tr><td></td><td></td></tr><tr><td><b>I2C BIT BANG
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#bbI2COpen">bbI2COpen</a></td><td>                 Opens GPIO for bit banging I2C
</td></tr><tr><td><a href="#bbI2CClose">bbI2CClose</a></td><td>                Closes GPIO for bit banging I2C
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#bbI2CZip">bbI2CZip</a></td><td>                  Performs bit banged I2C transactions
</td></tr><tr><td></td><td></td></tr><tr><td><b>I2C/SPI SLAVE
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#bscXfer">bscXfer</a></td><td>                   I2C/SPI as slave transfer
</td></tr><tr><td></td><td></td></tr><tr><td><b>SERIAL
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#serOpen">serOpen</a></td><td>                   Opens a serial device
</td></tr><tr><td><a href="#serClose">serClose</a></td><td>                  Closes a serial device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#serReadByte">serReadByte</a></td><td>               Reads a byte from a serial device
</td></tr><tr><td><a href="#serWriteByte">serWriteByte</a></td><td>              Writes a byte to a serial device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#serRead">serRead</a></td><td>                   Reads bytes from a serial device
</td></tr><tr><td><a href="#serWrite">serWrite</a></td><td>                  Writes bytes to a serial device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#serDataAvailable">serDataAvailable</a></td><td>          Returns number of bytes ready to be read
</td></tr><tr><td></td><td></td></tr><tr><td><b>SERIAL BIT BANG (read only)
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioSerialReadOpen">gpioSerialReadOpen</a></td><td>        Opens a GPIO for bit bang serial reads
</td></tr><tr><td><a href="#gpioSerialReadClose">gpioSerialReadClose</a></td><td>       Closes a GPIO for bit bang serial reads
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioSerialReadInvert">gpioSerialReadInvert</a></td><td>      Configures normal/inverted for serial reads
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioSerialRead">gpioSerialRead</a></td><td>            Reads bit bang serial data from a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><b>SPI
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#spiOpen">spiOpen</a></td><td>                   Opens a SPI device
</td></tr><tr><td><a href="#spiClose">spiClose</a></td><td>                  Closes a SPI device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#spiRead">spiRead</a></td><td>                   Reads bytes from a SPI device
</td></tr><tr><td><a href="#spiWrite">spiWrite</a></td><td>                  Writes bytes to a SPI device
</td></tr><tr><td><a href="#spiXfer">spiXfer</a></td><td>                   Transfers bytes with a SPI device
</td></tr><tr><td></td><td></td></tr><tr><td><b>SPI BIT BANG
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#bbSPIOpen">bbSPIOpen</a></td><td>                 Opens GPIO for bit banging SPI
</td></tr><tr><td><a href="#bbSPIClose">bbSPIClose</a></td><td>                Closes GPIO for bit banging SPI
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#bbSPIXfer">bbSPIXfer</a></td><td>                 Performs bit banged SPI transactions
</td></tr><tr><td></td><td></td></tr><tr><td><b>FILES
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#fileOpen">fileOpen</a></td><td>                  Opens a file
</td></tr><tr><td><a href="#fileClose">fileClose</a></td><td>                 Closes a file
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#fileRead">fileRead</a></td><td>                  Reads bytes from a file
</td></tr><tr><td><a href="#fileWrite">fileWrite</a></td><td>                 Writes bytes to a file
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#fileSeek">fileSeek</a></td><td>                  Seeks to a position within a file
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#fileList">fileList</a></td><td>                  List files which match a pattern
</td></tr><tr><td></td><td></td></tr><tr><td><b>WAVES
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioWaveClear">gpioWaveClear</a></td><td>             Deletes all waveforms
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioWaveAddNew">gpioWaveAddNew</a></td><td>            Starts a new waveform
</td></tr><tr><td><a href="#gpioWaveAddGeneric">gpioWaveAddGeneric</a></td><td>        Adds a series of pulses to the waveform
</td></tr><tr><td><a href="#gpioWaveAddSerial">gpioWaveAddSerial</a></td><td>         Adds serial data to the waveform
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioWaveCreate">gpioWaveCreate</a></td><td>            Creates a waveform from added data
</td></tr><tr><td><a href="#gpioWaveCreatePad">gpioWaveCreatePad</a></td><td>         Creates a waveform of fixed size from added data
</td></tr><tr><td><a href="#gpioWaveDelete">gpioWaveDelete</a></td><td>            Deletes a waveform
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioWaveTxSend">gpioWaveTxSend</a></td><td>            Transmits a waveform
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioWaveChain">gpioWaveChain</a></td><td>             Transmits a chain of waveforms
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioWaveTxAt">gpioWaveTxAt</a></td><td>              Returns the current transmitting waveform
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioWaveTxBusy">gpioWaveTxBusy</a></td><td>            Checks to see if the waveform has ended
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioWaveTxStop">gpioWaveTxStop</a></td><td>            Aborts the current waveform
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioWaveGetCbs">gpioWaveGetCbs</a></td><td>            Length in CBs of the current waveform
</td></tr><tr><td><a href="#gpioWaveGetHighCbs">gpioWaveGetHighCbs</a></td><td>        Length of longest waveform so far
</td></tr><tr><td><a href="#gpioWaveGetMaxCbs">gpioWaveGetMaxCbs</a></td><td>         Absolute maximum allowed CBs
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioWaveGetMicros">gpioWaveGetMicros</a></td><td>         Length in micros of the current waveform
</td></tr><tr><td><a href="#gpioWaveGetHighMicros">gpioWaveGetHighMicros</a></td><td>     Length of longest waveform so far
</td></tr><tr><td><a href="#gpioWaveGetMaxMicros">gpioWaveGetMaxMicros</a></td><td>      Absolute maximum allowed micros
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioWaveGetPulses">gpioWaveGetPulses</a></td><td>         Length in pulses of the current waveform
</td></tr><tr><td><a href="#gpioWaveGetHighPulses">gpioWaveGetHighPulses</a></td><td>     Length of longest waveform so far
</td></tr><tr><td><a href="#gpioWaveGetMaxPulses">gpioWaveGetMaxPulses</a></td><td>      Absolute maximum allowed pulses
</td></tr><tr><td></td><td></td></tr><tr><td><b>UTILITIES
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioDelay">gpioDelay</a></td><td>                 Delay for a number of microseconds
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioTick">gpioTick</a></td><td>                  Get current tick (microseconds)
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioHardwareRevision">gpioHardwareRevision</a></td><td>      Get hardware revision
</td></tr><tr><td><a href="#gpioVersion">gpioVersion</a></td><td>               Get the pigpio version
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#getBitInBytes">getBitInBytes</a></td><td>             Get the value of a bit
</td></tr><tr><td><a href="#putBitInBytes">putBitInBytes</a></td><td>             Set the value of a bit
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioTime">gpioTime</a></td><td>                  Get current time
</td></tr><tr><td><a href="#gpioSleep">gpioSleep</a></td><td>                 Sleep for specified time
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#time_sleep">time_sleep</a></td><td>                Sleeps for a float number of seconds
</td></tr><tr><td><a href="#time_time">time_time</a></td><td>                 Float number of seconds since the epoch
</td></tr><tr><td></td><td></td></tr><tr><td><b>CONFIGURATION
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioCfgBufferSize">gpioCfgBufferSize</a></td><td>         Configure the GPIO sample buffer size
</td></tr><tr><td><a href="#gpioCfgClock">gpioCfgClock</a></td><td>              Configure the GPIO sample rate
</td></tr><tr><td><a href="#gpioCfgDMAchannel">gpioCfgDMAchannel</a></td><td>         Configure the DMA channel (DEPRECATED)
</td></tr><tr><td><a href="#gpioCfgDMAchannels">gpioCfgDMAchannels</a></td><td>        Configure the DMA channels
</td></tr><tr><td><a href="#gpioCfgPermissions">gpioCfgPermissions</a></td><td>        Configure the GPIO access permissions
</td></tr><tr><td><a href="#gpioCfgInterfaces">gpioCfgInterfaces</a></td><td>         Configure user interfaces
</td></tr><tr><td><a href="#gpioCfgSocketPort">gpioCfgSocketPort</a></td><td>         Configure socket port
</td></tr><tr><td><a href="#gpioCfgMemAlloc">gpioCfgMemAlloc</a></td><td>           Configure DMA memory allocation mode
</td></tr><tr><td><a href="#gpioCfgNetAddr">gpioCfgNetAddr</a></td><td>            Configure allowed network addresses
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpioCfgGetInternals">gpioCfgGetInternals</a></td><td>       Get internal configuration settings
</td></tr><tr><td><a href="#gpioCfgSetInternals">gpioCfgSetInternals</a></td><td>       Set internal configuration settings
</td></tr><tr><td></td><td></td></tr><tr><td><b>EXPERT
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#rawWaveAddSPI">rawWaveAddSPI</a></td><td>             Not intended for general use
</td></tr><tr><td><a href="#rawWaveAddGeneric">rawWaveAddGeneric</a></td><td>         Not intended for general use
</td></tr><tr><td><a href="#rawWaveCB">rawWaveCB</a></td><td>                 Not intended for general use
</td></tr><tr><td><a href="#rawWaveCBAdr">rawWaveCBAdr</a></td><td>              Not intended for general use
</td></tr><tr><td><a href="#rawWaveGetOOL">rawWaveGetOOL</a></td><td>             Not intended for general use
</td></tr><tr><td><a href="#rawWaveSetOOL">rawWaveSetOOL</a></td><td>             Not intended for general use
</td></tr><tr><td><a href="#rawWaveGetOut">rawWaveGetOut</a></td><td>             Not intended for general use
</td></tr><tr><td><a href="#rawWaveSetOut">rawWaveSetOut</a></td><td>             Not intended for general use
</td></tr><tr><td><a href="#rawWaveGetIn">rawWaveGetIn</a></td><td>              Not intended for general use
</td></tr><tr><td><a href="#rawWaveSetIn">rawWaveSetIn</a></td><td>              Not intended for general use
</td></tr><tr><td><a href="#rawWaveInfo">rawWaveInfo</a></td><td>               Not intended for general use
</td></tr><tr><td><a href="#rawDumpWave">rawDumpWave</a></td><td>               Not intended for general use
</td></tr><tr><td><a href="#rawDumpScript">rawDumpScript</a></td><td>             Not intended for general use
</td></tr><tr><td></td><td></td></tr></tbody></table><h2>FUNCTIONS</h2><h3><a name="gpioInitialise"></a><a href="#int"><small>int</small></a> gpioInitialise<small>(void)</small></h3>
Initialises the library.
<br><br>Returns the pigpio version number if OK, otherwise PI_INIT_FAILED.
<br><br>gpioInitialise must be called before using the other library functions
with the following exceptions:
<br><br><code><a href="#gpioCfg*">gpioCfg*</a><br><a href="#gpioVersion">gpioVersion</a><br><a href="#gpioHardwareRevision">gpioHardwareRevision</a><br></code><br><br><b><small>Example</small></b><br><br><code>if&nbsp;(gpioInitialise()&nbsp;&lt;&nbsp;0)<br>{<br>&nbsp;&nbsp;&nbsp;//&nbsp;pigpio&nbsp;initialisation&nbsp;failed.<br>}<br>else<br>{<br>&nbsp;&nbsp;&nbsp;//&nbsp;pigpio&nbsp;initialised&nbsp;okay.<br>}<br></code><h3><a name="gpioTerminate"></a><a href="#void"><small>void</small></a> gpioTerminate<small>(void)</small></h3>
Terminates the library.
<br><br>Returns nothing.
<br><br>Call before program exit.
<br><br>This function resets the used DMA channels, releases memory, and
terminates any running threads.
<br><br><b><small>Example</small></b><br><br><code>gpioTerminate();<br></code><h3><a name="gpioSetMode"></a><a href="#int"><small>int</small></a> gpioSetMode<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>, <a href="#unsigned">unsigned</a> <a href="#mode">mode</a>)</small></h3>
Sets the GPIO mode, typically input or output.
<br><br><code>gpio:&nbsp;0-53<br>mode:&nbsp;0-7<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_MODE.
<br><br>Arduino style: pinMode.
<br><br><b><small>Example</small></b><br><br><code>gpioSetMode(17,&nbsp;PI_INPUT);&nbsp;&nbsp;//&nbsp;Set&nbsp;GPIO17&nbsp;as&nbsp;input.<br><br>gpioSetMode(18,&nbsp;PI_OUTPUT);&nbsp;//&nbsp;Set&nbsp;GPIO18&nbsp;as&nbsp;output.<br><br>gpioSetMode(22,PI_ALT0);&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Set&nbsp;GPIO22&nbsp;to&nbsp;alternative&nbsp;mode&nbsp;0.<br></code><br><br>See <a href="http://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf">http://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf</a> page 102 for an overview of the modes.
<h3><a name="gpioGetMode"></a><a href="#int"><small>int</small></a> gpioGetMode<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>)</small></h3>
Gets the GPIO mode.
<br><br><code>gpio:&nbsp;0-53<br></code><br><br>Returns the GPIO mode if OK, otherwise PI_BAD_GPIO.
<br><br><b><small>Example</small></b><br><br><code>if&nbsp;(gpioGetMode(17)&nbsp;!=&nbsp;PI_ALT0)<br>{<br>&nbsp;&nbsp;&nbsp;gpioSetMode(17,&nbsp;PI_ALT0);&nbsp;&nbsp;//&nbsp;set&nbsp;GPIO17&nbsp;to&nbsp;ALT0<br>}<br></code><h3><a name="gpioSetPullUpDown"></a><a href="#int"><small>int</small></a> gpioSetPullUpDown<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>, <a href="#unsigned">unsigned</a> <a href="#pud">pud</a>)</small></h3>
Sets or clears resistor pull ups or downs on the GPIO.
<br><br><code>gpio:&nbsp;0-53<br>&nbsp;pud:&nbsp;0-2<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_PUD.
<br><br><b><small>Example</small></b><br><br><code>gpioSetPullUpDown(17,&nbsp;PI_PUD_UP);&nbsp;&nbsp;&nbsp;//&nbsp;Sets&nbsp;a&nbsp;pull-up.<br><br>gpioSetPullUpDown(18,&nbsp;PI_PUD_DOWN);&nbsp;//&nbsp;Sets&nbsp;a&nbsp;pull-down.<br><br>gpioSetPullUpDown(23,&nbsp;PI_PUD_OFF);&nbsp;&nbsp;//&nbsp;Clear&nbsp;any&nbsp;pull-ups/downs.<br></code><h3><a name="gpioRead"></a><a href="#int"><small>int</small></a> gpioRead<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>)</small></h3>
Reads the GPIO level, on or off.
<br><br><code>gpio:&nbsp;0-53<br></code><br><br>Returns the GPIO level if OK, otherwise PI_BAD_GPIO.
<br><br>Arduino style: digitalRead.
<br><br><b><small>Example</small></b><br><br><code>printf("GPIO24&nbsp;is&nbsp;level&nbsp;%d",&nbsp;gpioRead(24));<br></code><h3><a name="gpioWrite"></a><a href="#int"><small>int</small></a> gpioWrite<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>, <a href="#unsigned">unsigned</a> <a href="#level">level</a>)</small></h3>
Sets the GPIO level, on or off.
<br><br><code>&nbsp;gpio:&nbsp;0-53<br>level:&nbsp;0-1<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_GPIO or PI_BAD_LEVEL.
<br><br>If PWM or servo pulses are active on the GPIO they are switched off.
<br><br>Arduino style: digitalWrite
<br><br><b><small>Example</small></b><br><br><code>gpioWrite(24,&nbsp;1);&nbsp;//&nbsp;Set&nbsp;GPIO24&nbsp;high.<br></code><h3><a name="gpioPWM"></a><a href="#int"><small>int</small></a> gpioPWM<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#unsigned">unsigned</a> <a href="#dutycycle">dutycycle</a>)</small></h3>
Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on).
Range defaults to 255.
<br><br><code>user_gpio:&nbsp;0-31<br>dutycycle:&nbsp;0-range<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYCYCLE.
<br><br>Arduino style: analogWrite
<br><br>This and the servo functionality use the DMA and PWM or PCM peripherals
to control and schedule the pulse lengths and dutycycles.
<br><br>The <a href="#gpioSetPWMrange">gpioSetPWMrange</a> function may be used to change the default
range of 255.
<br><br><b><small>Example</small></b><br><br><code>gpioPWM(17,&nbsp;255);&nbsp;//&nbsp;Sets&nbsp;GPIO17&nbsp;full&nbsp;on.<br><br>gpioPWM(18,&nbsp;128);&nbsp;//&nbsp;Sets&nbsp;GPIO18&nbsp;half&nbsp;on.<br><br>gpioPWM(23,&nbsp;0);&nbsp;&nbsp;&nbsp;//&nbsp;Sets&nbsp;GPIO23&nbsp;full&nbsp;off.<br></code><h3><a name="gpioGetPWMdutycycle"></a><a href="#int"><small>int</small></a> gpioGetPWMdutycycle<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>)</small></h3>
Returns the PWM dutycycle setting for the GPIO.
<br><br><code>user_gpio:&nbsp;0-31<br></code><br><br>Returns between 0 (off) and range (fully on) if OK, otherwise
PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO.
<br><br>For normal PWM the dutycycle will be out of the defined range
for the GPIO (see <a href="#gpioGetPWMrange">gpioGetPWMrange</a>).
<br><br>If a hardware clock is active on the GPIO the reported dutycycle
will be 500000 (500k) out of 1000000 (1M).
<br><br>If hardware PWM is active on the GPIO the reported dutycycle
will be out of a 1000000 (1M).
<br><br>Normal PWM range defaults to 255.
<h3><a name="gpioSetPWMrange"></a><a href="#int"><small>int</small></a> gpioSetPWMrange<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#unsigned">unsigned</a> <a href="#range">range</a>)</small></h3>
Selects the dutycycle range to be used for the GPIO.  Subsequent calls
to gpioPWM will use a dutycycle between 0 (off) and range (fully on).
<br><br><code>user_gpio:&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;range:&nbsp;25-40000<br></code><br><br>Returns the real range for the given GPIO's frequency if OK,
otherwise PI_BAD_USER_GPIO or PI_BAD_DUTYRANGE.
<br><br>If PWM is currently active on the GPIO its dutycycle will be scaled
to reflect the new range.
<br><br>The real range, the number of steps between fully off and fully
on for each frequency, is given in the following table.
<br><br><code>&nbsp;&nbsp;25,&nbsp;&nbsp;&nbsp;50,&nbsp;&nbsp;100,&nbsp;&nbsp;125,&nbsp;&nbsp;200,&nbsp;&nbsp;250,&nbsp;&nbsp;400,&nbsp;&nbsp;&nbsp;500,&nbsp;&nbsp;&nbsp;625,<br>&nbsp;800,&nbsp;1000,&nbsp;1250,&nbsp;2000,&nbsp;2500,&nbsp;4000,&nbsp;5000,&nbsp;10000,&nbsp;20000<br></code><br><br>The real value set by <a href="#gpioPWM">gpioPWM</a> is (dutycycle * real range) / range.
<br><br><b><small>Example</small></b><br><br><code>gpioSetPWMrange(24,&nbsp;2000);&nbsp;//&nbsp;Now&nbsp;2000&nbsp;is&nbsp;fully&nbsp;on<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1000&nbsp;is&nbsp;half&nbsp;on<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;500&nbsp;is&nbsp;quarter&nbsp;on,&nbsp;etc.<br></code><h3><a name="gpioGetPWMrange"></a><a href="#int"><small>int</small></a> gpioGetPWMrange<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>)</small></h3>
Returns the dutycycle range used for the GPIO if OK, otherwise
PI_BAD_USER_GPIO.
<br><br><code>user_gpio:&nbsp;0-31<br></code><br><br>If a hardware clock or hardware PWM is active on the GPIO
the reported range will be 1000000 (1M).
<br><br><b><small>Example</small></b><br><br><code>r&nbsp;=&nbsp;gpioGetPWMrange(23);<br></code><h3><a name="gpioGetPWMrealRange"></a><a href="#int"><small>int</small></a> gpioGetPWMrealRange<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>)</small></h3>
Returns the real range used for the GPIO if OK, otherwise
PI_BAD_USER_GPIO.
<br><br><code>user_gpio:&nbsp;0-31<br></code><br><br>If a hardware clock is active on the GPIO the reported real
range will be 1000000 (1M).
<br><br>If hardware PWM is active on the GPIO the reported real range
will be approximately 250M divided by the set PWM frequency.
<br><br><b><small>Example</small></b><br><br><code>rr&nbsp;=&nbsp;gpioGetPWMrealRange(17);<br></code><h3><a name="gpioSetPWMfrequency"></a><a href="#int"><small>int</small></a> gpioSetPWMfrequency<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#unsigned">unsigned</a> <a href="#frequency">frequency</a>)</small></h3>
Sets the frequency in hertz to be used for the GPIO.
<br><br><code>user_gpio:&nbsp;0-31<br>frequency:&nbsp;&gt;=0<br></code><br><br>Returns the numerically closest frequency if OK, otherwise
PI_BAD_USER_GPIO.
<br><br>If PWM is currently active on the GPIO it will be
switched off and then back on at the new frequency.
<br><br>Each GPIO can be independently set to one of 18 different PWM
frequencies.
<br><br>The selectable frequencies depend upon the sample rate which
may be 1, 2, 4, 5, 8, or 10 microseconds (default 5).
<br><br>The frequencies for each sample rate are:
<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hertz<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1:&nbsp;40000&nbsp;20000&nbsp;10000&nbsp;8000&nbsp;5000&nbsp;4000&nbsp;2500&nbsp;2000&nbsp;1600<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1250&nbsp;&nbsp;1000&nbsp;&nbsp;&nbsp;800&nbsp;&nbsp;500&nbsp;&nbsp;400&nbsp;&nbsp;250&nbsp;&nbsp;200&nbsp;&nbsp;100&nbsp;&nbsp;&nbsp;50<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2:&nbsp;20000&nbsp;10000&nbsp;&nbsp;5000&nbsp;4000&nbsp;2500&nbsp;2000&nbsp;1250&nbsp;1000&nbsp;&nbsp;800<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;625&nbsp;&nbsp;&nbsp;500&nbsp;&nbsp;&nbsp;400&nbsp;&nbsp;250&nbsp;&nbsp;200&nbsp;&nbsp;125&nbsp;&nbsp;100&nbsp;&nbsp;&nbsp;50&nbsp;&nbsp;&nbsp;25<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4:&nbsp;10000&nbsp;&nbsp;5000&nbsp;&nbsp;2500&nbsp;2000&nbsp;1250&nbsp;1000&nbsp;&nbsp;625&nbsp;&nbsp;500&nbsp;&nbsp;400<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;313&nbsp;&nbsp;&nbsp;250&nbsp;&nbsp;&nbsp;200&nbsp;&nbsp;125&nbsp;&nbsp;100&nbsp;&nbsp;&nbsp;63&nbsp;&nbsp;&nbsp;50&nbsp;&nbsp;&nbsp;25&nbsp;&nbsp;&nbsp;13<br>sample<br>&nbsp;rate<br>&nbsp;(us)&nbsp;&nbsp;5:&nbsp;&nbsp;8000&nbsp;&nbsp;4000&nbsp;&nbsp;2000&nbsp;1600&nbsp;1000&nbsp;&nbsp;800&nbsp;&nbsp;500&nbsp;&nbsp;400&nbsp;&nbsp;320<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;250&nbsp;&nbsp;&nbsp;200&nbsp;&nbsp;&nbsp;160&nbsp;&nbsp;100&nbsp;&nbsp;&nbsp;80&nbsp;&nbsp;&nbsp;50&nbsp;&nbsp;&nbsp;40&nbsp;&nbsp;&nbsp;20&nbsp;&nbsp;&nbsp;10<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;8:&nbsp;&nbsp;5000&nbsp;&nbsp;2500&nbsp;&nbsp;1250&nbsp;1000&nbsp;&nbsp;625&nbsp;&nbsp;500&nbsp;&nbsp;313&nbsp;&nbsp;250&nbsp;&nbsp;200<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;156&nbsp;&nbsp;&nbsp;125&nbsp;&nbsp;&nbsp;100&nbsp;&nbsp;&nbsp;63&nbsp;&nbsp;&nbsp;50&nbsp;&nbsp;&nbsp;31&nbsp;&nbsp;&nbsp;25&nbsp;&nbsp;&nbsp;13&nbsp;&nbsp;&nbsp;&nbsp;6<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10:&nbsp;&nbsp;4000&nbsp;&nbsp;2000&nbsp;&nbsp;1000&nbsp;&nbsp;800&nbsp;&nbsp;500&nbsp;&nbsp;400&nbsp;&nbsp;250&nbsp;&nbsp;200&nbsp;&nbsp;160<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;125&nbsp;&nbsp;&nbsp;100&nbsp;&nbsp;&nbsp;&nbsp;80&nbsp;&nbsp;&nbsp;50&nbsp;&nbsp;&nbsp;40&nbsp;&nbsp;&nbsp;25&nbsp;&nbsp;&nbsp;20&nbsp;&nbsp;&nbsp;10&nbsp;&nbsp;&nbsp;&nbsp;5<br></code><br><br><b><small>Example</small></b><br><br><code>gpioSetPWMfrequency(23,&nbsp;0);&nbsp;//&nbsp;Set&nbsp;GPIO23&nbsp;to&nbsp;lowest&nbsp;frequency.<br><br>gpioSetPWMfrequency(24,&nbsp;500);&nbsp;//&nbsp;Set&nbsp;GPIO24&nbsp;to&nbsp;500Hz.<br><br>gpioSetPWMfrequency(25,&nbsp;100000);&nbsp;//&nbsp;Set&nbsp;GPIO25&nbsp;to&nbsp;highest&nbsp;frequency.<br></code><h3><a name="gpioGetPWMfrequency"></a><a href="#int"><small>int</small></a> gpioGetPWMfrequency<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>)</small></h3>
Returns the frequency (in hertz) used for the GPIO if OK, otherwise
PI_BAD_USER_GPIO.
<br><br><code>user_gpio:&nbsp;0-31<br></code><br><br>For normal PWM the frequency will be that defined for the GPIO by
<a href="#gpioSetPWMfrequency">gpioSetPWMfrequency</a>.
<br><br>If a hardware clock is active on the GPIO the reported frequency
will be that set by <a href="#gpioHardwareClock">gpioHardwareClock</a>.
<br><br>If hardware PWM is active on the GPIO the reported frequency
will be that set by <a href="#gpioHardwarePWM">gpioHardwarePWM</a>.
<br><br><b><small>Example</small></b><br><br><code>f&nbsp;=&nbsp;gpioGetPWMfrequency(23);&nbsp;//&nbsp;Get&nbsp;frequency&nbsp;used&nbsp;for&nbsp;GPIO23.<br></code><h3><a name="gpioServo"></a><a href="#int"><small>int</small></a> gpioServo<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#unsigned">unsigned</a> <a href="#pulsewidth">pulsewidth</a>)</small></h3>
Starts servo pulses on the GPIO, 0 (off), 500 (most anti-clockwise) to
2500 (most clockwise).
<br><br><code>&nbsp;user_gpio:&nbsp;0-31<br>pulsewidth:&nbsp;0,&nbsp;500-2500<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_PULSEWIDTH.
<br><br>The range supported by servos varies and should probably be determined
by experiment.  A value of 1500 should always be safe and represents
the mid-point of rotation.  You can DAMAGE a servo if you command it
to move beyond its limits.
<br><br>The following causes an on pulse of 1500 microseconds duration to be
transmitted on GPIO 17 at a rate of 50 times per second. This will
command a servo connected to GPIO 17 to rotate to its mid-point.
<br><br><b><small>Example</small></b><br><br><code>gpioServo(17,&nbsp;1000);&nbsp;//&nbsp;Move&nbsp;servo&nbsp;to&nbsp;safe&nbsp;position&nbsp;anti-clockwise.<br><br>gpioServo(23,&nbsp;1500);&nbsp;//&nbsp;Move&nbsp;servo&nbsp;to&nbsp;centre&nbsp;position.<br><br>gpioServo(25,&nbsp;2000);&nbsp;//&nbsp;Move&nbsp;servo&nbsp;to&nbsp;safe&nbsp;position&nbsp;clockwise.<br></code><br><br>OTHER UPDATE RATES:
<br><br>This function updates servos at 50Hz.  If you wish to use a different
update frequency you will have to use the PWM functions.
<br><br><code>PWM&nbsp;Hz&nbsp;&nbsp;&nbsp;&nbsp;50&nbsp;&nbsp;&nbsp;100&nbsp;&nbsp;200&nbsp;&nbsp;400&nbsp;&nbsp;500<br>1E6/Hz&nbsp;20000&nbsp;10000&nbsp;5000&nbsp;2500&nbsp;2000<br></code><br><br>Firstly set the desired PWM frequency using <a href="#gpioSetPWMfrequency">gpioSetPWMfrequency</a>.
<br><br>Then set the PWM range using <a href="#gpioSetPWMrange">gpioSetPWMrange</a> to 1E6/frequency.
Doing this allows you to use units of microseconds when setting
the servo pulsewidth.
<br><br>E.g. If you want to update a servo connected to GPIO25 at 400Hz
<br><br><code>gpioSetPWMfrequency(25,&nbsp;400);<br><br>gpioSetPWMrange(25,&nbsp;2500);<br></code><br><br>Thereafter use the PWM command to move the servo,
e.g. gpioPWM(25, 1500) will set a 1500 us pulse.
<h3><a name="gpioGetServoPulsewidth"></a><a href="#int"><small>int</small></a> gpioGetServoPulsewidth<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>)</small></h3>
Returns the servo pulsewidth setting for the GPIO.
<br><br><code>user_gpio:&nbsp;0-31<br></code><br><br>Returns 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise)
if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO.
<h3><a name="gpioSetAlertFunc"></a><a href="#int"><small>int</small></a> gpioSetAlertFunc<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#gpioAlertFunc_t">gpioAlertFunc_t</a> <a href="#f">f</a>)</small></h3>
Registers a function to be called (a callback) when the specified
GPIO changes state.
<br><br><code>user_gpio:&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;callback&nbsp;function<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO.
<br><br>One callback may be registered per GPIO.
<br><br>The callback is passed the GPIO, the new level, and the tick.
<br><br><code>Parameter&nbsp;&nbsp;&nbsp;Value&nbsp;&nbsp;&nbsp;&nbsp;Meaning<br><br>GPIO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0-31&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;GPIO&nbsp;which&nbsp;has&nbsp;changed&nbsp;state<br><br>level&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0-2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;=&nbsp;change&nbsp;to&nbsp;low&nbsp;(a&nbsp;falling&nbsp;edge)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;=&nbsp;change&nbsp;to&nbsp;high&nbsp;(a&nbsp;rising&nbsp;edge)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;=&nbsp;no&nbsp;level&nbsp;change&nbsp;(a&nbsp;watchdog&nbsp;timeout)<br><br>tick&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;32&nbsp;bit&nbsp;&nbsp;&nbsp;The&nbsp;number&nbsp;of&nbsp;microseconds&nbsp;since&nbsp;boot<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WARNING:&nbsp;this&nbsp;wraps&nbsp;around&nbsp;from<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4294967295&nbsp;to&nbsp;0&nbsp;roughly&nbsp;every&nbsp;72&nbsp;minutes<br></code><br><br>The alert may be cancelled by passing NULL as the function.
<br><br>The GPIO are sampled at a rate set when the library is started.
<br><br>If a value isn't specifically set the default of 5 us is used.
<br><br>The number of samples per second is given in the following table.
<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;samples<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;per&nbsp;sec<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;1,000,000<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;500,000<br>sample&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;250,000<br>rate&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;200,000<br>(us)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;&nbsp;&nbsp;125,000<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10&nbsp;&nbsp;&nbsp;&nbsp;100,000<br></code><br><br>Level changes shorter than the sample rate may be missed.
<br><br>The thread which calls the alert functions is triggered nominally
1000 times per second.  The active alert functions will be called
once per level change since the last time the thread was activated.
i.e. The active alert functions will get all level changes but there
will be a latency.
<br><br>If you want to track the level of more than one GPIO do so by
maintaining the state in the callback.  Do not use <a href="#gpioRead">gpioRead</a>.
Remember the event that triggered the callback may have
happened several milliseconds before and the GPIO may have
changed level many times since then.
<br><br>The tick value is the time stamp of the sample in microseconds, see
<a href="#gpioTick">gpioTick</a> for more details.
<br><br><b><small>Example</small></b><br><br><code>void&nbsp;aFunction(int&nbsp;gpio,&nbsp;int&nbsp;level,&nbsp;uint32_t&nbsp;tick)<br>{<br>&nbsp;&nbsp;&nbsp;printf("GPIO&nbsp;%d&nbsp;became&nbsp;%d&nbsp;at&nbsp;%d",&nbsp;gpio,&nbsp;level,&nbsp;tick);<br>}<br><br>//&nbsp;call&nbsp;aFunction&nbsp;whenever&nbsp;GPIO&nbsp;4&nbsp;changes&nbsp;state<br><br>gpioSetAlertFunc(4,&nbsp;aFunction);<br></code><h3><a name="gpioSetAlertFuncEx"></a><a href="#int"><small>int</small></a> gpioSetAlertFuncEx<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#gpioAlertFuncEx_t">gpioAlertFuncEx_t</a> <a href="#f">f</a>, <a href="#void">void</a> <a href="#*userdata">*userdata</a>)</small></h3>
Registers a function to be called (a callback) when the specified
GPIO changes state.
<br><br><code>user_gpio:&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;callback&nbsp;function<br>&nbsp;userdata:&nbsp;pointer&nbsp;to&nbsp;arbitrary&nbsp;user&nbsp;data<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO.
<br><br>One callback may be registered per GPIO.
<br><br>The callback is passed the GPIO, the new level, the tick, and
the userdata pointer.
<br><br><code>Parameter&nbsp;&nbsp;&nbsp;Value&nbsp;&nbsp;&nbsp;&nbsp;Meaning<br><br>GPIO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0-31&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;GPIO&nbsp;which&nbsp;has&nbsp;changed&nbsp;state<br><br>level&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0-2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;=&nbsp;change&nbsp;to&nbsp;low&nbsp;(a&nbsp;falling&nbsp;edge)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;=&nbsp;change&nbsp;to&nbsp;high&nbsp;(a&nbsp;rising&nbsp;edge)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;=&nbsp;no&nbsp;level&nbsp;change&nbsp;(a&nbsp;watchdog&nbsp;timeout)<br><br>tick&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;32&nbsp;bit&nbsp;&nbsp;&nbsp;The&nbsp;number&nbsp;of&nbsp;microseconds&nbsp;since&nbsp;boot<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WARNING:&nbsp;this&nbsp;wraps&nbsp;around&nbsp;from<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4294967295&nbsp;to&nbsp;0&nbsp;roughly&nbsp;every&nbsp;72&nbsp;minutes<br><br>userdata&nbsp;&nbsp;&nbsp;&nbsp;pointer&nbsp;&nbsp;Pointer&nbsp;to&nbsp;an&nbsp;arbitrary&nbsp;object<br></code><br><br>See <a href="#gpioSetAlertFunc">gpioSetAlertFunc</a> for further details.
<br><br>Only one of <a href="#gpioSetAlertFunc">gpioSetAlertFunc</a> or <a href="#gpioSetAlertFuncEx">gpioSetAlertFuncEx</a> can be
registered per GPIO.
<h3><a name="gpioSetISRFunc"></a><a href="#int"><small>int</small></a> gpioSetISRFunc<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>, <a href="#unsigned">unsigned</a> <a href="#edge">edge</a>, <a href="#int">int</a> <a href="#timeout">timeout</a>, <a href="#gpioISRFunc_t">gpioISRFunc_t</a> <a href="#f">f</a>)</small></h3>
Registers a function to be called (a callback) whenever the specified
GPIO interrupt occurs.
<br><br><code>&nbsp;&nbsp;&nbsp;gpio:&nbsp;0-53<br>&nbsp;&nbsp;&nbsp;edge:&nbsp;RISING_EDGE,&nbsp;FALLING_EDGE,&nbsp;or&nbsp;EITHER_EDGE<br>timeout:&nbsp;interrupt&nbsp;timeout&nbsp;in&nbsp;milliseconds&nbsp;(&lt;=0&nbsp;to&nbsp;cancel)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;callback&nbsp;function<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE,
or PI_BAD_ISR_INIT.
<br><br>One function may be registered per GPIO.
<br><br>The function is passed the GPIO, the current level, and the
current tick.  The level will be PI_TIMEOUT if the optional
interrupt timeout expires.
<br><br><code>Parameter&nbsp;&nbsp;&nbsp;Value&nbsp;&nbsp;&nbsp;&nbsp;Meaning<br><br>GPIO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0-53&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;GPIO&nbsp;which&nbsp;has&nbsp;changed&nbsp;state<br><br>level&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0-2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;=&nbsp;change&nbsp;to&nbsp;low&nbsp;(a&nbsp;falling&nbsp;edge)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;=&nbsp;change&nbsp;to&nbsp;high&nbsp;(a&nbsp;rising&nbsp;edge)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;=&nbsp;no&nbsp;level&nbsp;change&nbsp;(interrupt&nbsp;timeout)<br><br>tick&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;32&nbsp;bit&nbsp;&nbsp;&nbsp;The&nbsp;number&nbsp;of&nbsp;microseconds&nbsp;since&nbsp;boot<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WARNING:&nbsp;this&nbsp;wraps&nbsp;around&nbsp;from<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4294967295&nbsp;to&nbsp;0&nbsp;roughly&nbsp;every&nbsp;72&nbsp;minutes<br></code><br><br>The underlying Linux sysfs GPIO interface is used to provide
the interrupt services.
<br><br>The first time the function is called, with a non-NULL f, the
GPIO is exported, set to be an input, and set to interrupt
on the given edge and timeout.
<br><br>Subsequent calls, with a non-NULL f, can vary one or more of the
edge, timeout, or function.
<br><br>The ISR may be cancelled by passing a NULL f, in which case the
GPIO is unexported.
<br><br>The tick is that read at the time the process was informed of
the interrupt.  This will be a variable number of microseconds
after the interrupt occurred.  Typically the latency will be of
the order of 50 microseconds.  The latency is not guaranteed
and will vary with system load.
<br><br>The level is that read at the time the process was informed of
the interrupt, or PI_TIMEOUT if the optional interrupt timeout
expired.  It may not be the same as the expected edge as
interrupts happening in rapid succession may be missed by the
kernel (i.e. this mechanism can not be used to capture several
interrupts only a few microseconds apart).
<h3><a name="gpioSetISRFuncEx"></a><a href="#int"><small>int</small></a> gpioSetISRFuncEx<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>, <a href="#unsigned">unsigned</a> <a href="#edge">edge</a>, <a href="#int">int</a> <a href="#timeout">timeout</a>, <a href="#gpioISRFuncEx_t">gpioISRFuncEx_t</a> <a href="#f">f</a>, <a href="#void">void</a> <a href="#*userdata">*userdata</a>)</small></h3>
Registers a function to be called (a callback) whenever the specified
GPIO interrupt occurs.
<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;gpio:&nbsp;0-53<br>&nbsp;&nbsp;&nbsp;&nbsp;edge:&nbsp;RISING_EDGE,&nbsp;FALLING_EDGE,&nbsp;or&nbsp;EITHER_EDGE<br>&nbsp;timeout:&nbsp;interrupt&nbsp;timeout&nbsp;in&nbsp;milliseconds&nbsp;(&lt;=0&nbsp;to&nbsp;cancel)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;callback&nbsp;function<br>userdata:&nbsp;pointer&nbsp;to&nbsp;arbitrary&nbsp;user&nbsp;data<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_EDGE,
or PI_BAD_ISR_INIT.
<br><br>The function is passed the GPIO, the current level, the
current tick, and the userdata pointer.
<br><br><code>Parameter&nbsp;&nbsp;&nbsp;Value&nbsp;&nbsp;&nbsp;&nbsp;Meaning<br><br>GPIO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0-53&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;GPIO&nbsp;which&nbsp;has&nbsp;changed&nbsp;state<br><br>level&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0-2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;=&nbsp;change&nbsp;to&nbsp;low&nbsp;(a&nbsp;falling&nbsp;edge)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;=&nbsp;change&nbsp;to&nbsp;high&nbsp;(a&nbsp;rising&nbsp;edge)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;=&nbsp;no&nbsp;level&nbsp;change&nbsp;(interrupt&nbsp;timeout)<br><br>tick&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;32&nbsp;bit&nbsp;&nbsp;&nbsp;The&nbsp;number&nbsp;of&nbsp;microseconds&nbsp;since&nbsp;boot<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WARNING:&nbsp;this&nbsp;wraps&nbsp;around&nbsp;from<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4294967295&nbsp;to&nbsp;0&nbsp;roughly&nbsp;every&nbsp;72&nbsp;minutes<br><br>userdata&nbsp;&nbsp;&nbsp;&nbsp;pointer&nbsp;&nbsp;Pointer&nbsp;to&nbsp;an&nbsp;arbitrary&nbsp;object<br></code><br><br>Only one of <a href="#gpioSetISRFunc">gpioSetISRFunc</a> or <a href="#gpioSetISRFuncEx">gpioSetISRFuncEx</a> can be
registered per GPIO.
<br><br>See <a href="#gpioSetISRFunc">gpioSetISRFunc</a> for further details.
<h3><a name="gpioNotifyOpen"></a><a href="#int"><small>int</small></a> gpioNotifyOpen<small>(void)</small></h3>
This function requests a free notification handle.
<br><br>Returns a handle greater than or equal to zero if OK,
otherwise PI_NO_HANDLE.
<br><br>A notification is a method for being notified of GPIO state changes
via a pipe or socket.
<br><br>Pipe notifications for handle x will be available at the pipe
named /dev/pigpiox (where x is the handle number).  E.g. if the
function returns 15 then the notifications must be read
from /dev/pigpio15.
<br><br>Socket notifications are returned to the socket which requested the
handle.
<br><br><b><small>Example</small></b><br><br><code>h&nbsp;=&nbsp;gpioNotifyOpen();<br><br>if&nbsp;(h&nbsp;&gt;=&nbsp;0)<br>{<br>&nbsp;&nbsp;&nbsp;sprintf(str,&nbsp;"/dev/pigpio%d",&nbsp;h);<br><br>&nbsp;&nbsp;&nbsp;fd&nbsp;=&nbsp;open(str,&nbsp;O_RDONLY);<br><br>&nbsp;&nbsp;&nbsp;if&nbsp;(fd&nbsp;&gt;=&nbsp;0)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Okay.<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Error.<br>&nbsp;&nbsp;&nbsp;}<br>}<br>else<br>{<br>&nbsp;&nbsp;&nbsp;//&nbsp;Error.<br>}<br></code><h3><a name="gpioNotifyOpenWithSize"></a><a href="#int"><small>int</small></a> gpioNotifyOpenWithSize<small>(<a href="#int">int</a> <a href="#bufSize">bufSize</a>)</small></h3>
This function requests a free notification handle.
<br><br>It differs from <a href="#gpioNotifyOpen">gpioNotifyOpen</a> in that the pipe size may be
specified, whereas <a href="#gpioNotifyOpen">gpioNotifyOpen</a> uses the default pipe size.
<br><br>See <a href="#gpioNotifyOpen">gpioNotifyOpen</a> for further details.
<h3><a name="gpioNotifyBegin"></a><a href="#int"><small>int</small></a> gpioNotifyBegin<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#uint32_t">uint32_t</a> <a href="#bits">bits</a>)</small></h3>
This function starts notifications on a previously opened handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;<a href="#gpioNotifyOpen">gpioNotifyOpen</a><br>&nbsp;&nbsp;bits:&nbsp;a&nbsp;bit&nbsp;mask&nbsp;indicating&nbsp;the&nbsp;GPIO&nbsp;of&nbsp;interest<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE.
<br><br>The notification sends state changes for each GPIO whose corresponding
bit in bits is set.
<br><br>Each notification occupies 12 bytes in the fifo and has the
following structure.
<br><br><code>typedef&nbsp;struct<br>{<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;seqno;<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;flags;<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;tick;<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;level;<br>}&nbsp;gpioReport_t;<br></code><br><br>seqno: starts at 0 each time the handle is opened and then increments
by one for each report.
<br><br>flags: three flags are defined, PI_NTFY_FLAGS_WDOG,
PI_NTFY_FLAGS_ALIVE, and PI_NTFY_FLAGS_EVENT.
<br><br>If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags
indicate a GPIO which has had a watchdog timeout.
<br><br>If bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive
signal on the pipe/socket and is sent once a minute in the absence
of other notification activity.
<br><br>If bit 7 is set (PI_NTFY_FLAGS_EVENT) then bits 0-4 of the flags
indicate an event which has been triggered.
<br><br>tick: the number of microseconds since system boot.  It wraps around
after 1h12m.
<br><br>level: indicates the level of each GPIO.  If bit 1&lt;&lt;x is set then
GPIO x is high.
<br><br><b><small>Example</small></b><br><br><code>//&nbsp;Start&nbsp;notifications&nbsp;for&nbsp;GPIO&nbsp;1,&nbsp;4,&nbsp;6,&nbsp;7,&nbsp;10.<br><br>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1<br>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;76&nbsp;4&nbsp;&nbsp;1<br>//&nbsp;(1234&nbsp;=&nbsp;0x04D2&nbsp;=&nbsp;0b0000010011010010)<br><br>gpioNotifyBegin(h,&nbsp;1234);<br></code><h3><a name="gpioNotifyPause"></a><a href="#int"><small>int</small></a> gpioNotifyPause<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>)</small></h3>
This function pauses notifications on a previously opened handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;<a href="#gpioNotifyOpen">gpioNotifyOpen</a><br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE.
<br><br>Notifications for the handle are suspended until <a href="#gpioNotifyBegin">gpioNotifyBegin</a>
is called again.
<br><br><b><small>Example</small></b><br><br><code>gpioNotifyPause(h);<br></code><h3><a name="gpioNotifyClose"></a><a href="#int"><small>int</small></a> gpioNotifyClose<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>)</small></h3>
This function stops notifications on a previously opened handle
and releases the handle for reuse.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;<a href="#gpioNotifyOpen">gpioNotifyOpen</a><br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE.
<br><br><b><small>Example</small></b><br><br><code>gpioNotifyClose(h);<br></code><h3><a name="gpioWaveClear"></a><a href="#int"><small>int</small></a> gpioWaveClear<small>(void)</small></h3>
This function clears all waveforms and any data added by calls to the
<a href="#gpioWaveAdd*">gpioWaveAdd*</a> functions.
<br><br>Returns 0 if OK.
<br><br><b><small>Example</small></b><br><br><code>gpioWaveClear();<br></code><h3><a name="gpioWaveAddNew"></a><a href="#int"><small>int</small></a> gpioWaveAddNew<small>(void)</small></h3>
This function starts a new empty waveform.
<br><br>You wouldn't normally need to call this function as it is automatically
called after a waveform is created with the <a href="#gpioWaveCreate">gpioWaveCreate</a> function.
<br><br>Returns 0 if OK.
<br><br><b><small>Example</small></b><br><br><code>gpioWaveAddNew();<br></code><h3><a name="gpioWaveAddGeneric"></a><a href="#int"><small>int</small></a> gpioWaveAddGeneric<small>(<a href="#unsigned">unsigned</a> <a href="#numPulses">numPulses</a>, <a href="#gpioPulse_t">gpioPulse_t</a> <a href="#*pulses">*pulses</a>)</small></h3>
This function adds a number of pulses to the current waveform.
<br><br><code>numPulses:&nbsp;the&nbsp;number&nbsp;of&nbsp;pulses<br>&nbsp;&nbsp;&nbsp;pulses:&nbsp;an&nbsp;array&nbsp;of&nbsp;pulses<br></code><br><br>Returns the new total number of pulses in the current waveform if OK,
otherwise PI_TOO_MANY_PULSES.
<br><br>The pulses are interleaved in time order within the existing waveform
(if any).
<br><br>Merging allows the waveform to be built in parts, that is the settings
for GPIO#1 can be added, and then GPIO#2 etc.
<br><br>If the added waveform is intended to start after or within the existing
waveform then the first pulse should consist of a delay.
<br><br><b><small>Example</small></b><br><br><code>//&nbsp;Construct&nbsp;and&nbsp;send&nbsp;a&nbsp;30&nbsp;microsecond&nbsp;square&nbsp;wave.<br><br>gpioSetMode(gpio,&nbsp;PI_OUTPUT);<br><br>pulse[0].gpioOn&nbsp;=&nbsp;(1&lt;&lt;gpio);<br>pulse[0].gpioOff&nbsp;=&nbsp;0;<br>pulse[0].usDelay&nbsp;=&nbsp;15;<br><br>pulse[1].gpioOn&nbsp;=&nbsp;0;<br>pulse[1].gpioOff&nbsp;=&nbsp;(1&lt;&lt;gpio);<br>pulse[1].usDelay&nbsp;=&nbsp;15;<br><br>gpioWaveAddNew();<br><br>gpioWaveAddGeneric(2,&nbsp;pulse);<br><br>wave_id&nbsp;=&nbsp;gpioWaveCreate();<br><br>if&nbsp;(wave_id&nbsp;&gt;=&nbsp;0)<br>{<br>&nbsp;&nbsp;&nbsp;gpioWaveTxSend(wave_id,&nbsp;PI_WAVE_MODE_REPEAT);<br><br>&nbsp;&nbsp;&nbsp;//&nbsp;Transmit&nbsp;for&nbsp;30&nbsp;seconds.<br><br>&nbsp;&nbsp;&nbsp;sleep(30);<br><br>&nbsp;&nbsp;&nbsp;gpioWaveTxStop();<br>}<br>else<br>{<br>&nbsp;&nbsp;&nbsp;//&nbsp;Wave&nbsp;create&nbsp;failed.<br>}<br></code><h3><a name="gpioWaveAddSerial"></a><a href="#int"><small>int</small></a> gpioWaveAddSerial<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#unsigned">unsigned</a> <a href="#baud">baud</a>, <a href="#unsigned">unsigned</a> <a href="#data_bits">data_bits</a>, <a href="#unsigned">unsigned</a> <a href="#stop_bits">stop_bits</a>, <a href="#unsigned">unsigned</a> <a href="#offset">offset</a>, <a href="#unsigned">unsigned</a> <a href="#numBytes">numBytes</a>, <a href="#char">char</a> <a href="#*str">*str</a>)</small></h3>
This function adds a waveform representing serial data to the
existing waveform (if any).  The serial data starts offset
microseconds from the start of the waveform.
<br><br><code>user_gpio:&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;baud:&nbsp;50-1000000<br>data_bits:&nbsp;1-32<br>stop_bits:&nbsp;2-8<br>&nbsp;&nbsp;&nbsp;offset:&nbsp;&gt;=0<br>&nbsp;numBytes:&nbsp;&gt;=1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str:&nbsp;an&nbsp;array&nbsp;of&nbsp;chars&nbsp;(which&nbsp;may&nbsp;contain&nbsp;nulls)<br></code><br><br>Returns the new total number of pulses in the current waveform if OK,
otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD, PI_BAD_DATABITS,
PI_BAD_STOPBITS, PI_TOO_MANY_CHARS, PI_BAD_SER_OFFSET,
or PI_TOO_MANY_PULSES.
<br><br>NOTES:
<br><br>The serial data is formatted as one start bit, data_bits data bits, and
stop_bits/2 stop bits.
<br><br>It is legal to add serial data streams with different baud rates to
the same waveform.
<br><br>numBytes is the number of bytes of data in str.
<br><br>The bytes required for each character depend upon data_bits.
<br><br>For data_bits 1-8 there will be one byte per character.<br>
For data_bits 9-16 there will be two bytes per character.<br>
For data_bits 17-32 there will be four bytes per character.
<br><br><b><small>Example</small></b><br><br><code>#define&nbsp;MSG_LEN&nbsp;8<br><br>int&nbsp;i;<br>char&nbsp;*str;<br>char&nbsp;data[MSG_LEN];<br><br>str&nbsp;=&nbsp;"Hello&nbsp;world!";<br><br>gpioWaveAddSerial(4,&nbsp;9600,&nbsp;8,&nbsp;2,&nbsp;0,&nbsp;strlen(str),&nbsp;str);<br><br>for&nbsp;(i=0;&nbsp;i&lt;MSG_LEN;&nbsp;i++)&nbsp;data[i]&nbsp;=&nbsp;i;<br><br>//&nbsp;Data&nbsp;added&nbsp;is&nbsp;offset&nbsp;1&nbsp;second&nbsp;from&nbsp;the&nbsp;waveform&nbsp;start.<br>gpioWaveAddSerial(4,&nbsp;9600,&nbsp;8,&nbsp;2,&nbsp;1000000,&nbsp;MSG_LEN,&nbsp;data);<br></code><h3><a name="gpioWaveCreate"></a><a href="#int"><small>int</small></a> gpioWaveCreate<small>(void)</small></h3>
This function creates a waveform from the data provided by the prior
calls to the <a href="#gpioWaveAdd*">gpioWaveAdd*</a> functions.  Upon success a wave id
greater than or equal to 0 is returned, otherwise PI_EMPTY_WAVEFORM,
PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID.
<br><br>The data provided by the <a href="#gpioWaveAdd*">gpioWaveAdd*</a> functions is consumed by this
function.
<br><br>As many waveforms may be created as there is space available.  The
wave id is passed to <a href="#gpioWaveTxSend">gpioWaveTxSend</a> to specify the waveform to transmit.
<br><br>Normal usage would be
<br><br>Step 1. <a href="#gpioWaveClear">gpioWaveClear</a> to clear all waveforms and added data.
<br><br>Step 2. <a href="#gpioWaveAdd*">gpioWaveAdd*</a> calls to supply the waveform data.
<br><br>Step 3. <a href="#gpioWaveCreate">gpioWaveCreate</a> to create the waveform and get a unique id
<br><br>Repeat steps 2 and 3 as needed.
<br><br>Step 4. <a href="#gpioWaveTxSend">gpioWaveTxSend</a> with the id of the waveform to transmit.
<br><br>A waveform comprises one of more pulses.  Each pulse consists of a
<a href="#gpioPulse_t">gpioPulse_t</a> structure.
<br><br><code>typedef&nbsp;struct<br>{<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;gpioOn;<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;gpioOff;<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;usDelay;<br>}&nbsp;gpioPulse_t;<br></code><br><br>The fields specify
<br><br>1) the GPIO to be switched on at the start of the pulse.<br>
2) the GPIO to be switched off at the start of the pulse.<br>
3) the delay in microseconds before the next pulse.
<br><br>Any or all the fields can be zero.  It doesn't make any sense to
set all the fields to zero (the pulse will be ignored).
<br><br>When a waveform is started each pulse is executed in order with the
specified delay between the pulse and the next.
<br><br>Returns the new waveform id if OK, otherwise PI_EMPTY_WAVEFORM,
PI_NO_WAVEFORM_ID, PI_TOO_MANY_CBS, or PI_TOO_MANY_OOL.
<h3><a name="gpioWaveCreatePad"></a><a href="#int"><small>int</small></a> gpioWaveCreatePad<small>(<a href="#int">int</a> <a href="#pctCB">pctCB</a>, <a href="#int">int</a> <a href="#pctBOOL">pctBOOL</a>, <a href="#int">int</a> <a href="#pctTOOL">pctTOOL</a>)</small></h3>
Similar to <a href="#gpioWaveCreate">gpioWaveCreate</a>, this function creates a waveform but pads the consumed
resources. Padded waves of equal dimension can be re-cycled efficiently allowing
newly created waves to re-use the resources of deleted waves of the same dimension.
<br><br><code>pctCB:&nbsp;0-100,&nbsp;the&nbsp;percent&nbsp;of&nbsp;all&nbsp;DMA&nbsp;control&nbsp;blocks&nbsp;to&nbsp;consume.<br>pctBOOL:&nbsp;0-100,&nbsp;percent&nbsp;On-Off-Level&nbsp;(OOL)&nbsp;buffer&nbsp;to&nbsp;consume&nbsp;for&nbsp;wave&nbsp;output.<br>pctTOOL:&nbsp;0-100,&nbsp;the&nbsp;percent&nbsp;of&nbsp;OOL&nbsp;buffer&nbsp;to&nbsp;consume&nbsp;for&nbsp;wave&nbsp;input&nbsp;(flags).<br></code><br><br>Upon success a wave id greater than or equal to 0 is returned, otherwise
PI_EMPTY_WAVEFORM, PI_TOO_MANY_CBS, PI_TOO_MANY_OOL, or PI_NO_WAVEFORM_ID.
<br><br>Waveform data provided by <a href="#gpioWaveAdd*">gpioWaveAdd*</a> and <a href="#rawWaveAdd*">rawWaveAdd*</a> functions are
consumed by this function.
<br><br>A usage would be the creation of two waves where one is filled while the other
is being transmitted. Each wave is assigned 50% of the resources.
This buffer structure allows the transmission of infinite wave sequences.
<br><br><b><small>Example</small></b><br><br><code>&nbsp;&nbsp;//&nbsp;get&nbsp;firstWaveChunk,&nbsp;somehow<br>&nbsp;&nbsp;gpioWaveAddGeneric(firstWaveChunk);<br>&nbsp;&nbsp;wid&nbsp;=&nbsp;gpioWaveCreatePad(50,&nbsp;50,&nbsp;0);<br>&nbsp;&nbsp;gpioWaveTxSend(wid,&nbsp;PI_WAVE_MODE_ONE_SHOT);<br>&nbsp;&nbsp;//&nbsp;get&nbsp;nextWaveChunk<br><br>&nbsp;&nbsp;while&nbsp;(nextWaveChunk)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gpioWaveAddGeneric(nextWaveChunk);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nextWid&nbsp;=&nbsp;gpioWaveCreatePad(50,&nbsp;50,&nbsp;0);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gpioWaveTxSend(nextWid,&nbsp;PI_WAVE_MODE_ONE_SHOT_SYNC);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(gpioWaveTxAt()&nbsp;==&nbsp;wid)&nbsp;time_sleep(0.1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gpioWaveDelete(wid);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wid&nbsp;=&nbsp;nextWid;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;get&nbsp;nextWaveChunk<br>&nbsp;&nbsp;}<br></code><h3><a name="gpioWaveDelete"></a><a href="#int"><small>int</small></a> gpioWaveDelete<small>(<a href="#unsigned">unsigned</a> <a href="#wave_id">wave_id</a>)</small></h3>
This function deletes the waveform with id wave_id.
<br><br>The wave is flagged for deletion.  The resources used by the wave
will only be reused when either of the following apply.
<br><br>- all waves with higher numbered wave ids have been deleted or have
been flagged for deletion.
<br><br>- a new wave is created which uses exactly the same resources as
the current wave (see the C source for gpioWaveCreate for details).
<br><br><code>wave_id:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;<a href="#gpioWaveCreate">gpioWaveCreate</a><br></code><br><br>Wave ids are allocated in order, 0, 1, 2, etc.
<br><br>Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
<h3><a name="gpioWaveTxSend"></a><a href="#int"><small>int</small></a> gpioWaveTxSend<small>(<a href="#unsigned">unsigned</a> <a href="#wave_id">wave_id</a>, <a href="#unsigned">unsigned</a> <a href="#wave_mode">wave_mode</a>)</small></h3>
This function transmits the waveform with id wave_id.  The mode
determines whether the waveform is sent once or cycles endlessly.
The SYNC variants wait for the current waveform to reach the
end of a cycle or finish before starting the new waveform.
<br><br>WARNING: bad things may happen if you delete the previous
waveform before it has been synced to the new waveform.
<br><br>NOTE: Any hardware PWM started by <a href="#gpioHardwarePWM">gpioHardwarePWM</a> will be cancelled.
<br><br><code>&nbsp;&nbsp;wave_id:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;<a href="#gpioWaveCreate">gpioWaveCreate</a><br>wave_mode:&nbsp;PI_WAVE_MODE_ONE_SHOT,&nbsp;PI_WAVE_MODE_REPEAT,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PI_WAVE_MODE_ONE_SHOT_SYNC,&nbsp;PI_WAVE_MODE_REPEAT_SYNC<br></code><br><br>Returns the number of DMA control blocks in the waveform if OK,
otherwise PI_BAD_WAVE_ID, or PI_BAD_WAVE_MODE.
<h3><a name="gpioWaveChain"></a><a href="#int"><small>int</small></a> gpioWaveChain<small>(<a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#bufSize">bufSize</a>)</small></h3>
This function transmits a chain of waveforms.
<br><br>NOTE: Any hardware PWM started by <a href="#gpioHardwarePWM">gpioHardwarePWM</a> will be cancelled.
<br><br>The waves to be transmitted are specified by the contents of buf
which contains an ordered list of <a href="#wave_id">wave_id</a>s and optional command
codes and related data.
<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;buf:&nbsp;pointer&nbsp;to&nbsp;the&nbsp;wave_ids&nbsp;and&nbsp;optional&nbsp;command&nbsp;codes<br>bufSize:&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;in&nbsp;buf<br></code><br><br>Returns 0 if OK, otherwise PI_CHAIN_NESTING, PI_CHAIN_LOOP_CNT, PI_BAD_CHAIN_LOOP, PI_BAD_CHAIN_CMD, PI_CHAIN_COUNTER,
PI_BAD_CHAIN_DELAY, PI_CHAIN_TOO_BIG, or PI_BAD_WAVE_ID.
<br><br>Each wave is transmitted in the order specified.  A wave may
occur multiple times per chain.
<br><br>A blocks of waves may be transmitted multiple times by using
the loop commands. The block is bracketed by loop start and
end commands.  Loops may be nested.
<br><br>Delays between waves may be added with the delay command.
<br><br>The following command codes are supported:
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Name</td><td>Cmd & Data</td><td>Meaning</td></tr><tr><td>Loop Start</td><td>255 0</td><td>Identify start of a wave block</td></tr><tr><td>Loop Repeat</td><td>255 1 x y</td><td>loop x + y*256 times</td></tr><tr><td>Delay</td><td>255 2 x y</td><td>delay x + y*256 microseconds</td></tr><tr><td>Loop Forever</td><td>255 3</td><td>loop forever</td></tr></tbody></table><br><br>If present Loop Forever must be the last entry in the chain.
<br><br>The code is currently dimensioned to support a chain with roughly
600 entries and 20 loop counters.
<br><br><b><small>Example</small></b><br><br><code>#include&nbsp;&lt;stdio.h&gt;<br>#include&nbsp;&lt;pigpio.h&gt;<br><br>#define&nbsp;WAVES&nbsp;5<br>#define&nbsp;GPIO&nbsp;4<br><br>int&nbsp;main(int&nbsp;argc,&nbsp;char&nbsp;*argv[])<br>{<br>&nbsp;&nbsp;&nbsp;int&nbsp;i,&nbsp;wid[WAVES];<br><br>&nbsp;&nbsp;&nbsp;if&nbsp;(gpioInitialise()&lt;0)&nbsp;return&nbsp;-1;<br><br>&nbsp;&nbsp;&nbsp;gpioSetMode(GPIO,&nbsp;PI_OUTPUT);<br><br>&nbsp;&nbsp;&nbsp;printf("start&nbsp;piscope,&nbsp;press&nbsp;return");&nbsp;getchar();<br><br>&nbsp;&nbsp;&nbsp;for&nbsp;(i=0;&nbsp;i&lt;WAVES;&nbsp;i++)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gpioWaveAddGeneric(2,&nbsp;(gpioPulse_t[])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{1&lt;&lt;GPIO,&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20},<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{0,&nbsp;1&lt;&lt;GPIO,&nbsp;(i+1)*200}});<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wid[i]&nbsp;=&nbsp;gpioWaveCreate();<br>&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;gpioWaveChain((char&nbsp;[])&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wid[4],&nbsp;wid[3],&nbsp;wid[2],&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;transmit&nbsp;waves&nbsp;4+3+2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255,&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;loop&nbsp;start<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wid[0],&nbsp;wid[0],&nbsp;wid[0],&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;transmit&nbsp;waves&nbsp;0+0+0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255,&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;loop&nbsp;start<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wid[0],&nbsp;wid[1],&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;transmit&nbsp;waves&nbsp;0+1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255,&nbsp;2,&nbsp;0x88,&nbsp;0x13,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;delay&nbsp;5000us<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255,&nbsp;1,&nbsp;30,&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;loop&nbsp;end&nbsp;(repeat&nbsp;30&nbsp;times)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255,&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;loop&nbsp;start<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wid[2],&nbsp;wid[3],&nbsp;wid[0],&nbsp;//&nbsp;transmit&nbsp;waves&nbsp;2+3+0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wid[3],&nbsp;wid[1],&nbsp;wid[2],&nbsp;//&nbsp;transmit&nbsp;waves&nbsp;3+1+2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255,&nbsp;1,&nbsp;10,&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;loop&nbsp;end&nbsp;(repeat&nbsp;10&nbsp;times)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255,&nbsp;1,&nbsp;5,&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;loop&nbsp;end&nbsp;(repeat&nbsp;5&nbsp;times)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wid[4],&nbsp;wid[4],&nbsp;wid[4],&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;transmit&nbsp;waves&nbsp;4+4+4<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255,&nbsp;2,&nbsp;0x20,&nbsp;0x4E,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;delay&nbsp;20000us<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wid[0],&nbsp;wid[0],&nbsp;wid[0],&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;transmit&nbsp;waves&nbsp;0+0+0<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},&nbsp;46);<br><br>&nbsp;&nbsp;&nbsp;while&nbsp;(gpioWaveTxBusy())&nbsp;time_sleep(0.1);<br><br>&nbsp;&nbsp;&nbsp;for&nbsp;(i=0;&nbsp;i&lt;WAVES;&nbsp;i++)&nbsp;gpioWaveDelete(wid[i]);<br><br>&nbsp;&nbsp;&nbsp;printf("stop&nbsp;piscope,&nbsp;press&nbsp;return");&nbsp;getchar();<br><br>&nbsp;&nbsp;&nbsp;gpioTerminate();<br>}<br></code><h3><a name="gpioWaveTxAt"></a><a href="#int"><small>int</small></a> gpioWaveTxAt<small>(void)</small></h3>
This function returns the id of the waveform currently being
transmitted using <a href="#gpioWaveTxSend">gpioWaveTxSend</a>.  Chained waves are not supported.
<br><br>Returns the waveform id or one of the following special values:
<br><br>PI_WAVE_NOT_FOUND (9998) - transmitted wave not found.<br>
PI_NO_TX_WAVE (9999) - no wave being transmitted.
<h3><a name="gpioWaveTxBusy"></a><a href="#int"><small>int</small></a> gpioWaveTxBusy<small>(void)</small></h3>
This function checks to see if a waveform is currently being
transmitted.
<br><br>Returns 1 if a waveform is currently being transmitted, otherwise 0.
<h3><a name="gpioWaveTxStop"></a><a href="#int"><small>int</small></a> gpioWaveTxStop<small>(void)</small></h3>
This function aborts the transmission of the current waveform.
<br><br>Returns 0 if OK.
<br><br>This function is intended to stop a waveform started in repeat mode.
<h3><a name="gpioWaveGetMicros"></a><a href="#int"><small>int</small></a> gpioWaveGetMicros<small>(void)</small></h3>
This function returns the length in microseconds of the current
waveform.
<h3><a name="gpioWaveGetHighMicros"></a><a href="#int"><small>int</small></a> gpioWaveGetHighMicros<small>(void)</small></h3>
This function returns the length in microseconds of the longest waveform
created since <a href="#gpioInitialise">gpioInitialise</a> was called.
<h3><a name="gpioWaveGetMaxMicros"></a><a href="#int"><small>int</small></a> gpioWaveGetMaxMicros<small>(void)</small></h3>
This function returns the maximum possible size of a waveform in
microseconds.
<h3><a name="gpioWaveGetPulses"></a><a href="#int"><small>int</small></a> gpioWaveGetPulses<small>(void)</small></h3>
This function returns the length in pulses of the current waveform.
<h3><a name="gpioWaveGetHighPulses"></a><a href="#int"><small>int</small></a> gpioWaveGetHighPulses<small>(void)</small></h3>
This function returns the length in pulses of the longest waveform
created since <a href="#gpioInitialise">gpioInitialise</a> was called.
<h3><a name="gpioWaveGetMaxPulses"></a><a href="#int"><small>int</small></a> gpioWaveGetMaxPulses<small>(void)</small></h3>
This function returns the maximum possible size of a waveform in pulses.
<h3><a name="gpioWaveGetCbs"></a><a href="#int"><small>int</small></a> gpioWaveGetCbs<small>(void)</small></h3>
This function returns the length in DMA control blocks of the current
waveform.
<h3><a name="gpioWaveGetHighCbs"></a><a href="#int"><small>int</small></a> gpioWaveGetHighCbs<small>(void)</small></h3>
This function returns the length in DMA control blocks of the longest
waveform created since <a href="#gpioInitialise">gpioInitialise</a> was called.
<h3><a name="gpioWaveGetMaxCbs"></a><a href="#int"><small>int</small></a> gpioWaveGetMaxCbs<small>(void)</small></h3>
This function returns the maximum possible size of a waveform in DMA
control blocks.
<h3><a name="gpioSerialReadOpen"></a><a href="#int"><small>int</small></a> gpioSerialReadOpen<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#unsigned">unsigned</a> <a href="#baud">baud</a>, <a href="#unsigned">unsigned</a> <a href="#data_bits">data_bits</a>)</small></h3>
This function opens a GPIO for bit bang reading of serial data.
<br><br><code>user_gpio:&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;baud:&nbsp;50-250000<br>data_bits:&nbsp;1-32<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_WAVE_BAUD,
PI_BAD_DATABITS, or PI_GPIO_IN_USE.
<br><br>The serial data is returned in a cyclic buffer and is read using
<a href="#gpioSerialRead">gpioSerialRead</a>.
<br><br>It is the caller's responsibility to read data from the cyclic buffer
in a timely fashion.
<h3><a name="gpioSerialReadInvert"></a><a href="#int"><small>int</small></a> gpioSerialReadInvert<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#unsigned">unsigned</a> <a href="#invert">invert</a>)</small></h3>
This function configures the level logic for bit bang serial reads.
<br><br>Use PI_BB_SER_INVERT to invert the serial logic and PI_BB_SER_NORMAL for
normal logic.  Default is PI_BB_SER_NORMAL.
<br><br><code>user_gpio:&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;invert:&nbsp;0-1<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_GPIO_IN_USE,
PI_NOT_SERIAL_GPIO, or PI_BAD_SER_INVERT.
<br><br>The GPIO must be opened for bit bang reading of serial data using
<a href="#gpioSerialReadOpen">gpioSerialReadOpen</a> prior to calling this function.
<h3><a name="gpioSerialRead"></a><a href="#int"><small>int</small></a> gpioSerialRead<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#void">void</a> <a href="#*buf">*buf</a>, <a href="#size_t">size_t</a> <a href="#bufSize">bufSize</a>)</small></h3>
This function copies up to bufSize bytes of data read from the
bit bang serial cyclic buffer to the buffer starting at buf.
<br><br><code>user_gpio:&nbsp;0-31,&nbsp;previously&nbsp;opened&nbsp;with&nbsp;<a href="#gpioSerialReadOpen">gpioSerialReadOpen</a><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf:&nbsp;an&nbsp;array&nbsp;to&nbsp;receive&nbsp;the&nbsp;read&nbsp;bytes<br>&nbsp;&nbsp;bufSize:&nbsp;&gt;=0<br></code><br><br>Returns the number of bytes copied if OK, otherwise PI_BAD_USER_GPIO
or PI_NOT_SERIAL_GPIO.
<br><br>The bytes returned for each character depend upon the number of
data bits <a href="#data_bits">data_bits</a> specified in the <a href="#gpioSerialReadOpen">gpioSerialReadOpen</a> command.
<br><br>For <a href="#data_bits">data_bits</a> 1-8 there will be one byte per character.<br>
For <a href="#data_bits">data_bits</a> 9-16 there will be two bytes per character.<br>
For <a href="#data_bits">data_bits</a> 17-32 there will be four bytes per character.
<h3><a name="gpioSerialReadClose"></a><a href="#int"><small>int</small></a> gpioSerialReadClose<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>)</small></h3>
This function closes a GPIO for bit bang reading of serial data.
<br><br><code>user_gpio:&nbsp;0-31,&nbsp;previously&nbsp;opened&nbsp;with&nbsp;<a href="#gpioSerialReadOpen">gpioSerialReadOpen</a><br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO.
<h3><a name="i2cOpen"></a><a href="#int"><small>int</small></a> i2cOpen<small>(<a href="#unsigned">unsigned</a> <a href="#i2cBus">i2cBus</a>, <a href="#unsigned">unsigned</a> <a href="#i2cAddr">i2cAddr</a>, <a href="#unsigned">unsigned</a> <a href="#i2cFlags">i2cFlags</a>)</small></h3>
This returns a handle for the device at the address on the I2C bus.
<br><br><code>&nbsp;&nbsp;i2cBus:&nbsp;&gt;=0<br>&nbsp;i2cAddr:&nbsp;0-0x7F<br>i2cFlags:&nbsp;0<br></code><br><br>No flags are currently defined.  This parameter should be set to zero.
<br><br>Physically buses 0 and 1 are available on the Pi.  Higher numbered buses
will be available if a kernel supported bus multiplexor is being used.
<br><br>The GPIO used are given in the following table.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td>SDA</td><td>SCL</td></tr><tr><td>I2C 0</td><td>0</td><td>1</td></tr><tr><td>I2C 1</td><td>2</td><td>3</td></tr></tbody></table><br><br>Returns a handle (&gt;=0) if OK, otherwise PI_BAD_I2C_BUS, PI_BAD_I2C_ADDR,
PI_BAD_FLAGS, PI_NO_HANDLE, or PI_I2C_OPEN_FAILED.
<br><br>For the SMBus commands the low level transactions are shown at the end
of the function description.  The following abbreviations are used.
<br><br><code>S&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(1&nbsp;bit)&nbsp;:&nbsp;Start&nbsp;bit<br>P&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(1&nbsp;bit)&nbsp;:&nbsp;Stop&nbsp;bit<br>Rd/Wr&nbsp;&nbsp;(1&nbsp;bit)&nbsp;:&nbsp;Read/Write&nbsp;bit.&nbsp;Rd&nbsp;equals&nbsp;1,&nbsp;Wr&nbsp;equals&nbsp;0.<br>A,&nbsp;NA&nbsp;&nbsp;(1&nbsp;bit)&nbsp;:&nbsp;Accept&nbsp;and&nbsp;not&nbsp;accept&nbsp;bit.<br><br>Addr&nbsp;&nbsp;&nbsp;(7&nbsp;bits):&nbsp;I2C&nbsp;7&nbsp;bit&nbsp;address.<br>i2cReg&nbsp;(8&nbsp;bits):&nbsp;Command&nbsp;byte,&nbsp;a&nbsp;byte&nbsp;which&nbsp;often&nbsp;selects&nbsp;a&nbsp;register.<br>Data&nbsp;&nbsp;&nbsp;(8&nbsp;bits):&nbsp;A&nbsp;data&nbsp;byte.<br>Count&nbsp;&nbsp;(8&nbsp;bits):&nbsp;A&nbsp;byte&nbsp;defining&nbsp;the&nbsp;length&nbsp;of&nbsp;a&nbsp;block&nbsp;operation.<br><br>[..]:&nbsp;Data&nbsp;sent&nbsp;by&nbsp;the&nbsp;device.<br></code><h3><a name="i2cClose"></a><a href="#int"><small>int</small></a> i2cClose<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>)</small></h3>
This closes the I2C device associated with the handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE.
<h3><a name="i2cWriteQuick"></a><a href="#int"><small>int</small></a> i2cWriteQuick<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#bit">bit</a>)</small></h3>
This sends a single bit (in the Rd/Wr bit) to the device associated
with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>&nbsp;&nbsp;&nbsp;bit:&nbsp;0-1,&nbsp;the&nbsp;value&nbsp;to&nbsp;write<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_WRITE_FAILED.
<br><br>Quick command. SMBus 2.0 5.5.1
<code>S&nbsp;Addr&nbsp;bit&nbsp;[A]&nbsp;P<br></code><h3><a name="i2cWriteByte"></a><a href="#int"><small>int</small></a> i2cWriteByte<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#bVal">bVal</a>)</small></h3>
This sends a single byte to the device associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>&nbsp;&nbsp;bVal:&nbsp;0-0xFF,&nbsp;the&nbsp;value&nbsp;to&nbsp;write<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_WRITE_FAILED.
<br><br>Send byte. SMBus 2.0 5.5.2
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;bVal&nbsp;[A]&nbsp;P<br></code><h3><a name="i2cReadByte"></a><a href="#int"><small>int</small></a> i2cReadByte<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>)</small></h3>
This reads a single byte from the device associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br></code><br><br>Returns the byte read (&gt;=0) if OK, otherwise PI_BAD_HANDLE,
or PI_I2C_READ_FAILED.
<br><br>Receive byte. SMBus 2.0 5.5.3
<code>S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[Data]&nbsp;NA&nbsp;P<br></code><h3><a name="i2cWriteByteData"></a><a href="#int"><small>int</small></a> i2cWriteByteData<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2cReg">i2cReg</a>, <a href="#unsigned">unsigned</a> <a href="#bVal">bVal</a>)</small></h3>
This writes a single byte to the specified register of the device
associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>i2cReg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;write<br>&nbsp;&nbsp;bVal:&nbsp;0-0xFF,&nbsp;the&nbsp;value&nbsp;to&nbsp;write<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_WRITE_FAILED.
<br><br>Write byte. SMBus 2.0 5.5.4
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;i2cReg&nbsp;[A]&nbsp;bVal&nbsp;[A]&nbsp;P<br></code><h3><a name="i2cWriteWordData"></a><a href="#int"><small>int</small></a> i2cWriteWordData<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2cReg">i2cReg</a>, <a href="#unsigned">unsigned</a> <a href="#wVal">wVal</a>)</small></h3>
This writes a single 16 bit word to the specified register of the device
associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>i2cReg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;write<br>&nbsp;&nbsp;wVal:&nbsp;0-0xFFFF,&nbsp;the&nbsp;value&nbsp;to&nbsp;write<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_WRITE_FAILED.
<br><br>Write word. SMBus 2.0 5.5.4
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;i2cReg&nbsp;[A]&nbsp;wValLow&nbsp;[A]&nbsp;wValHigh&nbsp;[A]&nbsp;P<br></code><h3><a name="i2cReadByteData"></a><a href="#int"><small>int</small></a> i2cReadByteData<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2cReg">i2cReg</a>)</small></h3>
This reads a single byte from the specified register of the device
associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>i2cReg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;read<br></code><br><br>Returns the byte read (&gt;=0) if OK, otherwise PI_BAD_HANDLE,
PI_BAD_PARAM, or PI_I2C_READ_FAILED.
<br><br>Read byte. SMBus 2.0 5.5.5
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;i2cReg&nbsp;[A]&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[Data]&nbsp;NA&nbsp;P<br></code><h3><a name="i2cReadWordData"></a><a href="#int"><small>int</small></a> i2cReadWordData<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2cReg">i2cReg</a>)</small></h3>
This reads a single 16 bit word from the specified register of the device
associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>i2cReg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;read<br></code><br><br>Returns the word read (&gt;=0) if OK, otherwise PI_BAD_HANDLE,
PI_BAD_PARAM, or PI_I2C_READ_FAILED.
<br><br>Read word. SMBus 2.0 5.5.5
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;i2cReg&nbsp;[A]&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[DataLow]&nbsp;A&nbsp;[DataHigh]&nbsp;NA&nbsp;P<br></code><h3><a name="i2cProcessCall"></a><a href="#int"><small>int</small></a> i2cProcessCall<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2cReg">i2cReg</a>, <a href="#unsigned">unsigned</a> <a href="#wVal">wVal</a>)</small></h3>
This writes 16 bits of data to the specified register of the device
associated with handle and reads 16 bits of data in return.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>i2cReg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;write/read<br>&nbsp;&nbsp;wVal:&nbsp;0-0xFFFF,&nbsp;the&nbsp;value&nbsp;to&nbsp;write<br></code><br><br>Returns the word read (&gt;=0) if OK, otherwise PI_BAD_HANDLE,
PI_BAD_PARAM, or PI_I2C_READ_FAILED.
<br><br>Process call. SMBus 2.0 5.5.6
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;i2cReg&nbsp;[A]&nbsp;wValLow&nbsp;[A]&nbsp;wValHigh&nbsp;[A]<br>&nbsp;&nbsp;&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[DataLow]&nbsp;A&nbsp;[DataHigh]&nbsp;NA&nbsp;P<br></code><h3><a name="i2cWriteBlockData"></a><a href="#int"><small>int</small></a> i2cWriteBlockData<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2cReg">i2cReg</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This writes up to 32 bytes to the specified register of the device
associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>i2cReg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;write<br>&nbsp;&nbsp;&nbsp;buf:&nbsp;an&nbsp;array&nbsp;with&nbsp;the&nbsp;data&nbsp;to&nbsp;send<br>&nbsp;count:&nbsp;1-32,&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;write<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_WRITE_FAILED.
<br><br>Block write. SMBus 2.0 5.5.7
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;i2cReg&nbsp;[A]&nbsp;count&nbsp;[A]<br>&nbsp;&nbsp;&nbsp;buf0&nbsp;[A]&nbsp;buf1&nbsp;[A]&nbsp;...&nbsp;[A]&nbsp;bufn&nbsp;[A]&nbsp;P<br></code><h3><a name="i2cReadBlockData"></a><a href="#int"><small>int</small></a> i2cReadBlockData<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2cReg">i2cReg</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>)</small></h3>
This reads a block of up to 32 bytes from the specified register of
the device associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>i2cReg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;read<br>&nbsp;&nbsp;&nbsp;buf:&nbsp;an&nbsp;array&nbsp;to&nbsp;receive&nbsp;the&nbsp;read&nbsp;data<br></code><br><br>The amount of returned data is set by the device.
<br><br>Returns the number of bytes read (&gt;=0) if OK, otherwise PI_BAD_HANDLE,
PI_BAD_PARAM, or PI_I2C_READ_FAILED.
<br><br>Block read. SMBus 2.0 5.5.7
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;i2cReg&nbsp;[A]<br>&nbsp;&nbsp;&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[Count]&nbsp;A&nbsp;[buf0]&nbsp;A&nbsp;[buf1]&nbsp;A&nbsp;...&nbsp;A&nbsp;[bufn]&nbsp;NA&nbsp;P<br></code><h3><a name="i2cBlockProcessCall"></a><a href="#int"><small>int</small></a> i2cBlockProcessCall<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2cReg">i2cReg</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This writes data bytes to the specified register of the device
associated with handle and reads a device specified number
of bytes of data in return.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>i2cReg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;write/read<br>&nbsp;&nbsp;&nbsp;buf:&nbsp;an&nbsp;array&nbsp;with&nbsp;the&nbsp;data&nbsp;to&nbsp;send&nbsp;and&nbsp;to&nbsp;receive&nbsp;the&nbsp;read&nbsp;data<br>&nbsp;count:&nbsp;1-32,&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;write<br></code><br><br>Returns the number of bytes read (&gt;=0) if OK, otherwise PI_BAD_HANDLE,
PI_BAD_PARAM, or PI_I2C_READ_FAILED.
<br><br>The SMBus 2.0 documentation states that a minimum of 1 byte may be
sent and a minimum of 1 byte may be received.  The total number of
bytes sent/received must be 32 or less.
<br><br>Block write-block read. SMBus 2.0 5.5.8
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;i2cReg&nbsp;[A]&nbsp;count&nbsp;[A]&nbsp;buf0&nbsp;[A]&nbsp;...&nbsp;bufn&nbsp;[A]<br>&nbsp;&nbsp;&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[Count]&nbsp;A&nbsp;[buf0]&nbsp;A&nbsp;...&nbsp;[bufn]&nbsp;A&nbsp;P<br></code><h3><a name="i2cReadI2CBlockData"></a><a href="#int"><small>int</small></a> i2cReadI2CBlockData<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2cReg">i2cReg</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This reads count bytes from the specified register of the device
associated with handle .  The count may be 1-32.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>i2cReg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;read<br>&nbsp;&nbsp;&nbsp;buf:&nbsp;an&nbsp;array&nbsp;to&nbsp;receive&nbsp;the&nbsp;read&nbsp;data<br>&nbsp;count:&nbsp;1-32,&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;read<br></code><br><br>Returns the number of bytes read (&gt;0) if OK, otherwise PI_BAD_HANDLE,
PI_BAD_PARAM, or PI_I2C_READ_FAILED.
<br><br><code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;i2cReg&nbsp;[A]<br>&nbsp;&nbsp;&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[buf0]&nbsp;A&nbsp;[buf1]&nbsp;A&nbsp;...&nbsp;A&nbsp;[bufn]&nbsp;NA&nbsp;P<br></code><h3><a name="i2cWriteI2CBlockData"></a><a href="#int"><small>int</small></a> i2cWriteI2CBlockData<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2cReg">i2cReg</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This writes 1 to 32 bytes to the specified register of the device
associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>i2cReg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;write<br>&nbsp;&nbsp;&nbsp;buf:&nbsp;the&nbsp;data&nbsp;to&nbsp;write<br>&nbsp;count:&nbsp;1-32,&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;write<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_WRITE_FAILED.
<br><br><code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;i2cReg&nbsp;[A]&nbsp;buf0&nbsp;[A]&nbsp;buf1&nbsp;[A]&nbsp;...&nbsp;[A]&nbsp;bufn&nbsp;[A]&nbsp;P<br></code><h3><a name="i2cReadDevice"></a><a href="#int"><small>int</small></a> i2cReadDevice<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This reads count bytes from the raw device into buf.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>&nbsp;&nbsp;&nbsp;buf:&nbsp;an&nbsp;array&nbsp;to&nbsp;receive&nbsp;the&nbsp;read&nbsp;data&nbsp;bytes<br>&nbsp;count:&nbsp;&gt;0,&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;read<br></code><br><br>Returns count (&gt;0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_READ_FAILED.
<br><br><code>S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[buf0]&nbsp;A&nbsp;[buf1]&nbsp;A&nbsp;...&nbsp;A&nbsp;[bufn]&nbsp;NA&nbsp;P<br></code><h3><a name="i2cWriteDevice"></a><a href="#int"><small>int</small></a> i2cWriteDevice<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This writes count bytes from buf to the raw device.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>&nbsp;&nbsp;&nbsp;buf:&nbsp;an&nbsp;array&nbsp;containing&nbsp;the&nbsp;data&nbsp;bytes&nbsp;to&nbsp;write<br>&nbsp;count:&nbsp;&gt;0,&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;write<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_I2C_WRITE_FAILED.
<br><br><code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;buf0&nbsp;[A]&nbsp;buf1&nbsp;[A]&nbsp;...&nbsp;[A]&nbsp;bufn&nbsp;[A]&nbsp;P<br></code><h3><a name="i2cSwitchCombined"></a><a href="#void"><small>void</small></a> i2cSwitchCombined<small>(<a href="#int">int</a> <a href="#setting">setting</a>)</small></h3>
This sets the I2C (i2c-bcm2708) module "use combined transactions"
parameter on or off.
<br><br><code>setting:&nbsp;0&nbsp;to&nbsp;set&nbsp;the&nbsp;parameter&nbsp;off,&nbsp;non-zero&nbsp;to&nbsp;set&nbsp;it&nbsp;on<br></code><br><br>NOTE: when the flag is on a write followed by a read to the same
slave address will use a repeated start (rather than a stop/start).
<h3><a name="i2cSegments"></a><a href="#int"><small>int</small></a> i2cSegments<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#pi_i2c_msg_t">pi_i2c_msg_t</a> <a href="#*segs">*segs</a>, <a href="#unsigned">unsigned</a> <a href="#numSegs">numSegs</a>)</small></h3>
This function executes multiple I2C segments in one transaction by
calling the I2C_RDWR ioctl.
<br><br><code>&nbsp;handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>&nbsp;&nbsp;&nbsp;segs:&nbsp;an&nbsp;array&nbsp;of&nbsp;I2C&nbsp;segments<br>numSegs:&nbsp;&gt;0,&nbsp;the&nbsp;number&nbsp;of&nbsp;I2C&nbsp;segments<br></code><br><br>Returns the number of segments if OK, otherwise PI_BAD_I2C_SEG.
<h3><a name="i2cZip"></a><a href="#int"><small>int</small></a> i2cZip<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#char">char</a> <a href="#*inBuf">*inBuf</a>, <a href="#unsigned">unsigned</a> <a href="#inLen">inLen</a>, <a href="#char">char</a> <a href="#*outBuf">*outBuf</a>, <a href="#unsigned">unsigned</a> <a href="#outLen">outLen</a>)</small></h3>
This function executes a sequence of I2C operations.  The
operations to be performed are specified by the contents of inBuf
which contains the concatenated command codes and associated data.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2cOpen">i2cOpen</a><br>&nbsp;inBuf:&nbsp;pointer&nbsp;to&nbsp;the&nbsp;concatenated&nbsp;I2C&nbsp;commands,&nbsp;see&nbsp;below<br>&nbsp;inLen:&nbsp;size&nbsp;of&nbsp;command&nbsp;buffer<br>outBuf:&nbsp;pointer&nbsp;to&nbsp;buffer&nbsp;to&nbsp;hold&nbsp;returned&nbsp;data<br>outLen:&nbsp;size&nbsp;of&nbsp;output&nbsp;buffer<br></code><br><br>Returns &gt;= 0 if OK (the number of bytes read), otherwise
PI_BAD_HANDLE, PI_BAD_POINTER, PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN.
PI_BAD_I2C_WLEN, or PI_BAD_I2C_SEG.
<br><br>The following command codes are supported:
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Name</td><td>Cmd & Data</td><td>Meaning</td></tr><tr><td>End</td><td>0</td><td>No more commands</td></tr><tr><td>Escape</td><td>1</td><td>Next P is two bytes</td></tr><tr><td>On</td><td>2</td><td>Switch combined flag on</td></tr><tr><td>Off</td><td>3</td><td>Switch combined flag off</td></tr><tr><td>Address</td><td>4 P</td><td>Set I2C address to P</td></tr><tr><td>Flags</td><td>5 lsb msb</td><td>Set I2C flags to lsb + (msb &lt;&lt; 8)</td></tr><tr><td>Read</td><td>6 P</td><td>Read P bytes of data</td></tr><tr><td>Write</td><td>7 P ...</td><td>Write P bytes of data</td></tr></tbody></table><br><br>The address, read, and write commands take a parameter P.
Normally P is one byte (0-255).  If the command is preceded by
the Escape command then P is two bytes (0-65535, least significant
byte first).
<br><br>The address defaults to that associated with the handle.
The flags default to 0.  The address and flags maintain their
previous value until updated.
<br><br>The returned I2C data is stored in consecutive locations of outBuf.
<br><br><b><small>Example</small></b><br><br><code>Set&nbsp;address&nbsp;0x53,&nbsp;write&nbsp;0x32,&nbsp;read&nbsp;6&nbsp;bytes<br>Set&nbsp;address&nbsp;0x1E,&nbsp;write&nbsp;0x03,&nbsp;read&nbsp;6&nbsp;bytes<br>Set&nbsp;address&nbsp;0x68,&nbsp;write&nbsp;0x1B,&nbsp;read&nbsp;8&nbsp;bytes<br>End<br><br>0x04&nbsp;0x53&nbsp;&nbsp;&nbsp;0x07&nbsp;0x01&nbsp;0x32&nbsp;&nbsp;&nbsp;0x06&nbsp;0x06<br>0x04&nbsp;0x1E&nbsp;&nbsp;&nbsp;0x07&nbsp;0x01&nbsp;0x03&nbsp;&nbsp;&nbsp;0x06&nbsp;0x06<br>0x04&nbsp;0x68&nbsp;&nbsp;&nbsp;0x07&nbsp;0x01&nbsp;0x1B&nbsp;&nbsp;&nbsp;0x06&nbsp;0x08<br>0x00<br></code><h3><a name="bbI2COpen"></a><a href="#int"><small>int</small></a> bbI2COpen<small>(<a href="#unsigned">unsigned</a> <a href="#SDA">SDA</a>, <a href="#unsigned">unsigned</a> <a href="#SCL">SCL</a>, <a href="#unsigned">unsigned</a> <a href="#baud">baud</a>)</small></h3>
This function selects a pair of GPIO for bit banging I2C at a
specified baud rate.
<br><br>Bit banging I2C allows for certain operations which are not possible
with the standard I2C driver.
<br><br>o baud rates as low as 50<br>
o repeated starts<br>
o clock stretching<br>
o I2C on any pair of spare GPIO
<br><br><code>&nbsp;SDA:&nbsp;0-31<br>&nbsp;SCL:&nbsp;0-31<br>baud:&nbsp;50-500000<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_I2C_BAUD, or
PI_GPIO_IN_USE.
<br><br>NOTE:
<br><br>The GPIO used for SDA and SCL must have pull-ups to 3V3 connected.  As
a guide the hardware pull-ups on pins 3 and 5 are 1k8 in value.
<h3><a name="bbI2CClose"></a><a href="#int"><small>int</small></a> bbI2CClose<small>(<a href="#unsigned">unsigned</a> <a href="#SDA">SDA</a>)</small></h3>
This function stops bit banging I2C on a pair of GPIO previously
opened with <a href="#bbI2COpen">bbI2COpen</a>.
<br><br><code>SDA:&nbsp;0-31,&nbsp;the&nbsp;SDA&nbsp;GPIO&nbsp;used&nbsp;in&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#bbI2COpen">bbI2COpen</a><br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO.
<h3><a name="bbI2CZip"></a><a href="#int"><small>int</small></a> bbI2CZip<small>(<a href="#unsigned">unsigned</a> <a href="#SDA">SDA</a>, <a href="#char">char</a> <a href="#*inBuf">*inBuf</a>, <a href="#unsigned">unsigned</a> <a href="#inLen">inLen</a>, <a href="#char">char</a> <a href="#*outBuf">*outBuf</a>, <a href="#unsigned">unsigned</a> <a href="#outLen">outLen</a>)</small></h3>
This function executes a sequence of bit banged I2C operations.  The
operations to be performed are specified by the contents of inBuf
which contains the concatenated command codes and associated data.
<br><br><code>&nbsp;&nbsp;&nbsp;SDA:&nbsp;0-31&nbsp;(as&nbsp;used&nbsp;in&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#bbI2COpen">bbI2COpen</a>)<br>&nbsp;inBuf:&nbsp;pointer&nbsp;to&nbsp;the&nbsp;concatenated&nbsp;I2C&nbsp;commands,&nbsp;see&nbsp;below<br>&nbsp;inLen:&nbsp;size&nbsp;of&nbsp;command&nbsp;buffer<br>outBuf:&nbsp;pointer&nbsp;to&nbsp;buffer&nbsp;to&nbsp;hold&nbsp;returned&nbsp;data<br>outLen:&nbsp;size&nbsp;of&nbsp;output&nbsp;buffer<br></code><br><br>Returns &gt;= 0 if OK (the number of bytes read), otherwise
PI_BAD_USER_GPIO, PI_NOT_I2C_GPIO, PI_BAD_POINTER,
PI_BAD_I2C_CMD, PI_BAD_I2C_RLEN, PI_BAD_I2C_WLEN,
PI_I2C_READ_FAILED, or PI_I2C_WRITE_FAILED.
<br><br>The following command codes are supported:
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Name</td><td>Cmd & Data</td><td>Meaning</td></tr><tr><td>End</td><td>0</td><td>No more commands</td></tr><tr><td>Escape</td><td>1</td><td>Next P is two bytes</td></tr><tr><td>Start</td><td>2</td><td>Start condition</td></tr><tr><td>Stop</td><td>3</td><td>Stop condition</td></tr><tr><td>Address</td><td>4 P</td><td>Set I2C address to P</td></tr><tr><td>Flags</td><td>5 lsb msb</td><td>Set I2C flags to lsb + (msb &lt;&lt; 8)</td></tr><tr><td>Read</td><td>6 P</td><td>Read P bytes of data</td></tr><tr><td>Write</td><td>7 P ...</td><td>Write P bytes of data</td></tr></tbody></table><br><br>The address, read, and write commands take a parameter P.
Normally P is one byte (0-255).  If the command is preceded by
the Escape command then P is two bytes (0-65535, least significant
byte first).
<br><br>The address and flags default to 0.  The address and flags maintain
their previous value until updated.
<br><br>No flags are currently defined.
<br><br>The returned I2C data is stored in consecutive locations of outBuf.
<br><br><b><small>Example</small></b><br><br><code>Set&nbsp;address&nbsp;0x53<br>start,&nbsp;write&nbsp;0x32,&nbsp;(re)start,&nbsp;read&nbsp;6&nbsp;bytes,&nbsp;stop<br>Set&nbsp;address&nbsp;0x1E<br>start,&nbsp;write&nbsp;0x03,&nbsp;(re)start,&nbsp;read&nbsp;6&nbsp;bytes,&nbsp;stop<br>Set&nbsp;address&nbsp;0x68<br>start,&nbsp;write&nbsp;0x1B,&nbsp;(re)start,&nbsp;read&nbsp;8&nbsp;bytes,&nbsp;stop<br>End<br><br>0x04&nbsp;0x53<br>0x02&nbsp;0x07&nbsp;0x01&nbsp;0x32&nbsp;&nbsp;&nbsp;0x02&nbsp;0x06&nbsp;0x06&nbsp;0x03<br><br>0x04&nbsp;0x1E<br>0x02&nbsp;0x07&nbsp;0x01&nbsp;0x03&nbsp;&nbsp;&nbsp;0x02&nbsp;0x06&nbsp;0x06&nbsp;0x03<br><br>0x04&nbsp;0x68<br>0x02&nbsp;0x07&nbsp;0x01&nbsp;0x1B&nbsp;&nbsp;&nbsp;0x02&nbsp;0x06&nbsp;0x08&nbsp;0x03<br><br>0x00<br></code><h3><a name="bscXfer"></a><a href="#int"><small>int</small></a> bscXfer<small>(<a href="#bsc_xfer_t">bsc_xfer_t</a> <a href="#*bsc_xfer">*bsc_xfer</a>)</small></h3>
This function provides a low-level interface to the SPI/I2C Slave
peripheral on the BCM chip.
<br><br>This peripheral allows the Pi to act as a hardware slave device
on an I2C or SPI bus.
<br><br>This is not a bit bang version and as such is OS timing
independent. The bus timing is handled directly by the chip.
<br><br>The output process is simple. You simply append data to the FIFO
buffer on the chip.  This works like a queue, you add data to the
queue and the master removes it.
<br><br>The function sets the BSC mode, writes any data in
the transmit buffer to the BSC transmit FIFO, and
copies any data in the BSC receive FIFO to the
receive buffer.
<br><br><code>bsc_xfer:=&nbsp;a&nbsp;structure&nbsp;defining&nbsp;the&nbsp;transfer<br><br>typedef&nbsp;struct<br>{<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;control;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Write<br>&nbsp;&nbsp;&nbsp;int&nbsp;rxCnt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Read&nbsp;only<br>&nbsp;&nbsp;&nbsp;char&nbsp;rxBuf[BSC_FIFO_SIZE];&nbsp;//&nbsp;Read&nbsp;only<br>&nbsp;&nbsp;&nbsp;int&nbsp;txCnt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Write<br>&nbsp;&nbsp;&nbsp;char&nbsp;txBuf[BSC_FIFO_SIZE];&nbsp;//&nbsp;Write<br>}&nbsp;bsc_xfer_t;<br></code><br><br>To start a transfer set control (see below), copy the bytes to
be added to the transmit FIFO (if any) to txBuf and set txCnt to
the number of copied bytes.
<br><br>Upon return rxCnt will be set to the number of received bytes placed
in rxBuf.
<br><br>Note that the control word sets the BSC mode.  The BSC will stay in
that mode until a different control word is sent.
<br><br>GPIO used for models other than those based on the BCM2711.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td>SDA</td><td>SCL</td><td>MOSI</td><td>SCLK</td><td>MISO</td><td>CE</td></tr><tr><td>I2C</td><td>18</td><td>19</td><td>-</td><td>-</td><td>-</td><td>-</td></tr><tr><td>SPI</td><td>-</td><td>-</td><td>20</td><td>19</td><td>18</td><td>21</td></tr></tbody></table><br><br>GPIO used for models based on the BCM2711 (e.g. the Pi4B).
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td>SDA</td><td>SCL</td><td>MOSI</td><td>SCLK</td><td>MISO</td><td>CE</td></tr><tr><td>I2C</td><td>10</td><td>11</td><td>-</td><td>-</td><td>-</td><td>-</td></tr><tr><td>SPI</td><td>-</td><td>-</td><td>9</td><td>11</td><td>10</td><td>8</td></tr></tbody></table><br><br>When a zero control word is received the used GPIO will be reset
to INPUT mode.
<br><br>The returned function value is the status of the transfer (see below).
<br><br>If there was an error the status will be less than zero
(and will contain the error code).
<br><br>The most significant word of the returned status contains the number
of bytes actually copied from txBuf to the BSC transmit FIFO (may be
less than requested if the FIFO already contained untransmitted data).
<br><br>control consists of the following bits.
<br><br><code>22&nbsp;21&nbsp;20&nbsp;19&nbsp;18&nbsp;17&nbsp;16&nbsp;15&nbsp;14&nbsp;13&nbsp;12&nbsp;11&nbsp;10&nbsp;&nbsp;9&nbsp;&nbsp;8&nbsp;&nbsp;7&nbsp;&nbsp;6&nbsp;&nbsp;5&nbsp;&nbsp;4&nbsp;&nbsp;3&nbsp;&nbsp;2&nbsp;&nbsp;1&nbsp;&nbsp;0<br>&nbsp;a&nbsp;&nbsp;a&nbsp;&nbsp;a&nbsp;&nbsp;a&nbsp;&nbsp;a&nbsp;&nbsp;a&nbsp;&nbsp;a&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;IT&nbsp;HC&nbsp;TF&nbsp;IR&nbsp;RE&nbsp;TE&nbsp;BK&nbsp;EC&nbsp;ES&nbsp;PL&nbsp;PH&nbsp;I2&nbsp;SP&nbsp;EN<br></code><br><br>Bits 0-13 are copied unchanged to the BSC CR register.  See
pages 163-165 of the Broadcom peripherals document for full
details.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>aaaaaaa</td><td>defines the I2C slave address (only relevant in I2C mode)</td></tr><tr><td>IT</td><td>invert transmit status flags</td></tr><tr><td>HC</td><td>enable host control</td></tr><tr><td>TF</td><td>enable test FIFO</td></tr><tr><td>IR</td><td>invert receive status flags</td></tr><tr><td>RE</td><td>enable receive</td></tr><tr><td>TE</td><td>enable transmit</td></tr><tr><td>BK</td><td>abort operation and clear FIFOs</td></tr><tr><td>EC</td><td>send control register as first I2C byte</td></tr><tr><td>ES</td><td>send status register as first I2C byte</td></tr><tr><td>PL</td><td>set SPI polarity high</td></tr><tr><td>PH</td><td>set SPI phase high</td></tr><tr><td>I2</td><td>enable I2C mode</td></tr><tr><td>SP</td><td>enable SPI mode</td></tr><tr><td>EN</td><td>enable BSC peripheral</td></tr></tbody></table><br><br>The returned status has the following format
<br><br><code>20&nbsp;19&nbsp;18&nbsp;17&nbsp;16&nbsp;15&nbsp;14&nbsp;13&nbsp;12&nbsp;11&nbsp;10&nbsp;&nbsp;9&nbsp;&nbsp;8&nbsp;&nbsp;7&nbsp;&nbsp;6&nbsp;&nbsp;5&nbsp;&nbsp;4&nbsp;&nbsp;3&nbsp;&nbsp;2&nbsp;&nbsp;1&nbsp;&nbsp;0<br>&nbsp;S&nbsp;&nbsp;S&nbsp;&nbsp;S&nbsp;&nbsp;S&nbsp;&nbsp;S&nbsp;&nbsp;R&nbsp;&nbsp;R&nbsp;&nbsp;R&nbsp;&nbsp;R&nbsp;&nbsp;R&nbsp;&nbsp;T&nbsp;&nbsp;T&nbsp;&nbsp;T&nbsp;&nbsp;T&nbsp;&nbsp;T&nbsp;RB&nbsp;TE&nbsp;RF&nbsp;TF&nbsp;RE&nbsp;TB<br></code><br><br>Bits 0-15 are copied unchanged from the BSC FR register.  See
pages 165-166 of the Broadcom peripherals document for full
details.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>SSSSS</td><td>number of bytes successfully copied to transmit FIFO</td></tr><tr><td>RRRRR</td><td>number of bytes in receive FIFO</td></tr><tr><td>TTTTT</td><td>number of bytes in transmit FIFO</td></tr><tr><td>RB</td><td>receive busy</td></tr><tr><td>TE</td><td>transmit FIFO empty</td></tr><tr><td>RF</td><td>receive FIFO full</td></tr><tr><td>TF</td><td>transmit FIFO full</td></tr><tr><td>RE</td><td>receive FIFO empty</td></tr><tr><td>TB</td><td>transmit busy</td></tr></tbody></table><br><br>The following example shows how to configure the BSC peripheral as
an I2C slave with address 0x13 and send four bytes.
<br><br><b><small>Example</small></b><br><br><code>bsc_xfer_t&nbsp;xfer;<br><br>xfer.control&nbsp;=&nbsp;(0x13&lt;&lt;16)&nbsp;|&nbsp;0x305;<br><br>memcpy(xfer.txBuf,&nbsp;"ABCD",&nbsp;4);<br>xfer.txCnt&nbsp;=&nbsp;4;<br><br>status&nbsp;=&nbsp;bscXfer(&xfer);<br><br>if&nbsp;(status&nbsp;&gt;=&nbsp;0)<br>{<br>&nbsp;&nbsp;&nbsp;//&nbsp;process&nbsp;transfer<br>}<br></code><br><br>The BSC slave in SPI mode deserializes data from the MOSI pin into its
receiver/FIFO when the LSB of the first byte is a 0.  No data is output on
the MISO pin.  When the LSB of the first byte on MOSI is a 1, the
transmitter/FIFO data is serialized onto the MISO pin while all other data
on the MOSI pin is ignored.
<br><br>The BK bit of the BSC control register is non-functional when in the SPI
mode.  The transmitter along with its FIFO can be dequeued by successively
disabling and re-enabling the TE bit on the BSC control register while in
SPI mode.
<h3><a name="bbSPIOpen"></a><a href="#int"><small>int</small></a> bbSPIOpen<small>(<a href="#unsigned">unsigned</a> <a href="#CS">CS</a>, <a href="#unsigned">unsigned</a> <a href="#MISO">MISO</a>, <a href="#unsigned">unsigned</a> <a href="#MOSI">MOSI</a>, <a href="#unsigned">unsigned</a> <a href="#SCLK">SCLK</a>, <a href="#unsigned">unsigned</a> <a href="#baud">baud</a>, <a href="#unsigned">unsigned</a> <a href="#spiFlags">spiFlags</a>)</small></h3>
This function selects a set of GPIO for bit banging SPI with
a specified baud rate and mode.
<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CS:&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;MISO:&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;MOSI:&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;SCLK:&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;baud:&nbsp;50-250000<br>spiFlags:&nbsp;see&nbsp;below<br></code><br><br>spiFlags consists of the least significant 22 bits.
<br><br><code>21&nbsp;20&nbsp;19&nbsp;18&nbsp;17&nbsp;16&nbsp;15&nbsp;14&nbsp;13&nbsp;12&nbsp;11&nbsp;10&nbsp;&nbsp;9&nbsp;&nbsp;8&nbsp;&nbsp;7&nbsp;&nbsp;6&nbsp;&nbsp;5&nbsp;&nbsp;4&nbsp;&nbsp;3&nbsp;&nbsp;2&nbsp;&nbsp;1&nbsp;&nbsp;0<br>&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;R&nbsp;&nbsp;T&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;0&nbsp;&nbsp;p&nbsp;&nbsp;m&nbsp;&nbsp;m<br></code><br><br>mm defines the SPI mode, defaults to 0
<br><br><code>Mode&nbsp;CPOL&nbsp;CPHA<br>&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;0<br>&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;1<br>&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;0<br>&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;1<br></code><br><br>p is 0 if CS is active low (default) and 1 for active high.
<br><br>T is 1 if the least significant bit is transmitted on MOSI first, the
default (0) shifts the most significant bit out first.
<br><br>R is 1 if the least significant bit is received on MISO first, the
default (0) receives the most significant bit first.
<br><br>The other bits in flags should be set to zero.
<br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or
PI_GPIO_IN_USE.
<br><br>If more than one device is connected to the SPI bus (defined by
SCLK, MOSI, and MISO) each must have its own CS.
<br><br><b><small>Example</small></b><br><br><code>bbSPIOpen(10,&nbsp;MISO,&nbsp;MOSI,&nbsp;SCLK,&nbsp;10000,&nbsp;0);&nbsp;//&nbsp;device&nbsp;1<br>bbSPIOpen(11,&nbsp;MISO,&nbsp;MOSI,&nbsp;SCLK,&nbsp;20000,&nbsp;3);&nbsp;//&nbsp;device&nbsp;2<br></code><h3><a name="bbSPIClose"></a><a href="#int"><small>int</small></a> bbSPIClose<small>(<a href="#unsigned">unsigned</a> <a href="#CS">CS</a>)</small></h3>
This function stops bit banging SPI on a set of GPIO
opened with <a href="#bbSPIOpen">bbSPIOpen</a>.
<br><br><code>CS:&nbsp;0-31,&nbsp;the&nbsp;CS&nbsp;GPIO&nbsp;used&nbsp;in&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#bbSPIOpen">bbSPIOpen</a><br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO.
<h3><a name="bbSPIXfer"></a><a href="#int"><small>int</small></a> bbSPIXfer<small>(<a href="#unsigned">unsigned</a> <a href="#CS">CS</a>, <a href="#char">char</a> <a href="#*inBuf">*inBuf</a>, <a href="#char">char</a> <a href="#*outBuf">*outBuf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This function executes a bit banged SPI transfer.
<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;CS:&nbsp;0-31&nbsp;(as&nbsp;used&nbsp;in&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#bbSPIOpen">bbSPIOpen</a>)<br>&nbsp;inBuf:&nbsp;pointer&nbsp;to&nbsp;buffer&nbsp;to&nbsp;hold&nbsp;data&nbsp;to&nbsp;be&nbsp;sent<br>outBuf:&nbsp;pointer&nbsp;to&nbsp;buffer&nbsp;to&nbsp;hold&nbsp;returned&nbsp;data<br>&nbsp;count:&nbsp;size&nbsp;of&nbsp;data&nbsp;transfer<br></code><br><br>Returns &gt;= 0 if OK (the number of bytes read), otherwise
PI_BAD_USER_GPIO, PI_NOT_SPI_GPIO or PI_BAD_POINTER.
<br><br><b><small>Example</small></b><br><br><code>//&nbsp;gcc&nbsp;-Wall&nbsp;-pthread&nbsp;-o&nbsp;bbSPIx_test&nbsp;bbSPIx_test.c&nbsp;-lpigpio<br>//&nbsp;sudo&nbsp;./bbSPIx_test<br><br>#include&nbsp;&lt;stdio.h&gt;<br><br>#include&nbsp;"pigpio.h"<br><br>#define&nbsp;CE0&nbsp;5<br>#define&nbsp;CE1&nbsp;6<br>#define&nbsp;MISO&nbsp;13<br>#define&nbsp;MOSI&nbsp;19<br>#define&nbsp;SCLK&nbsp;12<br><br>int&nbsp;main(int&nbsp;argc,&nbsp;char&nbsp;*argv[])<br>{<br>&nbsp;&nbsp;&nbsp;int&nbsp;i,&nbsp;count,&nbsp;set_val,&nbsp;read_val;<br>&nbsp;&nbsp;&nbsp;unsigned&nbsp;char&nbsp;inBuf[3];<br>&nbsp;&nbsp;&nbsp;char&nbsp;cmd1[]&nbsp;=&nbsp;{0,&nbsp;0};<br>&nbsp;&nbsp;&nbsp;char&nbsp;cmd2[]&nbsp;=&nbsp;{12,&nbsp;0};<br>&nbsp;&nbsp;&nbsp;char&nbsp;cmd3[]&nbsp;=&nbsp;{1,&nbsp;128,&nbsp;0};<br><br>&nbsp;&nbsp;&nbsp;if&nbsp;(gpioInitialise()&nbsp;&lt;&nbsp;0)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,&nbsp;"pigpio&nbsp;initialisation&nbsp;failed.\n");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;1;<br>&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;bbSPIOpen(CE0,&nbsp;MISO,&nbsp;MOSI,&nbsp;SCLK,&nbsp;10000,&nbsp;0);&nbsp;//&nbsp;MCP4251&nbsp;DAC<br>&nbsp;&nbsp;&nbsp;bbSPIOpen(CE1,&nbsp;MISO,&nbsp;MOSI,&nbsp;SCLK,&nbsp;20000,&nbsp;3);&nbsp;//&nbsp;MCP3008&nbsp;ADC<br><br>&nbsp;&nbsp;&nbsp;for&nbsp;(i=0;&nbsp;i&lt;256;&nbsp;i++)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmd1[1]&nbsp;=&nbsp;i;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count&nbsp;=&nbsp;bbSPIXfer(CE0,&nbsp;cmd1,&nbsp;(char&nbsp;*)inBuf,&nbsp;2);&nbsp;//&nbsp;&gt;&nbsp;DAC<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(count&nbsp;==&nbsp;2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count&nbsp;=&nbsp;bbSPIXfer(CE0,&nbsp;cmd2,&nbsp;(char&nbsp;*)inBuf,&nbsp;2);&nbsp;//&nbsp;&lt;&nbsp;DAC<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(count&nbsp;==&nbsp;2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set_val&nbsp;=&nbsp;inBuf[1];<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count&nbsp;=&nbsp;bbSPIXfer(CE1,&nbsp;cmd3,&nbsp;(char&nbsp;*)inBuf,&nbsp;3);&nbsp;//&nbsp;&lt;&nbsp;ADC<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(count&nbsp;==&nbsp;3)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;read_val&nbsp;=&nbsp;((inBuf[1]&3)&lt;&lt;8)&nbsp;|&nbsp;inBuf[2];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("%d&nbsp;%d\n",&nbsp;set_val,&nbsp;read_val);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;bbSPIClose(CE0);<br>&nbsp;&nbsp;&nbsp;bbSPIClose(CE1);<br><br>&nbsp;&nbsp;&nbsp;gpioTerminate();<br><br>&nbsp;&nbsp;&nbsp;return&nbsp;0;<br>}<br></code><h3><a name="spiOpen"></a><a href="#int"><small>int</small></a> spiOpen<small>(<a href="#unsigned">unsigned</a> <a href="#spiChan">spiChan</a>, <a href="#unsigned">unsigned</a> <a href="#baud">baud</a>, <a href="#unsigned">unsigned</a> <a href="#spiFlags">spiFlags</a>)</small></h3>
This function returns a handle for the SPI device on the channel.
Data will be transferred at baud bits per second.  The flags may
be used to modify the default behaviour of 4-wire operation, mode 0,
active low chip select.
<br><br>The Pi has two SPI peripherals: main and auxiliary.
<br><br>The main SPI has two chip selects (channels), the auxiliary has
three.
<br><br>The auxiliary SPI is available on all models but the A and B.
<br><br>The GPIO used are given in the following table.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td>MISO</td><td>MOSI</td><td>SCLK</td><td>CE0</td><td>CE1</td><td>CE2</td></tr><tr><td>Main SPI</td><td>9</td><td>10</td><td>11</td><td>8</td><td>7</td><td>-</td></tr><tr><td>Aux SPI</td><td>19</td><td>20</td><td>21</td><td>18</td><td>17</td><td>16</td></tr></tbody></table><br><br><code>&nbsp;spiChan:&nbsp;0-1&nbsp;(0-2&nbsp;for&nbsp;the&nbsp;auxiliary&nbsp;SPI)<br>&nbsp;&nbsp;&nbsp;&nbsp;baud:&nbsp;32K-125M&nbsp;(values&nbsp;above&nbsp;30M&nbsp;are&nbsp;unlikely&nbsp;to&nbsp;work)<br>spiFlags:&nbsp;see&nbsp;below<br></code><br><br>Returns a handle (&gt;=0) if OK, otherwise PI_BAD_SPI_CHANNEL,
PI_BAD_SPI_SPEED, PI_BAD_FLAGS, PI_NO_AUX_SPI, or PI_SPI_OPEN_FAILED.
<br><br>spiFlags consists of the least significant 22 bits.
<br><br><code>21&nbsp;20&nbsp;19&nbsp;18&nbsp;17&nbsp;16&nbsp;15&nbsp;14&nbsp;13&nbsp;12&nbsp;11&nbsp;10&nbsp;&nbsp;9&nbsp;&nbsp;8&nbsp;&nbsp;7&nbsp;&nbsp;6&nbsp;&nbsp;5&nbsp;&nbsp;4&nbsp;&nbsp;3&nbsp;&nbsp;2&nbsp;&nbsp;1&nbsp;&nbsp;0<br>&nbsp;b&nbsp;&nbsp;b&nbsp;&nbsp;b&nbsp;&nbsp;b&nbsp;&nbsp;b&nbsp;&nbsp;b&nbsp;&nbsp;R&nbsp;&nbsp;T&nbsp;&nbsp;n&nbsp;&nbsp;n&nbsp;&nbsp;n&nbsp;&nbsp;n&nbsp;&nbsp;W&nbsp;&nbsp;A&nbsp;u2&nbsp;u1&nbsp;u0&nbsp;p2&nbsp;p1&nbsp;p0&nbsp;&nbsp;m&nbsp;&nbsp;m<br></code><br><br>mm defines the SPI mode.
<br><br>Warning: modes 1 and 3 do not appear to work on the auxiliary SPI.
<br><br><code>Mode&nbsp;POL&nbsp;PHA<br>&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;0<br>&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;1<br>&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;0<br>&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;1<br></code><br><br>px is 0 if CEx is active low (default) and 1 for active high.
<br><br>ux is 0 if the CEx GPIO is reserved for SPI (default) and 1 otherwise.
<br><br>A is 0 for the main SPI, 1 for the auxiliary SPI.
<br><br>W is 0 if the device is not 3-wire, 1 if the device is 3-wire.  Main
SPI only.
<br><br>nnnn defines the number of bytes (0-15) to write before switching
the MOSI line to MISO to read data.  This field is ignored
if W is not set.  Main SPI only.
<br><br>T is 1 if the least significant bit is transmitted on MOSI first, the
default (0) shifts the most significant bit out first.  Auxiliary SPI
only.
<br><br>R is 1 if the least significant bit is received on MISO first, the
default (0) receives the most significant bit first.  Auxiliary SPI
only.
<br><br>bbbbbb defines the word size in bits (0-32).  The default (0)
sets 8 bits per word.  Auxiliary SPI only.
<br><br>The <a href="#spiRead">spiRead</a>, <a href="#spiWrite">spiWrite</a>, and <a href="#spiXfer">spiXfer</a> functions
transfer data packed into 1, 2, or 4 bytes according to
the word size in bits.
<br><br>For bits 1-8 there will be one byte per word.<br>
For bits 9-16 there will be two bytes per word.<br>
For bits 17-32 there will be four bytes per word.
<br><br>Multi-byte transfers are made in least significant byte first order.
<br><br>E.g. to transfer 32 11-bit words buf should contain 64 bytes
and count should be 64.
<br><br>E.g. to transfer the 14 bit value 0x1ABC send the bytes 0xBC followed
by 0x1A.
<br><br>The other bits in flags should be set to zero.
<h3><a name="spiClose"></a><a href="#int"><small>int</small></a> spiClose<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>)</small></h3>
This functions closes the SPI device identified by the handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#spiOpen">spiOpen</a><br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE.
<h3><a name="spiRead"></a><a href="#int"><small>int</small></a> spiRead<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This function reads count bytes of data from the SPI
device associated with the handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#spiOpen">spiOpen</a><br>&nbsp;&nbsp;&nbsp;buf:&nbsp;an&nbsp;array&nbsp;to&nbsp;receive&nbsp;the&nbsp;read&nbsp;data&nbsp;bytes<br>&nbsp;count:&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;read<br></code><br><br>Returns the number of bytes transferred if OK, otherwise
PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
<h3><a name="spiWrite"></a><a href="#int"><small>int</small></a> spiWrite<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This function writes count bytes of data from buf to the SPI
device associated with the handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#spiOpen">spiOpen</a><br>&nbsp;&nbsp;&nbsp;buf:&nbsp;the&nbsp;data&nbsp;bytes&nbsp;to&nbsp;write<br>&nbsp;count:&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;write<br></code><br><br>Returns the number of bytes transferred if OK, otherwise
PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
<h3><a name="spiXfer"></a><a href="#int"><small>int</small></a> spiXfer<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#char">char</a> <a href="#*txBuf">*txBuf</a>, <a href="#char">char</a> <a href="#*rxBuf">*rxBuf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This function transfers count bytes of data from txBuf to the SPI
device associated with the handle.  Simultaneously count bytes of
data are read from the device and placed in rxBuf.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#spiOpen">spiOpen</a><br>&nbsp;txBuf:&nbsp;the&nbsp;data&nbsp;bytes&nbsp;to&nbsp;write<br>&nbsp;rxBuf:&nbsp;the&nbsp;received&nbsp;data&nbsp;bytes<br>&nbsp;count:&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;transfer<br></code><br><br>Returns the number of bytes transferred if OK, otherwise
PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
<h3><a name="serOpen"></a><a href="#int"><small>int</small></a> serOpen<small>(<a href="#char">char</a> <a href="#*sertty">*sertty</a>, <a href="#unsigned">unsigned</a> <a href="#baud">baud</a>, <a href="#unsigned">unsigned</a> <a href="#serFlags">serFlags</a>)</small></h3>
This function opens a serial device at a specified baud rate
and with specified flags.  The device name must start with
/dev/tty or /dev/serial.
<br><br><code>&nbsp;&nbsp;sertty:&nbsp;the&nbsp;serial&nbsp;device&nbsp;to&nbsp;open<br>&nbsp;&nbsp;&nbsp;&nbsp;baud:&nbsp;the&nbsp;baud&nbsp;rate&nbsp;in&nbsp;bits&nbsp;per&nbsp;second,&nbsp;see&nbsp;below<br>serFlags:&nbsp;0<br></code><br><br>Returns a handle (&gt;=0) if OK, otherwise PI_NO_HANDLE, or
PI_SER_OPEN_FAILED.
<br><br>The baud rate must be one of 50, 75, 110, 134, 150,
200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200,
38400, 57600, 115200, or 230400.
<br><br>No flags are currently defined.  This parameter should be set to zero.
<h3><a name="serClose"></a><a href="#int"><small>int</small></a> serClose<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>)</small></h3>
This function closes the serial device associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#serOpen">serOpen</a><br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE.
<h3><a name="serWriteByte"></a><a href="#int"><small>int</small></a> serWriteByte<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#bVal">bVal</a>)</small></h3>
This function writes bVal to the serial port associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#serOpen">serOpen</a><br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_SER_WRITE_FAILED.
<h3><a name="serReadByte"></a><a href="#int"><small>int</small></a> serReadByte<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>)</small></h3>
This function reads a byte from the serial port associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#serOpen">serOpen</a><br></code><br><br>Returns the read byte (&gt;=0) if OK, otherwise PI_BAD_HANDLE,
PI_SER_READ_NO_DATA, or PI_SER_READ_FAILED.
<br><br>If no data is ready PI_SER_READ_NO_DATA is returned.
<h3><a name="serWrite"></a><a href="#int"><small>int</small></a> serWrite<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This function writes count bytes from buf to the the serial port
associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#serOpen">serOpen</a><br>&nbsp;&nbsp;&nbsp;buf:&nbsp;the&nbsp;array&nbsp;of&nbsp;bytes&nbsp;to&nbsp;write<br>&nbsp;count:&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;write<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_SER_WRITE_FAILED.
<h3><a name="serRead"></a><a href="#int"><small>int</small></a> serRead<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This function reads up count bytes from the the serial port
associated with handle and writes them to buf.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#serOpen">serOpen</a><br>&nbsp;&nbsp;&nbsp;buf:&nbsp;an&nbsp;array&nbsp;to&nbsp;receive&nbsp;the&nbsp;read&nbsp;data<br>&nbsp;count:&nbsp;the&nbsp;maximum&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;read<br></code><br><br>Returns the number of bytes read (&gt;0=) if OK, otherwise PI_BAD_HANDLE,
PI_BAD_PARAM, or PI_SER_READ_NO_DATA.
<br><br>If no data is ready zero is returned.
<h3><a name="serDataAvailable"></a><a href="#int"><small>int</small></a> serDataAvailable<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>)</small></h3>
This function returns the number of bytes available
to be read from the device associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#serOpen">serOpen</a><br></code><br><br>Returns the number of bytes of data available (&gt;=0) if OK,
otherwise PI_BAD_HANDLE.
<h3><a name="gpioTrigger"></a><a href="#int"><small>int</small></a> gpioTrigger<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#unsigned">unsigned</a> <a href="#pulseLen">pulseLen</a>, <a href="#unsigned">unsigned</a> <a href="#level">level</a>)</small></h3>
This function sends a trigger pulse to a GPIO.  The GPIO is set to
level for pulseLen microseconds and then reset to not level.
<br><br><code>user_gpio:&nbsp;0-31<br>&nbsp;pulseLen:&nbsp;1-100<br>&nbsp;&nbsp;&nbsp;&nbsp;level:&nbsp;0,1<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL,
or PI_BAD_PULSELEN.
<h3><a name="gpioSetWatchdog"></a><a href="#int"><small>int</small></a> gpioSetWatchdog<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#unsigned">unsigned</a> <a href="#timeout">timeout</a>)</small></h3>
Sets a watchdog for a GPIO.
<br><br><code>user_gpio:&nbsp;0-31<br>&nbsp;&nbsp;timeout:&nbsp;0-60000<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_BAD_WDOG_TIMEOUT.
<br><br>The watchdog is nominally in milliseconds.
<br><br>One watchdog may be registered per GPIO.
<br><br>The watchdog may be cancelled by setting timeout to 0.
<br><br>Until cancelled a timeout will be reported every timeout milliseconds
after the last GPIO activity.
<br><br>In particular:
<br><br>1) any registered alert function for the GPIO will be called with
   the level set to PI_TIMEOUT.
<br><br>2) any notification for the GPIO will have a report written to the
   fifo with the flags set to indicate a watchdog timeout.
<br><br><b><small>Example</small></b><br><br><code>void&nbsp;aFunction(int&nbsp;gpio,&nbsp;int&nbsp;level,&nbsp;uint32_t&nbsp;tick)<br>{<br>&nbsp;&nbsp;&nbsp;printf("GPIO&nbsp;%d&nbsp;became&nbsp;%d&nbsp;at&nbsp;%d",&nbsp;gpio,&nbsp;level,&nbsp;tick);<br>}<br><br>//&nbsp;call&nbsp;aFunction&nbsp;whenever&nbsp;GPIO&nbsp;4&nbsp;changes&nbsp;state<br>gpioSetAlertFunc(4,&nbsp;aFunction);<br><br>//&nbsp;&nbsp;or&nbsp;approximately&nbsp;every&nbsp;5&nbsp;millis<br>gpioSetWatchdog(4,&nbsp;5);<br></code><h3><a name="gpioNoiseFilter"></a><a href="#int"><small>int</small></a> gpioNoiseFilter<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#unsigned">unsigned</a> <a href="#steady">steady</a>, <a href="#unsigned">unsigned</a> <a href="#active">active</a>)</small></h3>
Sets a noise filter on a GPIO.
<br><br>Level changes on the GPIO are ignored until a level which has
been stable for <a href="#steady">steady</a> microseconds is detected.  Level changes
on the GPIO are then reported for <a href="#active">active</a> microseconds after
which the process repeats.
<br><br><code>user_gpio:&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;steady:&nbsp;0-300000<br>&nbsp;&nbsp;&nbsp;active:&nbsp;0-1000000<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
<br><br>This filter affects the GPIO samples returned to callbacks set up
with <a href="#gpioSetAlertFunc">gpioSetAlertFunc</a>, <a href="#gpioSetAlertFuncEx">gpioSetAlertFuncEx</a>, <a href="#gpioSetGetSamplesFunc">gpioSetGetSamplesFunc</a>,
and <a href="#gpioSetGetSamplesFuncEx">gpioSetGetSamplesFuncEx</a>.
<br><br>It does not affect interrupts set up with <a href="#gpioSetISRFunc">gpioSetISRFunc</a>,
<a href="#gpioSetISRFuncEx">gpioSetISRFuncEx</a>, or levels read by <a href="#gpioRead">gpioRead</a>,
<a href="#gpioRead_Bits_0_31">gpioRead_Bits_0_31</a>, or <a href="#gpioRead_Bits_32_53">gpioRead_Bits_32_53</a>.
<br><br>Level changes before and after the active period may
be reported.  Your software must be designed to cope with
such reports.
<h3><a name="gpioGlitchFilter"></a><a href="#int"><small>int</small></a> gpioGlitchFilter<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#unsigned">unsigned</a> <a href="#steady">steady</a>)</small></h3>
Sets a glitch filter on a GPIO.
<br><br>Level changes on the GPIO are not reported unless the level
has been stable for at least <a href="#steady">steady</a> microseconds.  The
level is then reported.  Level changes of less than <a href="#steady">steady</a>
microseconds are ignored.
<br><br><code>user_gpio:&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;steady:&nbsp;0-300000<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
<br><br>This filter affects the GPIO samples returned to callbacks set up
with <a href="#gpioSetAlertFunc">gpioSetAlertFunc</a>, <a href="#gpioSetAlertFuncEx">gpioSetAlertFuncEx</a>, <a href="#gpioSetGetSamplesFunc">gpioSetGetSamplesFunc</a>,
and <a href="#gpioSetGetSamplesFuncEx">gpioSetGetSamplesFuncEx</a>.
<br><br>It does not affect interrupts set up with <a href="#gpioSetISRFunc">gpioSetISRFunc</a>,
<a href="#gpioSetISRFuncEx">gpioSetISRFuncEx</a>, or levels read by <a href="#gpioRead">gpioRead</a>,
<a href="#gpioRead_Bits_0_31">gpioRead_Bits_0_31</a>, or <a href="#gpioRead_Bits_32_53">gpioRead_Bits_32_53</a>.
<br><br>Each (stable) edge will be timestamped <a href="#steady">steady</a> microseconds
after it was first detected.
<h3><a name="gpioSetGetSamplesFunc"></a><a href="#int"><small>int</small></a> gpioSetGetSamplesFunc<small>(<a href="#gpioGetSamplesFunc_t">gpioGetSamplesFunc_t</a> <a href="#f">f</a>, <a href="#uint32_t">uint32_t</a> <a href="#bits">bits</a>)</small></h3>
Registers a function to be called (a callback) every millisecond
with the latest GPIO samples.
<br><br><code>&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;function&nbsp;to&nbsp;call<br>bits:&nbsp;the&nbsp;GPIO&nbsp;of&nbsp;interest<br></code><br><br>Returns 0 if OK.
<br><br>The function is passed a pointer to the samples (an array of
<a href="#gpioSample_t">gpioSample_t</a>),  and the number of samples.
<br><br>Only one function can be registered.
<br><br>The callback may be cancelled by passing NULL as the function.
<br><br>The samples returned will be the union of bits, plus any active alerts,
plus any active notifications.
<br><br>e.g.  if there are alerts for GPIO 7, 8, and 9, notifications for GPIO
8, 10, 23, 24, and bits is (1&lt;&lt;23)|(1&lt;&lt;17) then samples for GPIO
7, 8, 9, 10, 17, 23, and 24 will be reported.
<h3><a name="gpioSetGetSamplesFuncEx"></a><a href="#int"><small>int</small></a> gpioSetGetSamplesFuncEx<small>(<a href="#gpioGetSamplesFuncEx_t">gpioGetSamplesFuncEx_t</a> <a href="#f">f</a>, <a href="#uint32_t">uint32_t</a> <a href="#bits">bits</a>, <a href="#void">void</a> <a href="#*userdata">*userdata</a>)</small></h3>
Registers a function to be called (a callback) every millisecond
with the latest GPIO samples.
<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;function&nbsp;to&nbsp;call<br>&nbsp;&nbsp;&nbsp;&nbsp;bits:&nbsp;the&nbsp;GPIO&nbsp;of&nbsp;interest<br>userdata:&nbsp;a&nbsp;pointer&nbsp;to&nbsp;arbitrary&nbsp;user&nbsp;data<br></code><br><br>Returns 0 if OK.
<br><br>The function is passed a pointer to the samples (an array of
<a href="#gpioSample_t">gpioSample_t</a>), the number of samples, and the userdata pointer.
<br><br>Only one of <a href="#gpioGetSamplesFunc">gpioGetSamplesFunc</a> or <a href="#gpioGetSamplesFuncEx">gpioGetSamplesFuncEx</a> can be
registered.
<br><br>See <a href="#gpioSetGetSamplesFunc">gpioSetGetSamplesFunc</a> for further details.
<h3><a name="gpioSetTimerFunc"></a><a href="#int"><small>int</small></a> gpioSetTimerFunc<small>(<a href="#unsigned">unsigned</a> <a href="#timer">timer</a>, <a href="#unsigned">unsigned</a> <a href="#millis">millis</a>, <a href="#gpioTimerFunc_t">gpioTimerFunc_t</a> <a href="#f">f</a>)</small></h3>
Registers a function to be called (a callback) every millis milliseconds.
<br><br><code>&nbsp;timer:&nbsp;0-9<br>millis:&nbsp;10-60000<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;function&nbsp;to&nbsp;call<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED.
<br><br>10 timers are supported numbered 0 to 9.
<br><br>One function may be registered per timer.
<br><br>The timer may be cancelled by passing NULL as the function.
<br><br><b><small>Example</small></b><br><br><code>void&nbsp;bFunction(void)<br>{<br>&nbsp;&nbsp;&nbsp;printf("two&nbsp;seconds&nbsp;have&nbsp;elapsed");<br>}<br><br>//&nbsp;call&nbsp;bFunction&nbsp;every&nbsp;2000&nbsp;milliseconds<br>gpioSetTimerFunc(0,&nbsp;2000,&nbsp;bFunction);<br></code><h3><a name="gpioSetTimerFuncEx"></a><a href="#int"><small>int</small></a> gpioSetTimerFuncEx<small>(<a href="#unsigned">unsigned</a> <a href="#timer">timer</a>, <a href="#unsigned">unsigned</a> <a href="#millis">millis</a>, <a href="#gpioTimerFuncEx_t">gpioTimerFuncEx_t</a> <a href="#f">f</a>, <a href="#void">void</a> <a href="#*userdata">*userdata</a>)</small></h3>
Registers a function to be called (a callback) every millis milliseconds.
<br><br><code>&nbsp;&nbsp;&nbsp;timer:&nbsp;0-9.<br>&nbsp;&nbsp;millis:&nbsp;10-60000<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;function&nbsp;to&nbsp;call<br>userdata:&nbsp;a&nbsp;pointer&nbsp;to&nbsp;arbitrary&nbsp;user&nbsp;data<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_TIMER, PI_BAD_MS, or PI_TIMER_FAILED.
<br><br>The function is passed the userdata pointer.
<br><br>Only one of <a href="#gpioSetTimerFunc">gpioSetTimerFunc</a> or <a href="#gpioSetTimerFuncEx">gpioSetTimerFuncEx</a> can be
registered per timer.
<br><br>See <a href="#gpioSetTimerFunc">gpioSetTimerFunc</a> for further details.
<h3><a name="gpioStartThread"></a><a href="#pthread_t"><small>pthread_t</small></a> *gpioStartThread<small>(<a href="#gpioThreadFunc_t">gpioThreadFunc_t</a> <a href="#f">f</a>, <a href="#void">void</a> <a href="#*userdata">*userdata</a>)</small></h3>
Starts a new thread of execution with f as the main routine.
<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;main&nbsp;function&nbsp;for&nbsp;the&nbsp;new&nbsp;thread<br>userdata:&nbsp;a&nbsp;pointer&nbsp;to&nbsp;arbitrary&nbsp;user&nbsp;data<br></code><br><br>Returns a pointer to pthread_t if OK, otherwise NULL.
<br><br>The function is passed the single argument arg.
<br><br>The thread can be cancelled by passing the pointer to pthread_t to
<a href="#gpioStopThread">gpioStopThread</a>.
<br><br><b><small>Example</small></b><br><br><code>#include&nbsp;&lt;stdio.h&gt;<br>#include&nbsp;&lt;pigpio.h&gt;<br><br>void&nbsp;*myfunc(void&nbsp;*arg)<br>{<br>&nbsp;&nbsp;&nbsp;while&nbsp;(1)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("%s",&nbsp;arg);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sleep(1);<br>&nbsp;&nbsp;&nbsp;}<br>}<br><br>int&nbsp;main(int&nbsp;argc,&nbsp;char&nbsp;*argv[])<br>{<br>&nbsp;&nbsp;&nbsp;pthread_t&nbsp;*p1,&nbsp;*p2,&nbsp;*p3;<br><br>&nbsp;&nbsp;&nbsp;if&nbsp;(gpioInitialise()&nbsp;&lt;&nbsp;0)&nbsp;return&nbsp;1;<br><br>&nbsp;&nbsp;&nbsp;p1&nbsp;=&nbsp;gpioStartThread(myfunc,&nbsp;"thread&nbsp;1");&nbsp;sleep(3);<br><br>&nbsp;&nbsp;&nbsp;p2&nbsp;=&nbsp;gpioStartThread(myfunc,&nbsp;"thread&nbsp;2");&nbsp;sleep(3);<br><br>&nbsp;&nbsp;&nbsp;p3&nbsp;=&nbsp;gpioStartThread(myfunc,&nbsp;"thread&nbsp;3");&nbsp;sleep(3);<br><br>&nbsp;&nbsp;&nbsp;gpioStopThread(p3);&nbsp;sleep(3);<br><br>&nbsp;&nbsp;&nbsp;gpioStopThread(p2);&nbsp;sleep(3);<br><br>&nbsp;&nbsp;&nbsp;gpioStopThread(p1);&nbsp;sleep(3);<br><br>&nbsp;&nbsp;&nbsp;gpioTerminate();<br>}<br></code><h3><a name="gpioStopThread"></a><a href="#void"><small>void</small></a> gpioStopThread<small>(<a href="#pthread_t">pthread_t</a> <a href="#*pth">*pth</a>)</small></h3>
Cancels the thread pointed at by pth.
<br><br><code>pth:&nbsp;a&nbsp;thread&nbsp;pointer&nbsp;returned&nbsp;by&nbsp;<a href="#gpioStartThread">gpioStartThread</a><br></code><br><br>No value is returned.
<br><br>The thread to be stopped should have been started with <a href="#gpioStartThread">gpioStartThread</a>.
<h3><a name="gpioStoreScript"></a><a href="#int"><small>int</small></a> gpioStoreScript<small>(<a href="#char">char</a> <a href="#*script">*script</a>)</small></h3>
This function stores a null terminated script for later execution.
<br><br>See <a href="http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts">http://abyz.me.uk/rpi/pigpio/pigs.html#Scripts</a> for details.
<br><br><code>script:&nbsp;the&nbsp;text&nbsp;of&nbsp;the&nbsp;script<br></code><br><br>The function returns a script id if the script is valid,
otherwise PI_BAD_SCRIPT.
<h3><a name="gpioRunScript"></a><a href="#int"><small>int</small></a> gpioRunScript<small>(<a href="#unsigned">unsigned</a> <a href="#script_id">script_id</a>, <a href="#unsigned">unsigned</a> <a href="#numPar">numPar</a>, <a href="#uint32_t">uint32_t</a> <a href="#*param">*param</a>)</small></h3>
This function runs a stored script.
<br><br><code>script_id:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;<a href="#gpioStoreScript">gpioStoreScript</a><br>&nbsp;&nbsp;&nbsp;numPar:&nbsp;0-10,&nbsp;the&nbsp;number&nbsp;of&nbsp;parameters<br>&nbsp;&nbsp;&nbsp;&nbsp;param:&nbsp;an&nbsp;array&nbsp;of&nbsp;parameters<br></code><br><br>The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
PI_TOO_MANY_PARAM.
<br><br>param is an array of up to 10 parameters which may be referenced in
the script as p0 to p9.
<h3><a name="gpioUpdateScript"></a><a href="#int"><small>int</small></a> gpioUpdateScript<small>(<a href="#unsigned">unsigned</a> <a href="#script_id">script_id</a>, <a href="#unsigned">unsigned</a> <a href="#numPar">numPar</a>, <a href="#uint32_t">uint32_t</a> <a href="#*param">*param</a>)</small></h3>
This function sets the parameters of a script.  The script may or
may not be running.  The first numPar parameters of the script are
overwritten with the new values.
<br><br><code>script_id:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;<a href="#gpioStoreScript">gpioStoreScript</a><br>&nbsp;&nbsp;&nbsp;numPar:&nbsp;0-10,&nbsp;the&nbsp;number&nbsp;of&nbsp;parameters<br>&nbsp;&nbsp;&nbsp;&nbsp;param:&nbsp;an&nbsp;array&nbsp;of&nbsp;parameters<br></code><br><br>The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID, or
PI_TOO_MANY_PARAM.
<br><br>param is an array of up to 10 parameters which may be referenced in
the script as p0 to p9.
<h3><a name="gpioScriptStatus"></a><a href="#int"><small>int</small></a> gpioScriptStatus<small>(<a href="#unsigned">unsigned</a> <a href="#script_id">script_id</a>, <a href="#uint32_t">uint32_t</a> <a href="#*param">*param</a>)</small></h3>
This function returns the run status of a stored script as well as
the current values of parameters 0 to 9.
<br><br><code>script_id:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;<a href="#gpioStoreScript">gpioStoreScript</a><br>&nbsp;&nbsp;&nbsp;&nbsp;param:&nbsp;an&nbsp;array&nbsp;to&nbsp;hold&nbsp;the&nbsp;returned&nbsp;10&nbsp;parameters<br></code><br><br>The function returns greater than or equal to 0 if OK,
otherwise PI_BAD_SCRIPT_ID.
<br><br>The run status may be
<br><br><code>PI_SCRIPT_INITING<br>PI_SCRIPT_HALTED<br>PI_SCRIPT_RUNNING<br>PI_SCRIPT_WAITING<br>PI_SCRIPT_FAILED<br></code><br><br>The current value of script parameters 0 to 9 are returned in param.
<h3><a name="gpioStopScript"></a><a href="#int"><small>int</small></a> gpioStopScript<small>(<a href="#unsigned">unsigned</a> <a href="#script_id">script_id</a>)</small></h3>
This function stops a running script.
<br><br><code>script_id:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;<a href="#gpioStoreScript">gpioStoreScript</a><br></code><br><br>The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
<h3><a name="gpioDeleteScript"></a><a href="#int"><small>int</small></a> gpioDeleteScript<small>(<a href="#unsigned">unsigned</a> <a href="#script_id">script_id</a>)</small></h3>
This function deletes a stored script.
<br><br><code>script_id:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;<a href="#gpioStoreScript">gpioStoreScript</a><br></code><br><br>The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
<h3><a name="gpioSetSignalFunc"></a><a href="#int"><small>int</small></a> gpioSetSignalFunc<small>(<a href="#unsigned">unsigned</a> <a href="#signum">signum</a>, <a href="#gpioSignalFunc_t">gpioSignalFunc_t</a> <a href="#f">f</a>)</small></h3>
Registers a function to be called (a callback) when a signal occurs.
<br><br><code>signum:&nbsp;0-63<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;callback&nbsp;function<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_SIGNUM.
<br><br>The function is passed the signal number.
<br><br>One function may be registered per signal.
<br><br>The callback may be cancelled by passing NULL.
<br><br>By default all signals are treated as fatal and cause the library
to call gpioTerminate and then exit.
<h3><a name="gpioSetSignalFuncEx"></a><a href="#int"><small>int</small></a> gpioSetSignalFuncEx<small>(<a href="#unsigned">unsigned</a> <a href="#signum">signum</a>, <a href="#gpioSignalFuncEx_t">gpioSignalFuncEx_t</a> <a href="#f">f</a>, <a href="#void">void</a> <a href="#*userdata">*userdata</a>)</small></h3>
Registers a function to be called (a callback) when a signal occurs.
<br><br><code>&nbsp;&nbsp;signum:&nbsp;0-63<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;callback&nbsp;function<br>userdata:&nbsp;a&nbsp;pointer&nbsp;to&nbsp;arbitrary&nbsp;user&nbsp;data<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_SIGNUM.
<br><br>The function is passed the signal number and the userdata pointer.
<br><br>Only one of gpioSetSignalFunc or gpioSetSignalFuncEx can be
registered per signal.
<br><br>See gpioSetSignalFunc for further details.
<h3><a name="gpioRead_Bits_0_31"></a><a href="#uint32_t"><small>uint32_t</small></a> gpioRead_Bits_0_31<small>(void)</small></h3>
Returns the current level of GPIO 0-31.
<h3><a name="gpioRead_Bits_32_53"></a><a href="#uint32_t"><small>uint32_t</small></a> gpioRead_Bits_32_53<small>(void)</small></h3>
Returns the current level of GPIO 32-53.
<h3><a name="gpioWrite_Bits_0_31_Clear"></a><a href="#int"><small>int</small></a> gpioWrite_Bits_0_31_Clear<small>(<a href="#uint32_t">uint32_t</a> <a href="#bits">bits</a>)</small></h3>
Clears GPIO 0-31 if the corresponding bit in bits is set.
<br><br><code>bits:&nbsp;a&nbsp;bit&nbsp;mask&nbsp;of&nbsp;GPIO&nbsp;to&nbsp;clear<br></code><br><br>Returns 0 if OK.
<br><br><b><small>Example</small></b><br><br><code>//&nbsp;To&nbsp;clear&nbsp;(set&nbsp;to&nbsp;0)&nbsp;GPIO&nbsp;4,&nbsp;7,&nbsp;and&nbsp;15<br>gpioWrite_Bits_0_31_Clear(&nbsp;(1&lt;&lt;4)&nbsp;|&nbsp;(1&lt;&lt;7)&nbsp;|&nbsp;(1&lt;&lt;15)&nbsp;);<br></code><h3><a name="gpioWrite_Bits_32_53_Clear"></a><a href="#int"><small>int</small></a> gpioWrite_Bits_32_53_Clear<small>(<a href="#uint32_t">uint32_t</a> <a href="#bits">bits</a>)</small></h3>
Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set.
<br><br><code>bits:&nbsp;a&nbsp;bit&nbsp;mask&nbsp;of&nbsp;GPIO&nbsp;to&nbsp;clear<br></code><br><br>Returns 0 if OK.
<h3><a name="gpioWrite_Bits_0_31_Set"></a><a href="#int"><small>int</small></a> gpioWrite_Bits_0_31_Set<small>(<a href="#uint32_t">uint32_t</a> <a href="#bits">bits</a>)</small></h3>
Sets GPIO 0-31 if the corresponding bit in bits is set.
<br><br><code>bits:&nbsp;a&nbsp;bit&nbsp;mask&nbsp;of&nbsp;GPIO&nbsp;to&nbsp;set<br></code><br><br>Returns 0 if OK.
<h3><a name="gpioWrite_Bits_32_53_Set"></a><a href="#int"><small>int</small></a> gpioWrite_Bits_32_53_Set<small>(<a href="#uint32_t">uint32_t</a> <a href="#bits">bits</a>)</small></h3>
Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set.
<br><br><code>bits:&nbsp;a&nbsp;bit&nbsp;mask&nbsp;of&nbsp;GPIO&nbsp;to&nbsp;set<br></code><br><br>Returns 0 if OK.
<br><br><b><small>Example</small></b><br><br><code>//&nbsp;To&nbsp;set&nbsp;(set&nbsp;to&nbsp;1)&nbsp;GPIO&nbsp;32,&nbsp;40,&nbsp;and&nbsp;53<br>gpioWrite_Bits_32_53_Set((1&lt;&lt;(32-32))&nbsp;|&nbsp;(1&lt;&lt;(40-32))&nbsp;|&nbsp;(1&lt;&lt;(53-32)));<br></code><h3><a name="gpioHardwareClock"></a><a href="#int"><small>int</small></a> gpioHardwareClock<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>, <a href="#unsigned">unsigned</a> <a href="#clkfreq">clkfreq</a>)</small></h3>
Starts a hardware clock on a GPIO at the specified frequency.
Frequencies above 30MHz are unlikely to work.
<br><br><code>&nbsp;&nbsp;&nbsp;gpio:&nbsp;see&nbsp;description<br>clkfreq:&nbsp;0&nbsp;(off)&nbsp;or&nbsp;4689-250M&nbsp;(13184-375M&nbsp;for&nbsp;the&nbsp;BCM2711)<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HCLK_GPIO,
PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS.
<br><br>The same clock is available on multiple GPIO.  The latest
frequency setting will be used by all GPIO which share a clock.
<br><br>The GPIO must be one of the following.
<br><br><code>4&nbsp;&nbsp;&nbsp;clock&nbsp;0&nbsp;&nbsp;All&nbsp;models<br>5&nbsp;&nbsp;&nbsp;clock&nbsp;1&nbsp;&nbsp;All&nbsp;models&nbsp;but&nbsp;A&nbsp;and&nbsp;B&nbsp;(reserved&nbsp;for&nbsp;system&nbsp;use)<br>6&nbsp;&nbsp;&nbsp;clock&nbsp;2&nbsp;&nbsp;All&nbsp;models&nbsp;but&nbsp;A&nbsp;and&nbsp;B<br>20&nbsp;&nbsp;clock&nbsp;0&nbsp;&nbsp;All&nbsp;models&nbsp;but&nbsp;A&nbsp;and&nbsp;B<br>21&nbsp;&nbsp;clock&nbsp;1&nbsp;&nbsp;All&nbsp;models&nbsp;but&nbsp;A&nbsp;and&nbsp;Rev.2&nbsp;B&nbsp;(reserved&nbsp;for&nbsp;system&nbsp;use)<br><br>32&nbsp;&nbsp;clock&nbsp;0&nbsp;&nbsp;Compute&nbsp;module&nbsp;only<br>34&nbsp;&nbsp;clock&nbsp;0&nbsp;&nbsp;Compute&nbsp;module&nbsp;only<br>42&nbsp;&nbsp;clock&nbsp;1&nbsp;&nbsp;Compute&nbsp;module&nbsp;only&nbsp;(reserved&nbsp;for&nbsp;system&nbsp;use)<br>43&nbsp;&nbsp;clock&nbsp;2&nbsp;&nbsp;Compute&nbsp;module&nbsp;only<br>44&nbsp;&nbsp;clock&nbsp;1&nbsp;&nbsp;Compute&nbsp;module&nbsp;only&nbsp;(reserved&nbsp;for&nbsp;system&nbsp;use)<br></code><br><br>Access to clock 1 is protected by a password as its use will likely
crash the Pi.  The password is given by or'ing 0x5A000000 with the
GPIO number.
<h3><a name="gpioHardwarePWM"></a><a href="#int"><small>int</small></a> gpioHardwarePWM<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>, <a href="#unsigned">unsigned</a> <a href="#PWMfreq">PWMfreq</a>, <a href="#unsigned">unsigned</a> <a href="#PWMduty">PWMduty</a>)</small></h3>
Starts hardware PWM on a GPIO at the specified frequency and dutycycle.
Frequencies above 30MHz are unlikely to work.
<br><br>NOTE: Any waveform started by <a href="#gpioWaveTxSend">gpioWaveTxSend</a>, or
<a href="#gpioWaveChain">gpioWaveChain</a> will be cancelled.
<br><br>This function is only valid if the pigpio main clock is PCM.  The
main clock defaults to PCM but may be overridden by a call to
<a href="#gpioCfgClock">gpioCfgClock</a>.
<br><br><code>&nbsp;&nbsp;&nbsp;gpio:&nbsp;see&nbsp;description<br>PWMfreq:&nbsp;0&nbsp;(off)&nbsp;or&nbsp;1-125M&nbsp;(1-187.5M&nbsp;for&nbsp;the&nbsp;BCM2711)<br>PWMduty:&nbsp;0&nbsp;(off)&nbsp;to&nbsp;1000000&nbsp;(1M)(fully&nbsp;on)<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_GPIO, PI_NOT_HPWM_GPIO,
PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ, or PI_HPWM_ILLEGAL.
<br><br>The same PWM channel is available on multiple GPIO.  The latest
frequency and dutycycle setting will be used by all GPIO which
share a PWM channel.
<br><br>The GPIO must be one of the following.
<br><br><code>12&nbsp;&nbsp;PWM&nbsp;channel&nbsp;0&nbsp;&nbsp;All&nbsp;models&nbsp;but&nbsp;A&nbsp;and&nbsp;B<br>13&nbsp;&nbsp;PWM&nbsp;channel&nbsp;1&nbsp;&nbsp;All&nbsp;models&nbsp;but&nbsp;A&nbsp;and&nbsp;B<br>18&nbsp;&nbsp;PWM&nbsp;channel&nbsp;0&nbsp;&nbsp;All&nbsp;models<br>19&nbsp;&nbsp;PWM&nbsp;channel&nbsp;1&nbsp;&nbsp;All&nbsp;models&nbsp;but&nbsp;A&nbsp;and&nbsp;B<br><br>40&nbsp;&nbsp;PWM&nbsp;channel&nbsp;0&nbsp;&nbsp;Compute&nbsp;module&nbsp;only<br>41&nbsp;&nbsp;PWM&nbsp;channel&nbsp;1&nbsp;&nbsp;Compute&nbsp;module&nbsp;only<br>45&nbsp;&nbsp;PWM&nbsp;channel&nbsp;1&nbsp;&nbsp;Compute&nbsp;module&nbsp;only<br>52&nbsp;&nbsp;PWM&nbsp;channel&nbsp;0&nbsp;&nbsp;Compute&nbsp;module&nbsp;only<br>53&nbsp;&nbsp;PWM&nbsp;channel&nbsp;1&nbsp;&nbsp;Compute&nbsp;module&nbsp;only<br></code><br><br>The actual number of steps beween off and fully on is the
integral part of 250M/PWMfreq (375M/PWMfreq for the BCM2711).
<br><br>The actual frequency set is 250M/steps (375M/steps for the BCM2711).
<br><br>There will only be a million steps for a PWMfreq of 250 (375 for
the BCM2711). Lower frequencies will have more steps and higher
frequencies will have fewer steps.  PWMduty is
automatically scaled to take this into account.
<h3><a name="gpioTime"></a><a href="#int"><small>int</small></a> gpioTime<small>(<a href="#unsigned">unsigned</a> <a href="#timetype">timetype</a>, <a href="#int">int</a> <a href="#*seconds">*seconds</a>, <a href="#int">int</a> <a href="#*micros">*micros</a>)</small></h3>
Updates the seconds and micros variables with the current time.
<br><br><code>timetype:&nbsp;0&nbsp;(relative),&nbsp;1&nbsp;(absolute)<br>&nbsp;seconds:&nbsp;a&nbsp;pointer&nbsp;to&nbsp;an&nbsp;int&nbsp;to&nbsp;hold&nbsp;seconds<br>&nbsp;&nbsp;micros:&nbsp;a&nbsp;pointer&nbsp;to&nbsp;an&nbsp;int&nbsp;to&nbsp;hold&nbsp;microseconds<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_TIMETYPE.
<br><br>If timetype is PI_TIME_ABSOLUTE updates seconds and micros with the
number of seconds and microseconds since the epoch (1st January 1970).
<br><br>If timetype is PI_TIME_RELATIVE updates seconds and micros with the
number of seconds and microseconds since the library was initialised.
<br><br><b><small>Example</small></b><br><br><code>int&nbsp;secs,&nbsp;mics;<br><br>//&nbsp;print&nbsp;the&nbsp;number&nbsp;of&nbsp;seconds&nbsp;since&nbsp;the&nbsp;library&nbsp;was&nbsp;started<br>gpioTime(PI_TIME_RELATIVE,&nbsp;&secs,&nbsp;&mics);<br>printf("library&nbsp;started&nbsp;%d.%03d&nbsp;seconds&nbsp;ago",&nbsp;secs,&nbsp;mics/1000);<br></code><h3><a name="gpioSleep"></a><a href="#int"><small>int</small></a> gpioSleep<small>(<a href="#unsigned">unsigned</a> <a href="#timetype">timetype</a>, <a href="#int">int</a> <a href="#seconds">seconds</a>, <a href="#int">int</a> <a href="#micros">micros</a>)</small></h3>
Sleeps for the number of seconds and microseconds specified by seconds
and micros.
<br><br><code>timetype:&nbsp;0&nbsp;(relative),&nbsp;1&nbsp;(absolute)<br>&nbsp;seconds:&nbsp;seconds&nbsp;to&nbsp;sleep<br>&nbsp;&nbsp;micros:&nbsp;microseconds&nbsp;to&nbsp;sleep<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_TIMETYPE, PI_BAD_SECONDS,
or PI_BAD_MICROS.
<br><br>If timetype is PI_TIME_ABSOLUTE the sleep ends when the number of seconds
and microseconds since the epoch (1st January 1970) has elapsed.  System
clock changes are taken into account.
<br><br>If timetype is PI_TIME_RELATIVE the sleep is for the specified number
of seconds and microseconds.  System clock changes do not effect the
sleep length.
<br><br>For short delays (say, 50 microseonds or less) use <a href="#gpioDelay">gpioDelay</a>.
<br><br><b><small>Example</small></b><br><br><code>gpioSleep(PI_TIME_RELATIVE,&nbsp;2,&nbsp;500000);&nbsp;//&nbsp;sleep&nbsp;for&nbsp;2.5&nbsp;seconds<br><br>gpioSleep(PI_TIME_RELATIVE,&nbsp;0,&nbsp;100000);&nbsp;//&nbsp;sleep&nbsp;for&nbsp;0.1&nbsp;seconds<br><br>gpioSleep(PI_TIME_RELATIVE,&nbsp;60,&nbsp;0);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;sleep&nbsp;for&nbsp;one&nbsp;minute<br></code><h3><a name="gpioDelay"></a><a href="#uint32_t"><small>uint32_t</small></a> gpioDelay<small>(<a href="#uint32_t">uint32_t</a> <a href="#micros">micros</a>)</small></h3>
Delays for at least the number of microseconds specified by micros.
<br><br><code>micros:&nbsp;the&nbsp;number&nbsp;of&nbsp;microseconds&nbsp;to&nbsp;sleep<br></code><br><br>Returns the actual length of the delay in microseconds.
<br><br>Delays of 100 microseconds or less use busy waits.
<h3><a name="gpioTick"></a><a href="#uint32_t"><small>uint32_t</small></a> gpioTick<small>(void)</small></h3>
Returns the current system tick.
<br><br>Tick is the number of microseconds since system boot.
<br><br>As tick is an unsigned 32 bit quantity it wraps around after
2^32 microseconds, which is approximately 1 hour 12 minutes.
<br><br>You don't need to worry about the wrap around as long as you
take a tick (uint32_t) from another tick, i.e. the following
code will always provide the correct difference.
<br><br><b><small>Example</small></b><br><br><code>uint32_t&nbsp;startTick,&nbsp;endTick;<br>int&nbsp;diffTick;<br><br>startTick&nbsp;=&nbsp;gpioTick();<br><br>//&nbsp;do&nbsp;some&nbsp;processing<br><br>endTick&nbsp;=&nbsp;gpioTick();<br><br>diffTick&nbsp;=&nbsp;endTick&nbsp;-&nbsp;startTick;<br><br>printf("some&nbsp;processing&nbsp;took&nbsp;%d&nbsp;microseconds",&nbsp;diffTick);<br></code><h3><a name="gpioHardwareRevision"></a><a href="#unsigned"><small>unsigned</small></a> gpioHardwareRevision<small>(void)</small></h3>
Returns the hardware revision.
<br><br>If the hardware revision can not be found or is not a valid hexadecimal
number the function returns 0.
<br><br>The hardware revision is the last few characters on the Revision line of
/proc/cpuinfo.
<br><br>The revision number can be used to determine the assignment of GPIO
to pins (see <a href="#gpio">gpio</a>).
<br><br>There are at least three types of board.
<br><br>Type 1 boards have hardware revision numbers of 2 and 3.
<br><br>Type 2 boards have hardware revision numbers of 4, 5, 6, and 15.
<br><br>Type 3 boards have hardware revision numbers of 16 or greater.
<br><br>for "Revision       : 0002" the function returns 2.<br>
for "Revision       : 000f" the function returns 15.<br>
for "Revision       : 000g" the function returns 0.
<h3><a name="gpioVersion"></a><a href="#unsigned"><small>unsigned</small></a> gpioVersion<small>(void)</small></h3>
Returns the pigpio version.
<h3><a name="gpioGetPad"></a><a href="#int"><small>int</small></a> gpioGetPad<small>(<a href="#unsigned">unsigned</a> <a href="#pad">pad</a>)</small></h3>
This function returns the pad drive strength in mA.
<br><br><code>pad:&nbsp;0-2,&nbsp;the&nbsp;pad&nbsp;to&nbsp;get<br></code><br><br>Returns the pad drive strength if OK, otherwise PI_BAD_PAD.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Pad</td><td>GPIO</td></tr><tr><td>0</td><td>0-27</td></tr><tr><td>1</td><td>28-45</td></tr><tr><td>2</td><td>46-53</td></tr></tbody></table><br><br><b><small>Example</small></b><br><br><code>strength&nbsp;=&nbsp;gpioGetPad(1);&nbsp;//&nbsp;get&nbsp;pad&nbsp;1&nbsp;strength<br></code><h3><a name="gpioSetPad"></a><a href="#int"><small>int</small></a> gpioSetPad<small>(<a href="#unsigned">unsigned</a> <a href="#pad">pad</a>, <a href="#unsigned">unsigned</a> <a href="#padStrength">padStrength</a>)</small></h3>
This function sets the pad drive strength in mA.
<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pad:&nbsp;0-2,&nbsp;the&nbsp;pad&nbsp;to&nbsp;set<br>padStrength:&nbsp;1-16&nbsp;mA<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_PAD, or PI_BAD_STRENGTH.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Pad</td><td>GPIO</td></tr><tr><td>0</td><td>0-27</td></tr><tr><td>1</td><td>28-45</td></tr><tr><td>2</td><td>46-53</td></tr></tbody></table><br><br><b><small>Example</small></b><br><br><code>gpioSetPad(0,&nbsp;16);&nbsp;//&nbsp;set&nbsp;pad&nbsp;0&nbsp;strength&nbsp;to&nbsp;16&nbsp;mA<br></code><h3><a name="eventMonitor"></a><a href="#int"><small>int</small></a> eventMonitor<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#uint32_t">uint32_t</a> <a href="#bits">bits</a>)</small></h3>
This function selects the events to be reported on a previously
opened handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;<a href="#gpioNotifyOpen">gpioNotifyOpen</a><br>&nbsp;&nbsp;bits:&nbsp;a&nbsp;bit&nbsp;mask&nbsp;indicating&nbsp;the&nbsp;events&nbsp;of&nbsp;interest<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE.
<br><br>A report is sent each time an event is triggered providing the
corresponding bit in bits is set.
<br><br>See <a href="#gpioNotifyBegin">gpioNotifyBegin</a> for the notification format.
<br><br><b><small>Example</small></b><br><br><code>//&nbsp;Start&nbsp;reporting&nbsp;events&nbsp;3,&nbsp;6,&nbsp;and&nbsp;7.<br><br>//&nbsp;&nbsp;bit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;76543210<br>//&nbsp;(0xC8&nbsp;=&nbsp;0b11001000)<br><br>eventMonitor(h,&nbsp;0xC8);<br></code><h3><a name="eventSetFunc"></a><a href="#int"><small>int</small></a> eventSetFunc<small>(<a href="#unsigned">unsigned</a> <a href="#event">event</a>, <a href="#eventFunc_t">eventFunc_t</a> <a href="#f">f</a>)</small></h3>
Registers a function to be called (a callback) when the specified
event occurs.
<br><br><code>event:&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;callback&nbsp;function<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_EVENT_ID.
<br><br>One function may be registered per event.
<br><br>The function is passed the event, and the tick.
<br><br>The callback may be cancelled by passing NULL as the function.
<h3><a name="eventSetFuncEx"></a><a href="#int"><small>int</small></a> eventSetFuncEx<small>(<a href="#unsigned">unsigned</a> <a href="#event">event</a>, <a href="#eventFuncEx_t">eventFuncEx_t</a> <a href="#f">f</a>, <a href="#void">void</a> <a href="#*userdata">*userdata</a>)</small></h3>
Registers a function to be called (a callback) when the specified
event occurs.
<br><br><code>&nbsp;&nbsp;&nbsp;event:&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;callback&nbsp;function<br>userdata:&nbsp;pointer&nbsp;to&nbsp;arbitrary&nbsp;user&nbsp;data<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_EVENT_ID.
<br><br>One function may be registered per event.
<br><br>The function is passed the event, the tick, and the ueserdata pointer.
<br><br>The callback may be cancelled by passing NULL as the function.
<br><br>Only one of <a href="#eventSetFunc">eventSetFunc</a> or <a href="#eventSetFuncEx">eventSetFuncEx</a> can be
registered per event.
<h3><a name="eventTrigger"></a><a href="#int"><small>int</small></a> eventTrigger<small>(<a href="#unsigned">unsigned</a> <a href="#event">event</a>)</small></h3>
This function signals the occurrence of an event.
<br><br><code>event:&nbsp;0-31,&nbsp;the&nbsp;event<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_EVENT_ID.
<br><br>An event is a signal used to inform one or more consumers
to start an action.  Each consumer which has registered an interest
in the event (e.g. by calling <a href="#eventSetFunc">eventSetFunc</a>) will be informed by
a callback.
<br><br>One event, PI_EVENT_BSC (31) is predefined.  This event is
auto generated on BSC slave activity.
<br><br>The meaning of other events is arbitrary.
<br><br>Note that other than its id and its tick there is no data associated
with an event.
<h3><a name="shell"></a><a href="#int"><small>int</small></a> shell<small>(<a href="#char">char</a> <a href="#*scriptName">*scriptName</a>, <a href="#char">char</a> <a href="#*scriptString">*scriptString</a>)</small></h3>
This function uses the system call to execute a shell script
with the given string as its parameter.
<br><br><code>&nbsp;&nbsp;scriptName:&nbsp;the&nbsp;name&nbsp;of&nbsp;the&nbsp;script,&nbsp;only&nbsp;alphanumeric&nbsp;characters,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'-'&nbsp;and&nbsp;'_'&nbsp;are&nbsp;allowed&nbsp;in&nbsp;the&nbsp;name<br>scriptString:&nbsp;the&nbsp;string&nbsp;to&nbsp;pass&nbsp;to&nbsp;the&nbsp;script<br></code><br><br>The exit status of the system call is returned if OK, otherwise
PI_BAD_SHELL_STATUS.
<br><br>scriptName must exist in /opt/pigpio/cgi and must be executable.
<br><br>The returned exit status is normally 256 times that set by the
shell script exit function.  If the script can't be found 32512 will
be returned.
<br><br>The following table gives some example returned statuses.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Script exit status</td><td>Returned system call status</td></tr><tr><td>1</td><td>256</td></tr><tr><td>5</td><td>1280</td></tr><tr><td>10</td><td>2560</td></tr><tr><td>200</td><td>51200</td></tr><tr><td>script not found</td><td>32512</td></tr></tbody></table><br><br><b><small>Example</small></b><br><br><code>//&nbsp;pass&nbsp;two&nbsp;parameters,&nbsp;hello&nbsp;and&nbsp;world<br>status&nbsp;=&nbsp;shell("scr1",&nbsp;"hello&nbsp;world");<br><br>//&nbsp;pass&nbsp;three&nbsp;parameters,&nbsp;hello,&nbsp;string&nbsp;with&nbsp;spaces,&nbsp;and&nbsp;world<br>status&nbsp;=&nbsp;shell("scr1",&nbsp;"hello&nbsp;'string&nbsp;with&nbsp;spaces'&nbsp;world");<br><br>//&nbsp;pass&nbsp;one&nbsp;parameter,&nbsp;hello&nbsp;string&nbsp;with&nbsp;spaces&nbsp;world<br>status&nbsp;=&nbsp;shell("scr1",&nbsp;"\"hello&nbsp;string&nbsp;with&nbsp;spaces&nbsp;world\"");<br></code><h3><a name="fileOpen"></a><a href="#int"><small>int</small></a> fileOpen<small>(<a href="#char">char</a> <a href="#*file">*file</a>, <a href="#unsigned">unsigned</a> <a href="#mode">mode</a>)</small></h3>
This function returns a handle to a file opened in a specified mode.
<br><br><code>file:&nbsp;the&nbsp;file&nbsp;to&nbsp;open<br>mode:&nbsp;the&nbsp;file&nbsp;open&nbsp;mode<br></code><br><br>Returns a handle (&gt;=0) if OK, otherwise PI_NO_HANDLE, PI_NO_FILE_ACCESS,
PI_BAD_FILE_MODE, PI_FILE_OPEN_FAILED, or PI_FILE_IS_A_DIR.
<br><br>File
<br><br>A file may only be opened if permission is granted by an entry in
/opt/pigpio/access.  This is intended to allow remote access to files
in a more or less controlled manner.
<br><br>Each entry in /opt/pigpio/access takes the form of a file path
which may contain wildcards followed by a single letter permission.
The permission may be R for read, W for write, U for read/write,
and N for no access.
<br><br>Where more than one entry matches a file the most specific rule
applies.  If no entry matches a file then access is denied.
<br><br>Suppose /opt/pigpio/access contains the following entries
<br><br><code>/home/*&nbsp;n<br>/home/pi/shared/dir_1/*&nbsp;w<br>/home/pi/shared/dir_2/*&nbsp;r<br>/home/pi/shared/dir_3/*&nbsp;u<br>/home/pi/shared/dir_1/file.txt&nbsp;n<br></code><br><br>Files may be written in directory dir_1 with the exception
of file.txt.
<br><br>Files may be read in directory dir_2.
<br><br>Files may be read and written in directory dir_3.
<br><br>If a directory allows read, write, or read/write access then files may
be created in that directory.
<br><br>In an attempt to prevent risky permissions the following paths are
ignored in /opt/pigpio/access.
<br><br><code>a&nbsp;path&nbsp;containing&nbsp;..<br>a&nbsp;path&nbsp;containing&nbsp;only&nbsp;wildcards&nbsp;(*?)<br>a&nbsp;path&nbsp;containing&nbsp;less&nbsp;than&nbsp;two&nbsp;non-wildcard&nbsp;parts<br></code><br><br>Mode
<br><br>The mode may have the following values.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Macro</td><td>Value</td><td>Meaning</td></tr><tr><td>PI_FILE_READ</td><td>1</td><td>open file for reading</td></tr><tr><td>PI_FILE_WRITE</td><td>2</td><td>open file for writing</td></tr><tr><td>PI_FILE_RW</td><td>3</td><td>open file for reading and writing</td></tr></tbody></table><br><br>The following values may be or'd into the mode.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Macro</td><td>Value</td><td>Meaning</td></tr><tr><td>PI_FILE_APPEND</td><td>4</td><td>Writes append data to the end of the file</td></tr><tr><td>PI_FILE_CREATE</td><td>8</td><td>The file is created if it doesn't exist</td></tr><tr><td>PI_FILE_TRUNC</td><td>16</td><td>The file is truncated</td></tr></tbody></table><br><br>Newly created files are owned by root with permissions owner read and write.
<br><br><b><small>Example</small></b><br><br><code>#include&nbsp;&lt;stdio.h&gt;<br>#include&nbsp;&lt;pigpio.h&gt;<br><br>int&nbsp;main(int&nbsp;argc,&nbsp;char&nbsp;*argv[])<br>{<br>&nbsp;&nbsp;&nbsp;int&nbsp;handle,&nbsp;c;<br>&nbsp;&nbsp;&nbsp;char&nbsp;buf[60000];<br><br>&nbsp;&nbsp;&nbsp;if&nbsp;(gpioInitialise()&nbsp;&lt;&nbsp;0)&nbsp;return&nbsp;1;<br><br>&nbsp;&nbsp;&nbsp;//&nbsp;assumes&nbsp;/opt/pigpio/access&nbsp;contains&nbsp;the&nbsp;following&nbsp;line<br>&nbsp;&nbsp;&nbsp;//&nbsp;/ram/*.c&nbsp;r<br><br>&nbsp;&nbsp;&nbsp;handle&nbsp;=&nbsp;fileOpen("/ram/pigpio.c",&nbsp;PI_FILE_READ);<br><br>&nbsp;&nbsp;&nbsp;if&nbsp;(handle&nbsp;&gt;=&nbsp;0)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;((c=fileRead(handle,&nbsp;buf,&nbsp;sizeof(buf)-1)))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf[c]&nbsp;=&nbsp;0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("%s",&nbsp;buf);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fileClose(handle);<br>&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;gpioTerminate();<br>}<br></code><h3><a name="fileClose"></a><a href="#int"><small>int</small></a> fileClose<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>)</small></h3>
This function closes the file associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#fileOpen">fileOpen</a><br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE.
<br><br><b><small>Example</small></b><br><br><code>fileClose(h);<br></code><h3><a name="fileWrite"></a><a href="#int"><small>int</small></a> fileWrite<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This function writes count bytes from buf to the the file
associated with handle.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#fileOpen">fileOpen</a><br>&nbsp;&nbsp;&nbsp;buf:&nbsp;the&nbsp;array&nbsp;of&nbsp;bytes&nbsp;to&nbsp;write<br>&nbsp;count:&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;write<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM,
PI_FILE_NOT_WOPEN, or PI_BAD_FILE_WRITE.
<br><br><b><small>Example</small></b><br><br><code>status&nbsp;=&nbsp;fileWrite(h,&nbsp;buf,&nbsp;count);<br>if&nbsp;(status&nbsp;==&nbsp;0)<br>{<br>&nbsp;&nbsp;&nbsp;//&nbsp;okay<br>}<br>else<br>{<br>&nbsp;&nbsp;&nbsp;//&nbsp;error<br>}<br></code><h3><a name="fileRead"></a><a href="#int"><small>int</small></a> fileRead<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This function reads up to count bytes from the the file
associated with handle and writes them to buf.
<br><br><code>handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#fileOpen">fileOpen</a><br>&nbsp;&nbsp;&nbsp;buf:&nbsp;an&nbsp;array&nbsp;to&nbsp;receive&nbsp;the&nbsp;read&nbsp;data<br>&nbsp;count:&nbsp;the&nbsp;maximum&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;read<br></code><br><br>Returns the number of bytes read (&gt;=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, PI_FILE_NOT_ROPEN, or PI_BAD_FILE_WRITE.
<br><br><b><small>Example</small></b><br><br><code>if&nbsp;(fileRead(h,&nbsp;buf,&nbsp;sizeof(buf))&nbsp;&gt;&nbsp;0)<br>{<br>&nbsp;&nbsp;&nbsp;//&nbsp;process&nbsp;read&nbsp;data<br>}<br></code><h3><a name="fileSeek"></a><a href="#int"><small>int</small></a> fileSeek<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#int32_t">int32_t</a> <a href="#seekOffset">seekOffset</a>, <a href="#int">int</a> <a href="#seekFrom">seekFrom</a>)</small></h3>
This function seeks to a position within the file associated
with handle.
<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#fileOpen">fileOpen</a><br>seekOffset:&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;move.&nbsp;&nbsp;Positive&nbsp;offsets<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;move&nbsp;forward,&nbsp;negative&nbsp;offsets&nbsp;backwards.<br>&nbsp;&nbsp;seekFrom:&nbsp;one&nbsp;of&nbsp;PI_FROM_START&nbsp;(0),&nbsp;PI_FROM_CURRENT&nbsp;(1),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or&nbsp;PI_FROM_END&nbsp;(2)<br></code><br><br>Returns the new byte position within the file (&gt;=0) if OK, otherwise PI_BAD_HANDLE, or PI_BAD_FILE_SEEK.
<br><br><b><small>Example</small></b><br><br><code>fileSeek(0,&nbsp;20,&nbsp;PI_FROM_START);&nbsp;//&nbsp;Seek&nbsp;to&nbsp;start&nbsp;plus&nbsp;20<br><br>size&nbsp;=&nbsp;fileSeek(0,&nbsp;0,&nbsp;PI_FROM_END);&nbsp;//&nbsp;Seek&nbsp;to&nbsp;end,&nbsp;return&nbsp;size<br><br>pos&nbsp;=&nbsp;fileSeek(0,&nbsp;0,&nbsp;PI_FROM_CURRENT);&nbsp;//&nbsp;Return&nbsp;current&nbsp;position<br></code><h3><a name="fileList"></a><a href="#int"><small>int</small></a> fileList<small>(<a href="#char">char</a> <a href="#*fpat">*fpat</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#count">count</a>)</small></h3>
This function returns a list of files which match a pattern.  The
pattern may contain wildcards.
<br><br><code>&nbsp;fpat:&nbsp;file&nbsp;pattern&nbsp;to&nbsp;match<br>&nbsp;&nbsp;buf:&nbsp;an&nbsp;array&nbsp;to&nbsp;receive&nbsp;the&nbsp;matching&nbsp;file&nbsp;names<br>count:&nbsp;the&nbsp;maximum&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;read<br></code><br><br>Returns the number of returned bytes if OK, otherwise PI_NO_FILE_ACCESS,
or PI_NO_FILE_MATCH.
<br><br>The pattern must match an entry in /opt/pigpio/access.  The pattern
may contain wildcards.  See <a href="#fileOpen">fileOpen</a>.
<br><br>NOTE
<br><br>The returned value is not the number of files, it is the number
of bytes in the buffer.  The file names are separated by newline
characters.
<br><br><b><small>Example</small></b><br><br><code>#include&nbsp;&lt;stdio.h&gt;<br>#include&nbsp;&lt;pigpio.h&gt;<br><br>int&nbsp;main(int&nbsp;argc,&nbsp;char&nbsp;*argv[])<br>{<br>&nbsp;&nbsp;&nbsp;int&nbsp;c;<br>&nbsp;&nbsp;&nbsp;char&nbsp;buf[1000];<br><br>&nbsp;&nbsp;&nbsp;if&nbsp;(gpioInitialise()&nbsp;&lt;&nbsp;0)&nbsp;return&nbsp;1;<br><br>&nbsp;&nbsp;&nbsp;//&nbsp;assumes&nbsp;/opt/pigpio/access&nbsp;contains&nbsp;the&nbsp;following&nbsp;line<br>&nbsp;&nbsp;&nbsp;//&nbsp;/ram/*.c&nbsp;r<br><br>&nbsp;&nbsp;&nbsp;c&nbsp;=&nbsp;fileList("/ram/p*.c",&nbsp;buf,&nbsp;sizeof(buf));<br><br>&nbsp;&nbsp;&nbsp;if&nbsp;(c&nbsp;&gt;=&nbsp;0)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;terminate&nbsp;string<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf[c]&nbsp;=&nbsp;0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("%s",&nbsp;buf);<br>&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;gpioTerminate();<br>}<br></code><h3><a name="gpioCfgBufferSize"></a><a href="#int"><small>int</small></a> gpioCfgBufferSize<small>(<a href="#unsigned">unsigned</a> <a href="#cfgMillis">cfgMillis</a>)</small></h3>
Configures pigpio to buffer cfgMillis milliseconds of GPIO samples.
<br><br>This function is only effective if called before <a href="#gpioInitialise">gpioInitialise</a>.
<br><br><code>cfgMillis:&nbsp;100-10000<br></code><br><br>The default setting is 120 milliseconds.
<br><br>The intention is to allow for bursts of data and protection against
other processes hogging cpu time.
<br><br>I haven't seen a process locked out for more than 100 milliseconds.
<br><br>Making the buffer bigger uses a LOT of memory at the more frequent
sampling rates as shown in the following table in MBs.
<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buffer&nbsp;milliseconds<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;120&nbsp;250&nbsp;500&nbsp;1sec&nbsp;2sec&nbsp;4sec&nbsp;8sec<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;16&nbsp;&nbsp;31&nbsp;&nbsp;55&nbsp;&nbsp;107&nbsp;&nbsp;---&nbsp;&nbsp;---&nbsp;&nbsp;---<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10&nbsp;&nbsp;18&nbsp;&nbsp;31&nbsp;&nbsp;&nbsp;55&nbsp;&nbsp;107&nbsp;&nbsp;---&nbsp;&nbsp;---<br>sample&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;12&nbsp;&nbsp;18&nbsp;&nbsp;&nbsp;31&nbsp;&nbsp;&nbsp;55&nbsp;&nbsp;107&nbsp;&nbsp;---<br>&nbsp;rate&nbsp;&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;10&nbsp;&nbsp;14&nbsp;&nbsp;&nbsp;24&nbsp;&nbsp;&nbsp;45&nbsp;&nbsp;&nbsp;87&nbsp;&nbsp;---<br>&nbsp;(us)&nbsp;&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;12&nbsp;&nbsp;&nbsp;18&nbsp;&nbsp;&nbsp;31&nbsp;&nbsp;&nbsp;55&nbsp;&nbsp;107<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;10&nbsp;&nbsp;&nbsp;14&nbsp;&nbsp;&nbsp;24&nbsp;&nbsp;&nbsp;45&nbsp;&nbsp;&nbsp;87<br></code><h3><a name="gpioCfgClock"></a><a href="#int"><small>int</small></a> gpioCfgClock<small>(<a href="#unsigned">unsigned</a> <a href="#cfgMicros">cfgMicros</a>, <a href="#unsigned">unsigned</a> <a href="#cfgPeripheral">cfgPeripheral</a>, <a href="#unsigned">unsigned</a> <a href="#cfgSource">cfgSource</a>)</small></h3>
Configures pigpio to use a particular sample rate timed by a specified
peripheral.
<br><br>This function is only effective if called before <a href="#gpioInitialise">gpioInitialise</a>.
<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;cfgMicros:&nbsp;1,&nbsp;2,&nbsp;4,&nbsp;5,&nbsp;8,&nbsp;10<br>cfgPeripheral:&nbsp;0&nbsp;(PWM),&nbsp;1&nbsp;(PCM)<br>&nbsp;&nbsp;&nbsp;&nbsp;cfgSource:&nbsp;deprecated,&nbsp;value&nbsp;is&nbsp;ignored<br></code><br><br>The timings are provided by the specified peripheral (PWM or PCM).
<br><br>The default setting is 5 microseconds using the PCM peripheral.
<br><br>The approximate CPU percentage used for each sample rate is:
<br><br><code>sample&nbsp;&nbsp;cpu<br>&nbsp;rate&nbsp;&nbsp;&nbsp;&nbsp;%<br><br>&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;25<br>&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;16<br>&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;11<br>&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10<br>&nbsp;&nbsp;8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;15<br>&nbsp;10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;14<br></code><br><br>A sample rate of 5 microseconds seeems to be the sweet spot.
<h3><a name="gpioCfgDMAchannel"></a><a href="#int"><small>int</small></a> gpioCfgDMAchannel<small>(<a href="#unsigned">unsigned</a> <a href="#DMAchannel">DMAchannel</a>)</small></h3>
Configures pigpio to use the specified DMA channel.
<br><br>This function is only effective if called before <a href="#gpioInitialise">gpioInitialise</a>.
<br><br><code>DMAchannel:&nbsp;0-14<br></code><br><br>The default setting is to use channel 14.
<h3><a name="gpioCfgDMAchannels"></a><a href="#int"><small>int</small></a> gpioCfgDMAchannels<small>(<a href="#unsigned">unsigned</a> <a href="#primaryChannel">primaryChannel</a>, <a href="#unsigned">unsigned</a> <a href="#secondaryChannel">secondaryChannel</a>)</small></h3>
Configures pigpio to use the specified DMA channels.
<br><br>This function is only effective if called before <a href="#gpioInitialise">gpioInitialise</a>.
<br><br><code>&nbsp;&nbsp;primaryChannel:&nbsp;0-14<br>secondaryChannel:&nbsp;0-14<br></code><br><br>The default setting depends on whether the Pi has a BCM2711 chip or
not (currently only the Pi4B has a BCM2711).
<br><br>The default setting for a non-BCM2711 is to use channel 14 for the
primary channel and channel 6 for the secondary channel.
<br><br>The default setting for a BCM2711 is to use channel 7 for the
primary channel and channel 6 for the secondary channel.
<br><br>The secondary channel is only used for the transmission of waves.
<br><br>If possible use one of channels 0 to 6 for the secondary channel
(a full channel).
<br><br>A full channel only requires one DMA control block regardless of the
length of a pulse delay.  Channels 7 to 14 (lite channels) require
one DMA control block for each 16383 microseconds of delay.  I.e.
a 10 second pulse delay requires one control block on a full channel
and 611 control blocks on a lite channel.
<h3><a name="gpioCfgPermissions"></a><a href="#int"><small>int</small></a> gpioCfgPermissions<small>(<a href="#uint64_t">uint64_t</a> <a href="#updateMask">updateMask</a>)</small></h3>
Configures pigpio to restrict GPIO updates via the socket or pipe
interfaces to the GPIO specified by the mask.  Programs directly
calling the pigpio library (i.e. linked with -lpigpio are not
affected).  A GPIO update is a write to a GPIO or a GPIO mode
change or any function which would force such an action.
<br><br>This function is only effective if called before <a href="#gpioInitialise">gpioInitialise</a>.
<br><br><code>updateMask:&nbsp;bit&nbsp;(1&lt;&lt;n)&nbsp;is&nbsp;set&nbsp;for&nbsp;each&nbsp;GPIO&nbsp;n&nbsp;which&nbsp;may&nbsp;be&nbsp;updated<br></code><br><br>The default setting depends upon the Pi model. The user GPIO are
added to the mask.
<br><br>If the board revision is not recognised then GPIO 2-27 are allowed.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Unknown board</td><td>PI_DEFAULT_UPDATE_MASK_UNKNOWN</td><td>0x0FFFFFFC<br></td></tr><tr><td>Type 1 board</td><td>PI_DEFAULT_UPDATE_MASK_B1</td><td>0x03E6CF93<br></td></tr><tr><td>Type 2 board</td><td>PI_DEFAULT_UPDATE_MASK_A_B2</td><td>0xFBC6CF9C</td></tr><tr><td>Type 3 board</td><td>PI_DEFAULT_UPDATE_MASK_R3</td><td>0x0FFFFFFC</td></tr></tbody></table><h3><a name="gpioCfgSocketPort"></a><a href="#int"><small>int</small></a> gpioCfgSocketPort<small>(<a href="#unsigned">unsigned</a> <a href="#port">port</a>)</small></h3>
Configures pigpio to use the specified socket port.
<br><br>This function is only effective if called before <a href="#gpioInitialise">gpioInitialise</a>.
<br><br><code>port:&nbsp;1024-32000<br></code><br><br>The default setting is to use port 8888.
<h3><a name="gpioCfgInterfaces"></a><a href="#int"><small>int</small></a> gpioCfgInterfaces<small>(<a href="#unsigned">unsigned</a> <a href="#ifFlags">ifFlags</a>)</small></h3>
Configures pigpio support of the fifo and socket interfaces.
<br><br>This function is only effective if called before <a href="#gpioInitialise">gpioInitialise</a>.
<br><br><code>ifFlags:&nbsp;0-7<br></code><br><br>The default setting (0) is that both interfaces are enabled.
<br><br>Or in PI_DISABLE_FIFO_IF to disable the pipe interface.
<br><br>Or in PI_DISABLE_SOCK_IF to disable the socket interface.
<br><br>Or in PI_LOCALHOST_SOCK_IF to disable remote socket
access (this means that the socket interface is only
usable from the local Pi).
<h3><a name="gpioCfgMemAlloc"></a><a href="#int"><small>int</small></a> gpioCfgMemAlloc<small>(<a href="#unsigned">unsigned</a> <a href="#memAllocMode">memAllocMode</a>)</small></h3>
Selects the method of DMA memory allocation.
<br><br>This function is only effective if called before <a href="#gpioInitialise">gpioInitialise</a>.
<br><br><code>memAllocMode:&nbsp;0-2<br></code><br><br>There are two methods of DMA memory allocation.  The original method
uses the /proc/self/pagemap file to allocate bus memory.  The new
method uses the mailbox property interface to allocate bus memory.
<br><br>Auto will use the mailbox method unless a larger than default buffer
size is requested with <a href="#gpioCfgBufferSize">gpioCfgBufferSize</a>.
<h3><a name="gpioCfgNetAddr"></a><a href="#int"><small>int</small></a> gpioCfgNetAddr<small>(<a href="#int">int</a> <a href="#numSockAddr">numSockAddr</a>, <a href="#uint32_t">uint32_t</a> <a href="#*sockAddr">*sockAddr</a>)</small></h3>
Sets the network addresses which are allowed to talk over the
socket interface.
<br><br>This function is only effective if called before <a href="#gpioInitialise">gpioInitialise</a>.
<br><br><code>numSockAddr:&nbsp;0-256&nbsp;(0&nbsp;means&nbsp;all&nbsp;addresses&nbsp;allowed)<br>&nbsp;&nbsp;&nbsp;sockAddr:&nbsp;an&nbsp;array&nbsp;of&nbsp;permitted&nbsp;network&nbsp;addresses.<br></code><h3><a name="gpioCfgGetInternals"></a><a href="#uint32_t"><small>uint32_t</small></a> gpioCfgGetInternals<small>(void)</small></h3>
This function returns the current library internal configuration
settings.
<h3><a name="gpioCfgSetInternals"></a><a href="#int"><small>int</small></a> gpioCfgSetInternals<small>(<a href="#uint32_t">uint32_t</a> <a href="#cfgVal">cfgVal</a>)</small></h3>
This function sets the current library internal configuration
settings.
<br><br><code>cfgVal:&nbsp;see&nbsp;source&nbsp;code<br></code><h3><a name="gpioCustom1"></a><a href="#int"><small>int</small></a> gpioCustom1<small>(<a href="#unsigned">unsigned</a> <a href="#arg1">arg1</a>, <a href="#unsigned">unsigned</a> <a href="#arg2">arg2</a>, <a href="#char">char</a> <a href="#*argx">*argx</a>, <a href="#unsigned">unsigned</a> <a href="#argc">argc</a>)</small></h3>
This function is available for user customisation.
<br><br>It returns a single integer value.
<br><br><code>arg1:&nbsp;&gt;=0<br>arg2:&nbsp;&gt;=0<br>argx:&nbsp;extra&nbsp;(byte)&nbsp;arguments<br>argc:&nbsp;number&nbsp;of&nbsp;extra&nbsp;arguments<br></code><br><br>Returns &gt;= 0 if OK, less than 0 indicates a user defined error.
<h3><a name="gpioCustom2"></a><a href="#int"><small>int</small></a> gpioCustom2<small>(<a href="#unsigned">unsigned</a> <a href="#arg1">arg1</a>, <a href="#char">char</a> <a href="#*argx">*argx</a>, <a href="#unsigned">unsigned</a> <a href="#argc">argc</a>, <a href="#char">char</a> <a href="#*retBuf">*retBuf</a>, <a href="#unsigned">unsigned</a> <a href="#retMax">retMax</a>)</small></h3>
This function is available for user customisation.
<br><br>It differs from gpioCustom1 in that it returns an array of bytes
rather than just an integer.
<br><br>The returned value is an integer indicating the number of returned bytes.
<code>&nbsp;&nbsp;arg1:&nbsp;&gt;=0<br>&nbsp;&nbsp;argx:&nbsp;extra&nbsp;(byte)&nbsp;arguments<br>&nbsp;&nbsp;argc:&nbsp;number&nbsp;of&nbsp;extra&nbsp;arguments<br>retBuf:&nbsp;buffer&nbsp;for&nbsp;returned&nbsp;bytes<br>retMax:&nbsp;maximum&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;return<br></code><br><br>Returns &gt;= 0 if OK, less than 0 indicates a user defined error.
<br><br>The number of returned bytes must be retMax or less.
<h3><a name="rawWaveAddSPI"></a><a href="#int"><small>int</small></a> rawWaveAddSPI<small>(<a href="#rawSPI_t">rawSPI_t</a> <a href="#*spi">*spi</a>, <a href="#unsigned">unsigned</a> <a href="#offset">offset</a>, <a href="#unsigned">unsigned</a> <a href="#spiSS">spiSS</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#unsigned">unsigned</a> <a href="#spiTxBits">spiTxBits</a>, <a href="#unsigned">unsigned</a> <a href="#spiBitFirst">spiBitFirst</a>, <a href="#unsigned">unsigned</a> <a href="#spiBitLast">spiBitLast</a>, <a href="#unsigned">unsigned</a> <a href="#spiBits">spiBits</a>)</small></h3>
This function adds a waveform representing SPI data to the
existing waveform (if any).
<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spi:&nbsp;a&nbsp;pointer&nbsp;to&nbsp;a&nbsp;spi&nbsp;object<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;offset:&nbsp;microseconds&nbsp;from&nbsp;the&nbsp;start&nbsp;of&nbsp;the&nbsp;waveform<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spiSS:&nbsp;the&nbsp;slave&nbsp;select&nbsp;GPIO<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf:&nbsp;the&nbsp;bits&nbsp;to&nbsp;transmit,&nbsp;most&nbsp;significant&nbsp;bit&nbsp;first<br>&nbsp;&nbsp;spiTxBits:&nbsp;the&nbsp;number&nbsp;of&nbsp;bits&nbsp;to&nbsp;write<br>spiBitFirst:&nbsp;the&nbsp;first&nbsp;bit&nbsp;to&nbsp;read<br>&nbsp;spiBitLast:&nbsp;the&nbsp;last&nbsp;bit&nbsp;to&nbsp;read<br>&nbsp;&nbsp;&nbsp;&nbsp;spiBits:&nbsp;the&nbsp;number&nbsp;of&nbsp;bits&nbsp;to&nbsp;transfer<br></code><br><br>Returns the new total number of pulses in the current waveform if OK,
otherwise PI_BAD_USER_GPIO, PI_BAD_SER_OFFSET, or PI_TOO_MANY_PULSES.
<br><br>Not intended for general use.
<h3><a name="rawWaveAddGeneric"></a><a href="#int"><small>int</small></a> rawWaveAddGeneric<small>(<a href="#unsigned">unsigned</a> <a href="#numPulses">numPulses</a>, <a href="#rawWave_t">rawWave_t</a> <a href="#*pulses">*pulses</a>)</small></h3>
This function adds a number of pulses to the current waveform.
<br><br><code>numPulses:&nbsp;the&nbsp;number&nbsp;of&nbsp;pulses<br>&nbsp;&nbsp;&nbsp;pulses:&nbsp;the&nbsp;array&nbsp;containing&nbsp;the&nbsp;pulses<br></code><br><br>Returns the new total number of pulses in the current waveform if OK,
otherwise PI_TOO_MANY_PULSES.
<br><br>The advantage of this function over gpioWaveAddGeneric is that it
allows the setting of the flags field.
<br><br>The pulses are interleaved in time order within the existing waveform
(if any).
<br><br>Merging allows the waveform to be built in parts, that is the settings
for GPIO#1 can be added, and then GPIO#2 etc.
<br><br>If the added waveform is intended to start after or within the existing
waveform then the first pulse should consist of a delay.
<br><br>Not intended for general use.
<h3><a name="rawWaveCB"></a><a href="#unsigned"><small>unsigned</small></a> rawWaveCB<small>(void)</small></h3>
Returns the number of the cb being currently output.
<br><br>Not intended for general use.
<h3><a name="rawWaveCBAdr"></a><a href="#rawCbs_t"><small>rawCbs_t</small></a> *rawWaveCBAdr<small>(<a href="#int">int</a> <a href="#cbNum">cbNum</a>)</small></h3>
Return the (Linux) address of contol block cbNum.
<br><br><code>cbNum:&nbsp;the&nbsp;cb&nbsp;of&nbsp;interest<br></code><br><br>Not intended for general use.
<h3><a name="rawWaveGetOOL"></a><a href="#uint32_t"><small>uint32_t</small></a> rawWaveGetOOL<small>(<a href="#int">int</a> <a href="#pos">pos</a>)</small></h3>
Gets the OOL parameter stored at pos.
<br><br><code>pos:&nbsp;the&nbsp;position&nbsp;of&nbsp;interest.<br></code><br><br>Not intended for general use.
<h3><a name="rawWaveSetOOL"></a><a href="#void"><small>void</small></a> rawWaveSetOOL<small>(<a href="#int">int</a> <a href="#pos">pos</a>, <a href="#uint32_t">uint32_t</a> <a href="#lVal">lVal</a>)</small></h3>
Sets the OOL parameter stored at pos to value.
<br><br><code>&nbsp;pos:&nbsp;the&nbsp;position&nbsp;of&nbsp;interest<br>lVal:&nbsp;the&nbsp;value&nbsp;to&nbsp;write<br></code><br><br>Not intended for general use.
<h3><a name="rawWaveGetOut"></a><a href="#uint32_t"><small>uint32_t</small></a> rawWaveGetOut<small>(<a href="#int">int</a> <a href="#pos">pos</a>)</small></h3>
Gets the wave output parameter stored at pos.
<br><br>DEPRECATED: use rawWaveGetOOL instead.
<br><br><code>pos:&nbsp;the&nbsp;position&nbsp;of&nbsp;interest.<br></code><br><br>Not intended for general use.
<h3><a name="rawWaveSetOut"></a><a href="#void"><small>void</small></a> rawWaveSetOut<small>(<a href="#int">int</a> <a href="#pos">pos</a>, <a href="#uint32_t">uint32_t</a> <a href="#lVal">lVal</a>)</small></h3>
Sets the wave output parameter stored at pos to value.
<br><br>DEPRECATED: use rawWaveSetOOL instead.
<br><br><code>&nbsp;pos:&nbsp;the&nbsp;position&nbsp;of&nbsp;interest<br>lVal:&nbsp;the&nbsp;value&nbsp;to&nbsp;write<br></code><br><br>Not intended for general use.
<h3><a name="rawWaveGetIn"></a><a href="#uint32_t"><small>uint32_t</small></a> rawWaveGetIn<small>(<a href="#int">int</a> <a href="#pos">pos</a>)</small></h3>
Gets the wave input value parameter stored at pos.
<br><br>DEPRECATED: use rawWaveGetOOL instead.
<br><br><code>pos:&nbsp;the&nbsp;position&nbsp;of&nbsp;interest<br></code><br><br>Not intended for general use.
<h3><a name="rawWaveSetIn"></a><a href="#void"><small>void</small></a> rawWaveSetIn<small>(<a href="#int">int</a> <a href="#pos">pos</a>, <a href="#uint32_t">uint32_t</a> <a href="#lVal">lVal</a>)</small></h3>
Sets the wave input value stored at pos to value.
<br><br>DEPRECATED: use rawWaveSetOOL instead.
<br><br><code>&nbsp;pos:&nbsp;the&nbsp;position&nbsp;of&nbsp;interest<br>lVal:&nbsp;the&nbsp;value&nbsp;to&nbsp;write<br></code><br><br>Not intended for general use.
<h3><a name="rawWaveInfo"></a><a href="#rawWaveInfo_t"><small>rawWaveInfo_t</small></a> rawWaveInfo<small>(<a href="#int">int</a> <a href="#wave_id">wave_id</a>)</small></h3>
Gets details about the wave with id wave_id.
<br><br><code>wave_id:&nbsp;the&nbsp;wave&nbsp;of&nbsp;interest<br></code><br><br>Not intended for general use.
<h3><a name="getBitInBytes"></a><a href="#int"><small>int</small></a> getBitInBytes<small>(<a href="#int">int</a> <a href="#bitPos">bitPos</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#int">int</a> <a href="#numBits">numBits</a>)</small></h3>
Returns the value of the bit bitPos bits from the start of buf.  Returns
0 if bitPos is greater than or equal to numBits.
<br><br><code>&nbsp;bitPos:&nbsp;bit&nbsp;index&nbsp;from&nbsp;the&nbsp;start&nbsp;of&nbsp;buf<br>&nbsp;&nbsp;&nbsp;&nbsp;buf:&nbsp;array&nbsp;of&nbsp;bits<br>numBits:&nbsp;number&nbsp;of&nbsp;valid&nbsp;bits&nbsp;in&nbsp;buf<br></code><h3><a name="putBitInBytes"></a><a href="#void"><small>void</small></a> putBitInBytes<small>(<a href="#int">int</a> <a href="#bitPos">bitPos</a>, <a href="#char">char</a> <a href="#*buf">*buf</a>, <a href="#int">int</a> <a href="#bit">bit</a>)</small></h3>
Sets the bit bitPos bits from the start of buf to bit.
<br><br><code>bitPos:&nbsp;bit&nbsp;index&nbsp;from&nbsp;the&nbsp;start&nbsp;of&nbsp;buf<br>&nbsp;&nbsp;&nbsp;buf:&nbsp;array&nbsp;of&nbsp;bits<br>&nbsp;&nbsp;&nbsp;bit:&nbsp;0-1,&nbsp;value&nbsp;to&nbsp;set<br></code><h3><a name="time_time"></a><a href="#double"><small>double</small></a> time_time<small>(void)</small></h3>
Return the current time in seconds since the Epoch.
<h3><a name="time_sleep"></a><a href="#void"><small>void</small></a> time_sleep<small>(<a href="#double">double</a> <a href="#seconds">seconds</a>)</small></h3>
Delay execution for a given number of seconds
<br><br><code>seconds:&nbsp;the&nbsp;number&nbsp;of&nbsp;seconds&nbsp;to&nbsp;sleep<br></code><h3><a name="rawDumpWave"></a><a href="#void"><small>void</small></a> rawDumpWave<small>(void)</small></h3>
Used to print a readable version of the current waveform to stderr.
<br><br>Not intended for general use.
<h3><a name="rawDumpScript"></a><a href="#void"><small>void</small></a> rawDumpScript<small>(<a href="#unsigned">unsigned</a> <a href="#script_id">script_id</a>)</small></h3>
Used to print a readable version of a script to stderr.
<br><br><code>script_id:&nbsp;&gt;=0,&nbsp;a&nbsp;script_id&nbsp;returned&nbsp;by&nbsp;<a href="#gpioStoreScript">gpioStoreScript</a><br></code><br><br>Not intended for general use.
<h2>PARAMETERS</h2><h3><a name="active">active</a>: 0-1000000</h3>
The number of microseconds level changes are reported for once
a noise filter has been triggered (by <a href="#steady">steady</a> microseconds of
a stable level).
<h3><a name="arg1">arg1</a></h3>
An unsigned argument passed to a user customised function.  Its
meaning is defined by the customiser.
<h3><a name="arg2">arg2</a></h3>
An unsigned argument passed to a user customised function.  Its
meaning is defined by the customiser.
<h3><a name="argc">argc</a></h3>
The count of bytes passed to a user customised function.
<h3><a name="*argx">*argx</a></h3>
A pointer to an array of bytes passed to a user customised function.
Its meaning and content is defined by the customiser.
<h3><a name="baud">baud</a></h3>
The speed of serial communication (I2C, SPI, serial link, waves) in
bits per second.
<h3><a name="bit">bit</a></h3>
A value of 0 or 1.
<h3><a name="bitPos">bitPos</a></h3>
A bit position within a byte or word.  The least significant bit is
position 0.
<h3><a name="bits">bits</a></h3>
A value used to select GPIO.  If bit n of bits is set then GPIO n is
selected.
<br><br>A convenient way to set bit n is to or in (1&lt;&lt;n).
<br><br>e.g. to select bits 5, 9, 23 you could use (1&lt;&lt;5) | (1&lt;&lt;9) | (1&lt;&lt;23).
<h3><a name="*bsc_xfer">*bsc_xfer</a></h3>
A pointer to a <a href="#bsc_xfer_t">bsc_xfer_t</a> object used to control a BSC transfer.
<h3><a name="bsc_xfer_t">bsc_xfer_t</a></h3>
<code>typedef&nbsp;struct<br>{<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;control;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Write<br>&nbsp;&nbsp;&nbsp;int&nbsp;rxCnt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Read&nbsp;only<br>&nbsp;&nbsp;&nbsp;char&nbsp;rxBuf[BSC_FIFO_SIZE];&nbsp;//&nbsp;Read&nbsp;only<br>&nbsp;&nbsp;&nbsp;int&nbsp;txCnt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Write<br>&nbsp;&nbsp;&nbsp;char&nbsp;txBuf[BSC_FIFO_SIZE];&nbsp;//&nbsp;Write<br>}&nbsp;bsc_xfer_t;<br></code><h3><a name="*buf">*buf</a></h3>
A buffer to hold data being sent or being received.
<h3><a name="bufSize">bufSize</a></h3>
The size in bytes of a buffer.
<h3><a name="bVal">bVal</a>: 0-255 (Hex 0x0-0xFF, Octal 0-0377)</h3>
An 8-bit byte value.
<h3><a name="cbNum">cbNum</a></h3>
A number identifying a DMA contol block.
<h3><a name="cfgMicros">cfgMicros</a></h3>
The GPIO sample rate in microseconds.  The default is 5us, or 200 thousand
samples per second.
<h3><a name="cfgMillis">cfgMillis</a>: 100-10000</h3>
The size of the sample buffer in milliseconds.  Generally this should be
left at the default of 120ms.  If you expect intense bursts of signals it
might be necessary to increase the buffer size.
<h3><a name="cfgPeripheral">cfgPeripheral</a></h3>
One of the PWM or PCM peripherals used to pace DMA transfers for timing
purposes.
<h3><a name="cfgSource">cfgSource</a></h3>
Deprecated.
<h3><a name="cfgVal">cfgVal</a></h3>
A number specifying the value of a configuration item.  See <a href="#cfgWhat">cfgWhat</a>.
<h3><a name="cfgWhat">cfgWhat</a></h3>
A number specifying a configuration item.
<br><br>562484977: print enhanced statistics at termination.<br>
984762879: set the initial debug level.
<h3><a name="char">char</a></h3>
A single character, an 8 bit quantity able to store 0-255.
<h3><a name="clkfreq">clkfreq</a>: 4689-250M (13184-375M for the BCM2711)</h3>
The hardware clock frequency.
<br><br><code>PI_HW_CLK_MIN_FREQ&nbsp;4689<br>PI_HW_CLK_MAX_FREQ&nbsp;250000000<br>PI_HW_CLK_MAX_FREQ_2711&nbsp;375000000<br></code><h3><a name="count">count</a></h3>
The number of bytes to be transferred in an I2C, SPI, or Serial
command.
<h3><a name="CS">CS</a></h3>
The GPIO used for the slave select signal when bit banging SPI.
<h3><a name="data_bits">data_bits</a>: 1-32</h3>
The number of data bits to be used when adding serial data to a
waveform.
<br><br><code>PI_MIN_WAVE_DATABITS&nbsp;1<br>PI_MAX_WAVE_DATABITS&nbsp;32<br></code><h3><a name="DMAchannel">DMAchannel</a>: 0-15</h3>
<code>PI_MIN_DMA_CHANNEL&nbsp;0<br>PI_MAX_DMA_CHANNEL&nbsp;15<br></code><h3><a name="double">double</a></h3>
A floating point number.
<h3><a name="dutycycle">dutycycle</a>: 0-range</h3>
A number representing the ratio of on time to off time for PWM.
<br><br>The number may vary between 0 and range (default 255) where
0 is off and range is fully on.
<h3><a name="edge">edge</a>: 0-2</h3>
The type of GPIO edge to generate an interrupt.  See <a href="#gpioSetISRFunc">gpioSetISRFunc</a>
and <a href="#gpioSetISRFuncEx">gpioSetISRFuncEx</a>.
<br><br><code>RISING_EDGE&nbsp;0<br>FALLING_EDGE&nbsp;1<br>EITHER_EDGE&nbsp;2<br></code><h3><a name="event">event</a>: 0-31</h3>
An event is a signal used to inform one or more consumers
to start an action.
<h3><a name="eventFunc_t">eventFunc_t</a></h3>
<code>typedef&nbsp;void&nbsp;(*eventFunc_t)&nbsp;(int&nbsp;event,&nbsp;uint32_t&nbsp;tick);<br></code><h3><a name="eventFuncEx_t">eventFuncEx_t</a></h3>
<code>typedef&nbsp;void&nbsp;(*eventFuncEx_t)<br>&nbsp;&nbsp;&nbsp;(int&nbsp;event,&nbsp;uint32_t&nbsp;tick,&nbsp;void&nbsp;*userdata);<br></code><h3><a name="f">f</a></h3>
A function.
<h3><a name="*file">*file</a></h3>
A full file path.  To be accessible the path must match an entry in
/opt/pigpio/access.
<h3><a name="*fpat">*fpat</a></h3>
A file path which may contain wildcards.  To be accessible the path
must match an entry in /opt/pigpio/access.
<h3><a name="frequency">frequency</a>: &gt;=0</h3>
The number of times a GPIO is swiched on and off per second.  This
can be set per GPIO and may be as little as 5Hz or as much as
40KHz.  The GPIO will be on for a proportion of the time as defined
by its dutycycle.
<h3><a name="gpio">gpio</a></h3>
A Broadcom numbered GPIO, in the range 0-53.
<br><br>There  are 54 General Purpose Input Outputs (GPIO) named GPIO0 through
GPIO53.
<br><br>They are split into two  banks.   Bank  1  consists  of  GPIO0  through
GPIO31.  Bank 2 consists of GPIO32 through GPIO53.
<br><br>All the GPIO which are safe for the user to read and write are in
bank 1.  Not all GPIO in bank 1 are safe though.  Type 1 boards
have 17  safe GPIO.  Type 2 boards have 21.  Type 3 boards have 26.
<br><br>See <a href="#gpioHardwareRevision">gpioHardwareRevision</a>.
<br><br>The user GPIO are marked with an X in the following table.
<br><br><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;1&nbsp;&nbsp;2&nbsp;&nbsp;3&nbsp;&nbsp;4&nbsp;&nbsp;5&nbsp;&nbsp;6&nbsp;&nbsp;7&nbsp;&nbsp;8&nbsp;&nbsp;9&nbsp;10&nbsp;11&nbsp;12&nbsp;13&nbsp;14&nbsp;15<br>Type&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;X&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;X&nbsp;&nbsp;X<br>Type&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;X&nbsp;&nbsp;X<br>Type&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;16&nbsp;17&nbsp;18&nbsp;19&nbsp;20&nbsp;21&nbsp;22&nbsp;23&nbsp;24&nbsp;25&nbsp;26&nbsp;27&nbsp;28&nbsp;29&nbsp;30&nbsp;31<br>Type&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;-<br>Type&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;-&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X<br>Type&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;X&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;-&nbsp;&nbsp;-<br></code><h3><a name="gpioAlertFunc_t">gpioAlertFunc_t</a></h3>
<code>typedef&nbsp;void&nbsp;(*gpioAlertFunc_t)&nbsp;(int&nbsp;gpio,&nbsp;int&nbsp;level,&nbsp;uint32_t&nbsp;tick);<br></code><h3><a name="gpioAlertFuncEx_t">gpioAlertFuncEx_t</a></h3>
<code>typedef&nbsp;void&nbsp;(*eventFuncEx_t)<br>&nbsp;&nbsp;&nbsp;(int&nbsp;event,&nbsp;int&nbsp;level,&nbsp;uint32_t&nbsp;tick,&nbsp;void&nbsp;*userdata);<br></code><h3><a name="gpioCfg*">gpioCfg*</a></h3>
These functions are only effective if called before <a href="#gpioInitialise">gpioInitialise</a>.
<br><br><a href="#gpioCfgBufferSize">gpioCfgBufferSize</a><br>
<a href="#gpioCfgClock">gpioCfgClock</a><br>
<a href="#gpioCfgDMAchannel">gpioCfgDMAchannel</a><br>
<a href="#gpioCfgDMAchannels">gpioCfgDMAchannels</a><br>
<a href="#gpioCfgPermissions">gpioCfgPermissions</a><br>
<a href="#gpioCfgInterfaces">gpioCfgInterfaces</a><br>
<a href="#gpioCfgSocketPort">gpioCfgSocketPort</a><br>
<a href="#gpioCfgMemAlloc">gpioCfgMemAlloc</a>
<h3><a name="gpioGetSamplesFunc_t">gpioGetSamplesFunc_t</a></h3>
<code>typedef&nbsp;void&nbsp;(*gpioGetSamplesFunc_t)<br>&nbsp;&nbsp;&nbsp;(const&nbsp;gpioSample_t&nbsp;*samples,&nbsp;int&nbsp;numSamples);<br></code><h3><a name="gpioGetSamplesFuncEx_t">gpioGetSamplesFuncEx_t</a></h3>
<code>typedef&nbsp;void&nbsp;(*gpioGetSamplesFuncEx_t)<br>&nbsp;&nbsp;&nbsp;(const&nbsp;gpioSample_t&nbsp;*samples,&nbsp;int&nbsp;numSamples,&nbsp;void&nbsp;*userdata);<br></code><h3><a name="gpioISRFunc_t">gpioISRFunc_t</a></h3>
<code>typedef&nbsp;void&nbsp;(*gpioISRFunc_t)<br>&nbsp;&nbsp;&nbsp;(int&nbsp;gpio,&nbsp;int&nbsp;level,&nbsp;uint32_t&nbsp;tick);<br></code><h3><a name="gpioISRFuncEx_t">gpioISRFuncEx_t</a></h3>
<code>typedef&nbsp;void&nbsp;(*gpioISRFuncEx_t)<br>&nbsp;&nbsp;&nbsp;(int&nbsp;gpio,&nbsp;int&nbsp;level,&nbsp;uint32_t&nbsp;tick,&nbsp;void&nbsp;*userdata);<br></code><h3><a name="gpioPulse_t">gpioPulse_t</a></h3>
<code>typedef&nbsp;struct<br>{<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;gpioOn;<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;gpioOff;<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;usDelay;<br>}&nbsp;gpioPulse_t;<br></code><h3><a name="gpioSample_t">gpioSample_t</a></h3>
<code>typedef&nbsp;struct<br>{<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;tick;<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;level;<br>}&nbsp;gpioSample_t;<br></code><h3><a name="gpioSignalFunc_t">gpioSignalFunc_t</a></h3>
<code>typedef&nbsp;void&nbsp;(*gpioSignalFunc_t)&nbsp;(int&nbsp;signum);<br></code><h3><a name="gpioSignalFuncEx_t">gpioSignalFuncEx_t</a></h3>
<code>typedef&nbsp;void&nbsp;(*gpioSignalFuncEx_t)&nbsp;(int&nbsp;signum,&nbsp;void&nbsp;*userdata);<br></code><h3><a name="gpioThreadFunc_t">gpioThreadFunc_t</a></h3>
<code>typedef&nbsp;void&nbsp;*(gpioThreadFunc_t)&nbsp;(void&nbsp;*);<br></code><h3><a name="gpioTimerFunc_t">gpioTimerFunc_t</a></h3>
<code>typedef&nbsp;void&nbsp;(*gpioTimerFunc_t)&nbsp;(void);<br></code><h3><a name="gpioTimerFuncEx_t">gpioTimerFuncEx_t</a></h3>
<code>typedef&nbsp;void&nbsp;(*gpioTimerFuncEx_t)&nbsp;(void&nbsp;*userdata);<br></code><h3><a name="gpioWaveAdd*">gpioWaveAdd*</a></h3>
One of
<br><br><a href="#gpioWaveAddNew">gpioWaveAddNew</a><br>
<a href="#gpioWaveAddGeneric">gpioWaveAddGeneric</a><br>
<a href="#gpioWaveAddSerial">gpioWaveAddSerial</a>
<h3><a name="handle">handle</a>: &gt;=0</h3>
A number referencing an object opened by one of
<br><br><a href="#fileOpen">fileOpen</a><br>
<a href="#gpioNotifyOpen">gpioNotifyOpen</a><br>
<a href="#i2cOpen">i2cOpen</a><br>
<a href="#serOpen">serOpen</a><br>
<a href="#spiOpen">spiOpen</a>
<h3><a name="i2cAddr">i2cAddr</a>: 0-0x7F</h3>
The address of a device on the I2C bus.
<h3><a name="i2cBus">i2cBus</a>: &gt;=0</h3>
An I2C bus number.
<h3><a name="i2cFlags">i2cFlags</a>: 0</h3>
Flags which modify an I2C open command.  None are currently defined.
<h3><a name="i2cReg">i2cReg</a>: 0-255</h3>
A register of an I2C device.
<h3><a name="ifFlags">ifFlags</a>: 0-3</h3>
<code>PI_DISABLE_FIFO_IF&nbsp;1<br>PI_DISABLE_SOCK_IF&nbsp;2<br></code><h3><a name="*inBuf">*inBuf</a></h3>
A buffer used to pass data to a function.
<h3><a name="inLen">inLen</a></h3>
The number of bytes of data in a buffer.
<h3><a name="int">int</a></h3>
A whole number, negative or positive.
<h3><a name="int32_t">int32_t</a></h3>
A 32-bit signed value.
<h3><a name="invert">invert</a></h3>
A flag used to set normal or inverted bit bang serial data level logic.
<h3><a name="level">level</a></h3>
The level of a GPIO.  Low or High.
<br><br><code>PI_OFF&nbsp;0<br>PI_ON&nbsp;1<br><br>PI_CLEAR&nbsp;0<br>PI_SET&nbsp;1<br><br>PI_LOW&nbsp;0<br>PI_HIGH&nbsp;1<br></code><br><br>There is one exception.  If a watchdog expires on a GPIO the level will be
reported as PI_TIMEOUT.  See <a href="#gpioSetWatchdog">gpioSetWatchdog</a>.
<br><br><code>PI_TIMEOUT&nbsp;2<br></code><h3><a name="lVal">lVal</a>: 0-4294967295 (Hex 0x0-0xFFFFFFFF, Octal 0-37777777777)</h3>
A 32-bit word value.
<h3><a name="memAllocMode">memAllocMode</a>: 0-2</h3>
The DMA memory allocation mode.
<br><br><code>PI_MEM_ALLOC_AUTO&nbsp;&nbsp;&nbsp;&nbsp;0<br>PI_MEM_ALLOC_PAGEMAP&nbsp;1<br>PI_MEM_ALLOC_MAILBOX&nbsp;2<br></code><h3><a name="*micros">*micros</a></h3>
A value representing microseconds.
<h3><a name="micros">micros</a></h3>
A value representing microseconds.
<h3><a name="millis">millis</a></h3>
A value representing milliseconds.
<h3><a name="MISO">MISO</a></h3>
The GPIO used for the MISO signal when bit banging SPI.
<h3><a name="mode">mode</a></h3>
1. The operational mode of a GPIO, normally INPUT or OUTPUT.
<br><br><code>PI_INPUT&nbsp;0<br>PI_OUTPUT&nbsp;1<br>PI_ALT0&nbsp;4<br>PI_ALT1&nbsp;5<br>PI_ALT2&nbsp;6<br>PI_ALT3&nbsp;7<br>PI_ALT4&nbsp;3<br>PI_ALT5&nbsp;2<br></code><br><br>2. A file open mode.
<br><br><code>PI_FILE_READ&nbsp;&nbsp;1<br>PI_FILE_WRITE&nbsp;2<br>PI_FILE_RW&nbsp;&nbsp;&nbsp;&nbsp;3<br></code><br><br>The following values can be or'd into the mode.
<br><br><code>PI_FILE_APPEND&nbsp;4<br>PI_FILE_CREATE&nbsp;8<br>PI_FILE_TRUNC&nbsp;&nbsp;16<br></code><h3><a name="MOSI">MOSI</a></h3>
The GPIO used for the MOSI signal when bit banging SPI.
<h3><a name="numBits">numBits</a></h3>
The number of bits stored in a buffer.
<h3><a name="numBytes">numBytes</a></h3>
The number of bytes used to store characters in a string.  Depending
on the number of bits per character there may be 1, 2, or 4 bytes
per character.
<h3><a name="numPar">numPar</a>: 0-10</h3>
The number of parameters passed to a script.
<h3><a name="numPulses">numPulses</a></h3>
The number of pulses to be added to a waveform.
<h3><a name="numSegs">numSegs</a></h3>
The number of segments in a combined I2C transaction.
<h3><a name="numSockAddr">numSockAddr</a></h3>
The number of network addresses allowed to use the socket interface.
<br><br>0 means all addresses allowed.
<h3><a name="offset">offset</a></h3>
The associated data starts this number of microseconds from the start of
the waveform.
<h3><a name="*outBuf">*outBuf</a></h3>
A buffer used to return data from a function.
<h3><a name="outLen">outLen</a></h3>
The size in bytes of an output buffer.
<h3><a name="pad">pad</a>: 0-2</h3>
A set of GPIO which share common drivers.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Pad</td><td>GPIO</td></tr><tr><td>0</td><td>0-27</td></tr><tr><td>1</td><td>28-45</td></tr><tr><td>2</td><td>46-53</td></tr></tbody></table><h3><a name="padStrength">padStrength</a>: 1-16</h3>
The mA which may be drawn from each GPIO whilst still guaranteeing the
high and low levels.
<h3><a name="*param">*param</a></h3>
An array of script parameters.
<h3><a name="pctBOOL">pctBOOL</a>: 0-100</h3>
percent On-Off-Level (OOL) buffer to consume for wave output.
<h3><a name="pctCB">pctCB</a>: 0-100</h3>
the percent of all DMA control blocks to consume.
<h3><a name="pctTOOL">pctTOOL</a>: 0-100</h3>
the percent of OOL buffer to consume for wave input (flags).
<h3><a name="pi_i2c_msg_t">pi_i2c_msg_t</a></h3>
<code>typedef&nbsp;struct<br>{<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;addr;&nbsp;&nbsp;//&nbsp;slave&nbsp;address<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;flags;<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;len;&nbsp;&nbsp;&nbsp;//&nbsp;msg&nbsp;length<br>&nbsp;&nbsp;&nbsp;uint8_t&nbsp;&nbsp;*buf;&nbsp;&nbsp;//&nbsp;pointer&nbsp;to&nbsp;msg&nbsp;data<br>}&nbsp;pi_i2c_msg_t;<br></code><h3><a name="port">port</a>: 1024-32000</h3>
The port used to bind to the pigpio socket.  Defaults to 8888.
<h3><a name="pos">pos</a></h3>
The position of an item.
<h3><a name="primaryChannel">primaryChannel</a>: 0-15</h3>
The DMA channel used to time the sampling of GPIO and to time servo and
PWM pulses.
<h3><a name="*pth">*pth</a></h3>
A thread identifier, returned by <a href="#gpioStartThread">gpioStartThread</a>.
<h3><a name="pthread_t">pthread_t</a></h3>
A thread identifier.
<h3><a name="pud">pud</a>: 0-2</h3>
The setting of the pull up/down resistor for a GPIO, which may be off,
pull-up, or pull-down.
<br><br><code>PI_PUD_OFF&nbsp;0<br>PI_PUD_DOWN&nbsp;1<br>PI_PUD_UP&nbsp;2<br></code><h3><a name="pulseLen">pulseLen</a></h3>
1-100, the length of a trigger pulse in microseconds.
<h3><a name="*pulses">*pulses</a></h3>
An array of pulses to be added to a waveform.
<h3><a name="pulsewidth">pulsewidth</a>: 0, 500-2500</h3>
<code>PI_SERVO_OFF&nbsp;0<br>PI_MIN_SERVO_PULSEWIDTH&nbsp;500<br>PI_MAX_SERVO_PULSEWIDTH&nbsp;2500<br></code><h3><a name="PWMduty">PWMduty</a>: 0-1000000 (1M)</h3>
The hardware PWM dutycycle.
<br><br><code>PI_HW_PWM_RANGE&nbsp;1000000<br></code><h3><a name="PWMfreq">PWMfreq</a>: 1-125M (1-187.5M for the BCM2711)</h3>
The hardware PWM frequency.
<br><br><code>PI_HW_PWM_MIN_FREQ&nbsp;1<br>PI_HW_PWM_MAX_FREQ&nbsp;125000000<br>PI_HW_PWM_MAX_FREQ_2711&nbsp;187500000<br></code><h3><a name="range">range</a>: 25-40000</h3>
<code>PI_MIN_DUTYCYCLE_RANGE&nbsp;25<br>PI_MAX_DUTYCYCLE_RANGE&nbsp;40000<br></code><h3><a name="rawCbs_t">rawCbs_t</a></h3>
<code>typedef&nbsp;struct&nbsp;//&nbsp;linux/arch/arm/mach-bcm2708/include/mach/dma.h<br>{<br>&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;info;<br>&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;src;<br>&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;dst;<br>&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;length;<br>&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;stride;<br>&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;next;<br>&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;pad[2];<br>}&nbsp;rawCbs_t;<br></code><h3><a name="rawSPI_t">rawSPI_t</a></h3>
<code>typedef&nbsp;struct<br>{<br>&nbsp;&nbsp;&nbsp;int&nbsp;clk;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;GPIO&nbsp;for&nbsp;clock<br>&nbsp;&nbsp;&nbsp;int&nbsp;mosi;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;GPIO&nbsp;for&nbsp;MOSI<br>&nbsp;&nbsp;&nbsp;int&nbsp;miso;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;GPIO&nbsp;for&nbsp;MISO<br>&nbsp;&nbsp;&nbsp;int&nbsp;ss_pol;&nbsp;&nbsp;//&nbsp;slave&nbsp;select&nbsp;off&nbsp;state<br>&nbsp;&nbsp;&nbsp;int&nbsp;ss_us;&nbsp;&nbsp;&nbsp;//&nbsp;delay&nbsp;after&nbsp;slave&nbsp;select<br>&nbsp;&nbsp;&nbsp;int&nbsp;clk_pol;&nbsp;//&nbsp;clock&nbsp;off&nbsp;state<br>&nbsp;&nbsp;&nbsp;int&nbsp;clk_pha;&nbsp;//&nbsp;clock&nbsp;phase<br>&nbsp;&nbsp;&nbsp;int&nbsp;clk_us;&nbsp;&nbsp;//&nbsp;clock&nbsp;micros<br>}&nbsp;rawSPI_t;<br></code><h3><a name="rawWave_t">rawWave_t</a></h3>
<code>typedef&nbsp;struct<br>{<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;gpioOn;<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;gpioOff;<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;usDelay;<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;flags;<br>}&nbsp;rawWave_t;<br></code><h3><a name="rawWaveInfo_t">rawWaveInfo_t</a></h3>
<code>typedef&nbsp;struct<br>{<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;botCB;&nbsp;&nbsp;//&nbsp;first&nbsp;CB&nbsp;used&nbsp;by&nbsp;wave<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;topCB;&nbsp;&nbsp;//&nbsp;last&nbsp;CB&nbsp;used&nbsp;by&nbsp;wave<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;botOOL;&nbsp;//&nbsp;last&nbsp;OOL&nbsp;used&nbsp;by&nbsp;wave<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;topOOL;&nbsp;//&nbsp;first&nbsp;OOL&nbsp;used&nbsp;by&nbsp;wave<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;deleted;<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;numCB;<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;numBOOL;<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;numTOOL;<br>}&nbsp;rawWaveInfo_t;<br></code><h3><a name="*retBuf">*retBuf</a></h3>
A buffer to hold a number of bytes returned to a used customised function,
<h3><a name="retMax">retMax</a></h3>
The maximum number of bytes a user customised function should return.
<h3><a name="*rxBuf">*rxBuf</a></h3>
A pointer to a buffer to receive data.
<h3><a name="SCL">SCL</a></h3>
The user GPIO to use for the clock when bit banging I2C.
<h3><a name="SCLK">SCLK</a></h3>
The GPIO used for the SCLK signal when bit banging SPI.
<h3><a name="*script">*script</a></h3>
A pointer to the text of a script.
<h3><a name="script_id">script_id</a></h3>
An id of a stored script as returned by <a href="#gpioStoreScript">gpioStoreScript</a>.
<h3><a name="*scriptName">*scriptName</a></h3>
The name of a <a href="#shell">shell</a> script to be executed.  The script must be present in
/opt/pigpio/cgi and must have execute permission.
<h3><a name="*scriptString">*scriptString</a></h3>
The string to be passed to a <a href="#shell">shell</a> script to be executed.
<h3><a name="SDA">SDA</a></h3>
The user GPIO to use for data when bit banging I2C.
<h3><a name="secondaryChannel">secondaryChannel</a>: 0-6</h3>
The DMA channel used to time output waveforms.
<h3><a name="*seconds">*seconds</a></h3>
A pointer to a uint32_t to store the second component of
a returned time.
<h3><a name="seconds">seconds</a></h3>
The number of seconds.
<h3><a name="seekFrom">seekFrom</a></h3>
<code>PI_FROM_START&nbsp;&nbsp;&nbsp;0<br>PI_FROM_CURRENT&nbsp;1<br>PI_FROM_END&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2<br></code><h3><a name="seekOffset">seekOffset</a></h3>
The number of bytes to move forward (positive) or backwards (negative)
from the seek position (start, current, or end of file).
<h3><a name="*segs">*segs</a></h3>
An array of segments which make up a combined I2C transaction.
<h3><a name="serFlags">serFlags</a></h3>
Flags which modify a serial open command.  None are currently defined.
<h3><a name="*sertty">*sertty</a></h3>
The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1.
<h3><a name="setting">setting</a></h3>
A value used to set a flag, 0 for false, non-zero for true.
<h3><a name="signum">signum</a>: 0-63</h3>
<code>PI_MIN_SIGNUM&nbsp;0<br>PI_MAX_SIGNUM&nbsp;63<br></code><h3><a name="size_t">size_t</a></h3>
A standard type used to indicate the size of an object in bytes.
<h3><a name="*sockAddr">*sockAddr</a></h3>
An array of network addresses allowed to use the socket interface encoded
as 32 bit numbers.
<br><br>E.g. address 192.168.1.66 would be encoded as 0x4201a8c0.
<h3><a name="*spi">*spi</a></h3>
A pointer to a <a href="#rawSPI_t">rawSPI_t</a> structure.
<h3><a name="spiBitFirst">spiBitFirst</a></h3>
GPIO reads are made from spiBitFirst to spiBitLast.
<h3><a name="spiBitLast">spiBitLast</a></h3>
GPIO reads are made from spiBitFirst to spiBitLast.
<h3><a name="spiBits">spiBits</a></h3>
The number of bits to transfer in a raw SPI transaction.
<h3><a name="spiChan">spiChan</a></h3>
A SPI channel, 0-2.
<h3><a name="spiFlags">spiFlags</a></h3>
See <a href="#spiOpen">spiOpen</a> and <a href="#bbSPIOpen">bbSPIOpen</a>.
<h3><a name="spiSS">spiSS</a></h3>
The SPI slave select GPIO in a raw SPI transaction.
<h3><a name="spiTxBits">spiTxBits</a></h3>
The number of bits to transfer dring a raw SPI transaction
<h3><a name="steady">steady</a>: 0-300000</h3>
The number of microseconds level changes must be stable for
before reporting the level changed (<a href="#gpioGlitchFilter">gpioGlitchFilter</a>) or triggering
the active part of a noise filter (<a href="#gpioNoiseFilter">gpioNoiseFilter</a>).
<h3><a name="stop_bits">stop_bits</a>: 2-8</h3>
The number of (half) stop bits to be used when adding serial data
to a waveform.
<br><br><code>PI_MIN_WAVE_HALFSTOPBITS&nbsp;2<br>PI_MAX_WAVE_HALFSTOPBITS&nbsp;8<br></code><h3><a name="*str">*str</a></h3>
An array of characters.
<h3><a name="timeout">timeout</a></h3>
A GPIO level change timeout in milliseconds.
<br><br><a href="#gpioSetWatchdog">gpioSetWatchdog</a>
<code>PI_MIN_WDOG_TIMEOUT&nbsp;0<br>PI_MAX_WDOG_TIMEOUT&nbsp;60000<br></code><br><br><a href="#gpioSetISRFunc">gpioSetISRFunc</a> and <a href="#gpioSetISRFuncEx">gpioSetISRFuncEx</a>
<code>&lt;=0&nbsp;cancel&nbsp;timeout<br>&gt;0&nbsp;timeout&nbsp;after&nbsp;specified&nbsp;milliseconds<br></code><h3><a name="timer">timer</a></h3>
<code>PI_MIN_TIMER&nbsp;0<br>PI_MAX_TIMER&nbsp;9<br></code><h3><a name="timetype">timetype</a></h3>
<code>PI_TIME_RELATIVE&nbsp;0<br>PI_TIME_ABSOLUTE&nbsp;1<br></code><h3><a name="*txBuf">*txBuf</a></h3>
An array of bytes to transmit.
<h3><a name="uint32_t">uint32_t</a>: 0-0-4,294,967,295 (Hex 0x0-0xFFFFFFFF)</h3>
A 32-bit unsigned value.
<h3><a name="uint64_t">uint64_t</a>: 0-(2^64)-1</h3>
A 64-bit unsigned value.
<h3><a name="unsigned">unsigned</a></h3>
A whole number &gt;= 0.
<h3><a name="updateMask">updateMask</a></h3>
A 64 bit mask indicating which GPIO may be written to by the user.
<br><br>If GPIO#n may be written then bit (1&lt;&lt;n) is set.
<h3><a name="user_gpio">user_gpio</a></h3>
0-31, a Broadcom numbered GPIO.
<br><br>See <a href="#gpio">gpio</a>.
<h3><a name="*userdata">*userdata</a></h3>
A pointer to arbitrary user data.  This may be used to identify the instance.
<br><br>You must ensure that the pointer is in scope at the time it is processed.  If
it is a pointer to a global this is automatic.  Do not pass the address of a
local variable.  If you want to pass a transient object then use the
following technique.
<br><br>In the calling function:
<br><br><code>user_type&nbsp;*userdata;<br><br>user_type&nbsp;my_userdata;<br><br>userdata&nbsp;=&nbsp;malloc(sizeof(user_type));<br><br>*userdata&nbsp;=&nbsp;my_userdata;<br></code><br><br>In the receiving function:
<br><br><code>user_type&nbsp;my_userdata&nbsp;=&nbsp;*(user_type*)userdata;<br><br>free(userdata);<br></code><h3><a name="void">void</a></h3>
Denoting no parameter is required
<h3><a name="wave_id">wave_id</a></h3>
A number identifying a waveform created by <a href="#gpioWaveCreate">gpioWaveCreate</a>.
<h3><a name="wave_mode">wave_mode</a></h3>
The mode determines if the waveform is sent once or cycles
repeatedly.  The SYNC variants wait for the current waveform
to reach the end of a cycle or finish before starting the new
waveform.
<br><br><code>PI_WAVE_MODE_ONE_SHOT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0<br>PI_WAVE_MODE_REPEAT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1<br>PI_WAVE_MODE_ONE_SHOT_SYNC&nbsp;2<br>PI_WAVE_MODE_REPEAT_SYNC&nbsp;&nbsp;&nbsp;3<br></code><h3><a name="wVal">wVal</a>: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)</h3>
A 16-bit word value.
<h2>Socket Command Codes</h2><code><br>#define&nbsp;PI_CMD_MODES&nbsp;&nbsp;0<br>#define&nbsp;PI_CMD_MODEG&nbsp;&nbsp;1<br>#define&nbsp;PI_CMD_PUD&nbsp;&nbsp;&nbsp;&nbsp;2<br>#define&nbsp;PI_CMD_READ&nbsp;&nbsp;&nbsp;3<br>#define&nbsp;PI_CMD_WRITE&nbsp;&nbsp;4<br>#define&nbsp;PI_CMD_PWM&nbsp;&nbsp;&nbsp;&nbsp;5<br>#define&nbsp;PI_CMD_PRS&nbsp;&nbsp;&nbsp;&nbsp;6<br>#define&nbsp;PI_CMD_PFS&nbsp;&nbsp;&nbsp;&nbsp;7<br>#define&nbsp;PI_CMD_SERVO&nbsp;&nbsp;8<br>#define&nbsp;PI_CMD_WDOG&nbsp;&nbsp;&nbsp;9<br>#define&nbsp;PI_CMD_BR1&nbsp;&nbsp;&nbsp;10<br>#define&nbsp;PI_CMD_BR2&nbsp;&nbsp;&nbsp;11<br>#define&nbsp;PI_CMD_BC1&nbsp;&nbsp;&nbsp;12<br>#define&nbsp;PI_CMD_BC2&nbsp;&nbsp;&nbsp;13<br>#define&nbsp;PI_CMD_BS1&nbsp;&nbsp;&nbsp;14<br>#define&nbsp;PI_CMD_BS2&nbsp;&nbsp;&nbsp;15<br>#define&nbsp;PI_CMD_TICK&nbsp;&nbsp;16<br>#define&nbsp;PI_CMD_HWVER&nbsp;17<br>#define&nbsp;PI_CMD_NO&nbsp;&nbsp;&nbsp;&nbsp;18<br>#define&nbsp;PI_CMD_NB&nbsp;&nbsp;&nbsp;&nbsp;19<br>#define&nbsp;PI_CMD_NP&nbsp;&nbsp;&nbsp;&nbsp;20<br>#define&nbsp;PI_CMD_NC&nbsp;&nbsp;&nbsp;&nbsp;21<br>#define&nbsp;PI_CMD_PRG&nbsp;&nbsp;&nbsp;22<br>#define&nbsp;PI_CMD_PFG&nbsp;&nbsp;&nbsp;23<br>#define&nbsp;PI_CMD_PRRG&nbsp;&nbsp;24<br>#define&nbsp;PI_CMD_HELP&nbsp;&nbsp;25<br>#define&nbsp;PI_CMD_PIGPV&nbsp;26<br>#define&nbsp;PI_CMD_WVCLR&nbsp;27<br>#define&nbsp;PI_CMD_WVAG&nbsp;&nbsp;28<br>#define&nbsp;PI_CMD_WVAS&nbsp;&nbsp;29<br>#define&nbsp;PI_CMD_WVGO&nbsp;&nbsp;30<br>#define&nbsp;PI_CMD_WVGOR&nbsp;31<br>#define&nbsp;PI_CMD_WVBSY&nbsp;32<br>#define&nbsp;PI_CMD_WVHLT&nbsp;33<br>#define&nbsp;PI_CMD_WVSM&nbsp;&nbsp;34<br>#define&nbsp;PI_CMD_WVSP&nbsp;&nbsp;35<br>#define&nbsp;PI_CMD_WVSC&nbsp;&nbsp;36<br>#define&nbsp;PI_CMD_TRIG&nbsp;&nbsp;37<br>#define&nbsp;PI_CMD_PROC&nbsp;&nbsp;38<br>#define&nbsp;PI_CMD_PROCD&nbsp;39<br>#define&nbsp;PI_CMD_PROCR&nbsp;40<br>#define&nbsp;PI_CMD_PROCS&nbsp;41<br>#define&nbsp;PI_CMD_SLRO&nbsp;&nbsp;42<br>#define&nbsp;PI_CMD_SLR&nbsp;&nbsp;&nbsp;43<br>#define&nbsp;PI_CMD_SLRC&nbsp;&nbsp;44<br>#define&nbsp;PI_CMD_PROCP&nbsp;45<br>#define&nbsp;PI_CMD_MICS&nbsp;&nbsp;46<br>#define&nbsp;PI_CMD_MILS&nbsp;&nbsp;47<br>#define&nbsp;PI_CMD_PARSE&nbsp;48<br>#define&nbsp;PI_CMD_WVCRE&nbsp;49<br>#define&nbsp;PI_CMD_WVDEL&nbsp;50<br>#define&nbsp;PI_CMD_WVTX&nbsp;&nbsp;51<br>#define&nbsp;PI_CMD_WVTXR&nbsp;52<br>#define&nbsp;PI_CMD_WVNEW&nbsp;53<br><br>#define&nbsp;PI_CMD_I2CO&nbsp;&nbsp;54<br>#define&nbsp;PI_CMD_I2CC&nbsp;&nbsp;55<br>#define&nbsp;PI_CMD_I2CRD&nbsp;56<br>#define&nbsp;PI_CMD_I2CWD&nbsp;57<br>#define&nbsp;PI_CMD_I2CWQ&nbsp;58<br>#define&nbsp;PI_CMD_I2CRS&nbsp;59<br>#define&nbsp;PI_CMD_I2CWS&nbsp;60<br>#define&nbsp;PI_CMD_I2CRB&nbsp;61<br>#define&nbsp;PI_CMD_I2CWB&nbsp;62<br>#define&nbsp;PI_CMD_I2CRW&nbsp;63<br>#define&nbsp;PI_CMD_I2CWW&nbsp;64<br>#define&nbsp;PI_CMD_I2CRK&nbsp;65<br>#define&nbsp;PI_CMD_I2CWK&nbsp;66<br>#define&nbsp;PI_CMD_I2CRI&nbsp;67<br>#define&nbsp;PI_CMD_I2CWI&nbsp;68<br>#define&nbsp;PI_CMD_I2CPC&nbsp;69<br>#define&nbsp;PI_CMD_I2CPK&nbsp;70<br><br>#define&nbsp;PI_CMD_SPIO&nbsp;&nbsp;71<br>#define&nbsp;PI_CMD_SPIC&nbsp;&nbsp;72<br>#define&nbsp;PI_CMD_SPIR&nbsp;&nbsp;73<br>#define&nbsp;PI_CMD_SPIW&nbsp;&nbsp;74<br>#define&nbsp;PI_CMD_SPIX&nbsp;&nbsp;75<br><br>#define&nbsp;PI_CMD_SERO&nbsp;&nbsp;76<br>#define&nbsp;PI_CMD_SERC&nbsp;&nbsp;77<br>#define&nbsp;PI_CMD_SERRB&nbsp;78<br>#define&nbsp;PI_CMD_SERWB&nbsp;79<br>#define&nbsp;PI_CMD_SERR&nbsp;&nbsp;80<br>#define&nbsp;PI_CMD_SERW&nbsp;&nbsp;81<br>#define&nbsp;PI_CMD_SERDA&nbsp;82<br><br>#define&nbsp;PI_CMD_GDC&nbsp;&nbsp;&nbsp;83<br>#define&nbsp;PI_CMD_GPW&nbsp;&nbsp;&nbsp;84<br><br>#define&nbsp;PI_CMD_HC&nbsp;&nbsp;&nbsp;&nbsp;85<br>#define&nbsp;PI_CMD_HP&nbsp;&nbsp;&nbsp;&nbsp;86<br><br>#define&nbsp;PI_CMD_CF1&nbsp;&nbsp;&nbsp;87<br>#define&nbsp;PI_CMD_CF2&nbsp;&nbsp;&nbsp;88<br><br>#define&nbsp;PI_CMD_BI2CC&nbsp;89<br>#define&nbsp;PI_CMD_BI2CO&nbsp;90<br>#define&nbsp;PI_CMD_BI2CZ&nbsp;91<br><br>#define&nbsp;PI_CMD_I2CZ&nbsp;&nbsp;92<br><br>#define&nbsp;PI_CMD_WVCHA&nbsp;93<br><br>#define&nbsp;PI_CMD_SLRI&nbsp;&nbsp;94<br><br>#define&nbsp;PI_CMD_CGI&nbsp;&nbsp;&nbsp;95<br>#define&nbsp;PI_CMD_CSI&nbsp;&nbsp;&nbsp;96<br><br>#define&nbsp;PI_CMD_FG&nbsp;&nbsp;&nbsp;&nbsp;97<br>#define&nbsp;PI_CMD_FN&nbsp;&nbsp;&nbsp;&nbsp;98<br><br>#define&nbsp;PI_CMD_NOIB&nbsp;&nbsp;99<br><br>#define&nbsp;PI_CMD_WVTXM&nbsp;100<br>#define&nbsp;PI_CMD_WVTAT&nbsp;101<br><br>#define&nbsp;PI_CMD_PADS&nbsp;&nbsp;102<br>#define&nbsp;PI_CMD_PADG&nbsp;&nbsp;103<br><br>#define&nbsp;PI_CMD_FO&nbsp;&nbsp;&nbsp;&nbsp;104<br>#define&nbsp;PI_CMD_FC&nbsp;&nbsp;&nbsp;&nbsp;105<br>#define&nbsp;PI_CMD_FR&nbsp;&nbsp;&nbsp;&nbsp;106<br>#define&nbsp;PI_CMD_FW&nbsp;&nbsp;&nbsp;&nbsp;107<br>#define&nbsp;PI_CMD_FS&nbsp;&nbsp;&nbsp;&nbsp;108<br>#define&nbsp;PI_CMD_FL&nbsp;&nbsp;&nbsp;&nbsp;109<br><br>#define&nbsp;PI_CMD_SHELL&nbsp;110<br><br>#define&nbsp;PI_CMD_BSPIC&nbsp;111<br>#define&nbsp;PI_CMD_BSPIO&nbsp;112<br>#define&nbsp;PI_CMD_BSPIX&nbsp;113<br><br>#define&nbsp;PI_CMD_BSCX&nbsp;&nbsp;114<br><br>#define&nbsp;PI_CMD_EVM&nbsp;&nbsp;&nbsp;115<br>#define&nbsp;PI_CMD_EVT&nbsp;&nbsp;&nbsp;116<br><br>#define&nbsp;PI_CMD_PROCU&nbsp;117<br>#define&nbsp;PI_CMD_WVCAP&nbsp;118<br><br></code><h2>Error Codes</h2><code><br>#define&nbsp;PI_INIT_FAILED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-1&nbsp;//&nbsp;gpioInitialise&nbsp;failed<br>#define&nbsp;PI_BAD_USER_GPIO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-2&nbsp;//&nbsp;GPIO&nbsp;not&nbsp;0-31<br>#define&nbsp;PI_BAD_GPIO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-3&nbsp;//&nbsp;GPIO&nbsp;not&nbsp;0-53<br>#define&nbsp;PI_BAD_MODE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-4&nbsp;//&nbsp;mode&nbsp;not&nbsp;0-7<br>#define&nbsp;PI_BAD_LEVEL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-5&nbsp;//&nbsp;level&nbsp;not&nbsp;0-1<br>#define&nbsp;PI_BAD_PUD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-6&nbsp;//&nbsp;pud&nbsp;not&nbsp;0-2<br>#define&nbsp;PI_BAD_PULSEWIDTH&nbsp;&nbsp;&nbsp;&nbsp;-7&nbsp;//&nbsp;pulsewidth&nbsp;not&nbsp;0&nbsp;or&nbsp;500-2500<br>#define&nbsp;PI_BAD_DUTYCYCLE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-8&nbsp;//&nbsp;dutycycle&nbsp;outside&nbsp;set&nbsp;range<br>#define&nbsp;PI_BAD_TIMER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-9&nbsp;//&nbsp;timer&nbsp;not&nbsp;0-9<br>#define&nbsp;PI_BAD_MS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-10&nbsp;//&nbsp;ms&nbsp;not&nbsp;10-60000<br>#define&nbsp;PI_BAD_TIMETYPE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-11&nbsp;//&nbsp;timetype&nbsp;not&nbsp;0-1<br>#define&nbsp;PI_BAD_SECONDS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-12&nbsp;//&nbsp;seconds&nbsp;&lt;&nbsp;0<br>#define&nbsp;PI_BAD_MICROS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-13&nbsp;//&nbsp;micros&nbsp;not&nbsp;0-999999<br>#define&nbsp;PI_TIMER_FAILED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-14&nbsp;//&nbsp;gpioSetTimerFunc&nbsp;failed<br>#define&nbsp;PI_BAD_WDOG_TIMEOUT&nbsp;-15&nbsp;//&nbsp;timeout&nbsp;not&nbsp;0-60000<br>#define&nbsp;PI_NO_ALERT_FUNC&nbsp;&nbsp;&nbsp;&nbsp;-16&nbsp;//&nbsp;DEPRECATED<br>#define&nbsp;PI_BAD_CLK_PERIPH&nbsp;&nbsp;&nbsp;-17&nbsp;//&nbsp;clock&nbsp;peripheral&nbsp;not&nbsp;0-1<br>#define&nbsp;PI_BAD_CLK_SOURCE&nbsp;&nbsp;&nbsp;-18&nbsp;//&nbsp;DEPRECATED<br>#define&nbsp;PI_BAD_CLK_MICROS&nbsp;&nbsp;&nbsp;-19&nbsp;//&nbsp;clock&nbsp;micros&nbsp;not&nbsp;1,&nbsp;2,&nbsp;4,&nbsp;5,&nbsp;8,&nbsp;or&nbsp;10<br>#define&nbsp;PI_BAD_BUF_MILLIS&nbsp;&nbsp;&nbsp;-20&nbsp;//&nbsp;buf&nbsp;millis&nbsp;not&nbsp;100-10000<br>#define&nbsp;PI_BAD_DUTYRANGE&nbsp;&nbsp;&nbsp;&nbsp;-21&nbsp;//&nbsp;dutycycle&nbsp;range&nbsp;not&nbsp;25-40000<br>#define&nbsp;PI_BAD_DUTY_RANGE&nbsp;&nbsp;&nbsp;-21&nbsp;//&nbsp;DEPRECATED&nbsp;(use&nbsp;PI_BAD_DUTYRANGE)<br>#define&nbsp;PI_BAD_SIGNUM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-22&nbsp;//&nbsp;signum&nbsp;not&nbsp;0-63<br>#define&nbsp;PI_BAD_PATHNAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-23&nbsp;//&nbsp;can't&nbsp;open&nbsp;pathname<br>#define&nbsp;PI_NO_HANDLE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-24&nbsp;//&nbsp;no&nbsp;handle&nbsp;available<br>#define&nbsp;PI_BAD_HANDLE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-25&nbsp;//&nbsp;unknown&nbsp;handle<br>#define&nbsp;PI_BAD_IF_FLAGS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-26&nbsp;//&nbsp;ifFlags&nbsp;&gt;&nbsp;4<br>#define&nbsp;PI_BAD_CHANNEL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-27&nbsp;//&nbsp;DMA&nbsp;channel&nbsp;not&nbsp;0-15<br>#define&nbsp;PI_BAD_PRIM_CHANNEL&nbsp;-27&nbsp;//&nbsp;DMA&nbsp;primary&nbsp;channel&nbsp;not&nbsp;0-15<br>#define&nbsp;PI_BAD_SOCKET_PORT&nbsp;&nbsp;-28&nbsp;//&nbsp;socket&nbsp;port&nbsp;not&nbsp;1024-32000<br>#define&nbsp;PI_BAD_FIFO_COMMAND&nbsp;-29&nbsp;//&nbsp;unrecognized&nbsp;fifo&nbsp;command<br>#define&nbsp;PI_BAD_SECO_CHANNEL&nbsp;-30&nbsp;//&nbsp;DMA&nbsp;secondary&nbsp;channel&nbsp;not&nbsp;0-15<br>#define&nbsp;PI_NOT_INITIALISED&nbsp;&nbsp;-31&nbsp;//&nbsp;function&nbsp;called&nbsp;before&nbsp;gpioInitialise<br>#define&nbsp;PI_INITIALISED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-32&nbsp;//&nbsp;function&nbsp;called&nbsp;after&nbsp;gpioInitialise<br>#define&nbsp;PI_BAD_WAVE_MODE&nbsp;&nbsp;&nbsp;&nbsp;-33&nbsp;//&nbsp;waveform&nbsp;mode&nbsp;not&nbsp;0-3<br>#define&nbsp;PI_BAD_CFG_INTERNAL&nbsp;-34&nbsp;//&nbsp;bad&nbsp;parameter&nbsp;in&nbsp;gpioCfgInternals&nbsp;call<br>#define&nbsp;PI_BAD_WAVE_BAUD&nbsp;&nbsp;&nbsp;&nbsp;-35&nbsp;//&nbsp;baud&nbsp;rate&nbsp;not&nbsp;50-250K(RX)/50-1M(TX)<br>#define&nbsp;PI_TOO_MANY_PULSES&nbsp;&nbsp;-36&nbsp;//&nbsp;waveform&nbsp;has&nbsp;too&nbsp;many&nbsp;pulses<br>#define&nbsp;PI_TOO_MANY_CHARS&nbsp;&nbsp;&nbsp;-37&nbsp;//&nbsp;waveform&nbsp;has&nbsp;too&nbsp;many&nbsp;chars<br>#define&nbsp;PI_NOT_SERIAL_GPIO&nbsp;&nbsp;-38&nbsp;//&nbsp;no&nbsp;bit&nbsp;bang&nbsp;serial&nbsp;read&nbsp;on&nbsp;GPIO<br>#define&nbsp;PI_BAD_SERIAL_STRUC&nbsp;-39&nbsp;//&nbsp;bad&nbsp;(null)&nbsp;serial&nbsp;structure&nbsp;parameter<br>#define&nbsp;PI_BAD_SERIAL_BUF&nbsp;&nbsp;&nbsp;-40&nbsp;//&nbsp;bad&nbsp;(null)&nbsp;serial&nbsp;buf&nbsp;parameter<br>#define&nbsp;PI_NOT_PERMITTED&nbsp;&nbsp;&nbsp;&nbsp;-41&nbsp;//&nbsp;GPIO&nbsp;operation&nbsp;not&nbsp;permitted<br>#define&nbsp;PI_SOME_PERMITTED&nbsp;&nbsp;&nbsp;-42&nbsp;//&nbsp;one&nbsp;or&nbsp;more&nbsp;GPIO&nbsp;not&nbsp;permitted<br>#define&nbsp;PI_BAD_WVSC_COMMND&nbsp;&nbsp;-43&nbsp;//&nbsp;bad&nbsp;WVSC&nbsp;subcommand<br>#define&nbsp;PI_BAD_WVSM_COMMND&nbsp;&nbsp;-44&nbsp;//&nbsp;bad&nbsp;WVSM&nbsp;subcommand<br>#define&nbsp;PI_BAD_WVSP_COMMND&nbsp;&nbsp;-45&nbsp;//&nbsp;bad&nbsp;WVSP&nbsp;subcommand<br>#define&nbsp;PI_BAD_PULSELEN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-46&nbsp;//&nbsp;trigger&nbsp;pulse&nbsp;length&nbsp;not&nbsp;1-100<br>#define&nbsp;PI_BAD_SCRIPT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-47&nbsp;//&nbsp;invalid&nbsp;script<br>#define&nbsp;PI_BAD_SCRIPT_ID&nbsp;&nbsp;&nbsp;&nbsp;-48&nbsp;//&nbsp;unknown&nbsp;script&nbsp;id<br>#define&nbsp;PI_BAD_SER_OFFSET&nbsp;&nbsp;&nbsp;-49&nbsp;//&nbsp;add&nbsp;serial&nbsp;data&nbsp;offset&nbsp;&gt;&nbsp;30&nbsp;minutes<br>#define&nbsp;PI_GPIO_IN_USE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-50&nbsp;//&nbsp;GPIO&nbsp;already&nbsp;in&nbsp;use<br>#define&nbsp;PI_BAD_SERIAL_COUNT&nbsp;-51&nbsp;//&nbsp;must&nbsp;read&nbsp;at&nbsp;least&nbsp;a&nbsp;byte&nbsp;at&nbsp;a&nbsp;time<br>#define&nbsp;PI_BAD_PARAM_NUM&nbsp;&nbsp;&nbsp;&nbsp;-52&nbsp;//&nbsp;script&nbsp;parameter&nbsp;id&nbsp;not&nbsp;0-9<br>#define&nbsp;PI_DUP_TAG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-53&nbsp;//&nbsp;script&nbsp;has&nbsp;duplicate&nbsp;tag<br>#define&nbsp;PI_TOO_MANY_TAGS&nbsp;&nbsp;&nbsp;&nbsp;-54&nbsp;//&nbsp;script&nbsp;has&nbsp;too&nbsp;many&nbsp;tags<br>#define&nbsp;PI_BAD_SCRIPT_CMD&nbsp;&nbsp;&nbsp;-55&nbsp;//&nbsp;illegal&nbsp;script&nbsp;command<br>#define&nbsp;PI_BAD_VAR_NUM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-56&nbsp;//&nbsp;script&nbsp;variable&nbsp;id&nbsp;not&nbsp;0-149<br>#define&nbsp;PI_NO_SCRIPT_ROOM&nbsp;&nbsp;&nbsp;-57&nbsp;//&nbsp;no&nbsp;more&nbsp;room&nbsp;for&nbsp;scripts<br>#define&nbsp;PI_NO_MEMORY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-58&nbsp;//&nbsp;can't&nbsp;allocate&nbsp;temporary&nbsp;memory<br>#define&nbsp;PI_SOCK_READ_FAILED&nbsp;-59&nbsp;//&nbsp;socket&nbsp;read&nbsp;failed<br>#define&nbsp;PI_SOCK_WRIT_FAILED&nbsp;-60&nbsp;//&nbsp;socket&nbsp;write&nbsp;failed<br>#define&nbsp;PI_TOO_MANY_PARAM&nbsp;&nbsp;&nbsp;-61&nbsp;//&nbsp;too&nbsp;many&nbsp;script&nbsp;parameters&nbsp;(&gt;&nbsp;10)<br>#define&nbsp;PI_NOT_HALTED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-62&nbsp;//&nbsp;DEPRECATED<br>#define&nbsp;PI_SCRIPT_NOT_READY&nbsp;-62&nbsp;//&nbsp;script&nbsp;initialising<br>#define&nbsp;PI_BAD_TAG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-63&nbsp;//&nbsp;script&nbsp;has&nbsp;unresolved&nbsp;tag<br>#define&nbsp;PI_BAD_MICS_DELAY&nbsp;&nbsp;&nbsp;-64&nbsp;//&nbsp;bad&nbsp;MICS&nbsp;delay&nbsp;(too&nbsp;large)<br>#define&nbsp;PI_BAD_MILS_DELAY&nbsp;&nbsp;&nbsp;-65&nbsp;//&nbsp;bad&nbsp;MILS&nbsp;delay&nbsp;(too&nbsp;large)<br>#define&nbsp;PI_BAD_WAVE_ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-66&nbsp;//&nbsp;non&nbsp;existent&nbsp;wave&nbsp;id<br>#define&nbsp;PI_TOO_MANY_CBS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-67&nbsp;//&nbsp;No&nbsp;more&nbsp;CBs&nbsp;for&nbsp;waveform<br>#define&nbsp;PI_TOO_MANY_OOL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-68&nbsp;//&nbsp;No&nbsp;more&nbsp;OOL&nbsp;for&nbsp;waveform<br>#define&nbsp;PI_EMPTY_WAVEFORM&nbsp;&nbsp;&nbsp;-69&nbsp;//&nbsp;attempt&nbsp;to&nbsp;create&nbsp;an&nbsp;empty&nbsp;waveform<br>#define&nbsp;PI_NO_WAVEFORM_ID&nbsp;&nbsp;&nbsp;-70&nbsp;//&nbsp;no&nbsp;more&nbsp;waveforms<br>#define&nbsp;PI_I2C_OPEN_FAILED&nbsp;&nbsp;-71&nbsp;//&nbsp;can't&nbsp;open&nbsp;I2C&nbsp;device<br>#define&nbsp;PI_SER_OPEN_FAILED&nbsp;&nbsp;-72&nbsp;//&nbsp;can't&nbsp;open&nbsp;serial&nbsp;device<br>#define&nbsp;PI_SPI_OPEN_FAILED&nbsp;&nbsp;-73&nbsp;//&nbsp;can't&nbsp;open&nbsp;SPI&nbsp;device<br>#define&nbsp;PI_BAD_I2C_BUS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-74&nbsp;//&nbsp;bad&nbsp;I2C&nbsp;bus<br>#define&nbsp;PI_BAD_I2C_ADDR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-75&nbsp;//&nbsp;bad&nbsp;I2C&nbsp;address<br>#define&nbsp;PI_BAD_SPI_CHANNEL&nbsp;&nbsp;-76&nbsp;//&nbsp;bad&nbsp;SPI&nbsp;channel<br>#define&nbsp;PI_BAD_FLAGS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-77&nbsp;//&nbsp;bad&nbsp;i2c/spi/ser&nbsp;open&nbsp;flags<br>#define&nbsp;PI_BAD_SPI_SPEED&nbsp;&nbsp;&nbsp;&nbsp;-78&nbsp;//&nbsp;bad&nbsp;SPI&nbsp;speed<br>#define&nbsp;PI_BAD_SER_DEVICE&nbsp;&nbsp;&nbsp;-79&nbsp;//&nbsp;bad&nbsp;serial&nbsp;device&nbsp;name<br>#define&nbsp;PI_BAD_SER_SPEED&nbsp;&nbsp;&nbsp;&nbsp;-80&nbsp;//&nbsp;bad&nbsp;serial&nbsp;baud&nbsp;rate<br>#define&nbsp;PI_BAD_PARAM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-81&nbsp;//&nbsp;bad&nbsp;i2c/spi/ser&nbsp;parameter<br>#define&nbsp;PI_I2C_WRITE_FAILED&nbsp;-82&nbsp;//&nbsp;i2c&nbsp;write&nbsp;failed<br>#define&nbsp;PI_I2C_READ_FAILED&nbsp;&nbsp;-83&nbsp;//&nbsp;i2c&nbsp;read&nbsp;failed<br>#define&nbsp;PI_BAD_SPI_COUNT&nbsp;&nbsp;&nbsp;&nbsp;-84&nbsp;//&nbsp;bad&nbsp;SPI&nbsp;count<br>#define&nbsp;PI_SER_WRITE_FAILED&nbsp;-85&nbsp;//&nbsp;ser&nbsp;write&nbsp;failed<br>#define&nbsp;PI_SER_READ_FAILED&nbsp;&nbsp;-86&nbsp;//&nbsp;ser&nbsp;read&nbsp;failed<br>#define&nbsp;PI_SER_READ_NO_DATA&nbsp;-87&nbsp;//&nbsp;ser&nbsp;read&nbsp;no&nbsp;data&nbsp;available<br>#define&nbsp;PI_UNKNOWN_COMMAND&nbsp;&nbsp;-88&nbsp;//&nbsp;unknown&nbsp;command<br>#define&nbsp;PI_SPI_XFER_FAILED&nbsp;&nbsp;-89&nbsp;//&nbsp;spi&nbsp;xfer/read/write&nbsp;failed<br>#define&nbsp;PI_BAD_POINTER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-90&nbsp;//&nbsp;bad&nbsp;(NULL)&nbsp;pointer<br>#define&nbsp;PI_NO_AUX_SPI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-91&nbsp;//&nbsp;no&nbsp;auxiliary&nbsp;SPI&nbsp;on&nbsp;Pi&nbsp;A&nbsp;or&nbsp;B<br>#define&nbsp;PI_NOT_PWM_GPIO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-92&nbsp;//&nbsp;GPIO&nbsp;is&nbsp;not&nbsp;in&nbsp;use&nbsp;for&nbsp;PWM<br>#define&nbsp;PI_NOT_SERVO_GPIO&nbsp;&nbsp;&nbsp;-93&nbsp;//&nbsp;GPIO&nbsp;is&nbsp;not&nbsp;in&nbsp;use&nbsp;for&nbsp;servo&nbsp;pulses<br>#define&nbsp;PI_NOT_HCLK_GPIO&nbsp;&nbsp;&nbsp;&nbsp;-94&nbsp;//&nbsp;GPIO&nbsp;has&nbsp;no&nbsp;hardware&nbsp;clock<br>#define&nbsp;PI_NOT_HPWM_GPIO&nbsp;&nbsp;&nbsp;&nbsp;-95&nbsp;//&nbsp;GPIO&nbsp;has&nbsp;no&nbsp;hardware&nbsp;PWM<br>#define&nbsp;PI_BAD_HPWM_FREQ&nbsp;&nbsp;&nbsp;&nbsp;-96&nbsp;//&nbsp;invalid&nbsp;hardware&nbsp;PWM&nbsp;frequency<br>#define&nbsp;PI_BAD_HPWM_DUTY&nbsp;&nbsp;&nbsp;&nbsp;-97&nbsp;//&nbsp;hardware&nbsp;PWM&nbsp;dutycycle&nbsp;not&nbsp;0-1M<br>#define&nbsp;PI_BAD_HCLK_FREQ&nbsp;&nbsp;&nbsp;&nbsp;-98&nbsp;//&nbsp;invalid&nbsp;hardware&nbsp;clock&nbsp;frequency<br>#define&nbsp;PI_BAD_HCLK_PASS&nbsp;&nbsp;&nbsp;&nbsp;-99&nbsp;//&nbsp;need&nbsp;password&nbsp;to&nbsp;use&nbsp;hardware&nbsp;clock&nbsp;1<br>#define&nbsp;PI_HPWM_ILLEGAL&nbsp;&nbsp;&nbsp;&nbsp;-100&nbsp;//&nbsp;illegal,&nbsp;PWM&nbsp;in&nbsp;use&nbsp;for&nbsp;main&nbsp;clock<br>#define&nbsp;PI_BAD_DATABITS&nbsp;&nbsp;&nbsp;&nbsp;-101&nbsp;//&nbsp;serial&nbsp;data&nbsp;bits&nbsp;not&nbsp;1-32<br>#define&nbsp;PI_BAD_STOPBITS&nbsp;&nbsp;&nbsp;&nbsp;-102&nbsp;//&nbsp;serial&nbsp;(half)&nbsp;stop&nbsp;bits&nbsp;not&nbsp;2-8<br>#define&nbsp;PI_MSG_TOOBIG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-103&nbsp;//&nbsp;socket/pipe&nbsp;message&nbsp;too&nbsp;big<br>#define&nbsp;PI_BAD_MALLOC_MODE&nbsp;-104&nbsp;//&nbsp;bad&nbsp;memory&nbsp;allocation&nbsp;mode<br>#define&nbsp;PI_TOO_MANY_SEGS&nbsp;&nbsp;&nbsp;-105&nbsp;//&nbsp;too&nbsp;many&nbsp;I2C&nbsp;transaction&nbsp;segments<br>#define&nbsp;PI_BAD_I2C_SEG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-106&nbsp;//&nbsp;an&nbsp;I2C&nbsp;transaction&nbsp;segment&nbsp;failed<br>#define&nbsp;PI_BAD_SMBUS_CMD&nbsp;&nbsp;&nbsp;-107&nbsp;//&nbsp;SMBus&nbsp;command&nbsp;not&nbsp;supported&nbsp;by&nbsp;driver<br>#define&nbsp;PI_NOT_I2C_GPIO&nbsp;&nbsp;&nbsp;&nbsp;-108&nbsp;//&nbsp;no&nbsp;bit&nbsp;bang&nbsp;I2C&nbsp;in&nbsp;progress&nbsp;on&nbsp;GPIO<br>#define&nbsp;PI_BAD_I2C_WLEN&nbsp;&nbsp;&nbsp;&nbsp;-109&nbsp;//&nbsp;bad&nbsp;I2C&nbsp;write&nbsp;length<br>#define&nbsp;PI_BAD_I2C_RLEN&nbsp;&nbsp;&nbsp;&nbsp;-110&nbsp;//&nbsp;bad&nbsp;I2C&nbsp;read&nbsp;length<br>#define&nbsp;PI_BAD_I2C_CMD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-111&nbsp;//&nbsp;bad&nbsp;I2C&nbsp;command<br>#define&nbsp;PI_BAD_I2C_BAUD&nbsp;&nbsp;&nbsp;&nbsp;-112&nbsp;//&nbsp;bad&nbsp;I2C&nbsp;baud&nbsp;rate,&nbsp;not&nbsp;50-500k<br>#define&nbsp;PI_CHAIN_LOOP_CNT&nbsp;&nbsp;-113&nbsp;//&nbsp;bad&nbsp;chain&nbsp;loop&nbsp;count<br>#define&nbsp;PI_BAD_CHAIN_LOOP&nbsp;&nbsp;-114&nbsp;//&nbsp;empty&nbsp;chain&nbsp;loop<br>#define&nbsp;PI_CHAIN_COUNTER&nbsp;&nbsp;&nbsp;-115&nbsp;//&nbsp;too&nbsp;many&nbsp;chain&nbsp;counters<br>#define&nbsp;PI_BAD_CHAIN_CMD&nbsp;&nbsp;&nbsp;-116&nbsp;//&nbsp;bad&nbsp;chain&nbsp;command<br>#define&nbsp;PI_BAD_CHAIN_DELAY&nbsp;-117&nbsp;//&nbsp;bad&nbsp;chain&nbsp;delay&nbsp;micros<br>#define&nbsp;PI_CHAIN_NESTING&nbsp;&nbsp;&nbsp;-118&nbsp;//&nbsp;chain&nbsp;counters&nbsp;nested&nbsp;too&nbsp;deeply<br>#define&nbsp;PI_CHAIN_TOO_BIG&nbsp;&nbsp;&nbsp;-119&nbsp;//&nbsp;chain&nbsp;is&nbsp;too&nbsp;long<br>#define&nbsp;PI_DEPRECATED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-120&nbsp;//&nbsp;deprecated&nbsp;function&nbsp;removed<br>#define&nbsp;PI_BAD_SER_INVERT&nbsp;&nbsp;-121&nbsp;//&nbsp;bit&nbsp;bang&nbsp;serial&nbsp;invert&nbsp;not&nbsp;0&nbsp;or&nbsp;1<br>#define&nbsp;PI_BAD_EDGE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-122&nbsp;//&nbsp;bad&nbsp;ISR&nbsp;edge&nbsp;value,&nbsp;not&nbsp;0-2<br>#define&nbsp;PI_BAD_ISR_INIT&nbsp;&nbsp;&nbsp;&nbsp;-123&nbsp;//&nbsp;bad&nbsp;ISR&nbsp;initialisation<br>#define&nbsp;PI_BAD_FOREVER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-124&nbsp;//&nbsp;loop&nbsp;forever&nbsp;must&nbsp;be&nbsp;last&nbsp;command<br>#define&nbsp;PI_BAD_FILTER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-125&nbsp;//&nbsp;bad&nbsp;filter&nbsp;parameter<br>#define&nbsp;PI_BAD_PAD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-126&nbsp;//&nbsp;bad&nbsp;pad&nbsp;number<br>#define&nbsp;PI_BAD_STRENGTH&nbsp;&nbsp;&nbsp;&nbsp;-127&nbsp;//&nbsp;bad&nbsp;pad&nbsp;drive&nbsp;strength<br>#define&nbsp;PI_FIL_OPEN_FAILED&nbsp;-128&nbsp;//&nbsp;file&nbsp;open&nbsp;failed<br>#define&nbsp;PI_BAD_FILE_MODE&nbsp;&nbsp;&nbsp;-129&nbsp;//&nbsp;bad&nbsp;file&nbsp;mode<br>#define&nbsp;PI_BAD_FILE_FLAG&nbsp;&nbsp;&nbsp;-130&nbsp;//&nbsp;bad&nbsp;file&nbsp;flag<br>#define&nbsp;PI_BAD_FILE_READ&nbsp;&nbsp;&nbsp;-131&nbsp;//&nbsp;bad&nbsp;file&nbsp;read<br>#define&nbsp;PI_BAD_FILE_WRITE&nbsp;&nbsp;-132&nbsp;//&nbsp;bad&nbsp;file&nbsp;write<br>#define&nbsp;PI_FILE_NOT_ROPEN&nbsp;&nbsp;-133&nbsp;//&nbsp;file&nbsp;not&nbsp;open&nbsp;for&nbsp;read<br>#define&nbsp;PI_FILE_NOT_WOPEN&nbsp;&nbsp;-134&nbsp;//&nbsp;file&nbsp;not&nbsp;open&nbsp;for&nbsp;write<br>#define&nbsp;PI_BAD_FILE_SEEK&nbsp;&nbsp;&nbsp;-135&nbsp;//&nbsp;bad&nbsp;file&nbsp;seek<br>#define&nbsp;PI_NO_FILE_MATCH&nbsp;&nbsp;&nbsp;-136&nbsp;//&nbsp;no&nbsp;files&nbsp;match&nbsp;pattern<br>#define&nbsp;PI_NO_FILE_ACCESS&nbsp;&nbsp;-137&nbsp;//&nbsp;no&nbsp;permission&nbsp;to&nbsp;access&nbsp;file<br>#define&nbsp;PI_FILE_IS_A_DIR&nbsp;&nbsp;&nbsp;-138&nbsp;//&nbsp;file&nbsp;is&nbsp;a&nbsp;directory<br>#define&nbsp;PI_BAD_SHELL_STATUS&nbsp;-139&nbsp;//&nbsp;bad&nbsp;shell&nbsp;return&nbsp;status<br>#define&nbsp;PI_BAD_SCRIPT_NAME&nbsp;-140&nbsp;//&nbsp;bad&nbsp;script&nbsp;name<br>#define&nbsp;PI_BAD_SPI_BAUD&nbsp;&nbsp;&nbsp;&nbsp;-141&nbsp;//&nbsp;bad&nbsp;SPI&nbsp;baud&nbsp;rate,&nbsp;not&nbsp;50-500k<br>#define&nbsp;PI_NOT_SPI_GPIO&nbsp;&nbsp;&nbsp;&nbsp;-142&nbsp;//&nbsp;no&nbsp;bit&nbsp;bang&nbsp;SPI&nbsp;in&nbsp;progress&nbsp;on&nbsp;GPIO<br>#define&nbsp;PI_BAD_EVENT_ID&nbsp;&nbsp;&nbsp;&nbsp;-143&nbsp;//&nbsp;bad&nbsp;event&nbsp;id<br>#define&nbsp;PI_CMD_INTERRUPTED&nbsp;-144&nbsp;//&nbsp;Used&nbsp;by&nbsp;Python<br>#define&nbsp;PI_NOT_ON_BCM2711&nbsp;&nbsp;-145&nbsp;//&nbsp;not&nbsp;available&nbsp;on&nbsp;BCM2711<br>#define&nbsp;PI_ONLY_ON_BCM2711&nbsp;-146&nbsp;//&nbsp;only&nbsp;available&nbsp;on&nbsp;BCM2711<br><br>#define&nbsp;PI_PIGIF_ERR_0&nbsp;&nbsp;&nbsp;&nbsp;-2000<br>#define&nbsp;PI_PIGIF_ERR_99&nbsp;&nbsp;&nbsp;-2099<br><br>#define&nbsp;PI_CUSTOM_ERR_0&nbsp;&nbsp;&nbsp;-3000<br>#define&nbsp;PI_CUSTOM_ERR_999&nbsp;-3999<br><br></code><h2>Defaults</h2><code><br>#define&nbsp;PI_DEFAULT_BUFFER_MILLIS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;120<br>#define&nbsp;PI_DEFAULT_CLK_MICROS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5<br>#define&nbsp;PI_DEFAULT_CLK_PERIPHERAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PI_CLOCK_PCM<br>#define&nbsp;PI_DEFAULT_IF_FLAGS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0<br>#define&nbsp;PI_DEFAULT_FOREGROUND&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0<br>#define&nbsp;PI_DEFAULT_DMA_CHANNEL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;14<br>#define&nbsp;PI_DEFAULT_DMA_PRIMARY_CHANNEL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;14<br>#define&nbsp;PI_DEFAULT_DMA_SECONDARY_CHANNEL&nbsp;&nbsp;&nbsp;6<br>#define&nbsp;PI_DEFAULT_DMA_PRIMARY_CH_2711&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7<br>#define&nbsp;PI_DEFAULT_DMA_SECONDARY_CH_2711&nbsp;&nbsp;&nbsp;6<br>#define&nbsp;PI_DEFAULT_DMA_NOT_SET&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;15<br>#define&nbsp;PI_DEFAULT_SOCKET_PORT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;8888<br>#define&nbsp;PI_DEFAULT_SOCKET_PORT_STR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"8888"<br>#define&nbsp;PI_DEFAULT_SOCKET_ADDR_STR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"localhost"<br>#define&nbsp;PI_DEFAULT_UPDATE_MASK_UNKNOWN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0x0000000FFFFFFCLL<br>#define&nbsp;PI_DEFAULT_UPDATE_MASK_B1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0x03E7CF93<br>#define&nbsp;PI_DEFAULT_UPDATE_MASK_A_B2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0xFBC7CF9C<br>#define&nbsp;PI_DEFAULT_UPDATE_MASK_APLUS_BPLUS&nbsp;0x0080480FFFFFFCLL<br>#define&nbsp;PI_DEFAULT_UPDATE_MASK_ZERO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0x0080000FFFFFFCLL<br>#define&nbsp;PI_DEFAULT_UPDATE_MASK_PI2B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0x0080480FFFFFFCLL<br>#define&nbsp;PI_DEFAULT_UPDATE_MASK_PI3B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0x0000000FFFFFFCLL<br>#define&nbsp;PI_DEFAULT_UPDATE_MASK_PI4B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0x0000000FFFFFFCLL<br>#define&nbsp;PI_DEFAULT_UPDATE_MASK_COMPUTE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0x00FFFFFFFFFFFFLL<br>#define&nbsp;PI_DEFAULT_MEM_ALLOC_MODE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PI_MEM_ALLOC_AUTO<br><br>#define&nbsp;PI_DEFAULT_CFG_INTERNALS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0<br><br></code>


file_name: sif
menu_title: Socket I/F
page_title: Socket Interface
pic1: remote-2.jpg
pic2: serial.jpg
pic3: srf02.jpg
body:
pigpio provides a socket interface to many of its functions.<br>
<br>
The socket interface is available whenever pigpio is running,
either because it has been started as a daemon, or it has been
linked in to a running user program.<br>
<br>
The socket interface can be disabled by the program which
initialises the library.&nbsp; pigpiod offers the -k option to
disable the socket interface.&nbsp; User programs should call
<a href="cif.html#gpioCfgInterfaces">gpioCfgInterfaces</a> if they
wish to disable the socket interface.<br>
<br>
pigpio listens for connections on port 8888 by default.&nbsp; This
default may be overridden when pigpio starts by the <a href=
"cif.html#gpioCfgSocketPort">gpioCfgSocketPort</a> function
call.&nbsp; The pigpio daemon uses this function to provide an
option to change the port number.<br>
<br>
The pigs utility is an example of using the socket interface from
C.<span style="font-weight: bold;"><br></span>
<h3><a name="Request" id="Request"></a>Request</h3>
<p>pigpio expects messages of type <a href=
"sif.html#cmdCmd_t">cmdCmd_t</a> immediately followed with an
extension for a few commands.<br>
<br>
The caller should fill in cmd, p1, p2, p3/res, and any extension as
needed.&nbsp; p3 will always be zero unless the command requires an
extension in which case p3 will be the length in bytes of the
extension.<br>
<br>
The <a href="sif.html#cmdCmd_t">cmdCmd_t</a> is echoed back with
the result, if any, in p3/res, and an extension immediately
afterwards for a few commands.<br></p>
<table summary="" style="width: 80%;" cellspacing="2" cellpadding=
"2" border="1">
<tbody>
<tr>
<td style="font-weight: bold;">COMMAND</td>
<td style="font-weight: bold;">cmd<br></td>
<td style="font-weight: bold;">p1</td>
<td style="font-weight: bold;">p2</td>
<td style="font-weight: bold;">p3</td>
<td style="font-weight: bold;">Extension<br></td>
</tr>
<tr>
<td>MODES</td>
<td>0</td>
<td>gpio</td>
<td>mode</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>MODEG</td>
<td>1</td>
<td>gpio</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PUD</td>
<td>2</td>
<td>gpio</td>
<td>pud</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>READ</td>
<td>3</td>
<td>gpio</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WRITE</td>
<td>4</td>
<td>gpio</td>
<td>level</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PWM</td>
<td>5</td>
<td>gpio</td>
<td>dutycycle</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PRS</td>
<td>6</td>
<td>gpio</td>
<td>range</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PFS</td>
<td>7</td>
<td>gpio</td>
<td>frequency</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>SERVO</td>
<td>8</td>
<td>gpio</td>
<td>pulsewidth</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WDOG</td>
<td>9</td>
<td>gpio</td>
<td>timeout</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>BR1</td>
<td>10</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>BR2</td>
<td>11</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>BC1</td>
<td>12</td>
<td>bits</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>BC2</td>
<td>13</td>
<td>bits</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>BS1</td>
<td>14</td>
<td>bits</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>BS2</td>
<td>15</td>
<td>bits</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>TICK</td>
<td>16</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>HWVER</td>
<td>17</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>NO</td>
<td>18</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>NB</td>
<td>19</td>
<td>handle</td>
<td>bits</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>NP</td>
<td>20</td>
<td>handle</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>NC</td>
<td>21</td>
<td>handle</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PRG</td>
<td>22</td>
<td>gpio</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PFG</td>
<td>23</td>
<td>gpio</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PRRG</td>
<td>24</td>
<td>gpio</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>HELP<br></td>
<td>25</td>
<td>N/A<br></td>
<td>N/A<br></td>
<td>N/A<br></td>
<td>N/A<br></td>
</tr>
<tr>
<td>PIGPV</td>
<td>26</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WVCLR</td>
<td>27</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WVAG</td>
<td>28</td>
<td>0</td>
<td>0</td>
<td>12*X</td>
<td>gpioPulse_t pulse[X]</td>
</tr>
<tr>
<td>WVAS</td>
<td>29</td>
<td>gpio</td>
<td>baud</td>
<td>12+X</td>
<td>uint32_t databits<br>
uint32_t stophalfbits<br>
uint32_t offset<br>
uint8_t data[X]</td>
</tr>
<tr>
<td>N/A<br></td>
<td>30</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>N/A<br></td>
<td>31</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WVBSY</td>
<td>32</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WVHLT</td>
<td>33</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WVSM</td>
<td>34</td>
<td>subcmd</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WVSP</td>
<td>35</td>
<td>subcmd</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WVSC</td>
<td>36</td>
<td>subcmd</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>TRIG</td>
<td>37</td>
<td>gpio</td>
<td>pulselen</td>
<td>4</td>
<td>uint32_t level</td>
</tr>
<tr>
<td>PROC</td>
<td>38</td>
<td>0</td>
<td>0</td>
<td>X</td>
<td>uint8_t text[X]</td>
</tr>
<tr>
<td>PROCD</td>
<td>39</td>
<td>script_id</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PROCR</td>
<td>40</td>
<td>script_id</td>
<td>0</td>
<td>4*X<br></td>
<td>uint32_t pars[X]<br></td>
</tr>
<tr>
<td>PROCS</td>
<td>41</td>
<td>script_id</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>SLRO</td>
<td>42</td>
<td>gpio</td>
<td>baud</td>
<td>4</td>
<td>uint32_t databits<br></td>
</tr>
<tr>
<td>SLR</td>
<td>43</td>
<td>gpio</td>
<td>count</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>SLRC</td>
<td>44</td>
<td>gpio</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PROCP</td>
<td>45</td>
<td>script_id</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>MICS</td>
<td>46</td>
<td>micros</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>MILS</td>
<td>47</td>
<td>millis</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PARSE</td>
<td>48</td>
<td>N/A</td>
<td>N/A<br></td>
<td>N/A<br></td>
<td>N/A</td>
</tr>
<tr>
<td>WVCRE</td>
<td>49</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WVDEL</td>
<td>50</td>
<td>wave_id</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WVTX</td>
<td>51</td>
<td>wave_id</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WVTXR</td>
<td>52</td>
<td>wave_id</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WVNEW</td>
<td>53</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CO</td>
<td>54</td>
<td>bus</td>
<td>device</td>
<td>4</td>
<td>uint32_t flags</td>
</tr>
<tr>
<td>I2CC</td>
<td>55</td>
<td>handle</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CRD</td>
<td>56</td>
<td>handle</td>
<td>count</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CWD</td>
<td>57</td>
<td>handle</td>
<td>0</td>
<td>X</td>
<td>uint8_t data[X]</td>
</tr>
<tr>
<td>I2CWQ</td>
<td>58</td>
<td>handle</td>
<td>bit</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CRS</td>
<td>59</td>
<td>handle</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CWS</td>
<td>60</td>
<td>handle</td>
<td>byte</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CRB</td>
<td>61</td>
<td>handle</td>
<td>register</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CWB</td>
<td>62</td>
<td>handle</td>
<td>register</td>
<td>4</td>
<td>uint32_t byte</td>
</tr>
<tr>
<td>I2CRW</td>
<td>63</td>
<td>handle</td>
<td>register</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CWW</td>
<td>64</td>
<td>handle</td>
<td>register</td>
<td>4</td>
<td>uint32_t word</td>
</tr>
<tr>
<td>I2CRK</td>
<td>65</td>
<td>handle</td>
<td>register<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CWK</td>
<td>66</td>
<td>handle</td>
<td>register<br></td>
<td>X</td>
<td>uint8_t bvs[X]<br></td>
</tr>
<tr>
<td>I2CRI</td>
<td>67</td>
<td>handle</td>
<td>register<br></td>
<td>4</td>
<td>uint32_t num<br></td>
</tr>
<tr>
<td>I2CWI</td>
<td>68</td>
<td>handle</td>
<td>register<br></td>
<td>X<br></td>
<td>uint8_t bvs[X]<br></td>
</tr>
<tr>
<td>I2CPC</td>
<td>69</td>
<td>handle</td>
<td>register<br></td>
<td>4</td>
<td>uint32_t word<br></td>
</tr>
<tr>
<td>I2CPK</td>
<td>70</td>
<td>handle</td>
<td>register<br></td>
<td>X<br></td>
<td>uint8_t data[X]<br></td>
</tr>
<tr>
<td>SPIO<br></td>
<td>71</td>
<td>channel</td>
<td>baud</td>
<td>4</td>
<td>uint32_t flags</td>
</tr>
<tr>
<td>SPIC</td>
<td>72</td>
<td>handle</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>SPIR</td>
<td>73</td>
<td>handle</td>
<td>count</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>SPIW</td>
<td>74</td>
<td>handle</td>
<td>0</td>
<td>X</td>
<td>uint8_t data[X]</td>
</tr>
<tr>
<td>SPIX</td>
<td>75</td>
<td>handle</td>
<td>0</td>
<td>X</td>
<td>uint8_t data[X]</td>
</tr>
<tr>
<td>SERO</td>
<td>76</td>
<td>baud</td>
<td>flags</td>
<td>X</td>
<td>uint8_t device[X]</td>
</tr>
<tr>
<td>SERC</td>
<td>77</td>
<td>handle</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>SERRB</td>
<td>78</td>
<td>handle</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>SERWB</td>
<td>79</td>
<td>handle</td>
<td>byte</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>SERR</td>
<td>80</td>
<td>handle</td>
<td>count</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>SERW</td>
<td>81</td>
<td>handle</td>
<td>0</td>
<td>X</td>
<td>uint8_t data[X]</td>
</tr>
<tr>
<td>SERDA</td>
<td>82</td>
<td>handle</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">GDC<br></td>
<td style="vertical-align: top;">83<br></td>
<td style="vertical-align: top;">gpio<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">GPW<br></td>
<td style="vertical-align: top;">84<br></td>
<td style="vertical-align: top;">gpio<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">HC<br></td>
<td style="vertical-align: top;">85<br></td>
<td style="vertical-align: top;">gpio<br></td>
<td style="vertical-align: top;">frequency<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">HP<br></td>
<td style="vertical-align: top;">86<br></td>
<td style="vertical-align: top;">gpio<br></td>
<td style="vertical-align: top;">frequency<br></td>
<td style="vertical-align: top;">4<br></td>
<td style="vertical-align: top;">uint32_t dutycycle<br></td>
</tr>
<tr>
<td style="vertical-align: top;">CF1<br></td>
<td style="vertical-align: top;">87<br></td>
<td style="vertical-align: top;">arg1<br></td>
<td style="vertical-align: top;">arg2<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t argx[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">CF2<br></td>
<td style="vertical-align: top;">88<br></td>
<td style="vertical-align: top;">arg1<br></td>
<td style="vertical-align: top;">retMax<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t argx[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">BI2CC<br></td>
<td style="vertical-align: top;">89<br></td>
<td style="vertical-align: top;">sda<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">BI2CO<br></td>
<td style="vertical-align: top;">90<br></td>
<td style="vertical-align: top;">sda<br></td>
<td style="vertical-align: top;">scl<br></td>
<td style="vertical-align: top;">4<br></td>
<td style="vertical-align: top;">uint32_t baud<br></td>
</tr>
<tr>
<td style="vertical-align: top;">BI2CZ<br></td>
<td style="vertical-align: top;">91<br></td>
<td style="vertical-align: top;">sda<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t data[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">I2CZ<br></td>
<td style="vertical-align: top;">92<br></td>
<td style="vertical-align: top;">handle<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t data[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">WVCHA<br></td>
<td style="vertical-align: top;">93<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t data[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">SLRI<br></td>
<td style="vertical-align: top;">94<br></td>
<td style="vertical-align: top;">gpio<br></td>
<td style="vertical-align: top;">invert<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">CGI<br></td>
<td style="vertical-align: top;">95<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">CSI<br></td>
<td style="vertical-align: top;">96<br></td>
<td style="vertical-align: top;">config<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FG<br></td>
<td style="vertical-align: top;">97<br></td>
<td style="vertical-align: top;">gpio<br></td>
<td style="vertical-align: top;">steady<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FN<br></td>
<td style="vertical-align: top;">98<br></td>
<td style="vertical-align: top;">gpio<br></td>
<td style="vertical-align: top;">steady<br></td>
<td style="vertical-align: top;">4<br></td>
<td style="vertical-align: top;">uint32_t active<br></td>
</tr>
<tr>
<td>NOIB</td>
<td>99</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">WVTXM<br></td>
<td style="vertical-align: top;">100<br></td>
<td style="vertical-align: top;">wave_id<br></td>
<td style="vertical-align: top;">mode<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">WVTAT<br></td>
<td style="vertical-align: top;">101<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">PADS<br></td>
<td style="vertical-align: top;">102<br></td>
<td style="vertical-align: top;">pad<br></td>
<td style="vertical-align: top;">strength<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">PADG<br></td>
<td style="vertical-align: top;">103<br></td>
<td style="vertical-align: top;">pad<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FO<br></td>
<td style="vertical-align: top;">104<br></td>
<td style="vertical-align: top;">mode<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t file[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FC<br></td>
<td style="vertical-align: top;">105<br></td>
<td style="vertical-align: top;">handle<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FR<br></td>
<td style="vertical-align: top;">106<br></td>
<td style="vertical-align: top;">handle<br></td>
<td style="vertical-align: top;">count<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FW<br></td>
<td style="vertical-align: top;">107<br></td>
<td style="vertical-align: top;">handle<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t data[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FS<br></td>
<td style="vertical-align: top;">108<br></td>
<td style="vertical-align: top;">handle<br></td>
<td style="vertical-align: top;">offset<br></td>
<td style="vertical-align: top;">4<br></td>
<td style="vertical-align: top;">uint32_t from<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FL<br></td>
<td style="vertical-align: top;">109<br></td>
<td style="vertical-align: top;">count<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t pattern[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">SHELL<br></td>
<td style="vertical-align: top;">110<br></td>
<td style="vertical-align: top;">len(name)<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">len(name)+<br>
1+<br>
len(string)<br></td>
<td style="vertical-align: top;">uint8_t name[len(name)]<br>
uint8_t null (0)<br>
uint8_t string[len(string)]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">BSPIC<br></td>
<td style="vertical-align: top;">111<br></td>
<td style="vertical-align: top;">CS<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">BSPIO<br></td>
<td style="vertical-align: top;">112<br></td>
<td style="vertical-align: top;">CS<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">20<br></td>
<td style="vertical-align: top;">uint32_t MISO<br>
uint32_t MOSI<br>
uint32_t SCLK<br>
uint32_t baud<br>
uint32_t spi_flags<br></td>
</tr>
<tr>
<td style="vertical-align: top;">BSPIX<br></td>
<td style="vertical-align: top;">113<br></td>
<td style="vertical-align: top;">CS<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t data[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">BSCX<br></td>
<td style="vertical-align: top;">114<br></td>
<td style="vertical-align: top;">control<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t data[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">EVM<br></td>
<td style="vertical-align: top;">115<br></td>
<td style="vertical-align: top;">handle<br></td>
<td style="vertical-align: top;">bits<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">EVT<br></td>
<td style="vertical-align: top;">116<br></td>
<td style="vertical-align: top;">event<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td valign="top">PROCU<br></td>
<td valign="top">117<br></td>
<td valign="top">script_id<br></td>
<td valign="top">0<br></td>
<td valign="top">4*X<br></td>
<td valign="top">uint32_t pars[X]<br></td>
</tr>
</tbody>
</table>
<h3><a name="Response" id="Response"></a>Response</h3>
<p>The response has cmd/p1/p2 as in the request.&nbsp; p3/res holds
the return value.&nbsp; If the command returns additional values
they will be in the immediately following extension.<br></p>
Normally res should be treated as a 32 bit signed value and will be
greater than or equal to zero.&nbsp; Upon failure res will be less
than 0 and contains an error code.<br>
<p>There are a few commands where the returned value should be
treated as a 32 bit unsigned value.&nbsp; These commands can not
fail.&nbsp; They are indicated with a * after the command
name.<br></p>
<p>Commands with an extension have the size of the extension in
bytes returned in res (or &lt;0 on error as above).</p>
<table summary="" style="width: 80%;" cellspacing="2" cellpadding=
"2" border="1">
<tbody>
<tr>
<td style="font-weight: bold;">COMMAND</td>
<td style="font-weight: bold;">cmd<br></td>
<td style="vertical-align: top; font-weight: bold;">p1<br></td>
<td style="vertical-align: top; font-weight: bold;">p2<br></td>
<td style="font-weight: bold;">res<br></td>
<td style="font-weight: bold;">Extension<br></td>
</tr>
<tr>
<td>MODES</td>
<td>0</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>MODEG</td>
<td>1</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>mode<br></td>
<td>-<br></td>
</tr>
<tr>
<td>PUD</td>
<td>2</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>READ</td>
<td>3</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>level<br></td>
<td>-<br></td>
</tr>
<tr>
<td>WRITE</td>
<td>4</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PWM</td>
<td>5</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PRS</td>
<td>6</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PFS</td>
<td>7</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>SERVO</td>
<td>8</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WDOG</td>
<td>9</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>BR1 *</td>
<td>10</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>bits<br></td>
<td>-<br></td>
</tr>
<tr>
<td>BR2 *</td>
<td>11</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>bits<br></td>
<td>-<br></td>
</tr>
<tr>
<td>BC1</td>
<td>12</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>BC2</td>
<td>13</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>BS1</td>
<td>14</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>BS2</td>
<td>15</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>TICK *<br></td>
<td>16</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>tick<br></td>
<td>-<br></td>
</tr>
<tr>
<td>HWVER *<br></td>
<td>17</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>version<br></td>
<td>-<br></td>
</tr>
<tr>
<td>NO</td>
<td>18</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>handle<br></td>
<td>-<br></td>
</tr>
<tr>
<td>NB</td>
<td>19</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>NP</td>
<td>20</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>NC</td>
<td>21</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PRG</td>
<td>22</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>range<br></td>
<td>-<br></td>
</tr>
<tr>
<td>PFG</td>
<td>23</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>frequency<br></td>
<td>-<br></td>
</tr>
<tr>
<td>PRRG</td>
<td>24</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>real range<br></td>
<td>-<br></td>
</tr>
<tr>
<td>HELP</td>
<td>25</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>N/A<br></td>
<td>N/A<br></td>
</tr>
<tr>
<td>PIGPV *<br></td>
<td>26</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>version<br></td>
<td>-<br></td>
</tr>
<tr>
<td>WVCLR</td>
<td>27</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WVAG</td>
<td>28</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>wave pulses<br></td>
<td>-<br></td>
</tr>
<tr>
<td>WVAS</td>
<td>29</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>wave pulses<br></td>
<td>-<br></td>
</tr>
<tr>
<td>N/A<br></td>
<td>30</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>-<br></td>
<td>-<br></td>
</tr>
<tr>
<td>N/A<br></td>
<td>31</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>-<br></td>
<td>-<br></td>
</tr>
<tr>
<td>WVBSY</td>
<td>32</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>busy (1) or not busy (0)<br></td>
<td>-<br></td>
</tr>
<tr>
<td>WVHLT</td>
<td>33</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WVSM</td>
<td>34</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>wave micros<br>
wave micros - high<br>
wave micros - max<br></td>
<td>-<br></td>
</tr>
<tr>
<td>WVSP</td>
<td>35</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>wave pulses<br>
wave pulses - high<br>
wave pulses - max<br></td>
<td>-<br></td>
</tr>
<tr>
<td>WVSC</td>
<td>36</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>wave DMA CBs<br>
wave DMA CBs - high<br>
wave DMA CBs - max<br></td>
<td>-<br></td>
</tr>
<tr>
<td>TRIG</td>
<td>37</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0<br></td>
<td>-</td>
</tr>
<tr>
<td>PROC</td>
<td>38</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>script id<br></td>
<td>-<br></td>
</tr>
<tr>
<td>PROCD</td>
<td>39</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PROCR</td>
<td>40</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>script status<br></td>
<td>-</td>
</tr>
<tr>
<td>PROCS</td>
<td>41</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>SLRO</td>
<td>42</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0<br></td>
<td>-<br></td>
</tr>
<tr>
<td>SLR</td>
<td>43</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>X<br></td>
<td>uint8_t data[X]<br></td>
</tr>
<tr>
<td>SLRC</td>
<td>44</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PROCP</td>
<td>45</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>44</td>
<td>uint32_t script_status<br>
uint32_t pars[10]<br></td>
</tr>
<tr>
<td>MICS</td>
<td>46</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>MILS</td>
<td>47</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>PARSE</td>
<td>48</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>N/A<br></td>
<td>-</td>
</tr>
<tr>
<td>WVCRE</td>
<td>49</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>wave id<br></td>
<td>-<br></td>
</tr>
<tr>
<td>WVDEL</td>
<td>50</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>WVTX</td>
<td>51</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>wave DMA CBs<br></td>
<td>-<br></td>
</tr>
<tr>
<td>WVTXR</td>
<td>52</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>wave DMA CBs<br></td>
<td>-<br></td>
</tr>
<tr>
<td>WVNEW</td>
<td>53</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CO</td>
<td>54</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>handle</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CC</td>
<td>55</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CRD</td>
<td>56</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>X<br></td>
<td>uint8_t data[X]<br></td>
</tr>
<tr>
<td>I2CWD</td>
<td>57</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0<br></td>
<td>-<br></td>
</tr>
<tr>
<td>I2CWQ</td>
<td>58</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CRS</td>
<td>59</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>byte value<br></td>
<td>-<br></td>
</tr>
<tr>
<td>I2CWS</td>
<td>60</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CRB</td>
<td>61</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>byte value<br></td>
<td>-<br></td>
</tr>
<tr>
<td>I2CWB</td>
<td>62</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0<br></td>
<td>-<br></td>
</tr>
<tr>
<td>I2CRW</td>
<td>63</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>word value<br></td>
<td>-<br></td>
</tr>
<tr>
<td>I2CWW</td>
<td>64</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0<br></td>
<td>-<br></td>
</tr>
<tr>
<td>I2CRK</td>
<td>65</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>I2CWK</td>
<td>66</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0<br></td>
<td>-<br></td>
</tr>
<tr>
<td>I2CRI</td>
<td>67</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>X<br></td>
<td>uint8_t data[X]<br></td>
</tr>
<tr>
<td>I2CWI</td>
<td>68</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0<br></td>
<td>-<br></td>
</tr>
<tr>
<td>I2CPC</td>
<td>69</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>word value<br></td>
<td>-<br></td>
</tr>
<tr>
<td>I2CPK</td>
<td>70</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>X<br></td>
<td>uint8_t data[X]<br></td>
</tr>
<tr>
<td>SPIO<br></td>
<td>71</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>handle<br></td>
<td>-<br></td>
</tr>
<tr>
<td>SPIC</td>
<td>72</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>SPIR</td>
<td>73</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>X<br></td>
<td>uint8_t data[X]<br></td>
</tr>
<tr>
<td>SPIW</td>
<td>74</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0<br></td>
<td>-<br></td>
</tr>
<tr>
<td>SPIX</td>
<td>75</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>X</td>
<td>uint8_t data[X]</td>
</tr>
<tr>
<td>SERO</td>
<td>76</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>handle<br></td>
<td>-</td>
</tr>
<tr>
<td>SERC</td>
<td>77</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>SERRB</td>
<td>78</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>byte value<br></td>
<td>-<br></td>
</tr>
<tr>
<td>SERWB</td>
<td>79</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td>SERR</td>
<td>80</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>X<br></td>
<td>uint8_t data[X]<br></td>
</tr>
<tr>
<td>SERW</td>
<td>81</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0<br></td>
<td>-<br></td>
</tr>
<tr>
<td>SERDA</td>
<td>82</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>data ready count<br></td>
<td>-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">GDC<br></td>
<td style="vertical-align: top;">83<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">dutycycle<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">GPW<br></td>
<td style="vertical-align: top;">84<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">pulsewidth<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">HC<br></td>
<td style="vertical-align: top;">85<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">HP<br></td>
<td style="vertical-align: top;">86<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">CF1<br></td>
<td style="vertical-align: top;">87<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">value<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">CF2<br></td>
<td style="vertical-align: top;">88<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t retBuf[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">BI2CC<br></td>
<td style="vertical-align: top;">89<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">BI2CO<br></td>
<td style="vertical-align: top;">90<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">handle<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">BI2CZ<br></td>
<td style="vertical-align: top;">91<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t data[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">I2CZ<br></td>
<td style="vertical-align: top;">92<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t data[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">WVCHA<br></td>
<td style="vertical-align: top;">93<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">SLRI<br></td>
<td style="vertical-align: top;">94<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">CGI<br></td>
<td style="vertical-align: top;">95<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">config<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">CSI<br></td>
<td style="vertical-align: top;">96<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FG<br></td>
<td style="vertical-align: top;">97<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FN<br></td>
<td style="vertical-align: top;">98<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td>NOIB</td>
<td>99</td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td>0</td>
<td>-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">WVTXM<br></td>
<td style="vertical-align: top;">100<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">wave DMA CBs<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">WVTAT<br></td>
<td style="vertical-align: top;">101<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">wave id<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">PADS<br></td>
<td style="vertical-align: top;">102<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">PADG<br></td>
<td style="vertical-align: top;">103<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">strength<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FO<br></td>
<td style="vertical-align: top;">104<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">handle<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FC<br></td>
<td style="vertical-align: top;">105<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FR<br></td>
<td style="vertical-align: top;">106<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t data[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FW<br></td>
<td style="vertical-align: top;">107<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FS<br></td>
<td style="vertical-align: top;">108<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">position<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">FL<br></td>
<td style="vertical-align: top;">109<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t filenames[X]<br></td>
</tr>
<tr>
<td style="vertical-align: top;">SHELL<br></td>
<td style="vertical-align: top;">110<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">exit status<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">BSPIC<br></td>
<td style="vertical-align: top;">111<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">BSPIO<br></td>
<td style="vertical-align: top;">112<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">BSPIX<br></td>
<td style="vertical-align: top;">113<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">X<br></td>
<td style="vertical-align: top;">uint8_t data[X]</td>
</tr>
<tr>
<td style="vertical-align: top;">BSCX<br></td>
<td style="vertical-align: top;">114<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">X+4<br></td>
<td style="vertical-align: top;">uint32_t status<br>
uint8_t data[X]</td>
</tr>
<tr>
<td style="vertical-align: top;">EVM<br></td>
<td style="vertical-align: top;">115<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td style="vertical-align: top;">EVT<br></td>
<td style="vertical-align: top;">116<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">-<br></td>
<td style="vertical-align: top;">0<br></td>
<td style="vertical-align: top;">-<br></td>
</tr>
<tr>
<td valign="top">PROCU<br></td>
<td valign="top">117<br></td>
<td valign="top">-<br></td>
<td valign="top">-<br></td>
<td valign="top">0<br></td>
<td valign="top">-<br></td>
</tr>
</tbody>
</table>
<code><br></code>
<h3><a name="cmdCmd_t" id="cmdCmd_t"></a>cmdCmd_t</h3>
<code>typedef struct<br>
{<br>
&nbsp;&nbsp; uint32_t cmd;<br>
&nbsp;&nbsp; uint32_t p1;<br>
&nbsp;&nbsp; uint32_t p2;<br>
&nbsp;&nbsp; union<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uint32_t p3;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uint32_t ext_len;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uint32_t res;<br>
&nbsp;&nbsp; };<br>
} cmdCmd_t;<br></code><br>


file_name: pif
menu_title: Pipe I/F
page_title: Pipe Interface
pic1: switches.jpg
pic2: uln2003a.jpg
pic3: yl-40.jpg
body:
pigpio provides a pipe interface to many of its functions.<br>
<br>
The pipe interface is available whenever pigpio is running, either
because it has been started as a daemon, or it has been linked in
to a running user program.&nbsp; The pipe interface can be disabled
by the program which initialises the library.&nbsp; pigpiod offers
the -f option to disable the pipe interface.&nbsp; User programs
should call <a href=
"http://abyz.me.uk/rpi/pigpio/cif.html#gpioCfgInterfaces">gpioCfgInterfaces</a>
if they wish to disable the pipe interface.<br>
<br>
pigpio listens for commands on pipe /dev/pigpio.&nbsp; The commands
consist of a command identifier with, depending on the command,
zero, one, or two parameters.&nbsp; The result, if any, may be read
from pipe /dev/pigout.&nbsp; If any errors are detected a message
will be written to pipe /dev/pigerr.<br>
<br>
<br>
The format of the commands is identical to those used by <a href=
"pigs.html">pigs</a>.


file_name: pig2vcd
menu_title: pig2vcd
page_title: pig2vcd
pic1: wheel.jpg
pic2: srf04.jpg
pic3: servo.jpg
body:
pig2vcd is a utility which reads notifications on stdin and writes the
output as a Value Change Dump (VCD) file on stdout.
<br><br>The VCD file can be viewed using GTKWave.
<h3>Notifications</h3>Notifications consist of 12 bytes with the following binary format.
<br><br><code>typedef&nbsp;struct<br>{<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;seqno;<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;flags;<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;tick;<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;level;<br>}&nbsp;gpioReport_t;<br></code><br><br>seqno: starts at 0 each time the handle is opened and then increments by one for each report.
<br><br>flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags indicate a gpio which has had a watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity.
<br><br>tick: the number of microseconds since system boot. It wraps around after 1h12m.
<br><br>level: indicates the level of each gpio. If bit 1&lt;&lt;x is set then gpio x is high. pig2vcd takes these notifications and outputs a text format VCD.
<h3>VCD format</h3>The VCD starts with a header.
<br><br><code>$date&nbsp;2013-05-31&nbsp;18:49:36&nbsp;$end<br>$version&nbsp;pig2vcd&nbsp;V1&nbsp;$end<br>$timescale&nbsp;1&nbsp;us&nbsp;$end<br>$scope&nbsp;module&nbsp;top&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;A&nbsp;0&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;B&nbsp;1&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;C&nbsp;2&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;D&nbsp;3&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;E&nbsp;4&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;F&nbsp;5&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;G&nbsp;6&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;H&nbsp;7&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;I&nbsp;8&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;J&nbsp;9&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;K&nbsp;10&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;L&nbsp;11&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;M&nbsp;12&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;N&nbsp;13&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;O&nbsp;14&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;P&nbsp;15&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;Q&nbsp;16&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;R&nbsp;17&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;S&nbsp;18&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;T&nbsp;19&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;U&nbsp;20&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;V&nbsp;21&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;W&nbsp;22&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;X&nbsp;23&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;Y&nbsp;24&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;Z&nbsp;25&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;a&nbsp;26&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;b&nbsp;27&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;c&nbsp;28&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;d&nbsp;29&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;e&nbsp;30&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;f&nbsp;31&nbsp;$end<br>$upscope&nbsp;$end<br>$enddefinitions&nbsp;$end<br></code><br><br>The header defines gpio identifiers and their name.  Each gpio identifier
must be unique.  pig2vcd arbitrarily uses 'A' through 'Z' for gpios 0
through 25, and 'a' through 'f' for gpios 26 through 31.
The corresponding names are 0 through 31.<br>
<br><br>The VCD file may be edited to give a frendlier name, e.g. 8 could be
changed to ENCODER_A if an encoder switch A is connected to gpio 8.
<br><br>Following the header pig2vcd takes notifications and outputs a timestamp
followed by a list of one or more gpios which have changed state.
The timestamp consists of a '#' followed by the microsecond tick.
The state lines contain the new state followed by the gpio identifier.
<br><br><code>#1058747<br>0H<br>0I<br>#1059012<br>1H<br>#1079777<br>1I<br>#1079782<br>0I<br>#1079852<br>1I<br>#1079857<br>0I<br>0H<br>#1165113<br>1H<br>#1165118<br>0H<br>#1165153<br>1H<br></code>


file_name: examples
menu_title: Examples
page_title: Examples
pic1: rotary.jpg
pic2: rf-rx.jpg
pic3: pins.jpg
body:
The following examples show various ways pigpio may be used to communicate with sensors via the GPIO.<br>
<br>
Although many are complete programs they are intended to be a starting point in producing your own code, not an end point.<br>
<br>
<a href="#Index">Index</a><br><br>
<a href="#Hardware">Hardware</a><br><br>
<a href="#Shell code">Shell code</a><br><br>
<a href="#C code">C code</a><br><br>
<a href="#C++ code">C++ code</a><br><br>
<a href="#pigpiod_if2 code">pigpiod_if2 code</a><br><br>
<a href="#Python code">Python code</a><br><br>
<a href="#Miscellaneous related code">Miscellaneous related code</a><br><br>
<a href="#External links">External links</a><br><br>
<h3><span id="Hardware">Hardware</span></h3>
A few practical examples of using pigpio with hardware.<br>
<br>
<table style="text-align: left; width: 90%;" border="0" cellpadding="4" cellspacing="4"><tbody><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Hardware_ex_ir_remote"><a href="ex_ir_remote.html">IR Receiver</a><br>2013-06-09</span></td><td>Reading an infrared remote receiver.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Hardware_ex_LDR"><a href="ex_LDR.html">Light Dependent Resistor</a><br>2013-06-09</span></td><td>Measuring brightness with a light dependent resistor (LDR). Improved methods of timing the start of the capacitor recharge are given for <a href="#C_pot_cap_charge_c">C</a> and <a href="#Python_pot_cap_py">Python</a>.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Hardware_ex_motor_shield"><a href="ex_motor_shield.html">Motor Shield</a><br>2013-12-15</span></td><td>Using an Arduino motor shield.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Hardware_ex_rotary_encoder"><a href="ex_rotary_encoder.html">Rotary Encoder</a><br>2013-06-09</span></td><td>Reading a rotary encoder.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Hardware_ex_sonar_ranger"><a href="ex_sonar_ranger.html">Sonar Ranger</a><br>2013-06-10</span></td><td>Measuring range with a sonar ranger.<br>
<br>
</td></tr></tbody></table><h3><span id="Shell code">Shell code</span></h3>
Examples of using pigpio with shell code.<br>
<br>
<table style="text-align: left; width: 90%;" border="0" cellpadding="4" cellspacing="4"><tbody><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Shell_gpiotest"><a href="code/gpiotest.zip">GPIO test</a><br>2014-08-11</span></td><td>This bash script tests the user GPIO. <a href="http://youtu.be/sCJFLKWaxHo">Video</a><br>
<br>
</td></tr></tbody></table><h3><span id="C code">C code</span></h3>
Examples of C pigpio programs.<br>
<br>
If your program is called foobar.c then build with<br>
<br>
gcc -Wall -o foobar foobar.c -lpigpio<br>
<br>
<table style="text-align: left; width: 90%;" border="0" cellpadding="4" cellspacing="4"><tbody><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_freq_count_1"><a href="code/freq_count_1.zip">Frequency Counter 1</a><br>2014-08-20</span></td><td>A program showing how to use the <a href="cif.html#gpioSetAlertFunc">gpioSetAlertFunc</a> function to set a callback for GPIO state changes.  A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1&mu;s).<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_freq_count_2"><a href="code/freq_count_2.zip">Frequency Counter 2</a><br>2014-08-20</span></td><td>A program showing how to use the <a href="cif.html#gpioSetGetSamplesFunc">gpioSetGetSamplesFunc</a> function to set a callback for accumulated GPIO state changes over the last millisecond.  A frequency count is generated for each monitored GPIO (frequencies up to 500kHz with a sample rate of 1&mu;s). Generally the method used is more complicated but more efficient than frequency counter 1.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_hall"><a href="code/hall.zip">Hall Effect Sensor</a><br>2014-06-13</span></td><td>Program to show status changes for a Hall effect sensor.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_I2C_sniffer"><a href="code/I2C_sniffer.zip">I2C Sniffer</a><br>2014-06-15</span></td><td>A program to passively sniff I2C transactions (100kHz bus maximum) and display the results.  This C program uses pigpio notifications.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_ir_hasher_c"><a href="code/ir_hasher_c.zip">IR Receiver</a><br>2015-02-25</span></td><td>Function to hash a code from an IR receiver (reading an IR remote control).<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_PCF8591"><a href="code/PCF8591.zip">PCF8591 YL-40</a><br>2014-08-26</span></td><td>A program to display readings from the (I2C) PCF8591.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_pot_cap_charge_c"><a href="code/pot_cap_charge_c.zip">Pot + Capacitor Recharge Timing</a><br>2014-03-14</span></td><td>Function to time capacitor charging (through a resistance).  The time can be used to estimate the resistance.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_pps_c"><a href="code/pps_c.zip">Pulse Per Second generator</a><br>2020-07-28</span></td><td>A program to generate a pulse on a GPIO every x seconds (1<=x<=60).  The pulse is synced with the wall time second boundary.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_rotary_encoder_c"><a href="code/rotary_encoder_c.zip">Rotary Encoder</a><br>2015-10-03</span></td><td>Function to decode a mechanical rotary encoder.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_rawMCP3008_c"><a href="code/rawMCP3008_c.zip">SPI bit bang MCP3008</a><br>2016-03-20</span></td><td>This program shows how to read multiple MCP3008 ADC simultaneously with accurately timed intervals.  One 10-bit channel of each ADC may be sampled at up to 25k samples per second.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_rawMCP3202_c"><a href="code/rawMCP3202_c.zip">SPI bit bang MCP3202</a><br>2016-03-20</span></td><td>This program shows how to read multiple MCP3202 ADC simultaneously with accurately timed intervals.  One 12-bit channel of each ADC may be sampled at up to 25k samples per second.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_rawMCP3XXX_c"><a href="code/rawMCP3XXX_c.zip">SPI bit bang MCP3008 and MCP3202</a><br>2016-03-20</span></td><td>This program shows how to read multiple MCP3008 and MCP3202 ADC simultaneously with accurately timed intervals.  One channel of each ADC may be sampled at up to 25k samples per second.  The 10-bit MCP3008 readings are multiplied by 4 so they have the same range (0-4095) as the 12-bit MCP3202.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_servo_demo"><a href="code/servo_demo.zip">Servo Pulse Generator</a><br>2016-10-08</span></td><td>This program generates servo pulses on one or more GPIO.  Each connected servo is swept between 1000µs and 2000µs at a different speed.<br>
<br>
sudo ./servo_demo # Generate pulses on GPIO 4.<br>
<br>
sudo ./servo_demo 5 9 20 # Generate pulses on GPIO 5, 9, and 20.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_code/spi-pigpio-speed.c"><a href="code/spi-pigpio-speed.c">SPI pigpio driver speed test</a><br>2016-11-06</span></td><td>This C code is used to benchmark the pigpio SPI driver on the Pi.  The code executes a given number of loops at a given baud rate and bytes per transfer.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C_wiegand_c"><a href="code/wiegand_c.zip">Wiegand Reader</a><br>2013-12-30</span></td><td>Function to read a Wiegand Reader.<br>
<br>
</td></tr></tbody></table><h3><span id="C++ code">C++ code</span></h3>
Examples of C++ pigpio programs.<br>
<br>
If your program is called foobar.cpp then build with<br>
<br>
g++ -Wall -pthread -o foobar foobar.cpp -lpigpio -lrt<br>
<br>
<table style="text-align: left; width: 90%;" border="0" cellpadding="4" cellspacing="4"><tbody><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C++_ir_hasher_cpp"><a href="code/ir_hasher_cpp.zip">IR Receiver</a><br>2015-02-22</span></td><td>Class to hash a code from an IR receiver (reading an IR remote control).<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C++_rotary_encoder_cpp"><a href="code/rotary_encoder_cpp.zip">Rotary Encoder</a><br>2013-12-30</span></td><td>Class to decode a mechanical rotary encoder.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="C++_wiegand_cpp"><a href="code/wiegand_cpp.zip">Wiegand Reader</a><br>2013-12-30</span></td><td>Class to read a Wiegand Reader.<br>
<br>
</td></tr></tbody></table><h3><span id="pigpiod_if2 code">pigpiod_if2 code</span></h3>The pigpiod_if2 code examples are linked with libpigpiod_if2 and are written in C.<br>
<br>
The pigpiod_if2 library may be compiled and run on any Linux machine and allows control of the GPIO on one or more networked Pis.<br>
<br>
It should be possible to adapt the library to run on Macs and PCs.<br>
<br>
Each Pi needs the pigpio daemon to be running.  The pigpio daemon may be started with the command sudo pigpiod.<br>
<br>
<table style="text-align: left; width: 90%;" border="0" cellpadding="4" cellspacing="4"><tbody><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="pdif2__433D"><a href="code/_433D.zip">433MHz Keyfob RX/TX</a><br>2015-11-17</span></td><td>Code to read and transmit 313 and 434 MHz key fob codes.  The codes to be read must use Manchester encoding.  The transmitted codes use Manchester encoding.<br>
<br>
./_433D -r10 # Print fob keycodes received on GPIO 10.<br>
<br>
./_433D -t5 8246184 # Transmit code on GPIO 5.<br>
<br>
./_433D -r10 -t5 8246184 # Transmit code on GPIO 5 then listen for codes<br>
<br>
./_433D -? for options.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="pdif2_DHTXXD"><a href="code/DHTXXD.zip">DHT11/21/22/33/44 Sensor</a><br>2016-02-16</span></td><td>Code to read the DHT temperature and humidity sensors.  The sensor may be auto detected.  A DHT11 sensor may be read once per second.  The other sensors should not be read more often than once every three seconds.<br>
<br>
The code auto detects the DHT model and generally only the GPIO needs to be specified.<br>
<br>
./DHTXXD -g17 # Read a DHT connected to GPIO 17.<br>
<br>
./DHTXXD -g5 -i3 # Read a DHT connected to GPIO 5 every three seconds.<br>
<br>
./DHTXXD -? # for options.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="pdif2_RED"><a href="code/RED.zip">Rotary Encoder</a><br>2015-11-18</span></td><td>Code to monitor a rotary encoder and show the position changes.  By default the detent changes are shown.  There is an option to show the four steps per detent instead.<br>
<br>
./RED -a7 -b8 -s30 # Show encoder on 7/8 detent changes for 30 seconds.<br>
<br>
./RED -a5 -b6 -m1 # Show encoder on 5/6 step changes forever.<br>
<br>
./RED -? # for options.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="pdif2_servo_demo_D"><a href="code/servo_demo_D.zip">Servo Pulse Generator</a><br>2016-10-08</span></td><td>This program generates servo pulses on one or more GPIO.  Each connected servo is swept between 1000µs and 2000µs at a different speed.<br>
<br>
./servo_demo_D # Generate pulses on GPIO 4.<br>
<br>
./servo_demo_D 5 9 20 # Generate pulses on GPIO 5, 9, and 20.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="pdif2_SRTED"><a href="code/SRTED.zip">Sonar Ranger</a><br>2015-11-16</span></td><td>Code to read the SRF-04 and SRF-05 type of sonar rangers which use the trigger echo method of operation.  A 10 &mu;s trigger pulse initiates a series of high frequency sonar chirps.  The echo line then goes high and stays high until an echo from an object is received.  The echo high time is used to calculate the distance of the object.<br>
<br>
For a one-off reading only the trigger and echo GPIO need to be specified.<br>
<br>
./SRTED -t5 -e6 # Read a sonar ranger connected to GPIO 5/6.<br>
<br>
./SRTED -t11 -e5 -i0.1 # Read a sonar ranger connected to GPIO 11/5 every 0.1 seconds.<br>
<br>
./SRTED -? # for options.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="pdif2_tx_RED"><a href="code/tx_RED.zip">Transmit Rotary Encoder Test Signals</a><br>2015-11-25</span></td><td>Code to transmit quadrature signals to test rotary encoder software.<br>
<br>
tx_RED -aGPIO -bGPIO [options]<br>
<br>
tx_RED -? for options<br>
<br>
E.g.<br>
<br>
tx_RED -a5 -b6 -s20 -r-100<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="pdif2_tx_WD"><a href="code/tx_WD.zip">Transmit Wiegand Test Signals</a><br>2015-11-25</span></td><td>Code to transmit Wiegand codes to test Wiegand decoder software.<br>
<br>
tx_WD -gGPIO -wGPIO [options] {code}+<br>
<br>
tx_WD -? for options<br>
<br>
E.g.<br>
<br>
tx_WD -g5 -w6 -s37 12345 67890 123 899999<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="pdif2_WD"><a href="code/WD.zip">Wiegand Reader</a><br>2015-11-25</span></td><td>Code to read a Wiegand Reader.<br>
<br>
./WD -g7 -w8 -s30 # Read Wiegand codes from GPIO 7/8 for 30 seconds.<br>
<br>
./WD -g5 -w6 # Read Wiegand codes from GPIO 5/6 forever.<br>
<br>
./WD -? # for options.<br>
<br>
</td></tr></tbody></table><h3><span id="Python code">Python code</span></h3>The Python code may be run on any Python machine and allows control of the GPIO on one or more networked Pis.<br>
<br>
The Python machine need not be a Pi, it may run Windows, Mac, Linux, anything as long as it supports Python.<br>
<br>
Each Pi needs the pigpio daemon to be running.  The pigpio daemon may be started with the command sudo pigpiod.<br>
<br>
<table style="text-align: left; width: 90%;" border="0" cellpadding="4" cellspacing="4"><tbody><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python__433_py"><a href="code/_433_py.zip">433MHz Keyfob RX/TX</a><br>2015-10-30</span></td><td>Classes to send and receive 433MHz wireless keyfob codes.  These keyfobs are widely used for remote control of devices.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python__7_segment"><a href="code/_7_segment.zip">7-Segment LED Display Multiplexing</a><br>2016-12-12</span></td><td>Script to multiplex several 7-segment LED displays.  Each display has the segments a-g and the decimal point connected in parallel but has an individual enable GPIO (connected to the common anode or cathode).<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_test-APA102_py"><a href="code/test-APA102_py.zip">APA102 LED strip driver</a><br>2017-03-28</span></td><td>Script to drive an APA102 LED strip.  Three different methods are demonstrated - using spidev SPI (only works on the local Pi), pigpio SPI, and pigpio waves.  The SPI solutions only work with the dedicated SPI GPIO.  Waves may use any spare GPIO.  Four different examples are given including a LED strip clock.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_BME280_py"><a href="code/BME280_py.zip">BME280 Sensor</a><br>2016-08-05</span></td><td>Class to read the relative humidity, temperature, and pressure from a BME280 sensor.  The sensor has both an I2C and a SPI interface which are both<br>
supported by the class.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_code/DHT.py"><a href="code/DHT.py">DHT11/21/22/33/44 Sensor</a><br>2019-11-07</span></td><td>Class to read the relative humidity and temperature from a DHT sensor.  It can automatically recognize the sensor type.<br>
<br>
The default script prints the reading from the specified DHT every 2 seconds.  E.g. ./DHT.py 22 27 displays the data for DHT connected to GPIO 22 and 27.<br>
<br>
The following data is printed for each DHT: timestamp, GPIO, status, temperature, and humidity.<br>
<br>
The timestamp is the number of seconds since the epoch (start of 1970).<br>
<br>
The status will be one of: 0 - a good reading, 1 - checksum failure, 2 - data had one or more invalid values, 3 - no response from sensor.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_DHT22_py"><a href="code/DHT22_py.zip">DHT22 AM2302 Sensor</a><br>2014-07-11</span></td><td>Class to read the relative humidity and temperature from a DHT22/AM2302 sensor.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_DS18B20-1_py"><a href="code/DS18B20-1_py.zip">DS18B20 Temperature Sensor</a><br>2016-06-29</span></td><td>Script to read the temperature from any DS18B20 sensors connected to the 1-wire bus.<br>
<br>
To enable the 1-wire bus add the following line to /boot/config.txt and reboot.<br>
<br>
dtoverlay=w1-gpio<br>
<br>
By default you should connect the DS18B20 data line to GPIO 4 (pin 7).<br>
<br>
Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4.<br>
<br>
This script uses the file features of pigpio to access the remote file system.<br>
<br>
The following entry must be in /opt/pigpio/access.<br>
<br>
/sys/bus/w1/devices/28*/w1_slave r<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_PPD42NS_py"><a href="code/PPD42NS_py.zip">Dust Sensor</a><br>2015-11-22</span></td><td>Class to read a Shinyei PPD42NS Dust Sensor, e.g. as used in the Grove dust sensor.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_gpio_status_py"><a href="code/gpio_status_py.zip">GPIO Status</a><br>2014-06-12</span></td><td>Script to display the status of GPIO 0-31.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_hall"><a href="code/hall.zip">Hall Effect Sensor</a><br>2014-06-13</span></td><td>Program to show status changes for a Hall effect sensor.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_HX711_py"><a href="code/HX711_py.zip">HX711 24-bit ADC</a><br>2018-03-05</span></td><td>Class to read the channels of a HX711 24-bit ADC.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_i2c_ADXL345_py"><a href="code/i2c_ADXL345_py.zip">I2C ADXL345 Accelerometer</a><br>2015-04-01</span></td><td>Script to display the X, Y, and Z values read from an ADXL345 accelerometer.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_i2c_HMC5883L_py"><a href="code/i2c_HMC5883L_py.zip">I2C HMC5883L Magnetometer</a><br>2015-04-01</span></td><td>Script to display the X, Y, and Z values read from a HMC5883L Magnetometer (compass).<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_i2c_ITG3205_py"><a href="code/i2c_ITG3205_py.zip">I2C ITG3205 Gyroscope</a><br>2015-04-01</span></td><td>Script to display the X, Y, Z, and temperature values read from an ITG3205 gyroscope.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_i2c_lcd_py"><a href="code/i2c_lcd_py.zip">I2C LCD Display</a><br>2016-04-20</span></td><td>Class to display text on a LCD character display.  The class supports the PCF8574T 8-bit I2C port expander connected to a HD44780 based LCD display.  These displays are commonly available in 16x2 and 20x4 character formats.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_bsc_arduino_py"><a href="code/bsc_arduino_py.zip">I2C slave device</a><br>2016-10-31</span></td><td>This script demonstrates how to transfer messages from an Arduino acting as the I2C bus master to the Pi acting as an I2C slave device.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_I2C_sniffer"><a href="code/I2C_sniffer.zip">I2C Sniffer</a><br>2015-06-15</span></td><td>A program to passively sniff I2C transactions (100kHz bus maximum) and display the results.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_i2c_sonar_py"><a href="code/i2c_sonar_py.zip">I2C Sonar</a><br>2016-03-24</span></td><td>A class to read up to 8 HC-SR04 sonar rangers connected to an MCP23017 port expander.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_ir_hasher_py"><a href="code/ir_hasher_py.zip">IR Receiver</a><br>2014-06-12</span></td><td>Class to hash a code from an IR receiver (reading an IR remote control).<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_irrp_py"><a href="code/irrp_py.zip">IR Record and Playback</a><br>2015-12-21</span></td><td>This script may be used to record and play back arbitrary IR codes.<br>
<br>
To record the GPIO connected to the IR receiver, a file for the recorded codes, and the codes to be recorded are given.<br>
<br>
E.g. ./irrp.py -r -g4 -fir-codes vol+ vol- 1 2 3 4 5 6 7 8 9 0<br>
<br>
To playback the GPIO connected to the IR transmitter, the file containing the recorded codes, and the codes to be played back are given.<br>
<br>
E.g. ./irrp.py -p -g18 -fir-codes 2 3 4<br>
<br>
./irrp.py -h # for options<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_kivy_GPIO_py"><a href="code/kivy_GPIO_py.zip">Kivy GPIO control</a><br>2016-12-11</span></td><td>This example shows how to use Kivy to control a Pi's GPIO.  The GPIO may be configured as inputs, outputs, or to generate Servo or PWM pulses.  Kivy is an Open source Python library for rapid development of applications.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_MAX6675_py"><a href="code/MAX6675_py.zip">MAX6675 SPI Temperature Sensor</a><br>2016-05-02</span></td><td>A script to read the temperature from a MAX6675 connected to a K-type thermocouple.  The MAX6675 supports readings in the range 0 - 1023.75 C.  Up to 4 readings may be made per second.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_monitor_py"><a href="code/monitor_py.zip">Monitor GPIO</a><br>2016-09-17</span></td><td>Script to monitor GPIO for level changes.  By default all GPIO are monitored.  At a level change the GPIO, new level, and microseconds since the last change is printed.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_morse_code_py"><a href="code/morse_code_py.zip">Morse Code</a><br>2015-06-17</span></td><td>Script to transmit the morse code corresponding to a text string.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_code/NRF24.py"><a href="code/NRF24.py">NRF24 radio transceiver</a><br>2018-01-06</span></td><td>Script to transmit and receive messages using the nRF24L01 radio transceiver.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_PCA9685_py"><a href="code/PCA9685_py.zip">PCA9685 16 Channel PWM</a><br>2016-01-31</span></td><td>Class to control the 16 PWM channels of the I2C PCA9685. All channels use the same frequency.  The duty cycle or pulse width may be set independently for each channel.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_PCF8591"><a href="code/PCF8591.zip">PCF8591 YL-40</a><br>2014-08-26</span></td><td>Script to display readings from the (I2C) PCF8591.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_code/PPM.py"><a href="code/PPM.py">PPM (Pulse Position Modulation) generation</a><br>2016-02-19</span></td><td>Script to generate PPM signals on a chosen GPIO.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_code/PPM_to_servo.py"><a href="code/PPM_to_servo.py">PPM (Pulse Position Modulation) to servo pulses</a><br>2019-10-09</span></td><td>Script to read a PPM signal on a GPIO and generate the corresponding servo signals on chosen GPIO.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_bench_1_py"><a href="code/bench_1_py.zip">pigpio Benchmark</a><br>2014-06-12</span></td><td>Script to benchmark the pigpio Python module's performance.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_pigpio_cgi_py"><a href="code/pigpio_cgi_py.zip">pigpio CGI</a><br>2015-05-04</span></td><td>Script demonstrating how to access the pigpio daemon using CGI from a browser.  Instructions on how to use with Apache2 on the Pi are given in the comments.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_playback_py"><a href="code/playback_py.zip">Playback piscope recordings</a><br>2016-12-23</span></td><td>Script to playback GPIO data recorded in piscope format.<br>
<br>
To playback GPIO 4 to GPIO 4 from file data.piscope<br>
./playback.py data.piscope 4<br>
<br>
To playback GPIO 4 to GPIO 7 from file rec.txt<br>
./playback.py rec.txt 7=4<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_pot_cap_py"><a href="code/pot_cap_py.zip">Pot + Capacitor Recharge Timing</a><br>2016-09-26</span></td><td>Class to time capacitor charging (through a resistance).  The time can be used to estimate the resistance.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_read_PWM_py"><a href="code/read_PWM_py.zip">PWM Monitor</a><br>2015-12-08</span></td><td>Class to monitor a PWM signal and calculate the frequency, pulse width, and duty cycle.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_rotary_encoder_py"><a href="code/rotary_encoder_py.zip">Rotary Encoder</a><br>2014-06-12</span></td><td>Class to decode a mechanical rotary encoder.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_read_RPM_py"><a href="code/read_RPM_py.zip">RPM Monitor</a><br>2016-01-20</span></td><td>Class to monitor speedometer pulses and calculate the RPM (Revolutions Per Minute).<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_Si7021_py"><a href="code/Si7021_py.zip">Si7021 I2C Temperature and Humidity Sensor</a><br>2016-05-07</span></td><td>Class to read the temperature and relative humidity from a Si7021.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_SPI_mon_py"><a href="code/SPI_mon_py.zip">SPI Monitor</a><br>2016-09-21</span></td><td>A program to passively sniff SPI transactions and display the results.  The SPI rate should be limited to about 70kbps if using the default pigpio 5µs sampling rate.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_servo_demo_py"><a href="code/servo_demo_py.zip">Servo Pulse Generator</a><br>2016-10-07</span></td><td>This script generates servo pulses on one or more GPIO.  Each connected servo is swept between 1000µs and 2000µs at a different speed.<br>
<br>
./servo_demo.py # Generate pulses on GPIO 4.<br>
<br>
./servo_demo.py 5 9 20 # Generate pulses on GPIO 5, 9, and 20.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_sonar_trigger_echo_py"><a href="code/sonar_trigger_echo_py.zip">Sonar Ranger</a><br>2014-06-12</span></td><td>Class to read sonar rangers with separate trigger and echo pins.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_TCS3200_py"><a href="code/TCS3200_py.zip">TCS3200 Colour Sensor</a><br>2015-07-03</span></td><td>Class to read the TCS3200 colour sensor<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_vw"><a href="code/vw.zip">Virtual Wire</a><br>2015-10-31</span></td><td>Class to send and receive radio messages compatible with the Virtual Wire library for Arduinos.  This library is commonly used with 313MHz and 434MHz radio tranceivers.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_code/create_wave.py"><a href="code/create_wave.py">Wave create</a><br>2019-11-18</span></td><td>Script to generate waves from a template defined in a text file.<br>
<br>
You can also specify one of py, c, or pdif - the script output will then be a complete program to generate the wave (py for Python script, c for a C program, pdif for a C program using the pigpio daemon I/F).<br>
<br>
If none of py, c, or pdif are chosen the waveform will be generated for 30 seconds.<br>
<br>
Example text file<br>
<br>
# GPIO  levels<br>
23      11000001<br>
11      01110000<br>
12      00011100<br>
4       00000111<br>
<br>
To generate a pdif program with a bit time of 100 microseconds<br>
./create_wave.py wave_file 100 pdif >wave_pdif.c<br>
<br>
To just transmit the wave with a bit time of 50 microseconds<br>
./create_wave.py wave_file 50<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_wave_PWM_py"><a href="code/wave_PWM_py.zip">Wave PWM 1</a><br>2016-03-19</span></td><td>Script to show how waves may be used to generate PWM at (one) arbitrary frequency on multiple GPIO.  For instance PWM at 10kHz may be generated with 100 steps between off and fully on.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_wavePWM_py"><a href="code/wavePWM_py.zip">Wave PWM 2</a><br>2016-10-06</span></td><td>Class to generate PWM on multiple GPIO.  It is more flexible than the Wave PWM 1 example in that the start of the pulse within each cycle may be specified as well as the duty cycle.  The start and length of each pulse may be specified on a GPIO by GPIO basis in microseconds or as a fraction of the cycle time.  The class includes a __main__ to demostrate its ability to send servo pulses.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Python_wiegand_py"><a href="code/wiegand_py.zip">Wiegand Reader</a><br>2014-06-12</span></td><td>Class to read a Wiegand reader.<br>
<br>
</td></tr></tbody></table><h3><span id="Miscellaneous related code">Miscellaneous related code</span></h3>
The following code examples do not use pigpio.<br>
<br>
<table style="text-align: left; width: 90%;" border="0" cellpadding="4" cellspacing="4"><tbody><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Misc_adxl345_c"><a href="code/adxl345_c.zip">ADXL345</a><br>2014-03-12</span></td><td>This C program reads x, y, and z accelerations from the ADXL345 via I2C address 0x53.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Misc_DS18B20_py"><a href="code/DS18B20_py.zip">DS18B20 Temperature Sensor</a><br>2016-04-25</span></td><td>This Python script reads the temperature from any DS18B20 sensors connected to the 1-wire bus.<br>
<br>
To enable the 1-wire bus add the following line to /boot/config.txt and reboot.<br>
<br>
dtoverlay=w1-gpio<br>
<br>
By default you should connect the DS18B20 data line to GPIO 4 (pin 7).<br>
<br>
Connect 3V3 or 5V for power, ground to ground, 4k7 pull-up on data line to 3V3, and data line to GPIO 4.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Misc_EasyAsPiServer"><a href="code/EasyAsPiServer.zip">Easy as Pi Server</a><br>2014-09-15</span></td><td>This Python class implements a simple server which allows broswer commands to be executed on the Pi.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Misc_minimal_clk"><a href="code/minimal_clk.zip">Minimal Clock Access</a><br>2015-05-20</span></td><td>This C code sets GPIO 4 to a specified clock frequency.  The frequency can be set between 4.6875 kHz and 500 MHz (untested).  The clock can be preferentially set from one of the sources OSC (19.2MHz), HDMI (216MHz), PLLD (500MHz), or PLLC (1000MHz).  MASH can be set between 0 and 3.  MASH may not work properly for clock dividers less than 5.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Misc_minimal_gpio"><a href="code/minimal_gpio.zip">Minimal GPIO Access</a><br>2019-07-03</span></td><td>This C code has a minimal set of functions needed to control the GPIO and other Broadcom peripherals.  The program requires root privileges to run. See Tiny GPIO access for an alternative which controls the GPIO (but not the other peripherals) and does not require root access.<br>
<br>
The code has been updated for the BCM2711 (Pi4B).<br>
<br>
The following functions are provided.<br>
<br>
gpioInitialise<br>
gpioSetMode<br>
gpioGetMode<br>
gpioSetPullUpDown<br>
gpioRead<br>
gpioWrite<br>
gpioTrigger<br>
gpioReadBank1<br>
gpioReadBank2<br>
gpioClearBank1<br>
gpioClearBank2<br>
gpioSetBank1<br>
gpioSetBank2<br>
gpioHardwareRevision<br>
gpioTick<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Misc_nanopulse_c"><a href="code/nanopulse_c.zip">Nanosecond Pulse Generation</a><br>2014-01-29</span></td><td>This C program uses the PWM peripheral to generate precisely timed pulses of very short duration.  Pulses as short as 4 nano seconds can be generated.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Misc_PCF8591-x"><a href="code/PCF8591-x.zip">PCF8591 YL-40</a><br>2014-08-26</span></td><td>C and Python code to read the (I2C) PCF8591.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Misc_code/spi-driver-speed.c"><a href="code/spi-driver-speed.c">SPI Linux driver speed test</a><br>2016-11-06</span></td><td>This C code is used to benchmark the Linux SPI driver on the Pi.  The code executes a given number of loops at a given baud rate and bytes per transfer.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="Misc_tiny_gpio"><a href="code/tiny_gpio.zip">Tiny GPIO Access</a><br>2016-04-30</span></td><td>This C code has a minimal set of functions needed to control the GPIO without needing root privileges (it uses /dev/gpiomem to access the GPIO).<br>
<br>
You may need to change the permissions and ownership of /dev/gpiomem if they have not been correctly set up.<br>
<br>
sudo chown root:gpio /dev/gpiomem<br>
sudo chmod g+rw /dev/gpiomem<br>
<br>
The user (default pi) needs to be in the gpio group.<br>
<br>
sudo adduser pi gpio<br>
<br>
The following functions are provided.<br>
<br>
gpioInitialise<br>
gpioSetMode<br>
gpioGetMode<br>
gpioSetPullUpDown<br>
gpioRead<br>
gpioWrite<br>
gpioTrigger<br>
gpioReadBank1<br>
gpioReadBank2<br>
gpioClearBank1<br>
gpioClearBank2<br>
gpioSetBank1<br>
gpioSetBank2<br>
gpioHardwareRevision<br>
<br>
</td></tr></tbody></table><h3><span id="External links">External links</span></h3>
Related code.<br>
<br>
<table style="text-align: left; width: 90%;" border="0" cellpadding="4" cellspacing="4"><tbody><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="External_https://pypi.org/project/nrf24/"><a href="https://pypi.org/project/nrf24/">NRF24</a><br>2020-04-20</span></td><td>Python Package Index (Pypi) NRF24 module.<br>
pip install nrf24<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="External_https://github.com/bjarne-hansen/py-nrf24"><a href="https://github.com/bjarne-hansen/py-nrf24">NRF24</a><br>2020-04-20</span></td><td>Code and example usage of the Pypi NRF24 module.  Cleaned up and added support for reading from multiple pipes using open_reading_pipe(pipe, address) and open_writing_pipe(address) in order to be more "compatible" with the way NRF24 is used on Arduinos.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="External_https://github.com/paulvee/pigpio-serial-bb-examples"><a href="https://github.com/paulvee/pigpio-serial-bb-examples">bit bang serial RX</a><br>2020-11-16</span></td><td>Example code showing how to use the bit banged serial links.<br>
<br>
One example shows how to read the serial data from an Arduino based counter, that sends results every 1,000 or 10,000 seconds.<br>
<br>
Another example shows how to parse into sentences the NMEA stream coming from a U-Blox GPS module.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="External_https://github.com/stripcode/pigpio-stepper-motor"><a href="https://github.com/stripcode/pigpio-stepper-motor">Stepper Motor</a><br>2016-08-12</span></td><td>Stepper motor code.<br>
<br>
</td></tr><tr><td style="width: 150px; vertical-align: top; font-size: 0.8em; font-weight: bold;"><span id="External_https://github.com/choeffer/360pibot"><a href="https://github.com/choeffer/360pibot">Parallax ActivityBot 360</a><br>2018-11-03</span></td><td>Python 3 implementation for programming a Parallax ActivityBot 360 Robot Kit with a Raspberry Pi.<br>
<br>
</td></tr></tbody></table><h3><span id="Index">Index</span></h3>
<table style="text-align: left; width: 90%;" border="0" cellpadding="4" cellspacing="4"><tbody>
<tr><td><span id="index_433mhz_keyfob_rx/tx"></span>433MHz Keyfob RX/TX</td><td> <a href="#pdif2__433D">pdif2</a>
 <a href="#Python__433_py">Python</a>
</td></tr><tr><td><span id="index_7-segment_led_display_multiplexing"></span>7-Segment LED Display Multiplexing</td><td> <a href="#Python__7_segment">Python</a>
</td></tr><tr><td><span id="index_adxl345"></span>ADXL345</td><td> <a href="#Misc_adxl345_c">Misc</a>
</td></tr><tr><td><span id="index_apa102_led_strip_driver"></span>APA102 LED strip driver</td><td> <a href="#Python_test-APA102_py">Python</a>
</td></tr><tr><td><span id="index_bit_bang_serial_rx"></span>bit bang serial RX</td><td> <a href="#External_https://github.com/paulvee/pigpio-serial-bb-examples">External</a>
</td></tr><tr><td><span id="index_bme280_sensor"></span>BME280 Sensor</td><td> <a href="#Python_BME280_py">Python</a>
</td></tr><tr><td><span id="index_dht11/21/22/33/44_sensor"></span>DHT11/21/22/33/44 Sensor</td><td> <a href="#pdif2_DHTXXD">pdif2</a>
 <a href="#Python_code/DHT.py">Python</a>
</td></tr><tr><td><span id="index_dht22_am2302_sensor"></span>DHT22 AM2302 Sensor</td><td> <a href="#Python_DHT22_py">Python</a>
</td></tr><tr><td><span id="index_ds18b20_temperature_sensor"></span>DS18B20 Temperature Sensor</td><td> <a href="#Python_DS18B20-1_py">Python</a>
 <a href="#Misc_DS18B20_py">Misc</a>
</td></tr><tr><td><span id="index_dust_sensor"></span>Dust Sensor</td><td> <a href="#Python_PPD42NS_py">Python</a>
</td></tr><tr><td><span id="index_easy_as_pi_server"></span>Easy as Pi Server</td><td> <a href="#Misc_EasyAsPiServer">Misc</a>
</td></tr><tr><td><span id="index_frequency_counter_1"></span>Frequency Counter 1</td><td> <a href="#C_freq_count_1">C</a>
</td></tr><tr><td><span id="index_frequency_counter_2"></span>Frequency Counter 2</td><td> <a href="#C_freq_count_2">C</a>
</td></tr><tr><td><span id="index_gpio_status"></span>GPIO Status</td><td> <a href="#Python_gpio_status_py">Python</a>
</td></tr><tr><td><span id="index_gpio_test"></span>GPIO test</td><td> <a href="#Shell_gpiotest">Shell</a>
</td></tr><tr><td><span id="index_hall_effect_sensor"></span>Hall Effect Sensor</td><td> <a href="#C_hall">C</a>
 <a href="#Python_hall">Python</a>
</td></tr><tr><td><span id="index_hx711_24-bit_adc"></span>HX711 24-bit ADC</td><td> <a href="#Python_HX711_py">Python</a>
</td></tr><tr><td><span id="index_i2c_adxl345_accelerometer"></span>I2C ADXL345 Accelerometer</td><td> <a href="#Python_i2c_ADXL345_py">Python</a>
</td></tr><tr><td><span id="index_i2c_hmc5883l_magnetometer"></span>I2C HMC5883L Magnetometer</td><td> <a href="#Python_i2c_HMC5883L_py">Python</a>
</td></tr><tr><td><span id="index_i2c_itg3205_gyroscope"></span>I2C ITG3205 Gyroscope</td><td> <a href="#Python_i2c_ITG3205_py">Python</a>
</td></tr><tr><td><span id="index_i2c_lcd_display"></span>I2C LCD Display</td><td> <a href="#Python_i2c_lcd_py">Python</a>
</td></tr><tr><td><span id="index_i2c_slave_device"></span>I2C slave device</td><td> <a href="#Python_bsc_arduino_py">Python</a>
</td></tr><tr><td><span id="index_i2c_sniffer"></span>I2C Sniffer</td><td> <a href="#C_I2C_sniffer">C</a>
 <a href="#Python_I2C_sniffer">Python</a>
</td></tr><tr><td><span id="index_i2c_sonar"></span>I2C Sonar</td><td> <a href="#Python_i2c_sonar_py">Python</a>
</td></tr><tr><td><span id="index_ir_receiver"></span>IR Receiver</td><td> <a href="#Hardware_ex_ir_remote">Hardware</a>
 <a href="#C_ir_hasher_c">C</a>
 <a href="#C++_ir_hasher_cpp">C++</a>
 <a href="#Python_ir_hasher_py">Python</a>
</td></tr><tr><td><span id="index_ir_record_and_playback"></span>IR Record and Playback</td><td> <a href="#Python_irrp_py">Python</a>
</td></tr><tr><td><span id="index_kivy_gpio_control"></span>Kivy GPIO control</td><td> <a href="#Python_kivy_GPIO_py">Python</a>
</td></tr><tr><td><span id="index_light_dependent_resistor"></span>Light Dependent Resistor</td><td> <a href="#Hardware_ex_LDR">Hardware</a>
</td></tr><tr><td><span id="index_max6675_spi_temperature_sensor"></span>MAX6675 SPI Temperature Sensor</td><td> <a href="#Python_MAX6675_py">Python</a>
</td></tr><tr><td><span id="index_minimal_clock_access"></span>Minimal Clock Access</td><td> <a href="#Misc_minimal_clk">Misc</a>
</td></tr><tr><td><span id="index_minimal_gpio_access"></span>Minimal GPIO Access</td><td> <a href="#Misc_minimal_gpio">Misc</a>
</td></tr><tr><td><span id="index_monitor_gpio"></span>Monitor GPIO</td><td> <a href="#Python_monitor_py">Python</a>
</td></tr><tr><td><span id="index_morse_code"></span>Morse Code</td><td> <a href="#Python_morse_code_py">Python</a>
</td></tr><tr><td><span id="index_motor_shield"></span>Motor Shield</td><td> <a href="#Hardware_ex_motor_shield">Hardware</a>
</td></tr><tr><td><span id="index_nanosecond_pulse_generation"></span>Nanosecond Pulse Generation</td><td> <a href="#Misc_nanopulse_c">Misc</a>
</td></tr><tr><td><span id="index_nrf24"></span>NRF24</td><td> <a href="#External_https://pypi.org/project/nrf24/">External</a>
 <a href="#External_https://github.com/bjarne-hansen/py-nrf24">External</a>
</td></tr><tr><td><span id="index_nrf24_radio_transceiver"></span>NRF24 radio transceiver</td><td> <a href="#Python_code/NRF24.py">Python</a>
</td></tr><tr><td><span id="index_parallax_activitybot_360"></span>Parallax ActivityBot 360</td><td> <a href="#External_https://github.com/choeffer/360pibot">External</a>
</td></tr><tr><td><span id="index_pca9685_16_channel_pwm"></span>PCA9685 16 Channel PWM</td><td> <a href="#Python_PCA9685_py">Python</a>
</td></tr><tr><td><span id="index_pcf8591_yl-40"></span>PCF8591 YL-40</td><td> <a href="#C_PCF8591">C</a>
 <a href="#Python_PCF8591">Python</a>
 <a href="#Misc_PCF8591-x">Misc</a>
</td></tr><tr><td><span id="index_pigpio_benchmark"></span>pigpio Benchmark</td><td> <a href="#Python_bench_1_py">Python</a>
</td></tr><tr><td><span id="index_pigpio_cgi"></span>pigpio CGI</td><td> <a href="#Python_pigpio_cgi_py">Python</a>
</td></tr><tr><td><span id="index_playback_piscope_recordings"></span>Playback piscope recordings</td><td> <a href="#Python_playback_py">Python</a>
</td></tr><tr><td><span id="index_pot_+_capacitor_recharge_timing"></span>Pot + Capacitor Recharge Timing</td><td> <a href="#C_pot_cap_charge_c">C</a>
 <a href="#Python_pot_cap_py">Python</a>
</td></tr><tr><td><span id="index_ppm_(pulse_position_modulation)_generation"></span>PPM (Pulse Position Modulation) generation</td><td> <a href="#Python_code/PPM.py">Python</a>
</td></tr><tr><td><span id="index_ppm_(pulse_position_modulation)_to_servo_pulses"></span>PPM (Pulse Position Modulation) to servo pulses</td><td> <a href="#Python_code/PPM_to_servo.py">Python</a>
</td></tr><tr><td><span id="index_pulse_per_second_generator"></span>Pulse Per Second generator</td><td> <a href="#C_pps_c">C</a>
</td></tr><tr><td><span id="index_pwm_monitor"></span>PWM Monitor</td><td> <a href="#Python_read_PWM_py">Python</a>
</td></tr><tr><td><span id="index_rotary_encoder"></span>Rotary Encoder</td><td> <a href="#Hardware_ex_rotary_encoder">Hardware</a>
 <a href="#C_rotary_encoder_c">C</a>
 <a href="#C++_rotary_encoder_cpp">C++</a>
 <a href="#pdif2_RED">pdif2</a>
 <a href="#Python_rotary_encoder_py">Python</a>
</td></tr><tr><td><span id="index_rpm_monitor"></span>RPM Monitor</td><td> <a href="#Python_read_RPM_py">Python</a>
</td></tr><tr><td><span id="index_servo_pulse_generator"></span>Servo Pulse Generator</td><td> <a href="#C_servo_demo">C</a>
 <a href="#pdif2_servo_demo_D">pdif2</a>
 <a href="#Python_servo_demo_py">Python</a>
</td></tr><tr><td><span id="index_si7021_i2c_temperature_and_humidity_sensor"></span>Si7021 I2C Temperature and Humidity Sensor</td><td> <a href="#Python_Si7021_py">Python</a>
</td></tr><tr><td><span id="index_sonar_ranger"></span>Sonar Ranger</td><td> <a href="#Hardware_ex_sonar_ranger">Hardware</a>
 <a href="#pdif2_SRTED">pdif2</a>
 <a href="#Python_sonar_trigger_echo_py">Python</a>
</td></tr><tr><td><span id="index_spi_bit_bang_mcp3008"></span>SPI bit bang MCP3008</td><td> <a href="#C_rawMCP3008_c">C</a>
</td></tr><tr><td><span id="index_spi_bit_bang_mcp3008_and_mcp3202"></span>SPI bit bang MCP3008 and MCP3202</td><td> <a href="#C_rawMCP3XXX_c">C</a>
</td></tr><tr><td><span id="index_spi_bit_bang_mcp3202"></span>SPI bit bang MCP3202</td><td> <a href="#C_rawMCP3202_c">C</a>
</td></tr><tr><td><span id="index_spi_linux_driver_speed_test"></span>SPI Linux driver speed test</td><td> <a href="#Misc_code/spi-driver-speed.c">Misc</a>
</td></tr><tr><td><span id="index_spi_monitor"></span>SPI Monitor</td><td> <a href="#Python_SPI_mon_py">Python</a>
</td></tr><tr><td><span id="index_spi_pigpio_driver_speed_test"></span>SPI pigpio driver speed test</td><td> <a href="#C_code/spi-pigpio-speed.c">C</a>
</td></tr><tr><td><span id="index_stepper_motor"></span>Stepper Motor</td><td> <a href="#External_https://github.com/stripcode/pigpio-stepper-motor">External</a>
</td></tr><tr><td><span id="index_tcs3200_colour_sensor"></span>TCS3200 Colour Sensor</td><td> <a href="#Python_TCS3200_py">Python</a>
</td></tr><tr><td><span id="index_tiny_gpio_access"></span>Tiny GPIO Access</td><td> <a href="#Misc_tiny_gpio">Misc</a>
</td></tr><tr><td><span id="index_transmit_rotary_encoder_test_signals"></span>Transmit Rotary Encoder Test Signals</td><td> <a href="#pdif2_tx_RED">pdif2</a>
</td></tr><tr><td><span id="index_transmit_wiegand_test_signals"></span>Transmit Wiegand Test Signals</td><td> <a href="#pdif2_tx_WD">pdif2</a>
</td></tr><tr><td><span id="index_virtual_wire"></span>Virtual Wire</td><td> <a href="#Python_vw">Python</a>
</td></tr><tr><td><span id="index_wave_create"></span>Wave create</td><td> <a href="#Python_code/create_wave.py">Python</a>
</td></tr><tr><td><span id="index_wave_pwm_1"></span>Wave PWM 1</td><td> <a href="#Python_wave_PWM_py">Python</a>
</td></tr><tr><td><span id="index_wave_pwm_2"></span>Wave PWM 2</td><td> <a href="#Python_wavePWM_py">Python</a>
</td></tr><tr><td><span id="index_wiegand_reader"></span>Wiegand Reader</td><td> <a href="#C_wiegand_c">C</a>
 <a href="#C++_wiegand_cpp">C++</a>
 <a href="#pdif2_WD">pdif2</a>
 <a href="#Python_wiegand_py">Python</a>
</td></tr></tbody></table>


file_name: ex_rotary_encoder
menu_title: Rotary Encoder
page_title: Rotary Encoder Example
pic1: msp430.jpg
pic2: leds.jpg
pic3: ldr.jpg
body:
<p>The following code shows one way to read an incremental
mechanical rotary enoder (the sort used for volume control in audio
systems).&nbsp; These rotary encoders have two switches A and B
which return a quadrature output, i.e. they are 90 degrees out of
phase.</p>
<h3>SETUP</h3>
<img alt="fritzing diagram" style="width: 200px; height: 300px;"
src="images/re-fritz.png" align="left" hspace="10">The common
(centre) terminal should be connected to a Pi ground.
<p>The A and B terminals may be connected to any spare gpios.</p>
<p>Here A to gpio18 (P1-12), common to ground (P1-20), B to gpio7
(P1-26).<br clear="all"></p>
<p><img src="images/re-photo.jpg" style=
"width: 400px; height: 300px;" alt="photo of set-up"></p>
<h3>CODE</h3>
<code>#include &lt;stdio.h&gt;<br>
<br>
#include &lt;pigpio.h&gt;<br>
<br>
/*<br>
&nbsp;&nbsp; Rotary encoder connections:<br>
<br>
&nbsp;&nbsp; Encoder A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - gpio
18&nbsp;&nbsp; (pin P1-12)<br>
&nbsp;&nbsp; Encoder B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - gpio
7&nbsp;&nbsp;&nbsp; (pin P1-26)<br>
&nbsp;&nbsp; Encoder Common - Pi ground (pin P1-20)<br>
*/<br>
<br>
#define ENCODER_A 18<br>
#define ENCODER_B&nbsp; 7<br>
<br>
static volatile int encoderPos;<br>
<br>
/* forward declaration */<br>
<br>
void encoderPulse(int gpio, int lev, uint32_t tick);<br>
<br>
int main(int argc, char * argv[])<br>
{<br>
&nbsp;&nbsp; int pos=0;<br>
<br>
&nbsp;&nbsp; if (gpioInitialise()&lt;0) return 1;<br>
<br>
&nbsp;&nbsp; gpioSetMode(ENCODER_A, PI_INPUT);<br>
&nbsp;&nbsp; gpioSetMode(ENCODER_B, PI_INPUT);<br>
<br>
&nbsp;&nbsp; /* pull up is needed as encoder common is grounded
*/<br>
<br>
&nbsp;&nbsp; gpioSetPullUpDown(ENCODER_A, PI_PUD_UP);<br>
&nbsp;&nbsp; gpioSetPullUpDown(ENCODER_B, PI_PUD_UP);<br>
<br>
&nbsp;&nbsp; encoderPos = pos;<br>
<br>
&nbsp;&nbsp; /* monitor encoder level changes */<br>
<br>
&nbsp;&nbsp; gpioSetAlertFunc(ENCODER_A, encoderPulse);<br>
&nbsp;&nbsp; gpioSetAlertFunc(ENCODER_B, encoderPulse);<br>
<br>
&nbsp;&nbsp; while (1)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (pos != encoderPos)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos =
encoderPos;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("pos=%d\ ",
pos);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioDelay(20000); /* check pos 50
times per second */<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; gpioTerminate();<br>
}<br>
<br>
void encoderPulse(int gpio, int level, uint32_t tick)<br>
{<br>
&nbsp;&nbsp; /*<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+---------+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+---------+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
&nbsp;&nbsp; A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
&nbsp;&nbsp;
+---------+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+---------+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +-----
1<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+---------+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+---------+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
&nbsp;&nbsp; B&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
&nbsp;&nbsp; ----+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+---------+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+---------+&nbsp; 1<br>
<br>
&nbsp;&nbsp; */<br>
<br>
&nbsp;&nbsp; static int levA=0, levB=0, lastGpio = -1;<br>
<br>
&nbsp;&nbsp; if (gpio == ENCODER_A) levA = level; else levB =
level;<br>
<br>
&nbsp;&nbsp; if (gpio != lastGpio) /* debounce */<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastGpio = gpio;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ((gpio == ENCODER_A) &amp;&amp;
(level == 0))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!levB)
++encoderPos;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if ((gpio == ENCODER_B)
&amp;&amp; (level == 1))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (levA)
--encoderPos;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp; }<br>
}<br></code>
<h3>BUILD</h3>
<code>cc -o rotary_encoder rotary_encoder.c -lpigpio -lrt
-lpthread<br></code>
<h3>RUN</h3>
<code>sudo ./rotary_encoder</code><br>
<p>While the program is running you can capture the waveform using
the notification feature built in to pigpio.&nbsp; Issue the
following commands on the Pi.</p>
<code>pigs no<br>
pig2vcd&nbsp; &lt;/dev/pigpio0 &gt;re.vcd &amp;<br>
pigs nb 0 0x40080 # set bits for gpios 7 (0x80) and 18
(0x40000)<br></code>
<p>Twiddle the rotary encoder forwards and backwards for a few
seconds.&nbsp; Then enter<br></p>
<code>pigs nc 0</code><br>
<p>The file re.vcd will contain the captured waveform, which can be
viewed using GTKWave.</p>
<br>
Overview<br>
<br>
<img src="images/re-wave-1.png" style=
"width: 600px; height: 100px;" alt=
"rotary encoder waveform overview"><br>
<br>
Detail of switch bounce.&nbsp; Contact A bounces for circa 700 us
before completing the level transition<br>
<br>
<img src="images/re-wave-2.png" style=
"width: 600px; height: 100px;" alt=
"rotary encoder waveform detail"><br>


file_name: ex_ir_remote
menu_title: IR Remote
page_title: IR Remote Example
pic1: driver.jpg
pic2: imu-3.jpg
pic3: ir-motion.jpg
body:
<p>The following code shows one way to read an infrared remote
control device (the sort used in TVs and stereo systems).</p>
<h3>SETUP</h3>
<img alt="fritzing diagram" style="width: 200px; height: 317px;"
src="images/ir-fritz.png" align="left" hspace="10">The device used
is a <span itemprop="name">SFH5110 (IR Receiver for remote control,
carrier 38 kHz).<br>
<br></span> Pin 1 (left from front) may be connected to any spare
gpio.&nbsp; Here it's connected via a 4K7 current limiting
resistor.&nbsp; This isn't really needed as the device has an
internal 23K resistor in-line.&nbsp; It does no harm though.<br>
<br>
Pin 2 should be connected to a Pi ground pin.<br>
<br>
Pin 3 should be connected to a Pi 5V pin.<br>
<p>Here pin 1 to gpio7 (P1-26) via a 4K7 resistor, pin 2 to ground
(P1-14), and pin 3 to 5V (P1-2).<br clear="all"></p>
<p><img src="images/ir-photo.jpg" style=
"width: 500px; height: 500px;" alt="photo of set-up"></p>
<h3>CODE</h3>
<code>#include &lt;stdio.h&gt;<br>
<br>
#include &lt;pigpio.h&gt;<br>
<br>
#define IR_PIN 7<br>
<br>
#define OUTSIDE_CODE 0<br>
#define INSIDE_CODE&nbsp; 1<br>
<br>
#define MIN_MESSAGE_GAP 3000<br>
#define MAX_MESSAGE_END 3000<br>
<br>
#define MAX_TRANSITIONS 500<br>
<br>
/*<br>
&nbsp;&nbsp; using the FNV-1a
hash&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>

&nbsp;&nbsp; from
http://isthe.com/chongo/tech/comp/fnv/#FNV-param<br>
*/<br>
<br>
#define FNV_PRIME_32 16777619<br>
#define FNV_BASIS_32 2166136261U<br>
<br>
static volatile uint32_t ir_hash = 0;<br>
<br>
typedef struct<br>
{<br>
&nbsp;&nbsp; int state;<br>
&nbsp;&nbsp; int count;<br>
&nbsp;&nbsp; int level;<br>
&nbsp;&nbsp; uint16_t micros[MAX_TRANSITIONS];<br>
} decode_t;<br>
<br>
/* forward declarations */<br>
<br>
void&nbsp;&nbsp;&nbsp;&nbsp; alert(int gpio, int level, uint32_t
tick);<br>
uint32_t getHash(decode_t * decode);<br>
void&nbsp;&nbsp;&nbsp;&nbsp; updateState(decode_t * decode, int
level, uint32_t micros);<br>
<br>
int main(int argc, char * argv[])<br>
{<br>
&nbsp;&nbsp; if (gpioInitialise()&lt;0)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1 ;<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; /* IR pin as input */<br>
<br>
&nbsp;&nbsp; gpioSetMode(IR_PIN, PI_INPUT);<br>
<br>
&nbsp;&nbsp; /* 5ms max gap after last pulse */<br>
<br>
&nbsp;&nbsp; gpioSetWatchdog(IR_PIN, 5);<br>
<br>
&nbsp;&nbsp; /* monitor IR level changes */<br>
<br>
&nbsp;&nbsp; gpioSetAlertFunc(IR_PIN, alert);<br>
<br>
&nbsp;&nbsp; while (1)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (ir_hash)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* non-zero means
new decode */<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("ir code is
%u\ ", ir_hash);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ir_hash = 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioDelay(100000); /* check remote
10 times per second */<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; gpioTerminate();<br>
}<br>
<br>
void alert(int gpio, int level, uint32_t tick)<br>
{<br>
&nbsp;&nbsp; static int inited = 0;<br>
<br>
&nbsp;&nbsp; static decode_t activeHigh, activeLow;<br>
<br>
&nbsp;&nbsp; static uint32_t lastTick;<br>
<br>
&nbsp;&nbsp; uint32_t diffTick;<br>
<br>
&nbsp;&nbsp; if (!inited)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inited = 1;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; activeHigh.state = OUTSIDE_CODE;
activeHigh.level = PI_LOW;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; activeLow.state&nbsp; =
OUTSIDE_CODE; activeLow.level&nbsp; = PI_HIGH;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastTick = tick;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; diffTick = tick - lastTick;<br>
<br>
&nbsp;&nbsp; if (level != PI_TIMEOUT) lastTick = tick;<br>
<br>
&nbsp;&nbsp; updateState(&amp;activeHigh, level, diffTick);<br>
&nbsp;&nbsp; updateState(&amp;activeLow, level, diffTick);<br>
}<br>
<br>
void updateState(decode_t * decode, int level, uint32_t micros)<br>
{<br>
&nbsp;&nbsp; /*<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; We are dealing with active high as
well as active low<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; remotes.&nbsp; Abstract the common
functionality.<br>
&nbsp;&nbsp; */<br>
<br>
&nbsp;&nbsp; if (decode-&gt;state == OUTSIDE_CODE)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (level == decode-&gt;level)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (micros &gt;
MIN_MESSAGE_GAP)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
decode-&gt;state = INSIDE_CODE;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
decode-&gt;count = 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; else<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (micros &gt; MAX_MESSAGE_END)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* end of message
*/<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* ignore if last
code not consumed */<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!ir_hash)
ir_hash = getHash(decode);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; decode-&gt;state =
OUTSIDE_CODE;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if
(decode-&gt;count &lt; (MAX_TRANSITIONS-1))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if (level != PI_TIMEOUT)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
decode-&gt;micros[decode-&gt;count++] = micros;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp; }<br>
}<br>
<br>
int compare(unsigned int oldval, unsigned int newval)<br>
{<br>
&nbsp;&nbsp; if&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (newval &lt; (oldval
* 0.75)) {return 1;}<br>
&nbsp;&nbsp; else if (oldval &lt; (newval * 0.75)) {return 2;}<br>
&nbsp;&nbsp;
else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{return 4;}<br>
}<br>
<br>
uint32_t getHash(decode_t * decode)<br>
{<br>
&nbsp;&nbsp; /* use FNV-1a */<br>
<br>
&nbsp;&nbsp; uint32_t hash;<br>
&nbsp;&nbsp; int i, value;<br>
<br>
&nbsp;&nbsp; if (decode-&gt;count &lt; 6) {return 0;}<br>
<br>
&nbsp;&nbsp; hash = FNV_BASIS_32;<br>
<br>
&nbsp;&nbsp; for (i=0; i&lt;(decode-&gt;count-2); i++)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value =
compare(decode-&gt;micros[i], decode-&gt;micros[i+2]);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hash = hash ^ value;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hash = (hash * FNV_PRIME_32);<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; return hash;<br>
}<br></code>
<h3>BUILD</h3>
<code>cc -o ir_remote ir_remote.c -lpigpio -lrt
-lpthread<br></code>
<h3>RUN</h3>
<code>sudo ./ir_remote</code><br>
<p>A hash code is formed from the level transitions detected during
a remote key press.&nbsp; This is likely to be unique over multiple
remotes and keys.</p>
<p>While the program is running you can capture the waveform using
the notification feature built in to pigpio.&nbsp; Issue the
following commands on the Pi.</p>
<code>pigs no<br>
pig2vcd&nbsp; &lt;/dev/pigpio0 &gt;ir.vcd &amp;<br>
pigs nb 0 0x80 # set bits for gpios 7 (0x80)<br></code>
<p>Press a few different remotes and keys.&nbsp; Then enter<br></p>
<code>pigs nc 0</code><br>
<p>The file ir.vcd will contain the captured waveform, which can be
viewed using GTKWave.</p>
<p>Overview</p>
<img src="images/ir-wave-1.png" style=
"width: 600px; height: 100px;" alt="ir remote waveform 1"><br>
<p>Remote A typical waveform</p>
<img src="images/ir-wave-2.png" style=
"width: 600px; height: 100px;" alt="ir remote waveform 2"><br>
<p>Remote B typical waveform</p>
<img style="width: 600px; height: 100px;" alt=
"ir remote waveform 3" src="images/ir-wave-3.png">


file_name: ex_LDR
menu_title: Light Dependent Resitor
page_title: LDR Example
pic1: keypad.jpg
pic2: ldr-cap.jpg
pic3: meter.jpg
body:
<p>The following code shows a method of reading analogue sensors on
the digital input only Pi.&nbsp; A Light Dependent Resistor (LDR)
varies its resistance according to the incident light
intensisty.</p>
<h3>SETUP</h3>
<img src="images/LDR-fritz.png" alt="fritzing diagram" style=
"width: 200px; height: 300px;" align="left" hspace="10">The LDR
used is a Cadmium Sulphide device with a 1MOhm dark resistance and
2-4KOhm at 100 lux.&nbsp; The capacitor is a 104
ceramic.<span itemprop="name"><br>
<br>
One end of the capacitor is connected to Pi ground.<br>
<br>
One end of the LDR is connected to Pi 3V3.<br>
<br>
The other ends of the capacitor and LDR are connected to a spare
gpio.</span><br>
<p>Here P1-1 is used for 3V3, P1-20 is used for ground, and gpio 18
(P1-12) is used for the gpio.<br clear="all"></p>
<p><img src="images/LDR-photo.jpg" style=
"width: 500px; height: 667px;" alt="photo of set-up"></p>
<h3>CODE</h3>
<code>#include &lt;stdio.h&gt;<br>
<br>
#include &lt;pigpio.h&gt;<br>
<br>
/*
-----------------------------------------------------------------------<br>

<br>
&nbsp;&nbsp; 3V3 ----- Light Dependent Resistor --+-- Capacitor
----- Ground<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+-- gpio<br>
<br>
<br>
&nbsp; cc -o LDR LDR.c -lpigpio -lpthread -lrt<br>
&nbsp; sudo ./LDR<br>
<br>
*/<br>
<br>
#define LDR 18<br>
<br>
/* forward declaration */<br>
<br>
void alert(int pin, int level, uint32_t tick);<br>
<br>
int main (int argc, char *argv[])<br>
{<br>
&nbsp;&nbsp; if (gpioInitialise()&lt;0) return 1;<br>
<br>
&nbsp;&nbsp; gpioSetAlertFunc(LDR, alert); /* call alert when LDR
changes state */<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp; while (1)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioSetMode(LDR, PI_OUTPUT); /*
drain capacitor */<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioWrite(LDR, PI_OFF);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioDelay(200); /* 50 micros is
enough, 200 is overkill */<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioSetMode(LDR, PI_INPUT); /* start
capacitor recharge */<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioDelay(10000); /* nominal 100
readings per second */<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; gpioTerminate();<br>
}<br>
<br>
void alert(int pin, int level, uint32_t tick)<br>
{<br>
&nbsp;&nbsp; static uint32_t inited = 0;<br>
&nbsp;&nbsp; static uint32_t lastTick, firstTick;<br>
<br>
&nbsp;&nbsp; uint32_t diffTick;<br>
<br>
&nbsp;&nbsp; if (inited)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diffTick = tick - lastTick;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastTick = tick;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (level == 1) printf("%u %d\ ",
tick-firstTick, diffTick);<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; else<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inited = 1;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; firstTick = tick;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastTick = firstTick;<br>
&nbsp;&nbsp; }<br>
}<br></code>
<h3>BUILD</h3>
<code>cc -o LDR LDR.c -lpigpio -lrt -lpthread<br></code>
<h3>RUN</h3>
<code>sudo ./LDR &gt;LDR.dat &amp;</code><br>
<br>
While the program is running you can capture the waveform using the
notification feature built in to pigpio.&nbsp; Issue the following
commands on the Pi.<br>
<br>
<code>pigs no<br>
pig2vcd&nbsp; &lt;/dev/pigpio0 &gt;LDR.vcd &amp;<br>
pigs nb 0 0x40000 # set bit for gpio 18<br></code>
<p>Change the light falling on the LDR for a few seconds (e.g.
shine a torch on it or shade it with your hands).<br></p>
<code>pigs nc 0</code><br>
<p>The file LDR.vcd will contain the captured waveform, which can
be viewed using GTKWave.</p>
<p>Overview</p>
<img src="images/LDR-wave-1.png" style=
"width: 600px; height: 100px;" alt="LDR waveform 1"><br>
<p>Reading circa every 10ms<br></p>
<img src="images/LDR-wave-2.png" style=
"width: 600px; height: 100px;" alt="LDR waveform 2"><br>
<p>One reading, circa 400us<br></p>
<img src="images/LDR-wave-3.png" style=
"width: 600px; height: 100px;" alt="LDR waveform 3"><br>
<p>The file LDR.dat will contain pairs of timestamps and recharge
time (in us).&nbsp; The following&nbsp; script will convert the
timestamps into seconds.<span style=
"font-style: italic;"><br></span></p>
<p><code>awk '{print $1/1000000, $2}' LDR.dat
&gt;LDR-secs.dat</code></p>
<p>Gnuplot is a useful tool to graph data.<br></p>
plot [14:24] 'LDR-secs.dat' with lines title 'LDR'
<p>Gnuplot readings 14-24 seconds<br></p>
<p><img src="images/LDR-gnup-1.png" style=
"width: 600px; height: 321px;" alt="gnuplot 1"></p>
plot [18:21] 'LDR-secs.dat' with lines title 'LDR'<br>
<br>
Gnuplot readings 18-21 seconds
<p><img src="images/LDR-gnup-2.png" style=
"width: 600px; height: 321px;" alt="Gnuplot 2"></p>


