# pigpio

file_name: download
menu_title: Download
page_title: Download & Install
pic1: rf-tx.jpg
pic2: rpi.jpg
pic3: speaker.jpg
body:
If the pigpio daemon is running it should be killed (sudo killall
pigpiod) before make install and restarted afterwards (sudo
pigpiod).<br>
<br>
<span style="font-weight: bold;">The initial part of the make, the
compilation of pigpio.c, takes 100 seconds on early model
Pis.&nbsp; Be patient.&nbsp; The overall install takes just over 3
minutes.</span><br style="font-weight: bold;">
<h3>Download and install latest version<br></h3>
<code>
wget https://github.com/joan2937/pigpio/archive/master.zip<br>
unzip master.zip<br>
cd pigpio-master<br>
make<br>
sudo make install<br>
</code>
<br>
If the Python part of the install fails it may be because you need
the setup tools.<br>
<br>
<code>sudo apt install python-setuptools
python3-setuptools<br></code><br>
<br>
<h3>To check the library</h3>
These tests make extensive use of GPIO 25 (pin 22).&nbsp; Make sure
nothing, or only a LED, is connected to the GPIO before running the
tests.&nbsp; Most tests are statistical in nature and so may on
occasion fail.&nbsp; Repeated failures on the same test or many
failures in a group of tests indicate a problem.<br>
<code><br>
sudo ./x_pigpio # check C I/F<br>
<br>
sudo pigpiod&nbsp;&nbsp;&nbsp; # start daemon<br>
<br>
./x_pigpiod_if2 # check C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I/F to
daemon<br>
./x_pigpio.py&nbsp;&nbsp; # check Python I/F to daemon<br>
./x_pigs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # check
pigs&nbsp;&nbsp; I/F to daemon<br>
./x_pipe&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # check
pipe&nbsp;&nbsp; I/F to daemon<br>
<br>
<br></code>
<h3>To compile, link, and run a C program</h3>
<code>gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt<br>
sudo ./foobar</code><code><br></code><br>
<h3>To start the pigpio daemon<br></h3>
<code>sudo pigpiod<br></code>
<h3>To stop the pigpio daemon<br></h3>
<code>sudo killall pigpiod<br></code><br>
<h3>github</h3>
<code>git clone https://github.com/joan2937/pigpio</code><br>
<h3>Raspbian (raspberrypi.org image)</h3>
<p>This may not be the most recent version.&nbsp; You can check the
version with the command pigpiod -v.<br></p>
<code>sudo apt-get update<br>
sudo apt-get install pigpio python-pigpio python3-pigpio</code><br>
<br>


file_name: ex_motor_shield
menu_title: Arduino Motor Shield
page_title: Arduino Motor Shield
pic1: stepper.jpg
pic2: transistors.jpg
pic3: wires.jpg
body:
The following example demonstrates the use of an Arduino shield
from the Rasperry Pi.<br>
<br>
The shield used is a clone of the Adafruit motor shield.&nbsp; See
<a href="http://shieldlist.org/adafruit/motor">shieldlist.org</a>
for details.<br>
<br>
For the demonstration DC motors 3 and 4 are being driven forwards
and backwards with changing speeds (speeds are controlled via
PWM).<br>
<br>
Seven connections are made between the Pi and the shield.&nbsp;
Four to latch the motor states (latch, enable, data, clock); Two to
control motor speed (PWM 3 and 4); and ground.<br>
<br>
The code used was ported from the Adafruit Arduino code and
converted to use the pigpio library.&nbsp; Only the DC motor code
was ported.<br>
<br>
A video of the shield in use is available at <a href=
"http://youtu.be/Z_l3C246oVI">youtube.com</a><br>
<code><br>
#include &lt;stdio.h&gt;</code> <code><br>
<br>
#include &lt;pigpio.h&gt;<br>
<br>
/*<br>
&nbsp;&nbsp; This code may be used to drive the Adafruit (or
clones) Motor Shield.<br>
<br>
&nbsp;&nbsp; The code as written only supports DC motors.<br>
<br>
&nbsp;&nbsp; http://shieldlist.org/adafruit/motor<br>
<br>
&nbsp;&nbsp; The shield pinouts are<br>
<br>
&nbsp;&nbsp; D12 MOTORLATCH<br>
&nbsp;&nbsp; D11 PMW motor 1<br>
&nbsp;&nbsp; D10 Servo 1<br>
&nbsp;&nbsp; D9&nbsp; Servo 2<br>
&nbsp;&nbsp; D8&nbsp; MOTORDATA<br>
<br>
&nbsp;&nbsp; D7&nbsp; MOTORENABLE<br>
&nbsp;&nbsp; D6&nbsp; PWM motor 4<br>
&nbsp;&nbsp; D5&nbsp; PWM motor 3<br>
&nbsp;&nbsp; D4&nbsp; MOTORCLK<br>
&nbsp;&nbsp; D3&nbsp; PWM motor 2<br>
<br>
&nbsp;&nbsp; The motor states (forward, backward, brake, release)
are encoded using the<br>
&nbsp;&nbsp; MOTOR_ latch pins.&nbsp; This saves four gpios.<br>
*/<br>
<br>
typedef unsigned char uint8_t;<br>
<br>
#define BIT(bit) (1 &lt;&lt; (bit))<br>
<br>
/* assign gpios to drive the shield pins */<br>
<br>
/*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Shield&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Pi */<br>
<br>
#define MOTORLATCH&nbsp; 14<br>
#define MOTORCLK&nbsp;&nbsp;&nbsp; 24<br>
#define MOTORENABLE 25<br>
#define MOTORDATA&nbsp;&nbsp; 15<br>
<br>
#define MOTOR_3_PWM&nbsp; 7<br>
#define MOTOR_4_PWM&nbsp; 8<br>
<br>
/*<br>
&nbsp;&nbsp; The only other connection needed between the Pi and
the shield<br>
&nbsp;&nbsp; is ground to ground. I used Pi P1-6 to shield gnd
(next to D13).<br>
*/<br>
<br>
/* assignment of motor states to latch */<br>
<br>
#define MOTOR1_A 2<br>
#define MOTOR1_B 3<br>
#define MOTOR2_A 1<br>
#define MOTOR2_B 4<br>
#define MOTOR4_A 0<br>
#define MOTOR4_B 6<br>
#define MOTOR3_A 5<br>
#define MOTOR3_B 7<br>
<br>
#define FORWARD&nbsp; 1<br>
#define BACKWARD 2<br>
#define BRAKE&nbsp;&nbsp;&nbsp; 3<br>
#define RELEASE&nbsp; 4<br>
<br>
static uint8_t latch_state;<br>
<br>
void latch_tx(void)<br>
{<br>
&nbsp;&nbsp; unsigned char i;<br>
<br>
&nbsp;&nbsp; gpioWrite(MOTORLATCH, PI_LOW);<br>
<br>
&nbsp;&nbsp; gpioWrite(MOTORDATA, PI_LOW);<br>
<br>
&nbsp;&nbsp; for (i=0; i&lt;8; i++)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioDelay(10);&nbsp; // 10 micros
delay<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioWrite(MOTORCLK, PI_LOW);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (latch_state &amp; BIT(7-i))
gpioWrite(MOTORDATA, PI_HIGH);<br>
&nbsp;&nbsp;&nbsp;&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;
gpioWrite(MOTORDATA, PI_LOW);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioDelay(10);&nbsp; // 10 micros
delay<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioWrite(MOTORCLK, PI_HIGH);<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; gpioWrite(MOTORLATCH, PI_HIGH);<br>
}<br>
<br>
void init(void)<br>
{<br>
&nbsp;&nbsp; latch_state = 0;<br>
<br>
&nbsp;&nbsp; latch_tx();<br>
<br>
&nbsp;&nbsp; gpioWrite(MOTORENABLE, PI_LOW);<br>
}<br>
<br>
void DCMotorInit(uint8_t num)<br>
{<br>
&nbsp;&nbsp; switch (num)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 1: latch_state &amp;=
~BIT(MOTOR1_A) &amp; ~BIT(MOTOR1_B); break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 2: latch_state &amp;=
~BIT(MOTOR2_A) &amp; ~BIT(MOTOR2_B); break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 3: latch_state &amp;=
~BIT(MOTOR3_A) &amp; ~BIT(MOTOR3_B); break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 4: latch_state &amp;=
~BIT(MOTOR4_A) &amp; ~BIT(MOTOR4_B); break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default: return;<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; latch_tx();<br>
<br>
&nbsp;&nbsp; printf("Latch=%08X\ ", latch_state);<br>
}<br>
<br>
void DCMotorRun(uint8_t motornum, uint8_t cmd)<br>
{<br>
&nbsp;&nbsp; uint8_t a, b;<br>
<br>
&nbsp;&nbsp; switch (motornum)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 1: a = MOTOR1_A; b = MOTOR1_B;
break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 2: a = MOTOR2_A; b = MOTOR2_B;
break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 3: a = MOTOR3_A; b = MOTOR3_B;
break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 4: a = MOTOR4_A; b = MOTOR4_B;
break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default: return;<br>
&nbsp;&nbsp; }<br>
&nbsp;<br>
&nbsp;&nbsp; switch (cmd)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case FORWARD:&nbsp; latch_state
|=&nbsp; BIT(a); latch_state &amp;= ~BIT(b); break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case BACKWARD: latch_state &amp;=
~BIT(a); latch_state |=&nbsp; BIT(b); break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case RELEASE:&nbsp; latch_state
&amp;= ~BIT(a); latch_state &amp;= ~BIT(b); break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default: return;<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; latch_tx();<br>
<br>
&nbsp;&nbsp; printf("Latch=%08X\ ", latch_state);<br>
}<br>
<br>
int main (int argc, char *argv[])<br>
{<br>
&nbsp;&nbsp; int i;<br>
<br>
&nbsp;&nbsp; if (gpioInitialise()&lt;0) return 1;<br>
<br>
&nbsp;&nbsp; gpioSetMode(MOTORLATCH,&nbsp; PI_OUTPUT);<br>
&nbsp;&nbsp; gpioSetMode(MOTORENABLE, PI_OUTPUT);<br>
&nbsp;&nbsp; gpioSetMode(MOTORDATA,&nbsp;&nbsp; PI_OUTPUT);<br>
&nbsp;&nbsp; gpioSetMode(MOTORCLK,&nbsp;&nbsp;&nbsp;
PI_OUTPUT);<br>
<br>
&nbsp;&nbsp; gpioSetMode(MOTOR_3_PWM, PI_OUTPUT);<br>
&nbsp;&nbsp; gpioSetMode(MOTOR_4_PWM, PI_OUTPUT);<br>
<br>
&nbsp;&nbsp; gpioPWM(MOTOR_3_PWM, 0);<br>
&nbsp;&nbsp; gpioPWM(MOTOR_4_PWM, 0);<br>
<br>
&nbsp;&nbsp; init();<br>
<br>
&nbsp;&nbsp; for (i=60; i&lt;160; i+=20)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioPWM(MOTOR_3_PWM, i);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioPWM(MOTOR_4_PWM, 220-i);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DCMotorRun(3, FORWARD);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DCMotorRun(4, BACKWARD);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sleep(2);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DCMotorRun(3, RELEASE);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DCMotorRun(4, RELEASE);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sleep(2);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioPWM(MOTOR_4_PWM, i);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioPWM(MOTOR_3_PWM, 220-i);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DCMotorRun(3, BACKWARD);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DCMotorRun(4, FORWARD);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sleep(2);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DCMotorRun(3, RELEASE);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DCMotorRun(4, RELEASE);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sleep(2);<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; gpioPWM(MOTOR_4_PWM, 0);<br>
&nbsp;&nbsp; gpioPWM(MOTOR_3_PWM, 0);<br>
<br>
&nbsp;&nbsp; DCMotorRun(3, RELEASE);<br>
&nbsp;&nbsp; DCMotorRun(4, RELEASE);<br>
<br>
&nbsp;&nbsp; gpioTerminate();<br>
}<br></code>


file_name: piscope
menu_title: piscope
page_title: piscope
pic1: pisc-1.jpg
pic2: pisc-2.jpg
pic3: pisc-3.jpg
body:
<h2>Introduction<br></h2>
<a href="piscope.tar">piscope</a> is a logic analyser (digital
waveform viewer) for the Raspberry.&nbsp; It shows the state (high
or low) of selected GPIO in real-time.<br>
<br>
See <a href="http://youtu.be/2apqOiLHEzs">video</a>.<br>
<br>
piscope uses the services of the pigpio <a href=
"download.html">library</a>.&nbsp; pigpio needs to be running on
the Pi whose GPIO are to be monitored.<br>
<br>
The pigpio library may be started as a daemon (background process)
by the following command.<br>
<br>
<code>sudo pigpiod<br></code><br>
piscope may be invoked in several different ways<br>
<br>
<table summary="" style=
"text-align: left; width: 90%; height: 246px;" cellspacing="2"
cellpadding="2" border="1">
<tbody>
<tr>
<td style="width: 15%;"><small>Pi<br></small></td>
<td style="vertical-align: top; width: 55%;"><small><span style=
"font-style: italic;">pi_host</span> ~ $ piscope
&amp;<br></small></td>
<td style="vertical-align: top; width: 30%;"><small>Pi captures
data<br>
Pi processes data<br>
Pi displays data<br></small></td>
</tr>
<tr>
<td style="vertical-align: top;"><small>Pi plus Linux PC<br>
<br>
(with the<br>
display on a remote<br>
&nbsp; Linux PC)<br></small></td>
<td style="vertical-align: top;"><small><span style=
"font-style: italic;">remote_host</span> ~ $ ssh -X <span style=
"font-style: italic;">pi_host</span><br></small><small><span style=
"font-style: italic;">pi_host</span> ~ $ piscope
&amp;</small><small><br></small></td>
<td style="vertical-align: top;"><small>Pi captures data<br>
Pi processes data<br>
Remote Linux PC displays data<br></small></td>
</tr>
<tr>
<td style="vertical-align: top;"><small>Pi plus Windows PC<br>
<br>
(with the<br>
display on a remote<br>
&nbsp; Windows PC)</small></td>
<td style="vertical-align: top;"><small>You need to install an SSH
client (putty suggested) and a X11 server (xming suggested).<br>
<br>
Run Program Files -&gt; Xming -&gt; XLaunch and accept the
defaults.<br>
<br>
Run putty and enter the Pi's host name or IP address.&nbsp; Click
on SSH X11 and tick Enable X11 forwarding and then select
Open.</small><br>
<small><br></small> <small><span style=
"font-style: italic;">pi_host</span> ~ $ piscope
&amp;</small><br></td>
<td style="vertical-align: top;"><small>Pi captures data<br>
Pi processes data<br>
Remote Windows PC displays data</small></td>
</tr>
<tr>
<td style="vertical-align: top;"><small>Pi plus Linux PC<br>
<br>
(with the display and processing on a remote Linux
PC)<br></small></td>
<td style="vertical-align: top;"><small><span style=
"font-style: italic;">remote_host</span> ~ $ export
PIGPIO_ADDR=<span style="font-style: italic;">pi_host</span><br>
<span style="font-style: italic;">remote_host</span> ~ $ piscope
&amp;<br></small></td>
<td style="vertical-align: top;"><small>Pi captures data<br>
Remote processes data<br>
Remote displays data<br></small></td>
</tr>
</tbody>
</table>
<br>
piscope operates in one of three modes<br>
<br>
<table summary="" style="text-align: left; width: 90%;"
cellspacing="2" cellpadding="2" border="1">
<tbody>
<tr>
<td style="vertical-align: top;">Live<br></td>
<td style="vertical-align: top;">The latest GPIO samples are
displayed.<br>
<br>
The mode will automatically change to Pause if a sampling trigger
is detected.<br>
<br>
There are four triggers.&nbsp; Each trigger is made up of a
combination of GPIO states (one of don't care, low, high, edge,
falling, or rising per GPIO).&nbsp; Triggers are always
counted.&nbsp; In addition a trigger may be sample to, sample
around, or sample from, a so called sampling trigger.<br></td>
<td style="vertical-align: top;">New samples are added to the
sample buffer.<br>
<br>
Once the sample buffer is full the <span style=
"font-weight: bold;">oldest</span> samples are discarded.</td>
</tr>
<tr>
<td style="vertical-align: top;">Play<br></td>
<td style="vertical-align: top;">Recorded GPIO samples are
displayed.<br>
<br>
The play speed may be varied between 64 times real-time to 1/32768
of real-time.<br>
<br>
The page up key increases the play speed by a factor of 2.&nbsp;
The page down key decreases the play speed by a factor of 2.&nbsp;
The home key sets the play speed to 1X.<br></td>
<td style="vertical-align: top;">New samples are added to the
sample buffer.<br>
<br>
Once the sample buffer is full <span style=
"font-weight: bold;">new</span> samples are discarded.</td>
</tr>
<tr>
<td style="vertical-align: top;">Pause<br></td>
<td style="vertical-align: top;">Recorded GPIO samples are
displayed.<br>
<br>
The left and right cursor keys move the blue marker to the previous
or next edge.&nbsp; By default all GPIO edges are considered.&nbsp;
Clicking on a GPIO name will limit edge searches to the highlighted
GPIO only.<br>
<br>
The left and right square bracket keys move the blue marker to the
previous or next trigger.<br>
<br>
The time between the blue and gold markers is displayed.&nbsp; The
gold marker is set to the blue marker by a press of the 'g'
key.<br></td>
<td style="vertical-align: top;">New samples are added to the
sample buffer.<br>
<br>
Once the sample buffer is full <span style=
"font-weight: bold;">new</span> samples are discarded.</td>
</tr>
</tbody>
</table>
<br>
In all modes the down and up cursor keys zoom the time scale in and
out.<br>
<br>
Samples can be saved with File Save All Samples or File Save
Selected Samples.
<p>To select samples enter pause mode. Press 1 to specify the start
of the samples (green marker) and 2 to specify the end of the
samples (red marker).</p>
<p>The samples may be saved in the native piscope format or in VCD
format.</p>
<p>Data saved in VCD format may be viewed and further processed
with GTKWave.</p>
<p>Data saved in the native piscope format may be restored later
with File Restore Saved Data.</p>
<h2>Installation</h2>
<p>To download and install piscope.</p>
<h3>Pi (pre-built image)</h3>
<code>wget abyz.me.uk/rpi/pigpio/piscope.tar<br>
tar xvf piscope.tar<br>
cd PISCOPE<br>
make hf<br>
make install</code><span style="font-weight: bold;"><br></span>
<h3>Linux 64 bit X86/AMD (pre-built image)</h3>
<code>wget abyz.me.uk/rpi/pigpio/piscope.tar<br>
tar xvf piscope.tar<br>
cd PISCOPE<br>
make x86_64<br>
make install<br></code>
<h3>All machines (building from source)</h3>
You only need to perform this step if you want to build the
executable from the source files.&nbsp; This is not needed if you
use a pre-built image.<br>
<span style="font-weight: bold;"><br>
WARNING</span>: Installing gtk+-3.0 uses a lot of SD card
space.<br>
<br>
Most of the space used by gtk+-3.0 is taken up by unneeded *-dbg
packages.<br>
<br>
With *-dbg packages an additional 3753MB SD space is required.<br>
<br>
If you edit the list of packages to be downloaded and remove the
*-dbg packages only 134MB of additional SD space is needed (as at
the time of writing).<br>
<br>
<code>#<br></code> <code># *** This may take a lot of time and use
a lot of SD card space ***<br></code> <code>#<br>
sudo apt-get install gtk+-3.0<br></code> <code>#<br></code>
<code>wget abyz.me.uk/rpi/pigpio/piscope.tar<br>
tar xvf piscope.tar<br>
cd PISCOPE<br>
make<br>
make install<br></code><br>


file_name: python
menu_title: Python
page_title: Python Interface
pic1: lcd.jpg
pic2: keypad.jpg
pic3: driver.jpg
body:
pigpio is a Python module for the Raspberry which talks to
the pigpio daemon to allow control of the general purpose
input outputs (GPIO).
<h3>Features</h3>o the pigpio Python module can run on Windows, Macs, or Linux
<br><br>o controls one or more Pi's
<br><br>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 creating and transmitting precisely timed waveforms
<br><br>o reading/writing GPIO and setting their modes
<br><br>o wrappers for I2C, SPI, and serial links
<br><br>o creating and running scripts on the pigpio daemon
<h3>GPIO</h3>ALL GPIO are identified by their Broadcom number.
<h3>Notes</h3>Transmitted waveforms are accurate to a microsecond.
<br><br>Callback level changes are time-stamped and will be
accurate to within a few microseconds.
<h3>Settings</h3>A number of settings are determined when the pigpio daemon is started.
<br><br>o the sample rate (1, 2, 4, 5, 8, or 10 us, default 5 us).
<br><br>o the set of GPIO which may be updated (generally written to).  The
  default set is those available on the Pi board revision.
<br><br>o the available PWM frequencies (see <a href="#set_PWM_frequency">set_PWM_frequency</a>).
<h3>Exceptions</h3>By default a fatal exception is raised if you pass an invalid
argument to a pigpio function.
<br><br>If you wish to handle the returned status yourself you should set
pigpio.exceptions to False.
<br><br>You may prefer to check the returned status in only a few parts
of your code.  In that case do the following:
<br><br><b><small>Example</small></b><br><br><code>pigpio.exceptions&nbsp;=&nbsp;False<br><br>#&nbsp;Code&nbsp;where&nbsp;you&nbsp;want&nbsp;to&nbsp;test&nbsp;the&nbsp;error&nbsp;status.<br><br>pigpio.exceptions&nbsp;=&nbsp;True<br></code><h3>Usage</h3>This module uses the services of the C pigpio library.  pigpio
must be running on the Pi(s) whose GPIO are to be manipulated.
<br><br>The normal way to start pigpio is as a daemon (during system
start).
<br><br>sudo pigpiod
<br><br>Your Python program must import pigpio and create one or more
instances of the pigpio.pi class.  This class gives access to
a specified Pi's GPIO.
<br><br><b><small>Example</small></b><br><br><code>pi1&nbsp;=&nbsp;pigpio.pi()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;pi1&nbsp;accesses&nbsp;the&nbsp;local&nbsp;Pi's&nbsp;GPIO<br>pi2&nbsp;=&nbsp;pigpio.pi('tom')&nbsp;&nbsp;#&nbsp;pi2&nbsp;accesses&nbsp;tom's&nbsp;GPIO<br>pi3&nbsp;=&nbsp;pigpio.pi('dick')&nbsp;#&nbsp;pi3&nbsp;accesses&nbsp;dick's&nbsp;GPIO<br><br>pi1.write(4,&nbsp;0)&nbsp;#&nbsp;set&nbsp;local&nbsp;Pi's&nbsp;GPIO&nbsp;4&nbsp;low<br>pi2.write(4,&nbsp;1)&nbsp;#&nbsp;set&nbsp;tom's&nbsp;GPIO&nbsp;4&nbsp;to&nbsp;high<br>pi3.read(4)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;get&nbsp;level&nbsp;of&nbsp;dick's&nbsp;GPIO&nbsp;4<br></code><br><br>The later example code snippets assume that pi is an instance of
the pigpio.pi class.
<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="#pigpio.pi">pigpio.pi</a></td><td>                Initialise Pi connection
</td></tr><tr><td><a href="#stop">stop</a></td><td>                     Stop a Pi connection
</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="#set_mode">set_mode</a></td><td>                 Set a GPIO mode
</td></tr><tr><td><a href="#get_mode">get_mode</a></td><td>                 Get a GPIO mode
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_pull_up_down">set_pull_up_down</a></td><td>         Set/clear GPIO pull up/down resistor
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#read">read</a></td><td>                     Read a GPIO
</td></tr><tr><td><a href="#write">write</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="#set_PWM_dutycycle">set_PWM_dutycycle</a></td><td>        Start/stop PWM pulses on a GPIO
</td></tr><tr><td><a href="#set_PWM_frequency">set_PWM_frequency</a></td><td>        Set PWM frequency of a GPIO
</td></tr><tr><td><a href="#set_PWM_range">set_PWM_range</a></td><td>            Configure PWM range of a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#get_PWM_dutycycle">get_PWM_dutycycle</a></td><td>        Get PWM dutycycle set on a GPIO
</td></tr><tr><td><a href="#get_PWM_frequency">get_PWM_frequency</a></td><td>        Get PWM frequency of a GPIO
</td></tr><tr><td><a href="#get_PWM_range">get_PWM_range</a></td><td>            Get configured PWM range of a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#get_PWM_real_range">get_PWM_real_range</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="#set_servo_pulsewidth">set_servo_pulsewidth</a></td><td>     Start/Stop servo pulses on a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#get_servo_pulsewidth">get_servo_pulsewidth</a></td><td>     Get servo pulsewidth set 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="#gpio_trigger">gpio_trigger</a></td><td>             Send a trigger pulse to a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_watchdog">set_watchdog</a></td><td>             Set a watchdog on a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#read_bank_1">read_bank_1</a></td><td>              Read all bank 1 GPIO
</td></tr><tr><td><a href="#read_bank_2">read_bank_2</a></td><td>              Read all bank 2 GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#clear_bank_1">clear_bank_1</a></td><td>             Clear selected GPIO in bank 1
</td></tr><tr><td><a href="#clear_bank_2">clear_bank_2</a></td><td>             Clear selected GPIO in bank 2
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_bank_1">set_bank_1</a></td><td>               Set selected GPIO in bank 1
</td></tr><tr><td><a href="#set_bank_2">set_bank_2</a></td><td>               Set selected GPIO in bank 2
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#callback">callback</a></td><td>                 Create GPIO level change callback
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wait_for_edge">wait_for_edge</a></td><td>            Wait for GPIO level change
</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="#notify_open">notify_open</a></td><td>              Request a notification handle
</td></tr><tr><td><a href="#notify_begin">notify_begin</a></td><td>             Start notifications for selected GPIO
</td></tr><tr><td><a href="#notify_pause">notify_pause</a></td><td>             Pause notifications
</td></tr><tr><td><a href="#notify_close">notify_close</a></td><td>             Close a notification
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#hardware_clock">hardware_clock</a></td><td>           Start hardware clock on supported GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#hardware_PWM">hardware_PWM</a></td><td>             Start hardware PWM on supported GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_glitch_filter">set_glitch_filter</a></td><td>        Set a glitch filter on a GPIO
</td></tr><tr><td><a href="#set_noise_filter">set_noise_filter</a></td><td>         Set a noise filter on a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_pad_strength">set_pad_strength</a></td><td>         Sets a pads drive strength
</td></tr><tr><td><a href="#get_pad_strength">get_pad_strength</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><b>Custom
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#custom_1">custom_1</a></td><td>                 User custom function 1
</td></tr><tr><td><a href="#custom_2">custom_2</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="#event_callback">event_callback</a></td><td>           Sets a callback for an event
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#event_trigger">event_trigger</a></td><td>            Triggers an event
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wait_for_event">wait_for_event</a></td><td>           Wait for 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="#store_script">store_script</a></td><td>             Store a script
</td></tr><tr><td><a href="#run_script">run_script</a></td><td>               Run a stored script
</td></tr><tr><td><a href="#update_script">update_script</a></td><td>            Set a scripts parameters
</td></tr><tr><td><a href="#script_status">script_status</a></td><td>            Get script status and parameters
</td></tr><tr><td><a href="#stop_script">stop_script</a></td><td>              Stop a running script
</td></tr><tr><td><a href="#delete_script">delete_script</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="#i2c_open">i2c_open</a></td><td>                 Opens an I2C device
</td></tr><tr><td><a href="#i2c_close">i2c_close</a></td><td>                Closes an I2C device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_write_quick">i2c_write_quick</a></td><td>          SMBus write quick
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_read_byte">i2c_read_byte</a></td><td>            SMBus read byte
</td></tr><tr><td><a href="#i2c_write_byte">i2c_write_byte</a></td><td>           SMBus write byte
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_read_byte_data">i2c_read_byte_data</a></td><td>       SMBus read byte data
</td></tr><tr><td><a href="#i2c_write_byte_data">i2c_write_byte_data</a></td><td>      SMBus write byte data
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_read_word_data">i2c_read_word_data</a></td><td>       SMBus read word data
</td></tr><tr><td><a href="#i2c_write_word_data">i2c_write_word_data</a></td><td>      SMBus write word data
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_read_block_data">i2c_read_block_data</a></td><td>      SMBus read block data
</td></tr><tr><td><a href="#i2c_write_block_data">i2c_write_block_data</a></td><td>     SMBus write block data
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_read_i2c_block_data">i2c_read_i2c_block_data</a></td><td>  SMBus read I2C block data
</td></tr><tr><td><a href="#i2c_write_i2c_block_data">i2c_write_i2c_block_data</a></td><td> SMBus write I2C block data
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_read_device">i2c_read_device</a></td><td>          Reads the raw I2C device
</td></tr><tr><td><a href="#i2c_write_device">i2c_write_device</a></td><td>         Writes the raw I2C device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_process_call">i2c_process_call</a></td><td>         SMBus process call
</td></tr><tr><td><a href="#i2c_block_process_call">i2c_block_process_call</a></td><td>   SMBus block process call
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_zip">i2c_zip</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="#bb_i2c_open">bb_i2c_open</a></td><td>              Opens GPIO for bit banging I2C
</td></tr><tr><td><a href="#bb_i2c_close">bb_i2c_close</a></td><td>             Closes GPIO for bit banging I2C
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#bb_i2c_zip">bb_i2c_zip</a></td><td>               Performs multiple 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="#bsc_xfer">bsc_xfer</a></td><td>                 I2C/SPI as slave transfer
</td></tr><tr><td><a href="#bsc_i2c">bsc_i2c</a></td><td>                  I2C 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="#serial_open">serial_open</a></td><td>              Opens a serial device
</td></tr><tr><td><a href="#serial_close">serial_close</a></td><td>             Closes a serial device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#serial_read_byte">serial_read_byte</a></td><td>         Reads a byte from a serial device
</td></tr><tr><td><a href="#serial_write_byte">serial_write_byte</a></td><td>        Writes a byte to a serial device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#serial_read">serial_read</a></td><td>              Reads bytes from a serial device
</td></tr><tr><td><a href="#serial_write">serial_write</a></td><td>             Writes bytes to a serial device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#serial_data_available">serial_data_available</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="#bb_serial_read_open">bb_serial_read_open</a></td><td>      Open a GPIO for bit bang serial reads
</td></tr><tr><td><a href="#bb_serial_read_close">bb_serial_read_close</a></td><td>     Close a GPIO for bit bang serial reads
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#bb_serial_invert">bb_serial_invert</a></td><td>         Invert serial logic (1 invert, 0 normal)
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#bb_serial_read">bb_serial_read</a></td><td>           Read 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="#spi_open">spi_open</a></td><td>                 Opens a SPI device
</td></tr><tr><td><a href="#spi_close">spi_close</a></td><td>                Closes a SPI device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#spi_read">spi_read</a></td><td>                 Reads bytes from a SPI device
</td></tr><tr><td><a href="#spi_write">spi_write</a></td><td>                Writes bytes to a SPI device
</td></tr><tr><td><a href="#spi_xfer">spi_xfer</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="#bb_spi_open">bb_spi_open</a></td><td>              Opens GPIO for bit banging SPI
</td></tr><tr><td><a href="#bb_spi_close">bb_spi_close</a></td><td>             Closes GPIO for bit banging SPI
</td></tr><tr><td><a href="#bb_spi_xfer">bb_spi_xfer</a></td><td>              Transfers bytes with bit banging SPI
</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="#file_open">file_open</a></td><td>                Opens a file
</td></tr><tr><td><a href="#file_close">file_close</a></td><td>               Closes a file
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#file_read">file_read</a></td><td>                Reads bytes from a file
</td></tr><tr><td><a href="#file_write">file_write</a></td><td>               Writes bytes to a file
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#file_seek">file_seek</a></td><td>                Seeks to a position within a file
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#file_list">file_list</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="#wave_clear">wave_clear</a></td><td>               Deletes all waveforms
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_add_new">wave_add_new</a></td><td>             Starts a new waveform
</td></tr><tr><td><a href="#wave_add_generic">wave_add_generic</a></td><td>         Adds a series of pulses to the waveform
</td></tr><tr><td><a href="#wave_add_serial">wave_add_serial</a></td><td>          Adds serial data to the waveform
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_create">wave_create</a></td><td>              Creates a waveform from added data
</td></tr><tr><td><a href="#wave_create_and_pad">wave_create_and_pad</a></td><td>      Creates a waveform of fixed size from added data
</td></tr><tr><td><a href="#wave_delete">wave_delete</a></td><td>              Deletes a waveform
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_send_once">wave_send_once</a></td><td>           Transmits a waveform once
</td></tr><tr><td><a href="#wave_send_repeat">wave_send_repeat</a></td><td>         Transmits a waveform repeatedly
</td></tr><tr><td><a href="#wave_send_using_mode">wave_send_using_mode</a></td><td>     Transmits a waveform in the chosen mode
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_chain">wave_chain</a></td><td>               Transmits a chain of waveforms
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_tx_at">wave_tx_at</a></td><td>               Returns the current transmitting waveform
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_tx_busy">wave_tx_busy</a></td><td>             Checks to see if a waveform has ended
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_tx_stop">wave_tx_stop</a></td><td>             Aborts the current waveform
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_get_cbs">wave_get_cbs</a></td><td>             Length in cbs of the current waveform
</td></tr><tr><td><a href="#wave_get_max_cbs">wave_get_max_cbs</a></td><td>         Absolute maximum allowed cbs
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_get_micros">wave_get_micros</a></td><td>          Length in microseconds of the current waveform
</td></tr><tr><td><a href="#wave_get_max_micros">wave_get_max_micros</a></td><td>      Absolute maximum allowed micros
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_get_pulses">wave_get_pulses</a></td><td>          Length in pulses of the current waveform
</td></tr><tr><td><a href="#wave_get_max_pulses">wave_get_max_pulses</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="#get_current_tick">get_current_tick</a></td><td>         Get current tick (microseconds)
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#get_hardware_revision">get_hardware_revision</a></td><td>    Get hardware revision
</td></tr><tr><td><a href="#get_pigpio_version">get_pigpio_version</a></td><td>       Get the pigpio version
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#pigpio.error_text">pigpio.error_text</a></td><td>        Gets error text from error number
</td></tr><tr><td><a href="#pigpio.tickDiff">pigpio.tickDiff</a></td><td>          Returns difference between two ticks
</td></tr><tr><td><b></b></td><td></td></tr></tbody></table><h2>    class pi
</h2><h3><a name="pigpio.pi">pigpio.pi<small>(<a href="#host">host</a>, <a href="#port">port</a>, <a href="#show_errors">show_errors</a>)</small></h3>
Grants access to a Pi's GPIO.
<br><br><b><small>Parameters</small></b><br><br><samp>host:=&nbsp;the&nbsp;host&nbsp;name&nbsp;of&nbsp;the&nbsp;Pi&nbsp;on&nbsp;which&nbsp;the&nbsp;pigpio&nbsp;daemon&nbsp;is<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;running.&nbsp;&nbsp;The&nbsp;default&nbsp;is&nbsp;localhost&nbsp;unless&nbsp;overridden&nbsp;by<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the&nbsp;PIGPIO_ADDR&nbsp;environment&nbsp;variable.<br></samp><br><br><b><small>Parameters</small></b><br><br><samp>port:=&nbsp;the&nbsp;port&nbsp;number&nbsp;on&nbsp;which&nbsp;the&nbsp;pigpio&nbsp;daemon&nbsp;is&nbsp;listening.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;default&nbsp;is&nbsp;8888&nbsp;unless&nbsp;overridden&nbsp;by&nbsp;the&nbsp;PIGPIO_PORT<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;environment&nbsp;variable.&nbsp;&nbsp;The&nbsp;pigpio&nbsp;daemon&nbsp;must&nbsp;have&nbsp;been<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;started&nbsp;with&nbsp;the&nbsp;same&nbsp;port&nbsp;number.<br></samp><br><br>This connects to the pigpio daemon and reserves resources
to be used for sending commands and receiving notifications.
<br><br>An instance attribute <a href="#connected">connected</a> may be used to check the
success of the connection.  If the connection is established
successfully <a href="#connected">connected</a> will be True, otherwise False.
<br><br><b><small>Example</small></b><br><br><code>pi&nbsp;=&nbsp;pigio.pi()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;use&nbsp;defaults<br>pi&nbsp;=&nbsp;pigpio.pi('mypi')&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;specify&nbsp;host,&nbsp;default&nbsp;port<br>pi&nbsp;=&nbsp;pigpio.pi('mypi',&nbsp;7777)&nbsp;#&nbsp;specify&nbsp;host&nbsp;and&nbsp;port<br><br>pi&nbsp;=&nbsp;pigpio.pi()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;exit&nbsp;script&nbsp;if&nbsp;no&nbsp;connection<br>if&nbsp;not&nbsp;pi.connected:<br>&nbsp;&nbsp;&nbsp;exit()<br></code><h3><a name="__repr__">__repr__<small>()</small></h3>
<h3><a name="bb_i2c_close">bb_i2c_close<small>(<a href="#SDA">SDA</a>)</small></h3>
This function stops bit banging I2C on a pair of GPIO
previously opened with <a href="#bb_i2c_open">bb_i2c_open</a>.
<br><br><b><small>Parameters</small></b><br><br><samp>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="#bb_i2c_open">bb_i2c_open</a><br></samp><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO.
<br><br><b><small>Example</small></b><br><br><code>pi.bb_i2c_close(SDA)<br></code><h3><a name="bb_i2c_open">bb_i2c_open<small>(<a href="#SDA">SDA</a>, <a href="#SCL">SCL</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
o repeated starts
o clock stretching
o I2C on any pair of spare GPIO
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;SDA:=&nbsp;0-31<br>&nbsp;SCL:=&nbsp;0-31<br>baud:=&nbsp;50-500000<br></samp><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.
<br><br><b><small>Example</small></b><br><br><code>h&nbsp;=&nbsp;pi.bb_i2c_open(4,&nbsp;5,&nbsp;50000)&nbsp;#&nbsp;bit&nbsp;bang&nbsp;on&nbsp;GPIO&nbsp;4/5&nbsp;at&nbsp;50kbps<br></code><h3><a name="bb_i2c_zip">bb_i2c_zip<small>(<a href="#SDA">SDA</a>, <a href="#data">data</a>)</small></h3>
This function executes a sequence of bit banged I2C operations.
The operations to be performed are specified by the contents
of data which contains the concatenated command codes and
associated data.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;SDA:=&nbsp;0-31&nbsp;(as&nbsp;used&nbsp;in&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#bb_i2c_open">bb_i2c_open</a>)<br>data:=&nbsp;the&nbsp;concatenated&nbsp;I2C&nbsp;commands,&nbsp;see&nbsp;below<br></samp><br><br>The returned value is a tuple of the number of bytes read and a
bytearray containing the bytes.  If there was an error the
number of bytes read will be less than zero (and will contain
the error code).
<br><br><b><small>Example</small></b><br><br><code>(count,&nbsp;data)&nbsp;=&nbsp;pi.bb_i2c_zip(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SDA,&nbsp;[4,&nbsp;0x53,&nbsp;2,&nbsp;7,&nbsp;1,&nbsp;0x32,&nbsp;2,&nbsp;6,&nbsp;6,&nbsp;3,&nbsp;0])<br></code><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>Any read I2C data is concatenated in the returned bytearray.
<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="bb_serial_invert">bb_serial_invert<small>(<a href="#user_gpio">user_gpio</a>, <a href="#invert">invert</a>)</small></h3>
Invert serial logic.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31&nbsp;(opened&nbsp;in&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#bb_serial_read_open">bb_serial_read_open</a>)<br>&nbsp;&nbsp;&nbsp;&nbsp;invert:=&nbsp;0-1&nbsp;(1&nbsp;invert,&nbsp;0&nbsp;normal)<br></samp><br><br><b><small>Example</small></b><br><br><code>status&nbsp;=&nbsp;pi.bb_serial_invert(17,&nbsp;1)<br></code><h3><a name="bb_serial_read">bb_serial_read<small>(<a href="#user_gpio">user_gpio</a>)</small></h3>
Returns data from the bit bang serial cyclic buffer.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31&nbsp;(opened&nbsp;in&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#bb_serial_read_open">bb_serial_read_open</a>)<br></samp><br><br>The returned value is a tuple of the number of bytes read and a
bytearray containing the bytes.  If there was an error the
number of bytes read will be less than zero (and will contain
the error code).
<br><br>The bytes returned for each character depend upon the number of
data bits <a href="#bb_bits">bb_bits</a> specified in the <a href="#bb_serial_read_open">bb_serial_read_open</a>
command.
<br><br>For <a href="#bb_bits">bb_bits</a> 1-8 there will be one byte per character.
For <a href="#bb_bits">bb_bits</a> 9-16 there will be two bytes per character.
For <a href="#bb_bits">bb_bits</a> 17-32 there will be four bytes per character.
<br><br><b><small>Example</small></b><br><br><code>(count,&nbsp;data)&nbsp;=&nbsp;pi.bb_serial_read(4)<br></code><h3><a name="bb_serial_read_close">bb_serial_read_close<small>(<a href="#user_gpio">user_gpio</a>)</small></h3>
Closes a GPIO for bit bang reading of serial data.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31&nbsp;(opened&nbsp;in&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#bb_serial_read_open">bb_serial_read_open</a>)<br></samp><br><br><b><small>Example</small></b><br><br><code>status&nbsp;=&nbsp;pi.bb_serial_read_close(17)<br></code><h3><a name="bb_serial_read_open">bb_serial_read_open<small>(<a href="#user_gpio">user_gpio</a>, <a href="#baud">baud</a>, <a href="#bb_bits">bb_bits</a>)</small></h3>
Opens a GPIO for bit bang reading of serial data.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31,&nbsp;the&nbsp;GPIO&nbsp;to&nbsp;use.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;baud:=&nbsp;50-250000,&nbsp;the&nbsp;baud&nbsp;rate.<br>&nbsp;&nbsp;bb_bits:=&nbsp;1-32,&nbsp;the&nbsp;number&nbsp;of&nbsp;bits&nbsp;per&nbsp;word,&nbsp;default&nbsp;8.<br></samp><br><br>The serial data is held in a cyclic buffer and is read using
<a href="#bb_serial_read">bb_serial_read</a>.
<br><br>It is the caller's responsibility to read data from the cyclic
buffer in a timely fashion.
<br><br><b><small>Example</small></b><br><br><code>status&nbsp;=&nbsp;pi.bb_serial_read_open(4,&nbsp;19200)<br>status&nbsp;=&nbsp;pi.bb_serial_read_open(17,&nbsp;9600)<br></code><h3><a name="bb_spi_close">bb_spi_close<small>(<a href="#CS">CS</a>)</small></h3>
This function stops bit banging SPI on a set of GPIO
opened with <a href="#bb_spi_open">bb_spi_open</a>.
<br><br><b><small>Parameters</small></b><br><br><samp>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="#bb_spi_open">bb_spi_open</a><br></samp><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SPI_GPIO.
<br><br><b><small>Example</small></b><br><br><code>pi.bb_spi_close(CS)<br></code><h3><a name="bb_spi_open">bb_spi_open<small>(<a href="#CS">CS</a>, <a href="#MISO">MISO</a>, <a href="#MOSI">MOSI</a>, <a href="#SCLK">SCLK</a>, <a href="#baud">baud</a>, <a href="#spi_flags">spi_flags</a>)</small></h3>
This function selects a set of GPIO for bit banging SPI at a
specified baud rate.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CS&nbsp;:=&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;MISO&nbsp;:=&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;MOSI&nbsp;:=&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;SCLK&nbsp;:=&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;&nbsp;baud&nbsp;:=&nbsp;50-250000<br>spiFlags&nbsp;:=&nbsp;see&nbsp;below<br></samp><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;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;0<br>&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;1<br>&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;0<br>&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;1<br></code><br><br>The following constants may be used to set the mode:
<br><br><code>pigpio.SPI_MODE_0<br>pigpio.SPI_MODE_1<br>pigpio.SPI_MODE_2<br>pigpio.SPI_MODE_3<br></code><br><br>Alternatively pigpio.SPI_CPOL and/or pigpio.SPI_CPHA
may be used.
<br><br>p is 0 if CS is active low (default) and 1 for active high.
pigpio.SPI_CS_HIGH_ACTIVE may be used to set this flag.
<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.
pigpio.SPI_TX_LSBFIRST may be used to set this flag.
<br><br>R is 1 if the least significant bit is received on MISO first,
the default (0) receives the most significant bit first.
pigpio.SPI_RX_LSBFIRST may be used to set this flag.
<br><br>The other bits in spiFlags 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>bb_spi_open(10,&nbsp;MISO,&nbsp;MOSI,&nbsp;SCLK,&nbsp;10000,&nbsp;0);&nbsp;//&nbsp;device&nbsp;1<br>bb_spi_open(11,&nbsp;MISO,&nbsp;MOSI,&nbsp;SCLK,&nbsp;20000,&nbsp;3);&nbsp;//&nbsp;device&nbsp;2<br></code><h3><a name="bb_spi_xfer">bb_spi_xfer<small>(<a href="#CS">CS</a>, <a href="#data">data</a>)</small></h3>
This function executes a bit banged SPI transfer.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;CS:=&nbsp;0-31&nbsp;(as&nbsp;used&nbsp;in&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#bb_spi_open">bb_spi_open</a>)<br>data:=&nbsp;data&nbsp;to&nbsp;be&nbsp;sent<br></samp><br><br>The returned value is a tuple of the number of bytes read and a
bytearray containing the bytes.  If there was an error the
number of bytes read will be less than zero (and will contain
the error code).
<br><br><b><small>Example</small></b><br><br><code>#!/usr/bin/env&nbsp;python<br><br>import&nbsp;pigpio<br><br>CE0=5<br>CE1=6<br>MISO=13<br>MOSI=19<br>SCLK=12<br><br>pi&nbsp;=&nbsp;pigpio.pi()<br>if&nbsp;not&nbsp;pi.connected:<br>&nbsp;&nbsp;&nbsp;exit()<br><br>pi.bb_spi_open(CE0,&nbsp;MISO,&nbsp;MOSI,&nbsp;SCLK,&nbsp;10000,&nbsp;0)&nbsp;#&nbsp;MCP4251&nbsp;DAC<br>pi.bb_spi_open(CE1,&nbsp;MISO,&nbsp;MOSI,&nbsp;SCLK,&nbsp;20000,&nbsp;3)&nbsp;#&nbsp;MCP3008&nbsp;ADC<br><br>for&nbsp;i&nbsp;in&nbsp;range(256):<br><br>&nbsp;&nbsp;&nbsp;count,&nbsp;data&nbsp;=&nbsp;pi.bb_spi_xfer(CE0,&nbsp;[0,&nbsp;i])&nbsp;#&nbsp;Set&nbsp;DAC&nbsp;value<br><br>&nbsp;&nbsp;&nbsp;if&nbsp;count&nbsp;==&nbsp;2:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count,&nbsp;data&nbsp;=&nbsp;pi.bb_spi_xfer(CE0,&nbsp;[12,&nbsp;0])&nbsp;#&nbsp;Read&nbsp;back&nbsp;DAC<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;count&nbsp;==&nbsp;2:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set_val&nbsp;=&nbsp;data[1]<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count,&nbsp;data&nbsp;=&nbsp;pi.bb_spi_xfer(CE1,&nbsp;[1,&nbsp;128,&nbsp;0])&nbsp;#&nbsp;Read&nbsp;ADC<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;count&nbsp;==&nbsp;3:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;read_val&nbsp;=&nbsp;((data[1]&3)&lt;&lt;8)&nbsp;|&nbsp;data[2]<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("{}&nbsp;{}".format(set_val,&nbsp;read_val))<br><br>pi.bb_spi_close(CE0)<br>pi.bb_spi_close(CE1)<br><br>pi.stop()<br></code><h3><a name="bsc_i2c">bsc_i2c<small>(<a href="#i2c_address">i2c_address</a>, <a href="#data">data</a>)</small></h3>
This function allows the Pi to act as a slave I2C device.
<br><br>This function is not available on the BCM2711 (e.g. as
used in the Pi4B).
<br><br>The data bytes (if any) are written to the BSC transmit
FIFO and the bytes in the BSC receive FIFO are returned.
<br><br><b><small>Parameters</small></b><br><br><samp>i2c_address:=&nbsp;the&nbsp;I2C&nbsp;slave&nbsp;address.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data:=&nbsp;the&nbsp;data&nbsp;bytes&nbsp;to&nbsp;transmit.<br></samp><br><br>The returned value is a tuple of the status, the number
of bytes read, and a bytearray containing the read bytes.
<br><br>See <a href="#bsc_xfer">bsc_xfer</a> for details of the status value.
<br><br>If there was an error the status will be less than zero
(and will contain the error code).
<br><br>Note that an i2c_address of 0 may be used to close
the BSC device and reassign the used GPIO as inputs.
<br><br>This example assumes GPIO 2/3 are connected to GPIO 18/19
(GPIO 10/11 on the BCM2711).
<br><br><b><small>Example</small></b><br><br><code>#!/usr/bin/env&nbsp;python<br>import&nbsp;time<br>import&nbsp;pigpio<br><br>I2C_ADDR=0x13<br><br>def&nbsp;i2c(id,&nbsp;tick):<br>&nbsp;&nbsp;&nbsp;&nbsp;global&nbsp;pi<br><br>&nbsp;&nbsp;&nbsp;&nbsp;s,&nbsp;b,&nbsp;d&nbsp;=&nbsp;pi.bsc_i2c(I2C_ADDR)<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;b:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;d[0]&nbsp;==&nbsp;ord('t'):&nbsp;#&nbsp;116&nbsp;send&nbsp;'HH:MM:SS*'<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("sent={}&nbsp;FR={}&nbsp;received={}&nbsp;[{}]".<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format(s&gt;&gt;16,&nbsp;s&0xfff,b,d))<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s,&nbsp;b,&nbsp;d&nbsp;=&nbsp;pi.bsc_i2c(I2C_ADDR,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"{}*".format(time.asctime()[11:19]))<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif&nbsp;d[0]&nbsp;==&nbsp;ord('d'):&nbsp;#&nbsp;100&nbsp;send&nbsp;'Sun&nbsp;Oct&nbsp;30*'<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("sent={}&nbsp;FR={}&nbsp;received={}&nbsp;[{}]".<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format(s&gt;&gt;16,&nbsp;s&0xfff,b,d))<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s,&nbsp;b,&nbsp;d&nbsp;=&nbsp;pi.bsc_i2c(I2C_ADDR,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"{}*".format(time.asctime()[:10]))<br><br>pi&nbsp;=&nbsp;pigpio.pi()<br><br>if&nbsp;not&nbsp;pi.connected:<br>&nbsp;&nbsp;&nbsp;&nbsp;exit()<br><br>#&nbsp;Respond&nbsp;to&nbsp;BSC&nbsp;slave&nbsp;activity<br><br>e&nbsp;=&nbsp;pi.event_callback(pigpio.EVENT_BSC,&nbsp;i2c)<br><br>pi.bsc_i2c(I2C_ADDR)&nbsp;#&nbsp;Configure&nbsp;BSC&nbsp;as&nbsp;I2C&nbsp;slave<br><br>time.sleep(600)<br><br>e.cancel()<br><br>pi.bsc_i2c(0)&nbsp;#&nbsp;Disable&nbsp;BSC&nbsp;peripheral<br><br>pi.stop()<br></code><br><br>While running the above.
<br><br><code>$&nbsp;i2cdetect&nbsp;-y&nbsp;1<br>&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;&nbsp;a&nbsp;&nbsp;b&nbsp;&nbsp;c&nbsp;&nbsp;d&nbsp;&nbsp;e&nbsp;&nbsp;f<br>00:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br>10:&nbsp;--&nbsp;--&nbsp;--&nbsp;13&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br>20:&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br>30:&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br>40:&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br>50:&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br>60:&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br>70:&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br><br>$&nbsp;pigs&nbsp;i2co&nbsp;1&nbsp;0x13&nbsp;0<br>0<br><br>$&nbsp;pigs&nbsp;i2cwd&nbsp;0&nbsp;116<br>$&nbsp;pigs&nbsp;i2crd&nbsp;0&nbsp;9&nbsp;-a<br>9&nbsp;10:13:58*<br><br>$&nbsp;pigs&nbsp;i2cwd&nbsp;0&nbsp;116<br>$&nbsp;pigs&nbsp;i2crd&nbsp;0&nbsp;9&nbsp;-a<br>9&nbsp;10:14:29*<br><br>$&nbsp;pigs&nbsp;i2cwd&nbsp;0&nbsp;100<br>$&nbsp;pigs&nbsp;i2crd&nbsp;0&nbsp;11&nbsp;-a<br>11&nbsp;Sun&nbsp;Oct&nbsp;30*<br><br>$&nbsp;pigs&nbsp;i2cwd&nbsp;0&nbsp;100<br>$&nbsp;pigs&nbsp;i2crd&nbsp;0&nbsp;11&nbsp;-a<br>11&nbsp;Sun&nbsp;Oct&nbsp;30*<br><br>$&nbsp;pigs&nbsp;i2cwd&nbsp;0&nbsp;116<br>$&nbsp;pigs&nbsp;i2crd&nbsp;0&nbsp;9&nbsp;-a<br>9&nbsp;10:23:16*<br><br>$&nbsp;pigs&nbsp;i2cwd&nbsp;0&nbsp;100<br>$&nbsp;pigs&nbsp;i2crd&nbsp;0&nbsp;11&nbsp;-a<br>11&nbsp;Sun&nbsp;Oct&nbsp;30*<br></code><h3><a name="bsc_xfer">bsc_xfer<small>(<a href="#bsc_control">bsc_control</a>, <a href="#data">data</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>I can't get SPI to work properly.  I tried with a
control word of 0x303 and swapped MISO and MOSI.
<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><b><small>Parameters</small></b><br><br><samp>bsc_control:=&nbsp;see&nbsp;below<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data:=&nbsp;the&nbsp;data&nbsp;bytes&nbsp;to&nbsp;place&nbsp;in&nbsp;the&nbsp;transmit&nbsp;FIFO.<br></samp><br><br>The returned value is a tuple of the status (see below),
the number of bytes read, and a bytearray containing the
read bytes.  If there was an error the status will be less
than zero (and will contain the error code).
<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>18</td><td>19</td><td>20</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>10</td><td>11</td><td>9</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>bsc_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 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 receieve 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><b><small>Example</small></b><br><br><code>(status,&nbsp;count,&nbsp;data)&nbsp;=&nbsp;pi.bsc_xfer(0x330305,&nbsp;"Hello!")<br></code><h3><a name="callback">callback<small>(<a href="#user_gpio">user_gpio</a>, <a href="#edge">edge</a>, <a href="#func">func</a>)</small></h3>
Calls a user supplied function (a callback) whenever the
specified GPIO edge is detected.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;edge:=&nbsp;EITHER_EDGE,&nbsp;RISING_EDGE&nbsp;(default),&nbsp;or&nbsp;FALLING_EDGE.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;func:=&nbsp;user&nbsp;supplied&nbsp;callback&nbsp;function.<br></samp><br><br>The user supplied callback receives three parameters, the GPIO,
the 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>If a user callback is not specified a default tally callback is
provided which simply counts edges.  The count may be retrieved
by calling the tally function.  The count may be reset to zero
by calling the reset_tally function.
<br><br>The callback may be cancelled by calling the cancel function.
<br><br>A GPIO may have multiple callbacks (although I can't think of
a reason to do so).
<br><br>The GPIO are sampled at a rate set when the pigpio daemon
is started (default 5 us).
<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>GPIO level changes shorter than the sample rate may be missed.
<br><br>The daemon software which generates the callbacks is triggered
1000 times per second.  The callbacks will be called once per
level change since the last time they were called.
i.e. The callbacks 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="#read">read</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><b><small>Example</small></b><br><br><code>def&nbsp;cbf(gpio,&nbsp;level,&nbsp;tick):<br>&nbsp;&nbsp;&nbsp;print(gpio,&nbsp;level,&nbsp;tick)<br><br>cb1&nbsp;=&nbsp;pi.callback(22,&nbsp;pigpio.EITHER_EDGE,&nbsp;cbf)<br><br>cb2&nbsp;=&nbsp;pi.callback(4,&nbsp;pigpio.EITHER_EDGE)<br><br>cb3&nbsp;=&nbsp;pi.callback(17)<br><br>print(cb3.tally())<br><br>cb3.reset_tally()<br><br>cb1.cancel()&nbsp;#&nbsp;To&nbsp;cancel&nbsp;callback&nbsp;cb1.<br></code><h3><a name="clear_bank_1">clear_bank_1<small>(<a href="#bits">bits</a>)</small></h3>
Clears GPIO 0-31 if the corresponding bit in bits is set.
<br><br><b><small>Parameters</small></b><br><br><samp>bits:=&nbsp;a&nbsp;32&nbsp;bit&nbsp;mask&nbsp;with&nbsp;1&nbsp;set&nbsp;if&nbsp;the&nbsp;corresponding&nbsp;GPIO&nbsp;is<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;be&nbsp;cleared.<br></samp><br><br>A returned status of PI_SOME_PERMITTED indicates that the user
is not allowed to write to one or more of the GPIO.
<br><br><b><small>Example</small></b><br><br><code>pi.clear_bank_1(int("111110010000",2))<br></code><h3><a name="clear_bank_2">clear_bank_2<small>(<a href="#bits">bits</a>)</small></h3>
Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set.
<br><br><b><small>Parameters</small></b><br><br><samp>bits:=&nbsp;a&nbsp;32&nbsp;bit&nbsp;mask&nbsp;with&nbsp;1&nbsp;set&nbsp;if&nbsp;the&nbsp;corresponding&nbsp;GPIO&nbsp;is<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;be&nbsp;cleared.<br></samp><br><br>A returned status of PI_SOME_PERMITTED indicates that the user
is not allowed to write to one or more of the GPIO.
<br><br><b><small>Example</small></b><br><br><code>pi.clear_bank_2(0x1010)<br></code><h3><a name="custom_1">custom_1<small>(<a href="#arg1">arg1</a>, <a href="#arg2">arg2</a>, <a href="#argx">argx</a>)</small></h3>
Calls a pigpio function customised by the user.
<br><br><b><small>Parameters</small></b><br><br><samp>arg1:=&nbsp;&gt;=0,&nbsp;default&nbsp;0.<br>arg2:=&nbsp;&gt;=0,&nbsp;default&nbsp;0.<br>argx:=&nbsp;extra&nbsp;arguments&nbsp;(each&nbsp;0-255),&nbsp;default&nbsp;empty.<br></samp><br><br>The returned value is an integer which by convention
should be &gt;=0 for OK and &lt;0 for error.
<br><br><b><small>Example</small></b><br><br><code>value&nbsp;=&nbsp;pi.custom_1()<br><br>value&nbsp;=&nbsp;pi.custom_1(23)<br><br>value&nbsp;=&nbsp;pi.custom_1(0,&nbsp;55)<br><br>value&nbsp;=&nbsp;pi.custom_1(23,&nbsp;56,&nbsp;[1,&nbsp;5,&nbsp;7])<br><br>value&nbsp;=&nbsp;pi.custom_1(23,&nbsp;56,&nbsp;b"hello")<br><br>value&nbsp;=&nbsp;pi.custom_1(23,&nbsp;56,&nbsp;"hello")<br></code><h3><a name="custom_2">custom_2<small>(<a href="#arg1">arg1</a>, <a href="#argx">argx</a>, <a href="#retMax">retMax</a>)</small></h3>
Calls a pigpio function customised by the user.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;arg1:=&nbsp;&gt;=0,&nbsp;default&nbsp;0.<br>&nbsp;&nbsp;argx:=&nbsp;extra&nbsp;arguments&nbsp;(each&nbsp;0-255),&nbsp;default&nbsp;empty.<br>retMax:=&nbsp;&gt;=0,&nbsp;maximum&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;return,&nbsp;default&nbsp;8192.<br></samp><br><br>The returned value is a tuple of the number of bytes
returned and a bytearray containing the bytes.  If
there was an error the number of bytes read will be
less than zero (and will contain the error code).
<br><br><b><small>Example</small></b><br><br><code>(count,&nbsp;data)&nbsp;=&nbsp;pi.custom_2()<br><br>(count,&nbsp;data)&nbsp;=&nbsp;pi.custom_2(23)<br><br>(count,&nbsp;data)&nbsp;=&nbsp;pi.custom_2(23,&nbsp;[1,&nbsp;5,&nbsp;7])<br><br>(count,&nbsp;data)&nbsp;=&nbsp;pi.custom_2(23,&nbsp;b"hello")<br><br>(count,&nbsp;data)&nbsp;=&nbsp;pi.custom_2(23,&nbsp;"hello",&nbsp;128)<br></code><h3><a name="delete_script">delete_script<small>(<a href="#script_id">script_id</a>)</small></h3>
Deletes a stored script.
<br><br><b><small>Parameters</small></b><br><br><samp>script_id:=&nbsp;id&nbsp;of&nbsp;stored&nbsp;script.<br></samp><br><br><b><small>Example</small></b><br><br><code>status&nbsp;=&nbsp;pi.delete_script(sid)<br></code><h3><a name="event_callback">event_callback<small>(<a href="#event">event</a>, <a href="#func">func</a>)</small></h3>
Calls a user supplied function (a callback) whenever the
specified event is signalled.
<br><br><b><small>Parameters</small></b><br><br><samp>event:=&nbsp;0-31.<br>&nbsp;func:=&nbsp;user&nbsp;supplied&nbsp;callback&nbsp;function.<br></samp><br><br>The user supplied callback receives two parameters, the event id,
and the tick.
<br><br>If a user callback is not specified a default tally callback is
provided which simply counts events.  The count may be retrieved
by calling the tally function.  The count may be reset to zero
by calling the reset_tally function.
<br><br>The callback may be canceled by calling the cancel function.
<br><br>An event may have multiple callbacks (although I can't think of
a reason to do so).
<br><br><b><small>Example</small></b><br><br><code>def&nbsp;cbf(event,&nbsp;tick):<br>&nbsp;&nbsp;&nbsp;print(event,&nbsp;tick)<br><br>cb1&nbsp;=&nbsp;pi.event_callback(22,&nbsp;cbf)<br><br>cb2&nbsp;=&nbsp;pi.event_callback(4)<br><br>print(cb2.tally())<br><br>cb2.reset_tally()<br><br>cb1.cancel()&nbsp;#&nbsp;To&nbsp;cancel&nbsp;callback&nbsp;cb1.<br></code><h3><a name="event_trigger">event_trigger<small>(<a href="#event">event</a>)</small></h3>
This function signals the occurrence of an event.
<br><br><b><small>Parameters</small></b><br><br><samp>event:=&nbsp;0-31,&nbsp;the&nbsp;event<br></samp><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="#event_callback">event_callback</a>) will
be informed by a callback.
<br><br>One event, 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.
<br><br><b><small>Example</small></b><br><br><code>pi.event_trigger(23)<br></code><h3><a name="file_close">file_close<small>(<a href="#handle">handle</a>)</small></h3>
Closes the file associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#file_open">file_open</a>).<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.file_close(handle)<br></code><h3><a name="file_list">file_list<small>(<a href="#fpattern">fpattern</a>)</small></h3>
Returns a list of files which match a pattern.
<br><br><b><small>Parameters</small></b><br><br><samp>fpattern:=&nbsp;file&nbsp;pattern&nbsp;to&nbsp;match.<br></samp><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="#file_open">file_open</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>#!/usr/bin/env&nbsp;python<br><br>import&nbsp;pigpio<br><br>pi&nbsp;=&nbsp;pigpio.pi()<br><br>if&nbsp;not&nbsp;pi.connected:<br>&nbsp;&nbsp;&nbsp;exit()<br><br>#&nbsp;Assumes&nbsp;/opt/pigpio/access&nbsp;contains&nbsp;the&nbsp;following&nbsp;line:<br>#&nbsp;/ram/*.c&nbsp;r<br><br>c,&nbsp;d&nbsp;=&nbsp;pi.file_list("/ram/p*.c")<br>if&nbsp;c&nbsp;&gt;&nbsp;0:<br>&nbsp;&nbsp;&nbsp;print(d)<br><br>pi.stop()<br></code><h3><a name="file_open">file_open<small>(<a href="#file_name">file_name</a>, <a href="#file_mode">file_mode</a>)</small></h3>
This function returns a handle to a file opened in a specified mode.
<br><br><b><small>Parameters</small></b><br><br><samp>file_name:=&nbsp;the&nbsp;file&nbsp;to&nbsp;open.<br>file_mode:=&nbsp;the&nbsp;file&nbsp;open&nbsp;mode.<br></samp><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><b><small>Example</small></b><br><br><code>h&nbsp;=&nbsp;pi.file_open("/home/pi/shared/dir_3/file.txt",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pigpio.FILE_WRITE&nbsp;|&nbsp;pigpio.FILE_CREATE)<br><br>pi.file_write(h,&nbsp;"Hello&nbsp;world")<br><br>pi.file_close(h)<br></code><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>Constant</td><td>Value</td><td>Meaning</td></tr><tr><td>FILE_READ</td><td>1</td><td>open file for reading</td></tr><tr><td>FILE_WRITE</td><td>2</td><td>open file for writing</td></tr><tr><td>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>Name</td><td>Value</td><td>Meaning</td></tr><tr><td>FILE_APPEND</td><td>4</td><td>All writes append data to the end of the file</td></tr><tr><td>FILE_CREATE</td><td>8</td><td>The file is created if it doesn't exist</td></tr><tr><td>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>#!/usr/bin/env&nbsp;python<br><br>import&nbsp;pigpio<br><br>pi&nbsp;=&nbsp;pigpio.pi()<br><br>if&nbsp;not&nbsp;pi.connected:<br>&nbsp;&nbsp;&nbsp;exit()<br><br>#&nbsp;Assumes&nbsp;/opt/pigpio/access&nbsp;contains&nbsp;the&nbsp;following&nbsp;line:<br>#&nbsp;/ram/*.c&nbsp;r<br><br>handle&nbsp;=&nbsp;pi.file_open("/ram/pigpio.c",&nbsp;pigpio.FILE_READ)<br><br>done&nbsp;=&nbsp;False<br><br>while&nbsp;not&nbsp;done:<br>&nbsp;&nbsp;&nbsp;c,&nbsp;d&nbsp;=&nbsp;pi.file_read(handle,&nbsp;60000)<br>&nbsp;&nbsp;&nbsp;if&nbsp;c&nbsp;&gt;&nbsp;0:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(d)<br>&nbsp;&nbsp;&nbsp;else:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;done&nbsp;=&nbsp;True<br><br>pi.file_close(handle)<br><br>pi.stop()<br></code><h3><a name="file_read">file_read<small>(<a href="#handle">handle</a>, <a href="#count">count</a>)</small></h3>
Reads up to count bytes from the file associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#file_open">file_open</a>).<br>&nbsp;count:=&nbsp;&gt;0,&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;read.<br></samp><br><br>The returned value is a tuple of the number of bytes read and a
bytearray containing the bytes.  If there was an error the
number of bytes read will be less than zero (and will contain
the error code).
<br><br><b><small>Example</small></b><br><br><code>(b,&nbsp;d)&nbsp;=&nbsp;pi.file_read(h2,&nbsp;100)<br>if&nbsp;b&nbsp;&gt;&nbsp;0:<br>&nbsp;&nbsp;&nbsp;#&nbsp;process&nbsp;read&nbsp;data<br></code><h3><a name="file_seek">file_seek<small>(<a href="#handle">handle</a>, <a href="#seek_offset">seek_offset</a>, <a href="#seek_from">seek_from</a>)</small></h3>
Seeks to a position relative to the start, current position,
or end of the file.  Returns the new position.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#file_open">file_open</a>).<br>seek_offset:=&nbsp;byte&nbsp;offset.<br>&nbsp;&nbsp;seek_from:=&nbsp;FROM_START,&nbsp;FROM_CURRENT,&nbsp;or&nbsp;FROM_END.<br></samp><br><br><b><small>Example</small></b><br><br><code>new_pos&nbsp;=&nbsp;pi.file_seek(h,&nbsp;100,&nbsp;pigpio.FROM_START)<br><br>cur_pos&nbsp;=&nbsp;pi.file_seek(h,&nbsp;0,&nbsp;pigpio.FROM_CURRENT)<br><br>file_size&nbsp;=&nbsp;pi.file_seek(h,&nbsp;0,&nbsp;pigpio.FROM_END)<br></code><h3><a name="file_write">file_write<small>(<a href="#handle">handle</a>, <a href="#data">data</a>)</small></h3>
Writes the data bytes to the file associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#file_open">file_open</a>).<br>&nbsp;&nbsp;data:=&nbsp;the&nbsp;bytes&nbsp;to&nbsp;write.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.file_write(h1,&nbsp;b'\x02\x03\x04')<br><br>pi.file_write(h2,&nbsp;b'help')<br><br>pi.file_write(h2,&nbsp;"hello")<br><br>pi.file_write(h1,&nbsp;[2,&nbsp;3,&nbsp;4])<br></code><h3><a name="get_PWM_dutycycle">get_PWM_dutycycle<small>(<a href="#user_gpio">user_gpio</a>)</small></h3>
Returns the PWM dutycycle being used on the GPIO.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31.<br></samp><br><br>Returns the PWM dutycycle.
<br><br>For normal PWM the dutycycle will be out of the defined range
for the GPIO (see <a href="#get_PWM_range">get_PWM_range</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><b><small>Example</small></b><br><br><code>pi.set_PWM_dutycycle(4,&nbsp;25)<br>print(pi.get_PWM_dutycycle(4))<br>25<br><br>pi.set_PWM_dutycycle(4,&nbsp;203)<br>print(pi.get_PWM_dutycycle(4))<br>203<br></code><h3><a name="get_PWM_frequency">get_PWM_frequency<small>(<a href="#user_gpio">user_gpio</a>)</small></h3>
Returns the frequency of PWM being used on the GPIO.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31.<br></samp><br><br>Returns the frequency (in Hz) used for the GPIO.
<br><br>For normal PWM the frequency will be that defined for the GPIO
by <a href="#set_PWM_frequency">set_PWM_frequency</a>.
<br><br>If a hardware clock is active on the GPIO the reported frequency
will be that set by <a href="#hardware_clock">hardware_clock</a>.
<br><br>If hardware PWM is active on the GPIO the reported frequency
will be that set by <a href="#hardware_PWM">hardware_PWM</a>.
<br><br><b><small>Example</small></b><br><br><code>pi.set_PWM_frequency(4,0)<br>print(pi.get_PWM_frequency(4))<br>10<br><br>pi.set_PWM_frequency(4,&nbsp;800)<br>print(pi.get_PWM_frequency(4))<br>800<br></code><h3><a name="get_PWM_range">get_PWM_range<small>(<a href="#user_gpio">user_gpio</a>)</small></h3>
Returns the range of PWM values being used on the GPIO.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31.<br></samp><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>pi.set_PWM_range(9,&nbsp;500)<br>print(pi.get_PWM_range(9))<br>500<br></code><h3><a name="get_PWM_real_range">get_PWM_real_range<small>(<a href="#user_gpio">user_gpio</a>)</small></h3>
Returns the real (underlying) range of PWM values being
used on the GPIO.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31.<br></samp><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>pi.set_PWM_frequency(4,&nbsp;800)<br>print(pi.get_PWM_real_range(4))<br>250<br></code><h3><a name="get_current_tick">get_current_tick<small>()</small></h3>
Returns the current system tick.
<br><br>Tick is the number of microseconds since system boot.  As an
unsigned 32 bit quantity tick wraps around approximately
every 71.6 minutes.
<br><br><b><small>Example</small></b><br><br><code>t1&nbsp;=&nbsp;pi.get_current_tick()<br>time.sleep(1)<br>t2&nbsp;=&nbsp;pi.get_current_tick()<br></code><h3><a name="get_hardware_revision">get_hardware_revision<small>()</small></h3>
Returns the Pi's hardware revision number.
<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>If the hardware revision can not be found or is not a valid
hexadecimal number the function returns 0.
<br><br><b><small>Example</small></b><br><br><code>print(pi.get_hardware_revision())<br>2<br></code><h3><a name="get_mode">get_mode<small>(<a href="#gpio">gpio</a>)</small></h3>
Returns the GPIO mode.
<br><br><b><small>Parameters</small></b><br><br><samp>gpio:=&nbsp;0-53.<br></samp><br><br>Returns a value as follows
<br><br><code>0&nbsp;=&nbsp;INPUT<br>1&nbsp;=&nbsp;OUTPUT<br>2&nbsp;=&nbsp;ALT5<br>3&nbsp;=&nbsp;ALT4<br>4&nbsp;=&nbsp;ALT0<br>5&nbsp;=&nbsp;ALT1<br>6&nbsp;=&nbsp;ALT2<br>7&nbsp;=&nbsp;ALT3<br></code><br><br><b><small>Example</small></b><br><br><code>print(pi.get_mode(0))<br>4<br></code><h3><a name="get_pad_strength">get_pad_strength<small>(<a href="#pad">pad</a>)</small></h3>
This function returns the pad drive strength in mA.
<br><br><b><small>Parameters</small></b><br><br><samp>pad:=&nbsp;0-2,&nbsp;the&nbsp;pad&nbsp;to&nbsp;get.<br></samp><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;pi.get_pad_strength(0)&nbsp;#&nbsp;Get&nbsp;pad&nbsp;0&nbsp;strength.<br></code><h3><a name="get_pigpio_version">get_pigpio_version<small>()</small></h3>
Returns the pigpio software version.
<br><br><b><small>Example</small></b><br><br><code>v&nbsp;=&nbsp;pi.get_pigpio_version()<br></code><h3><a name="get_servo_pulsewidth">get_servo_pulsewidth<small>(<a href="#user_gpio">user_gpio</a>)</small></h3>
Returns the servo pulsewidth being used on the GPIO.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31.<br></samp><br><br>Returns the servo pulsewidth.
<br><br><b><small>Example</small></b><br><br><code>pi.set_servo_pulsewidth(4,&nbsp;525)<br>print(pi.get_servo_pulsewidth(4))<br>525<br><br>pi.set_servo_pulsewidth(4,&nbsp;2130)<br>print(pi.get_servo_pulsewidth(4))<br>2130<br></code><h3><a name="gpio_trigger">gpio_trigger<small>(<a href="#user_gpio">user_gpio</a>, <a href="#pulse_len">pulse_len</a>, <a href="#level">level</a>)</small></h3>
Send a trigger pulse to a GPIO.  The GPIO is set to
level for pulse_len microseconds and then reset to not level.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31<br>pulse_len:=&nbsp;1-100<br>&nbsp;&nbsp;&nbsp;&nbsp;level:=&nbsp;0-1<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.gpio_trigger(23,&nbsp;10,&nbsp;1)<br></code><h3><a name="hardware_PWM">hardware_PWM<small>(<a href="#gpio">gpio</a>, <a href="#PWMfreq">PWMfreq</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="#wave_send_once">wave_send_once</a>,
<a href="#wave_send_repeat">wave_send_repeat</a>, or <a href="#wave_chain">wave_chain</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 when the
pigpio daemon is started (option -t).
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;&nbsp;gpio:=&nbsp;see&nbsp;descripton<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></samp><br><br>Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO,
PI_NOT_HPWM_GPIO, PI_BAD_HPWM_DUTY, PI_BAD_HPWM_FREQ.
<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.
<br><br><b><small>Example</small></b><br><br><code>pi.hardware_PWM(18,&nbsp;800,&nbsp;250000)&nbsp;#&nbsp;800Hz&nbsp;25%&nbsp;dutycycle<br><br>pi.hardware_PWM(18,&nbsp;2000,&nbsp;750000)&nbsp;#&nbsp;2000Hz&nbsp;75%&nbsp;dutycycle<br></code><h3><a name="hardware_clock">hardware_clock<small>(<a href="#gpio">gpio</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><b><small>Parameters</small></b><br><br><samp>&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></samp><br><br>Returns 0 if OK, otherwise PI_NOT_PERMITTED, 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.
<br><br><b><small>Example</small></b><br><br><code>pi.hardware_clock(4,&nbsp;5000)&nbsp;#&nbsp;5&nbsp;KHz&nbsp;clock&nbsp;on&nbsp;GPIO&nbsp;4<br><br>pi.hardware_clock(4,&nbsp;40000000)&nbsp;#&nbsp;40&nbsp;MHz&nbsp;clock&nbsp;on&nbsp;GPIO&nbsp;4<br></code><h3><a name="i2c_block_process_call">i2c_block_process_call<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>, <a href="#data">data</a>)</small></h3>
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><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>&nbsp;&nbsp;&nbsp;reg:=&nbsp;&gt;=0,&nbsp;the&nbsp;device&nbsp;register.<br>&nbsp;&nbsp;data:=&nbsp;the&nbsp;bytes&nbsp;to&nbsp;write.<br></samp><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>SMBus 2.0 5.5.8 - Block write-block read.
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;reg&nbsp;[A]&nbsp;len(data)&nbsp;[A]&nbsp;data0&nbsp;[A]&nbsp;...&nbsp;datan&nbsp;[A]<br>&nbsp;&nbsp;&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[Count]&nbsp;A&nbsp;[Data]&nbsp;...&nbsp;A&nbsp;P<br></code><br><br>The returned value is a tuple of the number of bytes read and a
bytearray containing the bytes.  If there was an error the
number of bytes read will be less than zero (and will contain
the error code).
<br><br><b><small>Example</small></b><br><br><code>(b,&nbsp;d)&nbsp;=&nbsp;pi.i2c_block_process_call(h,&nbsp;10,&nbsp;b'\x02\x05\x00')<br><br>(b,&nbsp;d)&nbsp;=&nbsp;pi.i2c_block_process_call(h,&nbsp;10,&nbsp;b'abcdr')<br><br>(b,&nbsp;d)&nbsp;=&nbsp;pi.i2c_block_process_call(h,&nbsp;10,&nbsp;"abracad")<br><br>(b,&nbsp;d)&nbsp;=&nbsp;pi.i2c_block_process_call(h,&nbsp;10,&nbsp;[2,&nbsp;5,&nbsp;16])<br></code><h3><a name="i2c_close">i2c_close<small>(<a href="#handle">handle</a>)</small></h3>
Closes the I2C device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.i2c_close(h)<br></code><h3><a name="i2c_open">i2c_open<small>(<a href="#i2c_bus">i2c_bus</a>, <a href="#i2c_address">i2c_address</a>, <a href="#i2c_flags">i2c_flags</a>)</small></h3>
Returns a handle (&gt;=0) for the device at the I2C bus address.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;&nbsp;&nbsp;i2c_bus:=&nbsp;&gt;=0.<br>i2c_address:=&nbsp;0-0x7F.<br>&nbsp;&nbsp;i2c_flags:=&nbsp;0,&nbsp;no&nbsp;flags&nbsp;are&nbsp;currently&nbsp;defined.<br></samp><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>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;(1&nbsp;bit)&nbsp;:&nbsp;Start&nbsp;bit<br>P&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(1&nbsp;bit)&nbsp;:&nbsp;Stop&nbsp;bit<br>Rd/Wr&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;(1&nbsp;bit)&nbsp;:&nbsp;Accept&nbsp;and&nbsp;not&nbsp;accept&nbsp;bit.<br>Addr&nbsp;&nbsp;(7&nbsp;bits):&nbsp;I2C&nbsp;7&nbsp;bit&nbsp;address.<br>reg&nbsp;&nbsp;&nbsp;(8&nbsp;bits):&nbsp;Command&nbsp;byte,&nbsp;which&nbsp;often&nbsp;selects&nbsp;a&nbsp;register.<br>Data&nbsp;&nbsp;(8&nbsp;bits):&nbsp;A&nbsp;data&nbsp;byte.<br>Count&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><br><br><b><small>Example</small></b><br><br><code>h&nbsp;=&nbsp;pi.i2c_open(1,&nbsp;0x53)&nbsp;#&nbsp;open&nbsp;device&nbsp;at&nbsp;address&nbsp;0x53&nbsp;on&nbsp;bus&nbsp;1<br></code><h3><a name="i2c_process_call">i2c_process_call<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>, <a href="#word_val">word_val</a>)</small></h3>
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><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reg:=&nbsp;&gt;=0,&nbsp;the&nbsp;device&nbsp;register.<br>word_val:=&nbsp;0-65535,&nbsp;the&nbsp;value&nbsp;to&nbsp;write.<br></samp><br><br>SMBus 2.0 5.5.6 - Process call.
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;reg&nbsp;[A]&nbsp;word_val_Low&nbsp;[A]&nbsp;word_val_High&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><br><br><b><small>Example</small></b><br><br><code>r&nbsp;=&nbsp;pi.i2c_process_call(h,&nbsp;4,&nbsp;0x1231)<br>r&nbsp;=&nbsp;pi.i2c_process_call(h,&nbsp;6,&nbsp;0)<br></code><h3><a name="i2c_read_block_data">i2c_read_block_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>)</small></h3>
Reads a block of up to 32 bytes from the specified register of
the device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>&nbsp;&nbsp;&nbsp;reg:=&nbsp;&gt;=0,&nbsp;the&nbsp;device&nbsp;register.<br></samp><br><br>SMBus 2.0 5.5.7 - Block read.
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;reg&nbsp;[A]<br>&nbsp;&nbsp;&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[Count]&nbsp;A&nbsp;[Data]&nbsp;A&nbsp;[Data]&nbsp;A&nbsp;...&nbsp;A&nbsp;[Data]&nbsp;NA&nbsp;P<br></code><br><br>The amount of returned data is set by the device.
<br><br>The returned value is a tuple of the number of bytes read and a
bytearray containing the bytes.  If there was an error the
number of bytes read will be less than zero (and will contain
the error code).
<br><br><b><small>Example</small></b><br><br><code>(b,&nbsp;d)&nbsp;=&nbsp;pi.i2c_read_block_data(h,&nbsp;10)<br>if&nbsp;b&nbsp;&gt;=&nbsp;0:<br>&nbsp;&nbsp;&nbsp;#&nbsp;process&nbsp;data<br>else:<br>&nbsp;&nbsp;&nbsp;#&nbsp;process&nbsp;read&nbsp;failure<br></code><h3><a name="i2c_read_byte">i2c_read_byte<small>(<a href="#handle">handle</a>)</small></h3>
Reads a single byte from the device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br></samp><br><br>SMBus 2.0 5.5.3 - Receive byte.
<code>S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[Data]&nbsp;NA&nbsp;P<br></code><br><br><b><small>Example</small></b><br><br><code>b&nbsp;=&nbsp;pi.i2c_read_byte(2)&nbsp;#&nbsp;read&nbsp;a&nbsp;byte&nbsp;from&nbsp;device&nbsp;2<br></code><h3><a name="i2c_read_byte_data">i2c_read_byte_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>)</small></h3>
Reads a single byte from the specified register of the device
associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>&nbsp;&nbsp;&nbsp;reg:=&nbsp;&gt;=0,&nbsp;the&nbsp;device&nbsp;register.<br></samp><br><br>SMBus 2.0 5.5.5 - Read byte.
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;reg&nbsp;[A]&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[Data]&nbsp;NA&nbsp;P<br></code><br><br><b><small>Example</small></b><br><br><code>#&nbsp;read&nbsp;byte&nbsp;from&nbsp;reg&nbsp;17&nbsp;of&nbsp;device&nbsp;2<br>b&nbsp;=&nbsp;pi.i2c_read_byte_data(2,&nbsp;17)<br><br>#&nbsp;read&nbsp;byte&nbsp;from&nbsp;reg&nbsp;&nbsp;1&nbsp;of&nbsp;device&nbsp;0<br>b&nbsp;=&nbsp;pi.i2c_read_byte_data(0,&nbsp;1)<br></code><h3><a name="i2c_read_device">i2c_read_device<small>(<a href="#handle">handle</a>, <a href="#count">count</a>)</small></h3>
Returns count bytes read from the raw device associated
with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>&nbsp;count:=&nbsp;&gt;0,&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;read.<br></samp><br><br><code>S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[Data]&nbsp;A&nbsp;[Data]&nbsp;A&nbsp;...&nbsp;A&nbsp;[Data]&nbsp;NA&nbsp;P<br></code><br><br>The returned value is a tuple of the number of bytes read and a
bytearray containing the bytes.  If there was an error the
number of bytes read will be less than zero (and will contain
the error code).
<br><br><b><small>Example</small></b><br><br><code>(count,&nbsp;data)&nbsp;=&nbsp;pi.i2c_read_device(h,&nbsp;12)<br></code><h3><a name="i2c_read_i2c_block_data">i2c_read_i2c_block_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>, <a href="#count">count</a>)</small></h3>
Reads count bytes from the specified register of the device
associated with handle .  The count may be 1-32.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>&nbsp;&nbsp;&nbsp;reg:=&nbsp;&gt;=0,&nbsp;the&nbsp;device&nbsp;register.<br>&nbsp;count:=&nbsp;&gt;0,&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;read.<br></samp><br><br><code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;reg&nbsp;[A]<br>&nbsp;&nbsp;&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[Data]&nbsp;A&nbsp;[Data]&nbsp;A&nbsp;...&nbsp;A&nbsp;[Data]&nbsp;NA&nbsp;P<br></code><br><br>The returned value is a tuple of the number of bytes read and a
bytearray containing the bytes.  If there was an error the
number of bytes read will be less than zero (and will contain
the error code).
<br><br><b><small>Example</small></b><br><br><code>(b,&nbsp;d)&nbsp;=&nbsp;pi.i2c_read_i2c_block_data(h,&nbsp;4,&nbsp;32)<br>if&nbsp;b&nbsp;&gt;=&nbsp;0:<br>&nbsp;&nbsp;&nbsp;#&nbsp;process&nbsp;data<br>else:<br>&nbsp;&nbsp;&nbsp;#&nbsp;process&nbsp;read&nbsp;failure<br></code><h3><a name="i2c_read_word_data">i2c_read_word_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>)</small></h3>
Reads a single 16 bit word from the specified register of the
device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>&nbsp;&nbsp;&nbsp;reg:=&nbsp;&gt;=0,&nbsp;the&nbsp;device&nbsp;register.<br></samp><br><br>SMBus 2.0 5.5.5 - Read word.
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;reg&nbsp;[A]&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[DataLow]&nbsp;A&nbsp;[DataHigh]&nbsp;NA&nbsp;P<br></code><br><br><b><small>Example</small></b><br><br><code>#&nbsp;read&nbsp;word&nbsp;from&nbsp;reg&nbsp;2&nbsp;of&nbsp;device&nbsp;3<br>w&nbsp;=&nbsp;pi.i2c_read_word_data(3,&nbsp;2)<br><br>#&nbsp;read&nbsp;word&nbsp;from&nbsp;reg&nbsp;7&nbsp;of&nbsp;device&nbsp;2<br>w&nbsp;=&nbsp;pi.i2c_read_word_data(2,&nbsp;7)<br></code><h3><a name="i2c_write_block_data">i2c_write_block_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>, <a href="#data">data</a>)</small></h3>
Writes up to 32 bytes to the specified register of the device
associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>&nbsp;&nbsp;&nbsp;reg:=&nbsp;&gt;=0,&nbsp;the&nbsp;device&nbsp;register.<br>&nbsp;&nbsp;data:=&nbsp;the&nbsp;bytes&nbsp;to&nbsp;write.<br></samp><br><br>SMBus 2.0 5.5.7 - Block write.
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;reg&nbsp;[A]&nbsp;len(data)&nbsp;[A]&nbsp;data0&nbsp;[A]&nbsp;data1&nbsp;[A]&nbsp;...&nbsp;[A]<br>&nbsp;&nbsp;&nbsp;datan&nbsp;[A]&nbsp;P<br></code><br><br><b><small>Example</small></b><br><br><code>pi.i2c_write_block_data(4,&nbsp;5,&nbsp;b'hello')<br><br>pi.i2c_write_block_data(4,&nbsp;5,&nbsp;"data&nbsp;bytes")<br><br>pi.i2c_write_block_data(5,&nbsp;0,&nbsp;b'\x00\x01\x22')<br><br>pi.i2c_write_block_data(6,&nbsp;2,&nbsp;[0,&nbsp;1,&nbsp;0x22])<br></code><h3><a name="i2c_write_byte">i2c_write_byte<small>(<a href="#handle">handle</a>, <a href="#byte_val">byte_val</a>)</small></h3>
Sends a single byte to the device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>byte_val:=&nbsp;0-255,&nbsp;the&nbsp;value&nbsp;to&nbsp;write.<br></samp><br><br>SMBus 2.0 5.5.2 - Send byte.
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;byte_val&nbsp;[A]&nbsp;P<br></code><br><br><b><small>Example</small></b><br><br><code>pi.i2c_write_byte(1,&nbsp;17)&nbsp;&nbsp;&nbsp;#&nbsp;send&nbsp;byte&nbsp;&nbsp;&nbsp;17&nbsp;to&nbsp;device&nbsp;1<br>pi.i2c_write_byte(2,&nbsp;0x23)&nbsp;#&nbsp;send&nbsp;byte&nbsp;0x23&nbsp;to&nbsp;device&nbsp;2<br></code><h3><a name="i2c_write_byte_data">i2c_write_byte_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>, <a href="#byte_val">byte_val</a>)</small></h3>
Writes a single byte to the specified register of the device
associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reg:=&nbsp;&gt;=0,&nbsp;the&nbsp;device&nbsp;register.<br>byte_val:=&nbsp;0-255,&nbsp;the&nbsp;value&nbsp;to&nbsp;write.<br></samp><br><br>SMBus 2.0 5.5.4 - Write byte.
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;reg&nbsp;[A]&nbsp;byte_val&nbsp;[A]&nbsp;P<br></code><br><br><b><small>Example</small></b><br><br><code>#&nbsp;send&nbsp;byte&nbsp;0xC5&nbsp;to&nbsp;reg&nbsp;2&nbsp;of&nbsp;device&nbsp;1<br>pi.i2c_write_byte_data(1,&nbsp;2,&nbsp;0xC5)<br><br>#&nbsp;send&nbsp;byte&nbsp;9&nbsp;to&nbsp;reg&nbsp;4&nbsp;of&nbsp;device&nbsp;2<br>pi.i2c_write_byte_data(2,&nbsp;4,&nbsp;9)<br></code><h3><a name="i2c_write_device">i2c_write_device<small>(<a href="#handle">handle</a>, <a href="#data">data</a>)</small></h3>
Writes the data bytes to the raw device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>&nbsp;&nbsp;data:=&nbsp;the&nbsp;bytes&nbsp;to&nbsp;write.<br></samp><br><br><code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;data0&nbsp;[A]&nbsp;data1&nbsp;[A]&nbsp;...&nbsp;[A]&nbsp;datan&nbsp;[A]&nbsp;P<br></code><br><br><b><small>Example</small></b><br><br><code>pi.i2c_write_device(h,&nbsp;b"\x12\x34\xA8")<br><br>pi.i2c_write_device(h,&nbsp;b"help")<br><br>pi.i2c_write_device(h,&nbsp;'help')<br><br>pi.i2c_write_device(h,&nbsp;[23,&nbsp;56,&nbsp;231])<br></code><h3><a name="i2c_write_i2c_block_data">i2c_write_i2c_block_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>, <a href="#data">data</a>)</small></h3>
Writes data bytes to the specified register of the device
associated with handle .  1-32 bytes may be written.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>&nbsp;&nbsp;&nbsp;reg:=&nbsp;&gt;=0,&nbsp;the&nbsp;device&nbsp;register.<br>&nbsp;&nbsp;data:=&nbsp;the&nbsp;bytes&nbsp;to&nbsp;write.<br></samp><br><br><code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;reg&nbsp;[A]&nbsp;data0&nbsp;[A]&nbsp;data1&nbsp;[A]&nbsp;...&nbsp;[A]&nbsp;datan&nbsp;[NA]&nbsp;P<br></code><br><br><b><small>Example</small></b><br><br><code>pi.i2c_write_i2c_block_data(4,&nbsp;5,&nbsp;'hello')<br><br>pi.i2c_write_i2c_block_data(4,&nbsp;5,&nbsp;b'hello')<br><br>pi.i2c_write_i2c_block_data(5,&nbsp;0,&nbsp;b'\x00\x01\x22')<br><br>pi.i2c_write_i2c_block_data(6,&nbsp;2,&nbsp;[0,&nbsp;1,&nbsp;0x22])<br></code><h3><a name="i2c_write_quick">i2c_write_quick<small>(<a href="#handle">handle</a>, <a href="#bit">bit</a>)</small></h3>
Sends a single bit to the device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>&nbsp;&nbsp;&nbsp;bit:=&nbsp;0&nbsp;or&nbsp;1,&nbsp;the&nbsp;value&nbsp;to&nbsp;write.<br></samp><br><br>SMBus 2.0 5.5.1 - Quick command.
<code>S&nbsp;Addr&nbsp;bit&nbsp;[A]&nbsp;P<br></code><br><br><b><small>Example</small></b><br><br><code>pi.i2c_write_quick(0,&nbsp;1)&nbsp;#&nbsp;send&nbsp;1&nbsp;to&nbsp;device&nbsp;0<br>pi.i2c_write_quick(3,&nbsp;0)&nbsp;#&nbsp;send&nbsp;0&nbsp;to&nbsp;device&nbsp;3<br></code><h3><a name="i2c_write_word_data">i2c_write_word_data<small>(<a href="#handle">handle</a>, <a href="#reg">reg</a>, <a href="#word_val">word_val</a>)</small></h3>
Writes a single 16 bit word to the specified register of the
device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reg:=&nbsp;&gt;=0,&nbsp;the&nbsp;device&nbsp;register.<br>word_val:=&nbsp;0-65535,&nbsp;the&nbsp;value&nbsp;to&nbsp;write.<br></samp><br><br>SMBus 2.0 5.5.4 - Write word.
<code>S&nbsp;Addr&nbsp;Wr&nbsp;[A]&nbsp;reg&nbsp;[A]&nbsp;word_val_Low&nbsp;[A]&nbsp;word_val_High&nbsp;[A]&nbsp;P<br></code><br><br><b><small>Example</small></b><br><br><code>#&nbsp;send&nbsp;word&nbsp;0xA0C5&nbsp;to&nbsp;reg&nbsp;5&nbsp;of&nbsp;device&nbsp;4<br>pi.i2c_write_word_data(4,&nbsp;5,&nbsp;0xA0C5)<br><br>#&nbsp;send&nbsp;word&nbsp;2&nbsp;to&nbsp;reg&nbsp;2&nbsp;of&nbsp;device&nbsp;5<br>pi.i2c_write_word_data(5,&nbsp;2,&nbsp;23)<br></code><h3><a name="i2c_zip">i2c_zip<small>(<a href="#handle">handle</a>, <a href="#data">data</a>)</small></h3>
This function executes a sequence of I2C operations.  The
operations to be performed are specified by the contents of data
which contains the concatenated command codes and associated data.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>).<br>&nbsp;&nbsp;data:=&nbsp;the&nbsp;concatenated&nbsp;I2C&nbsp;commands,&nbsp;see&nbsp;below<br></samp><br><br>The returned value is a tuple of the number of bytes read and a
bytearray containing the bytes.  If there was an error the
number of bytes read will be less than zero (and will contain
the error code).
<br><br><b><small>Example</small></b><br><br><code>(count,&nbsp;data)&nbsp;=&nbsp;pi.i2c_zip(h,&nbsp;[4,&nbsp;0x53,&nbsp;7,&nbsp;1,&nbsp;0x32,&nbsp;6,&nbsp;6,&nbsp;0])<br></code><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>Any read I2C data is concatenated in the returned bytearray.
<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="notify_begin">notify_begin<small>(<a href="#handle">handle</a>, <a href="#bits">bits</a>)</small></h3>
Starts notifications on a handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#notify_open">notify_open</a>)<br>&nbsp;&nbsp;bits:=&nbsp;a&nbsp;32&nbsp;bit&nbsp;mask&nbsp;indicating&nbsp;the&nbsp;GPIO&nbsp;to&nbsp;be&nbsp;notified.<br></samp><br><br>The notification sends state changes for each GPIO whose
corresponding bit in bits is set.
<br><br>The following code starts notifications for GPIO 1, 4,
6, 7, and 10 (1234 = 0x04D2 = 0b0000010011010010).
<br><br><b><small>Example</small></b><br><br><code>h&nbsp;=&nbsp;pi.notify_open()<br>if&nbsp;h&nbsp;&gt;=&nbsp;0:<br>&nbsp;&nbsp;&nbsp;pi.notify_begin(h,&nbsp;1234)<br></code><h3><a name="notify_close">notify_close<small>(<a href="#handle">handle</a>)</small></h3>
Stops notifications on a handle and releases the handle for reuse.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#notify_open">notify_open</a>)<br></samp><br><br><b><small>Example</small></b><br><br><code>h&nbsp;=&nbsp;pi.notify_open()<br>if&nbsp;h&nbsp;&gt;=&nbsp;0:<br>&nbsp;&nbsp;&nbsp;pi.notify_begin(h,&nbsp;1234)<br>&nbsp;&nbsp;&nbsp;...<br>&nbsp;&nbsp;&nbsp;pi.notify_close(h)<br>&nbsp;&nbsp;&nbsp;...<br></code><h3><a name="notify_open">notify_open<small>()</small></h3>
Returns a notification handle (&gt;=0).
<br><br>A notification is a method for being notified of GPIO state
changes via a pipe.
<br><br>Pipes are only accessible from the local machine so this
function serves no purpose if you are using Python from a
remote machine.  The in-built (socket) notifications
provided by <a href="#callback">callback</a> should be used instead.
<br><br>Notifications for handle x will be available at the pipe
named /dev/pigpiox (where x is the handle number).
<br><br>E.g. if the function returns 15 then the notifications must be
read from /dev/pigpio15.
<br><br>Notifications have the following structure:
<br><br><code>H&nbsp;seqno<br>H&nbsp;flags<br>I&nbsp;tick<br>I&nbsp;level<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>h&nbsp;=&nbsp;pi.notify_open()<br>if&nbsp;h&nbsp;&gt;=&nbsp;0:<br>&nbsp;&nbsp;&nbsp;pi.notify_begin(h,&nbsp;1234)<br></code><h3><a name="notify_pause">notify_pause<small>(<a href="#handle">handle</a>)</small></h3>
Pauses notifications on a handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#notify_open">notify_open</a>)<br></samp><br><br>Notifications for the handle are suspended until
<a href="#notify_begin">notify_begin</a> is called again.
<br><br><b><small>Example</small></b><br><br><code>h&nbsp;=&nbsp;pi.notify_open()<br>if&nbsp;h&nbsp;&gt;=&nbsp;0:<br>&nbsp;&nbsp;&nbsp;pi.notify_begin(h,&nbsp;1234)<br>&nbsp;&nbsp;&nbsp;...<br>&nbsp;&nbsp;&nbsp;pi.notify_pause(h)<br>&nbsp;&nbsp;&nbsp;...<br>&nbsp;&nbsp;&nbsp;pi.notify_begin(h,&nbsp;1234)<br>&nbsp;&nbsp;&nbsp;...<br></code><h3><a name="read">read<small>(<a href="#gpio">gpio</a>)</small></h3>
Returns the GPIO level.
<br><br><b><small>Parameters</small></b><br><br><samp>gpio:=&nbsp;0-53.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.set_mode(23,&nbsp;pigpio.INPUT)<br><br>pi.set_pull_up_down(23,&nbsp;pigpio.PUD_DOWN)<br>print(pi.read(23))<br>0<br><br>pi.set_pull_up_down(23,&nbsp;pigpio.PUD_UP)<br>print(pi.read(23))<br>1<br></code><h3><a name="read_bank_1">read_bank_1<small>()</small></h3>
Returns the levels of the bank 1 GPIO (GPIO 0-31).
<br><br>The returned 32 bit integer has a bit set if the corresponding
GPIO is high.  GPIO n has bit value (1&lt;&lt;n).
<br><br><b><small>Example</small></b><br><br><code>print(bin(pi.read_bank_1()))<br>0b10010100000011100100001001111<br></code><h3><a name="read_bank_2">read_bank_2<small>()</small></h3>
Returns the levels of the bank 2 GPIO (GPIO 32-53).
<br><br>The returned 32 bit integer has a bit set if the corresponding
GPIO is high.  GPIO n has bit value (1&lt;&lt;(n-32)).
<br><br><b><small>Example</small></b><br><br><code>print(bin(pi.read_bank_2()))<br>0b1111110000000000000000<br></code><h3><a name="run_script">run_script<small>(<a href="#script_id">script_id</a>, <a href="#params">params</a>)</small></h3>
Runs a stored script.
<br><br><b><small>Parameters</small></b><br><br><samp>script_id:=&nbsp;id&nbsp;of&nbsp;stored&nbsp;script.<br>&nbsp;&nbsp;&nbsp;params:=&nbsp;up&nbsp;to&nbsp;10&nbsp;parameters&nbsp;required&nbsp;by&nbsp;the&nbsp;script.<br></samp><br><br><b><small>Example</small></b><br><br><code>s&nbsp;=&nbsp;pi.run_script(sid,&nbsp;[par1,&nbsp;par2])<br><br>s&nbsp;=&nbsp;pi.run_script(sid)<br><br>s&nbsp;=&nbsp;pi.run_script(sid,&nbsp;[1,&nbsp;2,&nbsp;3,&nbsp;4,&nbsp;5,&nbsp;6,&nbsp;7,&nbsp;8,&nbsp;9,&nbsp;10])<br></code><h3><a name="script_status">script_status<small>(<a href="#script_id">script_id</a>)</small></h3>
Returns the run status of a stored script as well as the
current values of parameters 0 to 9.
<br><br><b><small>Parameters</small></b><br><br><samp>script_id:=&nbsp;id&nbsp;of&nbsp;stored&nbsp;script.<br></samp><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 return value is a tuple of run status and a list of
the 10 parameters.  On error the run status will be negative
and the parameter list will be empty.
<br><br><b><small>Example</small></b><br><br><code>(s,&nbsp;pars)&nbsp;=&nbsp;pi.script_status(sid)<br></code><h3><a name="serial_close">serial_close<small>(<a href="#handle">handle</a>)</small></h3>
Closes the serial device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#serial_open">serial_open</a>).<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.serial_close(h1)<br></code><h3><a name="serial_data_available">serial_data_available<small>(<a href="#handle">handle</a>)</small></h3>
Returns the number of bytes available to be read from the
device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#serial_open">serial_open</a>).<br></samp><br><br><b><small>Example</small></b><br><br><code>rdy&nbsp;=&nbsp;pi.serial_data_available(h1)<br><br>if&nbsp;rdy&nbsp;&gt;&nbsp;0:<br>&nbsp;&nbsp;&nbsp;(b,&nbsp;d)&nbsp;=&nbsp;pi.serial_read(h1,&nbsp;rdy)<br></code><h3><a name="serial_open">serial_open<small>(<a href="#tty">tty</a>, <a href="#baud">baud</a>, <a href="#ser_flags">ser_flags</a>)</small></h3>
Returns a handle for the serial tty device opened
at baud bits per second.  The device name must start
with /dev/tty or /dev/serial.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tty:=&nbsp;the&nbsp;serial&nbsp;device&nbsp;to&nbsp;open.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;baud:=&nbsp;baud&nbsp;rate&nbsp;in&nbsp;bits&nbsp;per&nbsp;second,&nbsp;see&nbsp;below.<br>ser_flags:=&nbsp;0,&nbsp;no&nbsp;flags&nbsp;are&nbsp;currently&nbsp;defined.<br></samp><br><br>Normally you would only use the <a href="#serial_*">serial_*</a> functions if
you are or will be connecting to the Pi over a network.  If
you will always run on the local Pi use the standard serial
module instead.
<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><b><small>Example</small></b><br><br><code>h1&nbsp;=&nbsp;pi.serial_open("/dev/ttyAMA0",&nbsp;300)<br><br>h2&nbsp;=&nbsp;pi.serial_open("/dev/ttyUSB1",&nbsp;19200,&nbsp;0)<br><br>h3&nbsp;=&nbsp;pi.serial_open("/dev/serial0",&nbsp;9600)<br></code><h3><a name="serial_read">serial_read<small>(<a href="#handle">handle</a>, <a href="#count">count</a>)</small></h3>
Reads up to count bytes from the device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#serial_open">serial_open</a>).<br>&nbsp;count:=&nbsp;&gt;0,&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;read&nbsp;(defaults&nbsp;to&nbsp;1000).<br></samp><br><br>The returned value is a tuple of the number of bytes read and
a bytearray containing the bytes.  If there was an error the
number of bytes read will be less than zero (and will contain
the error code).
<br><br>If no data is ready a bytes read of zero is returned.
<b><small>Example</small></b><br><br><code>(b,&nbsp;d)&nbsp;=&nbsp;pi.serial_read(h2,&nbsp;100)<br>if&nbsp;b&nbsp;&gt;&nbsp;0:<br>&nbsp;&nbsp;&nbsp;#&nbsp;process&nbsp;read&nbsp;data<br></code><h3><a name="serial_read_byte">serial_read_byte<small>(<a href="#handle">handle</a>)</small></h3>
Returns a single byte from the device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#serial_open">serial_open</a>).<br></samp><br><br>If no data is ready a negative error code will be returned.
<br><br><b><small>Example</small></b><br><br><code>b&nbsp;=&nbsp;pi.serial_read_byte(h1)<br></code><h3><a name="serial_write">serial_write<small>(<a href="#handle">handle</a>, <a href="#data">data</a>)</small></h3>
Writes the data bytes to the device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#serial_open">serial_open</a>).<br>&nbsp;&nbsp;data:=&nbsp;the&nbsp;bytes&nbsp;to&nbsp;write.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.serial_write(h1,&nbsp;b'\x02\x03\x04')<br><br>pi.serial_write(h2,&nbsp;b'help')<br><br>pi.serial_write(h2,&nbsp;"hello")<br><br>pi.serial_write(h1,&nbsp;[2,&nbsp;3,&nbsp;4])<br></code><h3><a name="serial_write_byte">serial_write_byte<small>(<a href="#handle">handle</a>, <a href="#byte_val">byte_val</a>)</small></h3>
Writes a single byte to the device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#serial_open">serial_open</a>).<br>byte_val:=&nbsp;0-255,&nbsp;the&nbsp;value&nbsp;to&nbsp;write.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.serial_write_byte(h1,&nbsp;23)<br><br>pi.serial_write_byte(h1,&nbsp;ord('Z'))<br></code><h3><a name="set_PWM_dutycycle">set_PWM_dutycycle<small>(<a href="#user_gpio">user_gpio</a>, <a href="#dutycycle">dutycycle</a>)</small></h3>
Starts (non-zero dutycycle) or stops (0) PWM pulses on the GPIO.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31.<br>dutycycle:=&nbsp;0-range&nbsp;(range&nbsp;defaults&nbsp;to&nbsp;255).<br></samp><br><br>The <a href="#set_PWM_range">set_PWM_range</a> function can change the default range of 255.
<br><br><b><small>Example</small></b><br><br><code>pi.set_PWM_dutycycle(4,&nbsp;&nbsp;&nbsp;0)&nbsp;#&nbsp;PWM&nbsp;off<br>pi.set_PWM_dutycycle(4,&nbsp;&nbsp;64)&nbsp;#&nbsp;PWM&nbsp;1/4&nbsp;on<br>pi.set_PWM_dutycycle(4,&nbsp;128)&nbsp;#&nbsp;PWM&nbsp;1/2&nbsp;on<br>pi.set_PWM_dutycycle(4,&nbsp;192)&nbsp;#&nbsp;PWM&nbsp;3/4&nbsp;on<br>pi.set_PWM_dutycycle(4,&nbsp;255)&nbsp;#&nbsp;PWM&nbsp;full&nbsp;on<br></code><h3><a name="set_PWM_frequency">set_PWM_frequency<small>(<a href="#user_gpio">user_gpio</a>, <a href="#frequency">frequency</a>)</small></h3>
Sets the frequency (in Hz) of the PWM to be used on the GPIO.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31.<br>frequency:=&nbsp;&gt;=0&nbsp;Hz<br></samp><br><br>Returns the numerically closest frequency if OK, otherwise
PI_BAD_USER_GPIO or PI_NOT_PERMITTED.
<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).  The
sample rate is set when the pigpio daemon is started.
<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>pi.set_PWM_frequency(4,0)<br>print(pi.get_PWM_frequency(4))<br>10<br><br>pi.set_PWM_frequency(4,100000)<br>print(pi.get_PWM_frequency(4))<br>8000<br></code><h3><a name="set_PWM_range">set_PWM_range<small>(<a href="#user_gpio">user_gpio</a>, <a href="#range_">range_</a>)</small></h3>
Sets the range of PWM values to be used on the GPIO.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31.<br>&nbsp;&nbsp;&nbsp;range_:=&nbsp;25-40000.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.set_PWM_range(9,&nbsp;100)&nbsp;&nbsp;#&nbsp;now&nbsp;&nbsp;25&nbsp;1/4,&nbsp;&nbsp;&nbsp;50&nbsp;1/2,&nbsp;&nbsp;&nbsp;75&nbsp;3/4&nbsp;on<br>pi.set_PWM_range(9,&nbsp;500)&nbsp;&nbsp;#&nbsp;now&nbsp;125&nbsp;1/4,&nbsp;&nbsp;250&nbsp;1/2,&nbsp;&nbsp;375&nbsp;3/4&nbsp;on<br>pi.set_PWM_range(9,&nbsp;3000)&nbsp;#&nbsp;now&nbsp;750&nbsp;1/4,&nbsp;1500&nbsp;1/2,&nbsp;2250&nbsp;3/4&nbsp;on<br></code><h3><a name="set_bank_1">set_bank_1<small>(<a href="#bits">bits</a>)</small></h3>
Sets GPIO 0-31 if the corresponding bit in bits is set.
<br><br><b><small>Parameters</small></b><br><br><samp>bits:=&nbsp;a&nbsp;32&nbsp;bit&nbsp;mask&nbsp;with&nbsp;1&nbsp;set&nbsp;if&nbsp;the&nbsp;corresponding&nbsp;GPIO&nbsp;is<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;be&nbsp;set.<br></samp><br><br>A returned status of PI_SOME_PERMITTED indicates that the user
is not allowed to write to one or more of the GPIO.
<br><br><b><small>Example</small></b><br><br><code>pi.set_bank_1(int("111110010000",2))<br></code><h3><a name="set_bank_2">set_bank_2<small>(<a href="#bits">bits</a>)</small></h3>
Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set.
<br><br><b><small>Parameters</small></b><br><br><samp>bits:=&nbsp;a&nbsp;32&nbsp;bit&nbsp;mask&nbsp;with&nbsp;1&nbsp;set&nbsp;if&nbsp;the&nbsp;corresponding&nbsp;GPIO&nbsp;is<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;be&nbsp;set.<br></samp><br><br>A returned status of PI_SOME_PERMITTED indicates that the user
is not allowed to write to one or more of the GPIO.
<br><br><b><small>Example</small></b><br><br><code>pi.set_bank_2(0x303)<br></code><h3><a name="set_glitch_filter">set_glitch_filter<small>(<a href="#user_gpio">user_gpio</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><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;steady:=&nbsp;0-300000<br></samp><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="#callback">callback</a> and <a href="#wait_for_edge">wait_for_edge</a>.
<br><br>It does not affect levels read by <a href="#read">read</a>,
<a href="#read_bank_1">read_bank_1</a>, or <a href="#read_bank_2">read_bank_2</a>.
<br><br>Each (stable) edge will be timestamped <a href="#steady">steady</a>
microseconds after it was first detected.
<br><br><b><small>Example</small></b><br><br><code>pi.set_glitch_filter(23,&nbsp;100)<br></code><h3><a name="set_mode">set_mode<small>(<a href="#gpio">gpio</a>, <a href="#mode">mode</a>)</small></h3>
Sets the GPIO mode.
<br><br><b><small>Parameters</small></b><br><br><samp>gpio:=&nbsp;0-53.<br>mode:=&nbsp;INPUT,&nbsp;OUTPUT,&nbsp;ALT0,&nbsp;ALT1,&nbsp;ALT2,&nbsp;ALT3,&nbsp;ALT4,&nbsp;ALT5.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.set_mode(&nbsp;4,&nbsp;pigpio.INPUT)&nbsp;&nbsp;#&nbsp;GPIO&nbsp;&nbsp;4&nbsp;as&nbsp;input<br>pi.set_mode(17,&nbsp;pigpio.OUTPUT)&nbsp;#&nbsp;GPIO&nbsp;17&nbsp;as&nbsp;output<br>pi.set_mode(24,&nbsp;pigpio.ALT2)&nbsp;&nbsp;&nbsp;#&nbsp;GPIO&nbsp;24&nbsp;as&nbsp;ALT2<br></code><h3><a name="set_noise_filter">set_noise_filter<small>(<a href="#user_gpio">user_gpio</a>, <a href="#steady">steady</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><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;0-31<br>&nbsp;&nbsp;&nbsp;steady:=&nbsp;0-300000<br>&nbsp;&nbsp;&nbsp;active:=&nbsp;0-1000000<br></samp><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="#callback">callback</a> and <a href="#wait_for_edge">wait_for_edge</a>.
<br><br>It does not affect levels read by <a href="#read">read</a>,
<a href="#read_bank_1">read_bank_1</a>, or <a href="#read_bank_2">read_bank_2</a>.
<br><br>Level changes before and after the active period may
be reported.  Your software must be designed to cope with
such reports.
<br><br><b><small>Example</small></b><br><br><code>pi.set_noise_filter(23,&nbsp;1000,&nbsp;5000)<br></code><h3><a name="set_pad_strength">set_pad_strength<small>(<a href="#pad">pad</a>, <a href="#pad_strength">pad_strength</a>)</small></h3>
This function sets the pad drive strength in mA.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pad:=&nbsp;0-2,&nbsp;the&nbsp;pad&nbsp;to&nbsp;set.<br>pad_strength:=&nbsp;1-16&nbsp;mA.<br></samp><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>pi.set_pad_strength(2,&nbsp;14)&nbsp;#&nbsp;Set&nbsp;pad&nbsp;2&nbsp;to&nbsp;14&nbsp;mA.<br></code><h3><a name="set_pull_up_down">set_pull_up_down<small>(<a href="#gpio">gpio</a>, <a href="#pud">pud</a>)</small></h3>
Sets or clears the internal GPIO pull-up/down resistor.
<br><br><b><small>Parameters</small></b><br><br><samp>gpio:=&nbsp;0-53.<br>&nbsp;pud:=&nbsp;PUD_UP,&nbsp;PUD_DOWN,&nbsp;PUD_OFF.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.set_pull_up_down(17,&nbsp;pigpio.PUD_OFF)<br>pi.set_pull_up_down(23,&nbsp;pigpio.PUD_UP)<br>pi.set_pull_up_down(24,&nbsp;pigpio.PUD_DOWN)<br></code><h3><a name="set_servo_pulsewidth">set_servo_pulsewidth<small>(<a href="#user_gpio">user_gpio</a>, <a href="#pulsewidth">pulsewidth</a>)</small></h3>
Starts (500-2500) or stops (0) servo pulses on the GPIO.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;user_gpio:=&nbsp;0-31.<br>pulsewidth:=&nbsp;0&nbsp;(off),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;500&nbsp;(most&nbsp;anti-clockwise)&nbsp;-&nbsp;2500&nbsp;(most&nbsp;clockwise).<br></samp><br><br>The selected pulsewidth will continue to be transmitted until
changed by a subsequent call to set_servo_pulsewidth.
<br><br>The pulsewidths 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.
<br><br>You can DAMAGE a servo if you command it to move beyond its
limits.
<br><br><b><small>Example</small></b><br><br><code>pi.set_servo_pulsewidth(17,&nbsp;0)&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;off<br>pi.set_servo_pulsewidth(17,&nbsp;1000)&nbsp;#&nbsp;safe&nbsp;anti-clockwise<br>pi.set_servo_pulsewidth(17,&nbsp;1500)&nbsp;#&nbsp;centre<br>pi.set_servo_pulsewidth(17,&nbsp;2000)&nbsp;#&nbsp;safe&nbsp;clockwise<br></code><h3><a name="set_watchdog">set_watchdog<small>(<a href="#user_gpio">user_gpio</a>, <a href="#wdog_timeout">wdog_timeout</a>)</small></h3>
Sets a watchdog timeout for a GPIO.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;&nbsp;user_gpio:=&nbsp;0-31.<br>wdog_timeout:=&nbsp;0-60000.<br></samp><br><br>The watchdog is nominally in milliseconds.
<br><br>Only one watchdog may be registered per GPIO.
<br><br>The watchdog may be cancelled by setting timeout to 0.
<br><br>Once a watchdog has been started callbacks for the GPIO
will be triggered every timeout interval after the last
GPIO activity.
<br><br>The callback will receive the special level TIMEOUT.
<br><br><b><small>Example</small></b><br><br><code>pi.set_watchdog(23,&nbsp;1000)&nbsp;#&nbsp;1000&nbsp;ms&nbsp;watchdog&nbsp;on&nbsp;GPIO&nbsp;23<br>pi.set_watchdog(23,&nbsp;0)&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;cancel&nbsp;watchdog&nbsp;on&nbsp;GPIO&nbsp;23<br></code><h3><a name="shell">shell<small>(<a href="#shellscr">shellscr</a>, <a href="#pstring">pstring</a>)</small></h3>
This function uses the system call to execute a shell script
with the given string as its parameter.
<br><br><b><small>Parameters</small></b><br><br><samp>shellscr:=&nbsp;the&nbsp;name&nbsp;of&nbsp;the&nbsp;script,&nbsp;only&nbsp;alphanumerics,<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>pstring&nbsp;:=&nbsp;the&nbsp;parameter&nbsp;string&nbsp;to&nbsp;pass&nbsp;to&nbsp;the&nbsp;script<br></samp><br><br>The exit status of the system call is returned if OK,
otherwise PI_BAD_SHELL_STATUS.
<br><br><a href="#shellscr">shellscr</a> 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;pi.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;pi.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;pi.shell("scr1",&nbsp;"\"hello&nbsp;string&nbsp;with&nbsp;spaces&nbsp;world\"");<br></code><h3><a name="spi_close">spi_close<small>(<a href="#handle">handle</a>)</small></h3>
Closes the SPI device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#spi_open">spi_open</a>).<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.spi_close(h)<br></code><h3><a name="spi_open">spi_open<small>(<a href="#spi_channel">spi_channel</a>, <a href="#baud">baud</a>, <a href="#spi_flags">spi_flags</a>)</small></h3>
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><b><small>Parameters</small></b><br><br><samp>spi_channel:=&nbsp;0-1&nbsp;(0-2&nbsp;for&nbsp;the&nbsp;auxiliary&nbsp;SPI).<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;baud:=&nbsp;32K-125M&nbsp;(values&nbsp;above&nbsp;30M&nbsp;are&nbsp;unlikely&nbsp;to&nbsp;work).<br>&nbsp;&nbsp;spi_flags:=&nbsp;see&nbsp;below.<br></samp><br><br>spi_flags 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="#spi_read">spi_read</a>, <a href="#spi_write">spi_write</a>, and <a href="#spi_xfer">spi_xfer</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 character.
For bits 9-16 there will be two bytes per character.
For bits 17-32 there will be four bytes per character.
<br><br>Multi-byte transfers are made in least significant byte
first order.
<br><br>E.g. to transfer 32 11-bit words data should
contain 64 bytes.
<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.
<br><br><b><small>Example</small></b><br><br><code>#&nbsp;open&nbsp;SPI&nbsp;device&nbsp;on&nbsp;channel&nbsp;1&nbsp;in&nbsp;mode&nbsp;3&nbsp;at&nbsp;50000&nbsp;bits&nbsp;per&nbsp;second<br><br>h&nbsp;=&nbsp;pi.spi_open(1,&nbsp;50000,&nbsp;3)<br></code><h3><a name="spi_read">spi_read<small>(<a href="#handle">handle</a>, <a href="#count">count</a>)</small></h3>
Reads count bytes from the SPI device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#spi_open">spi_open</a>).<br>&nbsp;count:=&nbsp;&gt;0,&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;to&nbsp;read.<br></samp><br><br>The returned value is a tuple of the number of bytes read and a
bytearray containing the bytes.  If there was an error the
number of bytes read will be less than zero (and will contain
the error code).
<br><br><b><small>Example</small></b><br><br><code>(b,&nbsp;d)&nbsp;=&nbsp;pi.spi_read(h,&nbsp;60)&nbsp;#&nbsp;read&nbsp;60&nbsp;bytes&nbsp;from&nbsp;device&nbsp;h<br>if&nbsp;b&nbsp;==&nbsp;60:<br>&nbsp;&nbsp;&nbsp;#&nbsp;process&nbsp;read&nbsp;data<br>else:<br>&nbsp;&nbsp;&nbsp;#&nbsp;error&nbsp;path<br></code><h3><a name="spi_write">spi_write<small>(<a href="#handle">handle</a>, <a href="#data">data</a>)</small></h3>
Writes the data bytes to the SPI device associated with handle.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#spi_open">spi_open</a>).<br>&nbsp;&nbsp;data:=&nbsp;the&nbsp;bytes&nbsp;to&nbsp;write.<br></samp><br><br><b><small>Example</small></b><br><br><code>pi.spi_write(0,&nbsp;b'\x02\xc0\x80')&nbsp;#&nbsp;write&nbsp;3&nbsp;bytes&nbsp;to&nbsp;device&nbsp;0<br><br>pi.spi_write(0,&nbsp;b'defgh')&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;write&nbsp;5&nbsp;bytes&nbsp;to&nbsp;device&nbsp;0<br><br>pi.spi_write(0,&nbsp;"def")&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;write&nbsp;3&nbsp;bytes&nbsp;to&nbsp;device&nbsp;0<br><br>pi.spi_write(1,&nbsp;[2,&nbsp;192,&nbsp;128])&nbsp;&nbsp;&nbsp;#&nbsp;write&nbsp;3&nbsp;bytes&nbsp;to&nbsp;device&nbsp;1<br></code><h3><a name="spi_xfer">spi_xfer<small>(<a href="#handle">handle</a>, <a href="#data">data</a>)</small></h3>
Writes the data bytes to the SPI device associated with handle,
returning the data bytes read from the device.
<br><br><b><small>Parameters</small></b><br><br><samp>handle:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#spi_open">spi_open</a>).<br>&nbsp;&nbsp;data:=&nbsp;the&nbsp;bytes&nbsp;to&nbsp;write.<br></samp><br><br>The returned value is a tuple of the number of bytes read and a
bytearray containing the bytes.  If there was an error the
number of bytes read will be less than zero (and will contain
the error code).
<br><br><b><small>Example</small></b><br><br><code>(count,&nbsp;rx_data)&nbsp;=&nbsp;pi.spi_xfer(h,&nbsp;b'\x01\x80\x00')<br><br>(count,&nbsp;rx_data)&nbsp;=&nbsp;pi.spi_xfer(h,&nbsp;[1,&nbsp;128,&nbsp;0])<br><br>(count,&nbsp;rx_data)&nbsp;=&nbsp;pi.spi_xfer(h,&nbsp;b"hello")<br><br>(count,&nbsp;rx_data)&nbsp;=&nbsp;pi.spi_xfer(h,&nbsp;"hello")<br></code><h3><a name="stop">stop<small>()</small></h3>
Release pigpio resources.
<br><br><b><small>Example</small></b><br><br><code>pi.stop()<br></code><h3><a name="stop_script">stop_script<small>(<a href="#script_id">script_id</a>)</small></h3>
Stops a running script.
<br><br><b><small>Parameters</small></b><br><br><samp>script_id:=&nbsp;id&nbsp;of&nbsp;stored&nbsp;script.<br></samp><br><br><b><small>Example</small></b><br><br><code>status&nbsp;=&nbsp;pi.stop_script(sid)<br></code><h3><a name="store_script">store_script<small>(<a href="#script">script</a>)</small></h3>
Store a 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><b><small>Parameters</small></b><br><br><samp>script:=&nbsp;the&nbsp;script&nbsp;text&nbsp;as&nbsp;a&nbsp;series&nbsp;of&nbsp;bytes.<br></samp><br><br>Returns a &gt;=0 script id if OK.
<br><br><b><small>Example</small></b><br><br><code>sid&nbsp;=&nbsp;pi.store_script(<br>&nbsp;&nbsp;&nbsp;b'tag&nbsp;0&nbsp;w&nbsp;22&nbsp;1&nbsp;mils&nbsp;100&nbsp;w&nbsp;22&nbsp;0&nbsp;mils&nbsp;100&nbsp;dcr&nbsp;p0&nbsp;jp&nbsp;0')<br></code><h3><a name="update_script">update_script<small>(<a href="#script_id">script_id</a>, <a href="#params">params</a>)</small></h3>
Sets the parameters of a script.  The script may or
may not be running.  The first parameters of the script are
overwritten with the new values.
<br><br><b><small>Parameters</small></b><br><br><samp>script_id:=&nbsp;id&nbsp;of&nbsp;stored&nbsp;script.<br>&nbsp;&nbsp;&nbsp;params:=&nbsp;up&nbsp;to&nbsp;10&nbsp;parameters&nbsp;required&nbsp;by&nbsp;the&nbsp;script.<br></samp><br><br><b><small>Example</small></b><br><br><code>s&nbsp;=&nbsp;pi.update_script(sid,&nbsp;[par1,&nbsp;par2])<br><br>s&nbsp;=&nbsp;pi.update_script(sid,&nbsp;[1,&nbsp;2,&nbsp;3,&nbsp;4,&nbsp;5,&nbsp;6,&nbsp;7,&nbsp;8,&nbsp;9,&nbsp;10])<br></code><h3><a name="wait_for_edge">wait_for_edge<small>(<a href="#user_gpio">user_gpio</a>, <a href="#edge">edge</a>, <a href="#wait_timeout">wait_timeout</a>)</small></h3>
Wait for an edge event on a GPIO.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;&nbsp;user_gpio:=&nbsp;0-31.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;edge:=&nbsp;EITHER_EDGE,&nbsp;RISING_EDGE&nbsp;(default),&nbsp;or<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FALLING_EDGE.<br>wait_timeout:=&nbsp;&gt;=0.0&nbsp;(default&nbsp;60.0).<br></samp><br><br>The function returns when the edge is detected or after
the number of seconds specified by timeout has expired.
<br><br>Do not use this function for precise timing purposes,
the edge is only checked 20 times a second. Whenever
you need to know the accurate time of GPIO events use
a <a href="#callback">callback</a> function.
<br><br>The function returns True if the edge is detected,
otherwise False.
<br><br><b><small>Example</small></b><br><br><code>if&nbsp;pi.wait_for_edge(23):<br>&nbsp;&nbsp;&nbsp;print("Rising&nbsp;edge&nbsp;detected")<br>else:<br>&nbsp;&nbsp;&nbsp;print("wait&nbsp;for&nbsp;edge&nbsp;timed&nbsp;out")<br><br>if&nbsp;pi.wait_for_edge(23,&nbsp;pigpio.FALLING_EDGE,&nbsp;5.0):<br>&nbsp;&nbsp;&nbsp;print("Falling&nbsp;edge&nbsp;detected")<br>else:<br>&nbsp;&nbsp;&nbsp;print("wait&nbsp;for&nbsp;falling&nbsp;edge&nbsp;timed&nbsp;out")<br></code><h3><a name="wait_for_event">wait_for_event<small>(<a href="#event">event</a>, <a href="#wait_timeout">wait_timeout</a>)</small></h3>
Wait for an event.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;event:=&nbsp;0-31.<br>wait_timeout:=&nbsp;&gt;=0.0&nbsp;(default&nbsp;60.0).<br></samp><br><br>The function returns when the event is signalled or after
the number of seconds specified by timeout has expired.
<br><br>The function returns True if the event is detected,
otherwise False.
<br><br><b><small>Example</small></b><br><br><code>if&nbsp;pi.wait_for_event(23):<br>&nbsp;&nbsp;&nbsp;print("event&nbsp;detected")<br>else:<br>&nbsp;&nbsp;&nbsp;print("wait&nbsp;for&nbsp;event&nbsp;timed&nbsp;out")<br></code><h3><a name="wave_add_generic">wave_add_generic<small>(<a href="#pulses">pulses</a>)</small></h3>
Adds a list of pulses to the current waveform.
<br><br><b><small>Parameters</small></b><br><br><samp>pulses:=&nbsp;list&nbsp;of&nbsp;pulses&nbsp;to&nbsp;add&nbsp;to&nbsp;the&nbsp;waveform.<br></samp><br><br>Returns the new total number of pulses in the current waveform.
<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
solely of a delay.
<br><br><b><small>Example</small></b><br><br><code>G1=4<br>G2=24<br><br>pi.set_mode(G1,&nbsp;pigpio.OUTPUT)<br>pi.set_mode(G2,&nbsp;pigpio.OUTPUT)<br><br>flash_500=[]&nbsp;#&nbsp;flash&nbsp;every&nbsp;500&nbsp;ms<br>flash_100=[]&nbsp;#&nbsp;flash&nbsp;every&nbsp;100&nbsp;ms<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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OFF&nbsp;&nbsp;DELAY<br><br>flash_500.append(pigpio.pulse(1&lt;&lt;G1,&nbsp;1&lt;&lt;G2,&nbsp;500000))<br>flash_500.append(pigpio.pulse(1&lt;&lt;G2,&nbsp;1&lt;&lt;G1,&nbsp;500000))<br><br>flash_100.append(pigpio.pulse(1&lt;&lt;G1,&nbsp;1&lt;&lt;G2,&nbsp;100000))<br>flash_100.append(pigpio.pulse(1&lt;&lt;G2,&nbsp;1&lt;&lt;G1,&nbsp;100000))<br><br>pi.wave_clear()&nbsp;#&nbsp;clear&nbsp;any&nbsp;existing&nbsp;waveforms<br><br>pi.wave_add_generic(flash_500)&nbsp;#&nbsp;500&nbsp;ms&nbsp;flashes<br>f500&nbsp;=&nbsp;pi.wave_create()&nbsp;#&nbsp;create&nbsp;and&nbsp;save&nbsp;id<br><br>pi.wave_add_generic(flash_100)&nbsp;#&nbsp;100&nbsp;ms&nbsp;flashes<br>f100&nbsp;=&nbsp;pi.wave_create()&nbsp;#&nbsp;create&nbsp;and&nbsp;save&nbsp;id<br><br>pi.wave_send_repeat(f500)<br><br>time.sleep(4)<br><br>pi.wave_send_repeat(f100)<br><br>time.sleep(4)<br><br>pi.wave_send_repeat(f500)<br><br>time.sleep(4)<br><br>pi.wave_tx_stop()&nbsp;#&nbsp;stop&nbsp;waveform<br><br>pi.wave_clear()&nbsp;#&nbsp;clear&nbsp;all&nbsp;waveforms<br></code><h3><a name="wave_add_new">wave_add_new<small>()</small></h3>
Starts a new empty waveform.
<br><br>You would not normally need to call this function as it is
automatically called after a waveform is created with the
<a href="#wave_create">wave_create</a> function.
<br><br><b><small>Example</small></b><br><br><code>pi.wave_add_new()<br></code><h3><a name="wave_add_serial">wave_add_serial<small>(<a href="#user_gpio">user_gpio</a>, <a href="#baud">baud</a>, <a href="#data">data</a>, <a href="#offset">offset</a>, <a href="#bb_bits">bb_bits</a>, <a href="#bb_stop">bb_stop</a>)</small></h3>
Adds a waveform representing serial data to the existing
waveform (if any).  The serial data starts <a href="#offset">offset</a>
microseconds from the start of the waveform.
<br><br><b><small>Parameters</small></b><br><br><samp>user_gpio:=&nbsp;GPIO&nbsp;to&nbsp;transmit&nbsp;data.&nbsp;&nbsp;You&nbsp;must&nbsp;set&nbsp;the&nbsp;GPIO&nbsp;mode<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;output.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;baud:=&nbsp;50-1000000&nbsp;bits&nbsp;per&nbsp;second.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data:=&nbsp;the&nbsp;bytes&nbsp;to&nbsp;write.<br>&nbsp;&nbsp;&nbsp;offset:=&nbsp;number&nbsp;of&nbsp;microseconds&nbsp;from&nbsp;the&nbsp;start&nbsp;of&nbsp;the<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;waveform,&nbsp;default&nbsp;0.<br>&nbsp;&nbsp;bb_bits:=&nbsp;number&nbsp;of&nbsp;data&nbsp;bits,&nbsp;default&nbsp;8.<br>&nbsp;&nbsp;bb_stop:=&nbsp;number&nbsp;of&nbsp;stop&nbsp;half&nbsp;bits,&nbsp;default&nbsp;2.<br></samp><br><br>Returns the new total number of pulses in the current waveform.
<br><br>The serial data is formatted as one start bit, <a href="#bb_bits">bb_bits</a>
data bits, and <a href="#bb_stop">bb_stop</a>/2 stop bits.
<br><br>It is legal to add serial data streams with different baud
rates to the same waveform.
<br><br>The bytes required for each character depend upon <a href="#bb_bits">bb_bits</a>.
<br><br>For <a href="#bb_bits">bb_bits</a> 1-8 there will be one byte per character.
For <a href="#bb_bits">bb_bits</a> 9-16 there will be two bytes per character.
For <a href="#bb_bits">bb_bits</a> 17-32 there will be four bytes per character.
<br><br><b><small>Example</small></b><br><br><code>pi.wave_add_serial(4,&nbsp;300,&nbsp;'Hello&nbsp;world')<br><br>pi.wave_add_serial(4,&nbsp;300,&nbsp;b"Hello&nbsp;world")<br><br>pi.wave_add_serial(4,&nbsp;300,&nbsp;b'\x23\x01\x00\x45')<br><br>pi.wave_add_serial(17,&nbsp;38400,&nbsp;[23,&nbsp;128,&nbsp;234],&nbsp;5000)<br></code><h3><a name="wave_chain">wave_chain<small>(<a href="#data">data</a>)</small></h3>
This function transmits a chain of waveforms.
<br><br>NOTE: Any hardware PWM started by <a href="#hardware_PWM">hardware_PWM</a>
will be cancelled.
<br><br>The waves to be transmitted are specified by the contents
of data which contains an ordered list of <a href="#wave_id">wave_id</a>s
and optional command codes and related data.
<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>#!/usr/bin/env&nbsp;python<br><br>import&nbsp;time<br>import&nbsp;pigpio<br><br>WAVES=5<br>GPIO=4<br><br>wid=[0]*WAVES<br><br>pi&nbsp;=&nbsp;pigpio.pi()&nbsp;#&nbsp;Connect&nbsp;to&nbsp;local&nbsp;Pi.<br><br>pi.set_mode(GPIO,&nbsp;pigpio.OUTPUT);<br><br>for&nbsp;i&nbsp;in&nbsp;range(WAVES):<br>&nbsp;&nbsp;&nbsp;pi.wave_add_generic([<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pigpio.pulse(1&lt;&lt;GPIO,&nbsp;0,&nbsp;20),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pigpio.pulse(0,&nbsp;1&lt;&lt;GPIO,&nbsp;(i+1)*200)]);<br><br>&nbsp;&nbsp;&nbsp;wid[i]&nbsp;=&nbsp;pi.wave_create();<br><br>pi.wave_chain([<br>&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;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;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;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;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;255,&nbsp;2,&nbsp;0x88,&nbsp;0x13,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;delay&nbsp;5000us<br>&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;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;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;wid[3],&nbsp;wid[1],&nbsp;wid[2],&nbsp;#&nbsp;transmit&nbsp;waves&nbsp;3+1+2<br>&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;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;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;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;wid[0],&nbsp;wid[0],&nbsp;wid[0],&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;transmit&nbsp;waves&nbsp;0+0+0<br>&nbsp;&nbsp;&nbsp;])<br><br>while&nbsp;pi.wave_tx_busy():<br>&nbsp;&nbsp;&nbsp;time.sleep(0.1);<br><br>for&nbsp;i&nbsp;in&nbsp;range(WAVES):<br>&nbsp;&nbsp;&nbsp;pi.wave_delete(wid[i])<br><br>pi.stop()<br></code><h3><a name="wave_clear">wave_clear<small>()</small></h3>
Clears all waveforms and any data added by calls to the
<a href="#wave_add_*">wave_add_*</a> functions.
<br><br><b><small>Example</small></b><br><br><code>pi.wave_clear()<br></code><h3><a name="wave_create">wave_create<small>()</small></h3>
Creates a waveform from the data provided by the prior calls
to the <a href="#wave_add_*">wave_add_*</a> functions.
<br><br>Returns a wave id (&gt;=0) if OK,  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="#wave_add_*">wave_add_*</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="#wave_send_*">wave_send_*</a> to specify the waveform
to transmit.
<br><br>Normal usage would be
<br><br>Step 1. <a href="#wave_clear">wave_clear</a> to clear all waveforms and added data.
<br><br>Step 2. <a href="#wave_add_*">wave_add_*</a> calls to supply the waveform data.
<br><br>Step 3. <a href="#wave_create">wave_create</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="#wave_send_*">wave_send_*</a> with the id of the waveform to transmit.
<br><br>A waveform comprises one or more pulses.
<br><br>A pulse specifies
<br><br>1) the GPIO to be switched on at the start of the pulse.
2) the GPIO to be switched off at the start of the pulse.
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><b><small>Example</small></b><br><br><code>wid&nbsp;=&nbsp;pi.wave_create()<br></code><h3><a name="wave_create_and_pad">wave_create_and_pad<small>(<a href="#percent">percent</a>)</small></h3>
This function creates a waveform like <a href="#wave_create">wave_create</a> but pads the consumed
resources. Where percent gives the percentage of the resources to use
(in terms of the theoretical maximum, not the current amount free).
This allows the reuse of deleted waves while a transmission is active.
<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><code>percent:&nbsp;0-100,&nbsp;size&nbsp;of&nbsp;waveform&nbsp;as&nbsp;percentage&nbsp;of&nbsp;maximum&nbsp;available.<br></code><br><br>The data provided by the <a href="#wave_add_*">wave_add_*</a> functions are 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="#wave_send_*">wave_send_*</a> to specify the waveform to transmit.
<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>Normal usage:
<br><br>Step 1. <a href="#wave_clear">wave_clear</a> to clear all waveforms and added data.
<br><br>Step 2. <a href="#wave_add_*">wave_add_*</a> calls to supply the waveform data.
<br><br>Step 3. <a href="#wave_create_and_pad">wave_create_and_pad</a> to create a waveform of uniform size.
<br><br>Step 4. <a href="#wave_send_*">wave_send_*</a> with the id of the waveform to transmit.
<br><br>Repeat steps 2-4 as needed.
<br><br>Step 5. Any wave id can now be deleted and another wave of the same size
        can be created in its place.
<br><br><b><small>Example</small></b><br><br><code>wid&nbsp;=&nbsp;pi.wave_create_and_pad(50)<br></code><h3><a name="wave_delete">wave_delete<small>(<a href="#wave_id">wave_id</a>)</small></h3>
This function deletes the waveform with id wave_id.
<br><br><b><small>Parameters</small></b><br><br><samp>wave_id:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#wave_create">wave_create</a>).<br></samp><br><br>Wave ids are allocated in order, 0, 1, 2, etc.
<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><b><small>Example</small></b><br><br><code>pi.wave_delete(6)&nbsp;#&nbsp;delete&nbsp;waveform&nbsp;with&nbsp;id&nbsp;6<br><br>pi.wave_delete(0)&nbsp;#&nbsp;delete&nbsp;waveform&nbsp;with&nbsp;id&nbsp;0<br></code><h3><a name="wave_get_cbs">wave_get_cbs<small>()</small></h3>
Returns the length in DMA control blocks of the current
waveform.
<br><br><b><small>Example</small></b><br><br><code>cbs&nbsp;=&nbsp;pi.wave_get_cbs()<br></code><h3><a name="wave_get_max_cbs">wave_get_max_cbs<small>()</small></h3>
Returns the maximum possible size of a waveform in DMA
control blocks.
<br><br><b><small>Example</small></b><br><br><code>cbs&nbsp;=&nbsp;pi.wave_get_max_cbs()<br></code><h3><a name="wave_get_max_micros">wave_get_max_micros<small>()</small></h3>
Returns the maximum possible size of a waveform in microseconds.
<br><br><b><small>Example</small></b><br><br><code>micros&nbsp;=&nbsp;pi.wave_get_max_micros()<br></code><h3><a name="wave_get_max_pulses">wave_get_max_pulses<small>()</small></h3>
Returns the maximum possible size of a waveform in pulses.
<br><br><b><small>Example</small></b><br><br><code>pulses&nbsp;=&nbsp;pi.wave_get_max_pulses()<br></code><h3><a name="wave_get_micros">wave_get_micros<small>()</small></h3>
Returns the length in microseconds of the current waveform.
<br><br><b><small>Example</small></b><br><br><code>micros&nbsp;=&nbsp;pi.wave_get_micros()<br></code><h3><a name="wave_get_pulses">wave_get_pulses<small>()</small></h3>
Returns the length in pulses of the current waveform.
<br><br><b><small>Example</small></b><br><br><code>pulses&nbsp;=&nbsp;pi.wave_get_pulses()<br></code><h3><a name="wave_send_once">wave_send_once<small>(<a href="#wave_id">wave_id</a>)</small></h3>
Transmits the waveform with id wave_id.  The waveform is sent
once.
<br><br>NOTE: Any hardware PWM started by <a href="#hardware_PWM">hardware_PWM</a> will
be cancelled.
<br><br><b><small>Parameters</small></b><br><br><samp>wave_id:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#wave_create">wave_create</a>).<br></samp><br><br>Returns the number of DMA control blocks used in the waveform.
<br><br><b><small>Example</small></b><br><br><code>cbs&nbsp;=&nbsp;pi.wave_send_once(wid)<br></code><h3><a name="wave_send_repeat">wave_send_repeat<small>(<a href="#wave_id">wave_id</a>)</small></h3>
Transmits the waveform with id wave_id.  The waveform repeats
until wave_tx_stop is called or another call to <a href="#wave_send_*">wave_send_*</a>
is made.
<br><br>NOTE: Any hardware PWM started by <a href="#hardware_PWM">hardware_PWM</a> will
be cancelled.
<br><br><b><small>Parameters</small></b><br><br><samp>wave_id:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#wave_create">wave_create</a>).<br></samp><br><br>Returns the number of DMA control blocks used in the waveform.
<br><br><b><small>Example</small></b><br><br><code>cbs&nbsp;=&nbsp;pi.wave_send_repeat(wid)<br></code><h3><a name="wave_send_using_mode">wave_send_using_mode<small>(<a href="#wave_id">wave_id</a>, <a href="#mode">mode</a>)</small></h3>
Transmits the waveform with id wave_id using mode mode.
<br><br><b><small>Parameters</small></b><br><br><samp>wave_id:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#wave_create">wave_create</a>).<br>&nbsp;&nbsp;&nbsp;mode:=&nbsp;WAVE_MODE_ONE_SHOT,&nbsp;WAVE_MODE_REPEAT,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WAVE_MODE_ONE_SHOT_SYNC,&nbsp;or&nbsp;WAVE_MODE_REPEAT_SYNC.<br></samp><br><br>WAVE_MODE_ONE_SHOT: same as <a href="#wave_send_once">wave_send_once</a>.
<br><br>WAVE_MODE_REPEAT same as <a href="#wave_send_repeat">wave_send_repeat</a>.
<br><br>WAVE_MODE_ONE_SHOT_SYNC same as <a href="#wave_send_once">wave_send_once</a> but tries
to sync with the previous waveform.
<br><br>WAVE_MODE_REPEAT_SYNC same as <a href="#wave_send_repeat">wave_send_repeat</a> but tries
to sync with the previous 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="#hardware_PWM">hardware_PWM</a> will
be cancelled.
<br><br><b><small>Parameters</small></b><br><br><samp>wave_id:=&nbsp;&gt;=0&nbsp;(as&nbsp;returned&nbsp;by&nbsp;a&nbsp;prior&nbsp;call&nbsp;to&nbsp;<a href="#wave_create">wave_create</a>).<br></samp><br><br>Returns the number of DMA control blocks used in the waveform.
<br><br><b><small>Example</small></b><br><br><code>cbs&nbsp;=&nbsp;pi.wave_send_using_mode(wid,&nbsp;WAVE_MODE_REPEAT_SYNC)<br></code><h3><a name="wave_tx_at">wave_tx_at<small>()</small></h3>
Returns the id of the waveform currently being
transmitted using <a href="#wave_send*">wave_send*</a>.  Chained waves are not supported.
<br><br>Returns the waveform id or one of the following special
values:
<br><br>WAVE_NOT_FOUND (9998) - transmitted wave not found.
NO_TX_WAVE (9999) - no wave being transmitted.
<br><br><b><small>Example</small></b><br><br><code>wid&nbsp;=&nbsp;pi.wave_tx_at()<br></code><h3><a name="wave_tx_busy">wave_tx_busy<small>()</small></h3>
Returns 1 if a waveform is currently being transmitted,
otherwise 0.
<br><br><b><small>Example</small></b><br><br><code>pi.wave_send_once(0)&nbsp;#&nbsp;send&nbsp;first&nbsp;waveform<br><br>while&nbsp;pi.wave_tx_busy():&nbsp;#&nbsp;wait&nbsp;for&nbsp;waveform&nbsp;to&nbsp;be&nbsp;sent<br>&nbsp;&nbsp;&nbsp;time.sleep(0.1)<br><br>pi.wave_send_once(1)&nbsp;#&nbsp;send&nbsp;next&nbsp;waveform<br></code><h3><a name="wave_tx_repeat">wave_tx_repeat<small>()</small></h3>
This function is deprecated and has beeen removed.
<br><br>Use <a href="#wave_create">wave_create</a>/<a href="#wave_send_*">wave_send_*</a> instead.
<h3><a name="wave_tx_start">wave_tx_start<small>()</small></h3>
This function is deprecated and has been removed.
<br><br>Use <a href="#wave_create">wave_create</a>/<a href="#wave_send_*">wave_send_*</a> instead.
<h3><a name="wave_tx_stop">wave_tx_stop<small>()</small></h3>
Stops the transmission of the current waveform.
<br><br>This function is intended to stop a waveform started with
wave_send_repeat.
<br><br><b><small>Example</small></b><br><br><code>pi.wave_send_repeat(3)<br><br>time.sleep(5)<br><br>pi.wave_tx_stop()<br></code><h3><a name="write">write<small>(<a href="#gpio">gpio</a>, <a href="#level">level</a>)</small></h3>
Sets the GPIO level.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;GPIO:=&nbsp;0-53.<br>level:=&nbsp;0,&nbsp;1.<br></samp><br><br>If PWM or servo pulses are active on the GPIO they are
switched off.
<br><br><b><small>Example</small></b><br><br><code>pi.set_mode(17,&nbsp;pigpio.OUTPUT)<br><br>pi.write(17,0)<br>print(pi.read(17))<br>0<br><br>pi.write(17,1)<br>print(pi.read(17))<br>1<br></code><h2>    class pulse
</h2><h3><a name="pigpio.pulse">pigpio.pulse<small>(<a href="#gpio_on">gpio_on</a>, <a href="#gpio_off">gpio_off</a>, <a href="#delay">delay</a>)</small></h3>
Initialises a pulse.
<br><br><b><small>Parameters</small></b><br><br><samp>&nbsp;gpio_on:=&nbsp;the&nbsp;GPIO&nbsp;to&nbsp;switch&nbsp;on&nbsp;at&nbsp;the&nbsp;start&nbsp;of&nbsp;the&nbsp;pulse.<br>gpio_off:=&nbsp;the&nbsp;GPIO&nbsp;to&nbsp;switch&nbsp;off&nbsp;at&nbsp;the&nbsp;start&nbsp;of&nbsp;the&nbsp;pulse.<br>&nbsp;&nbsp;&nbsp;delay:=&nbsp;the&nbsp;delay&nbsp;in&nbsp;microseconds&nbsp;before&nbsp;the&nbsp;next&nbsp;pulse.<br></samp><h2>FUNCTIONS</h2><h3><a name="pigpio.error_text">pigpio.error_text<small>(<a href="#errnum">errnum</a>)</small></h3>
Returns a text description of a pigpio error.
<br><br><b><small>Parameters</small></b><br><br><samp>errnum:=&nbsp;&lt;0,&nbsp;the&nbsp;error&nbsp;number<br></samp><br><br><b><small>Example</small></b><br><br><code>print(pigpio.error_text(-5))<br>level&nbsp;not&nbsp;0-1<br></code><h3><a name="pigpio.tickDiff">pigpio.tickDiff<small>(<a href="#t1">t1</a>, <a href="#t2">t2</a>)</small></h3>
Returns the microsecond difference between two ticks.
<br><br><b><small>Parameters</small></b><br><br><samp>t1:=&nbsp;the&nbsp;earlier&nbsp;tick<br>t2:=&nbsp;the&nbsp;later&nbsp;tick<br></samp><br><br><b><small>Example</small></b><br><br><code>print(pigpio.tickDiff(4294967272,&nbsp;12))<br>36<br></code><h3><a name="pigpio.u2i">pigpio.u2i<small>(<a href="#uint32">uint32</a>)</small></h3>
Converts a 32 bit unsigned number to signed.
<br><br><b><small>Parameters</small></b><br><br><samp>uint32:=&nbsp;an&nbsp;unsigned&nbsp;32&nbsp;bit&nbsp;number<br></samp><br><br><b><small>Example</small></b><br><br><code>print(u2i(4294967272))<br>-24<br>print(u2i(37))<br>37<br></code><h2>PARAMETERS</h2><h3><a name="active"></a>active: 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"></a>arg1: </h3>An unsigned argument passed to a user customised function.  Its
meaning is defined by the customiser.
<h3><a name="arg2"></a>arg2: </h3>An unsigned argument passed to a user customised function.  Its
meaning is defined by the customiser.
<h3><a name="argx"></a>argx: </h3>An array of bytes passed to a user customised function.
Its meaning and content is defined by the customiser.
<h3><a name="baud"></a>baud: </h3>The speed of serial communication (I2C, SPI, serial link, waves)
in bits per second.
<h3><a name="bb_bits"></a>bb_bits: 1-32</h3>The number of data bits to be used when adding serial data to a
waveform.
<h3><a name="bb_stop"></a>bb_stop: 2-8</h3>The number of (half) stop bits to be used when adding serial data
to a waveform.
<h3><a name="bit"></a>bit: 0-1</h3>A value of 0 or 1.
<h3><a name="bits"></a>bits: 32 bit number</h3>A mask used to select GPIO to be operated on.  If bit n is set
then GPIO n is selected.  A convenient way of setting bit n is to
bit or in the value (1&lt;&lt;n).
<br><br>To select GPIO 1, 7, 23
<br><br>bits = (1&lt;&lt;1) | (1&lt;&lt;7) | (1&lt;&lt;23)
<h3><a name="bsc_control"></a>bsc_control: </h3><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>aaaaaaa defines the I2C slave address (only relevant in I2C mode)
<br><br>Bits 0-13 are copied unchanged to the BSC CR register.  See
pages 163-165 of the Broadcom peripherals document.
<h3><a name="byte_val"></a>byte_val: 0-255</h3>A whole number.
<h3><a name="clkfreq"></a>clkfreq: 4689-250M (13184-375M for the BCM2711)</h3>The hardware clock frequency.
<h3><a name="connected"></a>connected: </h3>True if a connection was established, False otherwise.
<h3><a name="count"></a>count: </h3>The number of bytes of data to be transferred.
<h3><a name="CS"></a>CS: </h3>The GPIO used for the slave select signal when bit banging SPI.
<h3><a name="data"></a>data: </h3>Data to be transmitted, a series of bytes.
<h3><a name="delay"></a>delay: &gt;=1</h3>The length of a pulse in microseconds.
<h3><a name="dutycycle"></a>dutycycle: 0-range_</h3>A number between 0 and range_.
<br><br>The dutycycle sets the proportion of time on versus time off during each
PWM cycle.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Dutycycle</td><td>On time</td></tr><tr><td>0</td><td>Off</td></tr><tr><td>range_ * 0.25</td><td>25% On</td></tr><tr><td>range_ * 0.50</td><td>50% On</td></tr><tr><td>range_ * 0.75</td><td>75% On</td></tr><tr><td>range_</td><td>Fully On</td></tr></tbody></table><h3><a name="edge"></a>edge: 0-2</h3><code>EITHER_EDGE&nbsp;=&nbsp;2<br>FALLING_EDGE&nbsp;=&nbsp;1<br>RISING_EDGE&nbsp;=&nbsp;0<br></code><h3><a name="errnum"></a>errnum: &lt;0</h3><code>PI_BAD_USER_GPIO&nbsp;=&nbsp;-2<br>PI_BAD_GPIO&nbsp;=&nbsp;-3<br>PI_BAD_MODE&nbsp;=&nbsp;-4<br>PI_BAD_LEVEL&nbsp;=&nbsp;-5<br>PI_BAD_PUD&nbsp;=&nbsp;-6<br>PI_BAD_PULSEWIDTH&nbsp;=&nbsp;-7<br>PI_BAD_DUTYCYCLE&nbsp;=&nbsp;-8<br>PI_BAD_WDOG_TIMEOUT&nbsp;=&nbsp;-15<br>PI_BAD_DUTYRANGE&nbsp;=&nbsp;-21<br>PI_NO_HANDLE&nbsp;=&nbsp;-24<br>PI_BAD_HANDLE&nbsp;=&nbsp;-25<br>PI_BAD_WAVE_BAUD&nbsp;=&nbsp;-35<br>PI_TOO_MANY_PULSES&nbsp;=&nbsp;-36<br>PI_TOO_MANY_CHARS&nbsp;=&nbsp;-37<br>PI_NOT_SERIAL_GPIO&nbsp;=&nbsp;-38<br>PI_NOT_PERMITTED&nbsp;=&nbsp;-41<br>PI_SOME_PERMITTED&nbsp;=&nbsp;-42<br>PI_BAD_WVSC_COMMND&nbsp;=&nbsp;-43<br>PI_BAD_WVSM_COMMND&nbsp;=&nbsp;-44<br>PI_BAD_WVSP_COMMND&nbsp;=&nbsp;-45<br>PI_BAD_PULSELEN&nbsp;=&nbsp;-46<br>PI_BAD_SCRIPT&nbsp;=&nbsp;-47<br>PI_BAD_SCRIPT_ID&nbsp;=&nbsp;-48<br>PI_BAD_SER_OFFSET&nbsp;=&nbsp;-49<br>PI_GPIO_IN_USE&nbsp;=&nbsp;-50<br>PI_BAD_SERIAL_COUNT&nbsp;=&nbsp;-51<br>PI_BAD_PARAM_NUM&nbsp;=&nbsp;-52<br>PI_DUP_TAG&nbsp;=&nbsp;-53<br>PI_TOO_MANY_TAGS&nbsp;=&nbsp;-54<br>PI_BAD_SCRIPT_CMD&nbsp;=&nbsp;-55<br>PI_BAD_VAR_NUM&nbsp;=&nbsp;-56<br>PI_NO_SCRIPT_ROOM&nbsp;=&nbsp;-57<br>PI_NO_MEMORY&nbsp;=&nbsp;-58<br>PI_SOCK_READ_FAILED&nbsp;=&nbsp;-59<br>PI_SOCK_WRIT_FAILED&nbsp;=&nbsp;-60<br>PI_TOO_MANY_PARAM&nbsp;=&nbsp;-61<br>PI_SCRIPT_NOT_READY&nbsp;=&nbsp;-62<br>PI_BAD_TAG&nbsp;=&nbsp;-63<br>PI_BAD_MICS_DELAY&nbsp;=&nbsp;-64<br>PI_BAD_MILS_DELAY&nbsp;=&nbsp;-65<br>PI_BAD_WAVE_ID&nbsp;=&nbsp;-66<br>PI_TOO_MANY_CBS&nbsp;=&nbsp;-67<br>PI_TOO_MANY_OOL&nbsp;=&nbsp;-68<br>PI_EMPTY_WAVEFORM&nbsp;=&nbsp;-69<br>PI_NO_WAVEFORM_ID&nbsp;=&nbsp;-70<br>PI_I2C_OPEN_FAILED&nbsp;=&nbsp;-71<br>PI_SER_OPEN_FAILED&nbsp;=&nbsp;-72<br>PI_SPI_OPEN_FAILED&nbsp;=&nbsp;-73<br>PI_BAD_I2C_BUS&nbsp;=&nbsp;-74<br>PI_BAD_I2C_ADDR&nbsp;=&nbsp;-75<br>PI_BAD_SPI_CHANNEL&nbsp;=&nbsp;-76<br>PI_BAD_FLAGS&nbsp;=&nbsp;-77<br>PI_BAD_SPI_SPEED&nbsp;=&nbsp;-78<br>PI_BAD_SER_DEVICE&nbsp;=&nbsp;-79<br>PI_BAD_SER_SPEED&nbsp;=&nbsp;-80<br>PI_BAD_PARAM&nbsp;=&nbsp;-81<br>PI_I2C_WRITE_FAILED&nbsp;=&nbsp;-82<br>PI_I2C_READ_FAILED&nbsp;=&nbsp;-83<br>PI_BAD_SPI_COUNT&nbsp;=&nbsp;-84<br>PI_SER_WRITE_FAILED&nbsp;=&nbsp;-85<br>PI_SER_READ_FAILED&nbsp;=&nbsp;-86<br>PI_SER_READ_NO_DATA&nbsp;=&nbsp;-87<br>PI_UNKNOWN_COMMAND&nbsp;=&nbsp;-88<br>PI_SPI_XFER_FAILED&nbsp;=&nbsp;-89<br>PI_NO_AUX_SPI&nbsp;=&nbsp;-91<br>PI_NOT_PWM_GPIO&nbsp;=&nbsp;-92<br>PI_NOT_SERVO_GPIO&nbsp;=&nbsp;-93<br>PI_NOT_HCLK_GPIO&nbsp;=&nbsp;-94<br>PI_NOT_HPWM_GPIO&nbsp;=&nbsp;-95<br>PI_BAD_HPWM_FREQ&nbsp;=&nbsp;-96<br>PI_BAD_HPWM_DUTY&nbsp;=&nbsp;-97<br>PI_BAD_HCLK_FREQ&nbsp;=&nbsp;-98<br>PI_BAD_HCLK_PASS&nbsp;=&nbsp;-99<br>PI_HPWM_ILLEGAL&nbsp;=&nbsp;-100<br>PI_BAD_DATABITS&nbsp;=&nbsp;-101<br>PI_BAD_STOPBITS&nbsp;=&nbsp;-102<br>PI_MSG_TOOBIG&nbsp;=&nbsp;-103<br>PI_BAD_MALLOC_MODE&nbsp;=&nbsp;-104<br>PI_BAD_SMBUS_CMD&nbsp;=&nbsp;-107<br>PI_NOT_I2C_GPIO&nbsp;=&nbsp;-108<br>PI_BAD_I2C_WLEN&nbsp;=&nbsp;-109<br>PI_BAD_I2C_RLEN&nbsp;=&nbsp;-110<br>PI_BAD_I2C_CMD&nbsp;=&nbsp;-111<br>PI_BAD_I2C_BAUD&nbsp;=&nbsp;-112<br>PI_CHAIN_LOOP_CNT&nbsp;=&nbsp;-113<br>PI_BAD_CHAIN_LOOP&nbsp;=&nbsp;-114<br>PI_CHAIN_COUNTER&nbsp;=&nbsp;-115<br>PI_BAD_CHAIN_CMD&nbsp;=&nbsp;-116<br>PI_BAD_CHAIN_DELAY&nbsp;=&nbsp;-117<br>PI_CHAIN_NESTING&nbsp;=&nbsp;-118<br>PI_CHAIN_TOO_BIG&nbsp;=&nbsp;-119<br>PI_DEPRECATED&nbsp;=&nbsp;-120<br>PI_BAD_SER_INVERT&nbsp;=&nbsp;-121<br>PI_BAD_FOREVER&nbsp;=&nbsp;-124<br>PI_BAD_FILTER&nbsp;=&nbsp;-125<br>PI_BAD_PAD&nbsp;=&nbsp;-126<br>PI_BAD_STRENGTH&nbsp;=&nbsp;-127<br>PI_FIL_OPEN_FAILED&nbsp;=&nbsp;-128<br>PI_BAD_FILE_MODE&nbsp;=&nbsp;-129<br>PI_BAD_FILE_FLAG&nbsp;=&nbsp;-130<br>PI_BAD_FILE_READ&nbsp;=&nbsp;-131<br>PI_BAD_FILE_WRITE&nbsp;=&nbsp;-132<br>PI_FILE_NOT_ROPEN&nbsp;=&nbsp;-133<br>PI_FILE_NOT_WOPEN&nbsp;=&nbsp;-134<br>PI_BAD_FILE_SEEK&nbsp;=&nbsp;-135<br>PI_NO_FILE_MATCH&nbsp;=&nbsp;-136<br>PI_NO_FILE_ACCESS&nbsp;=&nbsp;-137<br>PI_FILE_IS_A_DIR&nbsp;=&nbsp;-138<br>PI_BAD_SHELL_STATUS&nbsp;=&nbsp;-139<br>PI_BAD_SCRIPT_NAME&nbsp;=&nbsp;-140<br>PI_BAD_SPI_BAUD&nbsp;=&nbsp;-141<br>PI_NOT_SPI_GPIO&nbsp;=&nbsp;-142<br>PI_BAD_EVENT_ID&nbsp;=&nbsp;-143<br>PI_CMD_INTERRUPTED&nbsp;=&nbsp;-144<br>PI_NOT_ON_BCM2711&nbsp;&nbsp;&nbsp;=&nbsp;-145<br>PI_ONLY_ON_BCM2711&nbsp;&nbsp;=&nbsp;-146<br></code><h3><a name="event"></a>event: 0-31</h3>An event is a signal used to inform one or more consumers
to start an action.
<h3><a name="file_mode"></a>file_mode: </h3>The mode may have the following values
<br><br><code>FILE_READ&nbsp;&nbsp;&nbsp;1<br>FILE_WRITE&nbsp;&nbsp;2<br>FILE_RW&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3<br></code><br><br>The following values can be or'd into the file open mode
<br><br><code>FILE_APPEND&nbsp;4<br>FILE_CREATE&nbsp;8<br>FILE_TRUNC&nbsp;&nbsp;16<br></code><h3><a name="file_name"></a>file_name: </h3>A full file path.  To be accessible the path must match
an entry in /opt/pigpio/access.
<h3><a name="fpattern"></a>fpattern: </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"></a>frequency: 0-40000</h3>Defines the frequency to be used for PWM on a GPIO.
The closest permitted frequency will be used.
<h3><a name="func"></a>func: </h3>A user supplied callback function.
<h3><a name="gpio"></a>gpio: 0-53</h3>A Broadcom numbered GPIO.  All the user GPIO are in the range 0-31.
<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="#get_hardware_revision">get_hardware_revision</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="gpio_off"></a>gpio_off: </h3>A mask used to select GPIO to be operated on.  See <a href="#bits">bits</a>.
<br><br>This mask selects the GPIO to be switched off at the start
of a pulse.
<h3><a name="gpio_on"></a>gpio_on: </h3>A mask used to select GPIO to be operated on.  See <a href="#bits">bits</a>.
<br><br>This mask selects the GPIO to be switched on at the start
of a pulse.
<h3><a name="handle"></a>handle: &gt;=0</h3>A number referencing an object opened by one of the following
<br><br><a href="#file_open">file_open</a>
<a href="#i2c_open">i2c_open</a>
<a href="#notify_open">notify_open</a>
<a href="#serial_open">serial_open</a>
<a href="#spi_open">spi_open</a>
<h3><a name="host"></a>host: </h3>The name or IP address of the Pi running the pigpio daemon.
<h3><a name="i2c_address"></a>i2c_address: 0-0x7F</h3>The address of a device on the I2C bus.
<h3><a name="i2c_bus"></a>i2c_bus: &gt;=0</h3>An I2C bus number.
<h3><a name="i2c_flags"></a>i2c_flags: 0</h3>No I2C flags are currently defined.
<h3><a name="invert"></a>invert: 0-1</h3>A flag used to set normal or inverted bit bang serial data
level logic.
<h3><a name="level"></a>level: 0-1 (2)</h3><code>CLEAR&nbsp;=&nbsp;0<br>HIGH&nbsp;=&nbsp;1<br>LOW&nbsp;=&nbsp;0<br>OFF&nbsp;=&nbsp;0<br>ON&nbsp;=&nbsp;1<br>SET&nbsp;=&nbsp;1<br>TIMEOUT&nbsp;=&nbsp;2&nbsp;#&nbsp;only&nbsp;returned&nbsp;for&nbsp;a&nbsp;watchdog&nbsp;timeout<br></code><h3><a name="MISO"></a>MISO: </h3>The GPIO used for the MISO signal when bit banging SPI.
<h3><a name="mode"></a>mode: </h3>1.The operational mode of a GPIO, normally INPUT or OUTPUT.
<br><br><code>ALT0&nbsp;=&nbsp;4<br>ALT1&nbsp;=&nbsp;5<br>ALT2&nbsp;=&nbsp;6<br>ALT3&nbsp;=&nbsp;7<br>ALT4&nbsp;=&nbsp;3<br>ALT5&nbsp;=&nbsp;2<br>INPUT&nbsp;=&nbsp;0<br>OUTPUT&nbsp;=&nbsp;1<br></code><br><br>2. The mode of waveform transmission.
<br><br><code>WAVE_MODE_ONE_SHOT&nbsp;=&nbsp;0<br>WAVE_MODE_REPEAT&nbsp;=&nbsp;1<br>WAVE_MODE_ONE_SHOT_SYNC&nbsp;=&nbsp;2<br>WAVE_MODE_REPEAT_SYNC&nbsp;=&nbsp;3<br></code><h3><a name="MOSI"></a>MOSI: </h3>The GPIO used for the MOSI signal when bit banging SPI.
<h3><a name="offset"></a>offset: &gt;=0</h3>The offset wave data starts from the beginning of the waveform
being currently defined.
<h3><a name="pad"></a>pad: 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="pad_strength"></a>pad_strength: 1-16</h3>The mA which may be drawn from each GPIO whilst still guaranteeing the
high and low levels.
<h3><a name="params"></a>params: 32 bit number</h3>When scripts are started they can receive up to 10 parameters
to define their operation.
<h3><a name="percent"></a>percent: : 0-100</h3>The size of waveform as percentage of maximum available.
<h3><a name="port"></a>port: </h3>The port used by the pigpio daemon, defaults to 8888.
<h3><a name="pstring"></a>pstring: </h3>The string to be passed to a <a href="#shell">shell</a> script to be executed.
<h3><a name="pud"></a>pud: 0-2</h3><code>PUD_DOWN&nbsp;=&nbsp;1<br>PUD_OFF&nbsp;=&nbsp;0<br>PUD_UP&nbsp;=&nbsp;2<br></code><h3><a name="pulse_len"></a>pulse_len: 1-100</h3>The length of the trigger pulse in microseconds.
<h3><a name="pulses"></a>pulses: </h3>A list of class pulse objects defining the characteristics of a
waveform.
<h3><a name="pulsewidth"></a>pulsewidth: </h3>The servo pulsewidth in microseconds.  0 switches pulses off.
<h3><a name="PWMduty"></a>PWMduty: 0-1000000 (1M)</h3>The hardware PWM dutycycle.
<h3><a name="PWMfreq"></a>PWMfreq: 1-125M (1-187.5M for the BCM2711)</h3>The hardware PWM frequency.
<h3><a name="range_"></a>range_: 25-40000</h3>Defines the limits for the <a href="#dutycycle">dutycycle</a> parameter.
<br><br>range_ defaults to 255.
<h3><a name="reg"></a>reg: 0-255</h3>An I2C device register.  The usable registers depend on the
actual device.
<h3><a name="retMax"></a>retMax: &gt;=0</h3>The maximum number of bytes a user customised function
should return, default 8192.
<h3><a name="SCL"></a>SCL: </h3>The user GPIO to use for the clock when bit banging I2C.
<h3><a name="SCLK"></a>SCLK: :</h3>The GPIO used for the SCLK signal when bit banging SPI.
<h3><a name="script"></a>script: </h3>The text of a script to store on the pigpio daemon.
<h3><a name="script_id"></a>script_id: &gt;=0</h3>A number referencing a script created by <a href="#store_script">store_script</a>.
<h3><a name="SDA"></a>SDA: </h3>The user GPIO to use for data when bit banging I2C.
<h3><a name="seek_from"></a>seek_from: 0-2</h3>Direction to seek for <a href="#file_seek">file_seek</a>.
<br><br><code>FROM_START=0<br>FROM_CURRENT=1<br>FROM_END=2<br></code><h3><a name="seek_offset"></a>seek_offset: </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="ser_flags"></a>ser_flags: 32 bit</h3>No serial flags are currently defined.
<h3><a name="serial_*"></a>serial_*: </h3>One of the serial_ functions.
<h3><a name="shellscr"></a>shellscr: </h3>The name of a shell script.  The script must exist
in /opt/pigpio/cgi and must be executable.
<h3><a name="show_errors"></a>show_errors: </h3>Controls the display of pigpio daemon connection failures.
The default of True prints the probable failure reasons to
standard output.
<h3><a name="spi_channel"></a>spi_channel: 0-2</h3>A SPI channel.
<h3><a name="spi_flags"></a>spi_flags: 32 bit</h3>See <a href="#spi_open">spi_open</a>.
<h3><a name="steady"></a>steady: 0-300000</h3>The number of microseconds level changes must be stable for
before reporting the level changed (<a href="#set_glitch_filter">set_glitch_filter</a>)
or triggering the active part of a noise filter
(<a href="#set_noise_filter">set_noise_filter</a>).
<h3><a name="t1"></a>t1: </h3>A tick (earlier).
<h3><a name="t2"></a>t2: </h3>A tick (later).
<h3><a name="tty"></a>tty: </h3>A Pi serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0
<h3><a name="uint32"></a>uint32: </h3>An unsigned 32 bit number.
<h3><a name="user_gpio"></a>user_gpio: 0-31</h3>A Broadcom numbered GPIO.
<br><br>All the user GPIO are in the range 0-31.
<br><br>Not all the GPIO within this range are usable, some are reserved
for system use.
<br><br>See <a href="#gpio">gpio</a>.
<h3><a name="wait_timeout"></a>wait_timeout: 0.0 -</h3>The number of seconds to wait in <a href="#wait_for_edge">wait_for_edge</a> before timing out.
<h3><a name="wave_add_*"></a>wave_add_*: </h3>One of the following
<br><br><a href="#wave_add_new">wave_add_new</a>
<a href="#wave_add_generic">wave_add_generic</a>
<a href="#wave_add_serial">wave_add_serial</a>
<h3><a name="wave_id"></a>wave_id: &gt;=0</h3>A number referencing a wave created by <a href="#wave_create">wave_create</a>.
<h3><a name="wave_send_*"></a>wave_send_*: </h3>One of the following
<br><br><a href="#wave_send_once">wave_send_once</a>
<a href="#wave_send_repeat">wave_send_repeat</a>
<h3><a name="wdog_timeout"></a>wdog_timeout: 0-60000</h3>Defines a GPIO watchdog timeout in milliseconds.  If no level
change is detected on the GPIO for timeout millisecond a watchdog
timeout report is issued (with level TIMEOUT).
<h3><a name="word_val"></a>word_val: 0-65535</h3>A whole number.
<br><br>


file_name: misc
menu_title: Misc
page_title: Miscellaneous
pic1: msp430.jpg
pic2: motor.jpg
pic3: leds.jpg
body:
There are two C libraries which provide a socket interface to the
pigpio daemon.&nbsp; They provide an interface very similar to the
pigpio Python module.<br>
<ul>
<li>The original <a href="./pdif.html">pigpiod_if</a> library is
now deprecated and will no longer be updated.&nbsp; This library is
limited to controlling one Pi at a time.</li>
</ul>
<ul>
<li>The new <a href="./pdif2.html">pigpiod_if2</a> library which
should be used for new code.&nbsp; This library allows multiple Pis
to be controlled at one time.</li>
</ul>
Additional details of the pigpio <a href="./sif.html">socket</a>
interface.<br>
<br>
Additional details of the pigpio <a href="./pif.html">pipe</a>
interface.<br>
<br>
<a href="pig2vcd.html">pig2vcd</a> is a utility which converts
pigpio notifications into the VCD (Value Change Dump) format.&nbsp;
VCD can be read by many programs, in particular <a href=
"http://gtkwave.sourceforge.net/">GTKWave</a>.


file_name: pdif
menu_title: pigpiod_if
page_title: pigpiod_if
pic1: pot.jpg
pic2: rotary.jpg
pic3: psu.jpg
body:
<br><br>THIS LIBRARY IS DEPRECATED.  NEW CODE SHOULD BE WRITTEN TO
USE THE MORE VERSATILE pigpiod_if2 LIBRARY.
<br><br>pigpiod_if is a C library for the Raspberry which allows control
of the GPIO via the socket interface to the pigpio daemon.<br>
<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 on the pigpio daemon
<h3>GPIO</h3>ALL GPIO are identified by their Broadcom number.
<h3>Notes</h3>The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals.
<h3>Usage</h3>Include &lt;pigpiod_if.h&gt; in your source files.
<br><br>Assuming your source is in prog.c use the following command to build
<br><br><code>gcc&nbsp;-Wall&nbsp;-pthread&nbsp;-o&nbsp;prog&nbsp;prog.c&nbsp;-lpigpiod_if&nbsp;-lrt<br></code><br><br>to run make sure the pigpio daemon is running
<br><br><code>sudo&nbsp;pigpiod<br><br>&nbsp;./prog&nbsp;#&nbsp;sudo&nbsp;is&nbsp;not&nbsp;required&nbsp;to&nbsp;run&nbsp;programs&nbsp;linked&nbsp;to&nbsp;pigpiod_if<br></code><br><br>For examples see x_pigpiod_if.c within the pigpio archive file.
<h3>Notes</h3>All the functions which return an int return &lt; 0 on error
<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="#pigpio_start">pigpio_start</a></td><td>              Connects to the pigpio daemon
</td></tr><tr><td><a href="#pigpio_stop">pigpio_stop</a></td><td>               Disconnects from the pigpio daemon
</td></tr><tr><td></td><td></td></tr><tr><td><b>BEGINNER
</b></td><td></td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_mode">set_mode</a></td><td>                  Set a GPIO mode
</td></tr><tr><td><a href="#get_mode">get_mode</a></td><td>                  Get a GPIO mode
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_pull_up_down">set_pull_up_down</a></td><td>          Set/clear GPIO pull up/down resistor
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#gpio_read">gpio_read</a></td><td>                 Read a GPIO
</td></tr><tr><td><a href="#gpio_write">gpio_write</a></td><td>                Write a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_PWM_dutycycle">set_PWM_dutycycle</a></td><td>         Start/stop PWM pulses on a GPIO
</td></tr><tr><td><a href="#get_PWM_dutycycle">get_PWM_dutycycle</a></td><td>         Get the PWM dutycycle in use on a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_servo_pulsewidth">set_servo_pulsewidth</a></td><td>      Start/stop servo pulses on a GPIO
</td></tr><tr><td><a href="#get_servo_pulsewidth">get_servo_pulsewidth</a></td><td>      Get the servo pulsewidth in use on a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#callback">callback</a></td><td>                  Create GPIO level change callback
</td></tr><tr><td><a href="#callback_ex">callback_ex</a></td><td>               Create GPIO level change callback
</td></tr><tr><td><a href="#callback_cancel">callback_cancel</a></td><td>           Cancel a callback
</td></tr><tr><td><a href="#wait_for_edge">wait_for_edge</a></td><td>             Wait for GPIO level change
</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="#gpio_trigger">gpio_trigger</a></td><td>              Send a trigger pulse to a GPIO.
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_watchdog">set_watchdog</a></td><td>              Set a watchdog on a GPIO.
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_PWM_range">set_PWM_range</a></td><td>             Configure PWM range for a GPIO
</td></tr><tr><td><a href="#get_PWM_range">get_PWM_range</a></td><td>             Get configured PWM range for a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_PWM_frequency">set_PWM_frequency</a></td><td>         Configure PWM frequency for a GPIO
</td></tr><tr><td><a href="#get_PWM_frequency">get_PWM_frequency</a></td><td>         Get configured PWM frequency for a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#read_bank_1">read_bank_1</a></td><td>               Read all GPIO in bank 1
</td></tr><tr><td><a href="#read_bank_2">read_bank_2</a></td><td>               Read all GPIO in bank 2
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#clear_bank_1">clear_bank_1</a></td><td>              Clear selected GPIO in bank 1
</td></tr><tr><td><a href="#clear_bank_2">clear_bank_2</a></td><td>              Clear selected GPIO in bank 2
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_bank_1">set_bank_1</a></td><td>                Set selected GPIO in bank 1
</td></tr><tr><td><a href="#set_bank_2">set_bank_2</a></td><td>                Set selected GPIO in bank 2
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#start_thread">start_thread</a></td><td>              Start a new thread
</td></tr><tr><td><a href="#stop_thread">stop_thread</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="#get_PWM_real_range">get_PWM_real_range</a></td><td>        Get underlying PWM range for a GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#notify_open">notify_open</a></td><td>               Request a notification handle
</td></tr><tr><td><a href="#notify_begin">notify_begin</a></td><td>              Start notifications for selected GPIO
</td></tr><tr><td><a href="#notify_pause">notify_pause</a></td><td>              Pause notifications
</td></tr><tr><td><a href="#notify_close">notify_close</a></td><td>              Close a notification
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#bb_serial_read_open">bb_serial_read_open</a></td><td>       Opens a GPIO for bit bang serial reads
</td></tr><tr><td><a href="#bb_serial_read">bb_serial_read</a></td><td>            Reads bit bang serial data from a GPIO
</td></tr><tr><td><a href="#bb_serial_read_close">bb_serial_read_close</a></td><td>      Closes a GPIO for bit bang serial reads
</td></tr><tr><td><a href="#bb_serial_invert">bb_serial_invert</a></td><td>          Invert serial logic (1 invert, 0 normal)
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#hardware_clock">hardware_clock</a></td><td>            Start hardware clock on supported GPIO
</td></tr><tr><td><a href="#hardware_PWM">hardware_PWM</a></td><td>              Start hardware PWM on supported GPIO
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#set_glitch_filter">set_glitch_filter</a></td><td>        Set a glitch filter on a GPIO
</td></tr><tr><td><a href="#set_noise_filter">set_noise_filter</a></td><td>         Set a noise filter on a GPIO
</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="#store_script">store_script</a></td><td>              Store a script
</td></tr><tr><td><a href="#run_script">run_script</a></td><td>                Run a stored script
</td></tr><tr><td><a href="#script_status">script_status</a></td><td>             Get script status and parameters
</td></tr><tr><td><a href="#stop_script">stop_script</a></td><td>               Stop a running script
</td></tr><tr><td><a href="#delete_script">delete_script</a></td><td>             Delete a stored script
</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="#wave_clear">wave_clear</a></td><td>                Deletes all waveforms
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_add_new">wave_add_new</a></td><td>              Starts a new waveform
</td></tr><tr><td><a href="#wave_add_generic">wave_add_generic</a></td><td>          Adds a series of pulses to the waveform
</td></tr><tr><td><a href="#wave_add_serial">wave_add_serial</a></td><td>           Adds serial data to the waveform
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_create">wave_create</a></td><td>               Creates a waveform from added data
</td></tr><tr><td><a href="#wave_delete">wave_delete</a></td><td>               Deletes one or more waveforms
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_send_once">wave_send_once</a></td><td>            Transmits a waveform once
</td></tr><tr><td><a href="#wave_send_repeat">wave_send_repeat</a></td><td>          Transmits a waveform repeatedly
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_chain">wave_chain</a></td><td>                Transmits a chain of waveforms
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_tx_busy">wave_tx_busy</a></td><td>              Checks to see if the waveform has ended
</td></tr><tr><td><a href="#wave_tx_stop">wave_tx_stop</a></td><td>              Aborts the current waveform
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_get_micros">wave_get_micros</a></td><td>           Length in microseconds of the current waveform
</td></tr><tr><td><a href="#wave_get_high_micros">wave_get_high_micros</a></td><td>      Length of longest waveform so far
</td></tr><tr><td><a href="#wave_get_max_micros">wave_get_max_micros</a></td><td>       Absolute maximum allowed micros
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_get_pulses">wave_get_pulses</a></td><td>           Length in pulses of the current waveform
</td></tr><tr><td><a href="#wave_get_high_pulses">wave_get_high_pulses</a></td><td>      Length of longest waveform so far
</td></tr><tr><td><a href="#wave_get_max_pulses">wave_get_max_pulses</a></td><td>       Absolute maximum allowed pulses
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#wave_get_cbs">wave_get_cbs</a></td><td>              Length in cbs of the current waveform
</td></tr><tr><td><a href="#wave_get_high_cbs">wave_get_high_cbs</a></td><td>         Length of longest waveform so far
</td></tr><tr><td><a href="#wave_get_max_cbs">wave_get_max_cbs</a></td><td>          Absolute maximum allowed cbs
</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="#i2c_open">i2c_open</a></td><td>                  Opens an I2C device
</td></tr><tr><td><a href="#i2c_close">i2c_close</a></td><td>                 Closes an I2C device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_write_quick">i2c_write_quick</a></td><td>           smbus write quick
</td></tr><tr><td><a href="#i2c_write_byte">i2c_write_byte</a></td><td>            smbus write byte
</td></tr><tr><td><a href="#i2c_read_byte">i2c_read_byte</a></td><td>             smbus read byte
</td></tr><tr><td><a href="#i2c_write_byte_data">i2c_write_byte_data</a></td><td>       smbus write byte data
</td></tr><tr><td><a href="#i2c_write_word_data">i2c_write_word_data</a></td><td>       smbus write word data
</td></tr><tr><td><a href="#i2c_read_byte_data">i2c_read_byte_data</a></td><td>        smbus read byte data
</td></tr><tr><td><a href="#i2c_read_word_data">i2c_read_word_data</a></td><td>        smbus read word data
</td></tr><tr><td><a href="#i2c_process_call">i2c_process_call</a></td><td>          smbus process call
</td></tr><tr><td><a href="#i2c_write_block_data">i2c_write_block_data</a></td><td>      smbus write block data
</td></tr><tr><td><a href="#i2c_read_block_data">i2c_read_block_data</a></td><td>       smbus read block data
</td></tr><tr><td><a href="#i2c_block_process_call">i2c_block_process_call</a></td><td>    smbus block process call
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_write_i2c_block_data">i2c_write_i2c_block_data</a></td><td>  smbus write I2C block data
</td></tr><tr><td><a href="#i2c_read_i2c_block_data">i2c_read_i2c_block_data</a></td><td>   smbus read I2C block data
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_read_device">i2c_read_device</a></td><td>           Reads the raw I2C device
</td></tr><tr><td><a href="#i2c_write_device">i2c_write_device</a></td><td>          Writes the raw I2C device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#i2c_zip">i2c_zip</a></td><td>                   Performs multiple I2C transactions
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#bb_i2c_open">bb_i2c_open</a></td><td>               Opens GPIO for bit banging I2C
</td></tr><tr><td><a href="#bb_i2c_close">bb_i2c_close</a></td><td>              Closes GPIO for bit banging I2C
</td></tr><tr><td><a href="#bb_i2c_zip">bb_i2c_zip</a></td><td>                Performs multiple bit banged I2C transactions
</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="#spi_open">spi_open</a></td><td>                  Opens a SPI device
</td></tr><tr><td><a href="#spi_close">spi_close</a></td><td>                 Closes a SPI device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#spi_read">spi_read</a></td><td>                  Reads bytes from a SPI device
</td></tr><tr><td><a href="#spi_write">spi_write</a></td><td>                 Writes bytes to a SPI device
</td></tr><tr><td><a href="#spi_xfer">spi_xfer</a></td><td>                  Transfers bytes with a SPI device
</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="#serial_open">serial_open</a></td><td>               Opens a serial device
</td></tr><tr><td><a href="#serial_close">serial_close</a></td><td>              Closes a serial device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#serial_write_byte">serial_write_byte</a></td><td>         Writes a byte to a serial device
</td></tr><tr><td><a href="#serial_read_byte">serial_read_byte</a></td><td>          Reads a byte from a serial device
</td></tr><tr><td><a href="#serial_write">serial_write</a></td><td>              Writes bytes to a serial device
</td></tr><tr><td><a href="#serial_read">serial_read</a></td><td>               Reads bytes from a serial device
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#serial_data_available">serial_data_available</a></td><td>     Returns number of bytes ready to be read
</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="#custom_1">custom_1</a></td><td>                  User custom function 1
</td></tr><tr><td><a href="#custom_2">custom_2</a></td><td>                  User custom function 2
</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="#get_current_tick">get_current_tick</a></td><td>          Get current tick (microseconds)
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#get_hardware_revision">get_hardware_revision</a></td><td>     Get hardware revision
</td></tr><tr><td><a href="#get_pigpio_version">get_pigpio_version</a></td><td>        Get the pigpio version
</td></tr><tr><td><a href="#pigpiod_if_version">pigpiod_if_version</a></td><td>        Get the pigpiod_if version
</td></tr><tr><td></td><td></td></tr><tr><td><a href="#pigpio_error">pigpio_error</a></td><td>              Get a text description of an error code.
</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></tbody></table><h2>FUNCTIONS</h2><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;delay.<br></code><h3><a name="pigpio_error"></a><a href="#char"><small>char</small></a> *pigpio_error<small>(<a href="#int">int</a> <a href="#errnum">errnum</a>)</small></h3>
Return a text description for an error code.
<br><br><code>errnum:&nbsp;the&nbsp;error&nbsp;code.<br></code><h3><a name="pigpiod_if_version"></a><a href="#unsigned"><small>unsigned</small></a> pigpiod_if_version<small>(void)</small></h3>
Return the pigpiod_if version.
<h3><a name="start_thread"></a><a href="#pthread_t"><small>pthread_t</small></a> *start_thread<small>(<a href="#gpioThreadFunc_t">gpioThreadFunc_t</a> <a href="#thread_func">thread_func</a>, <a href="#void">void</a> <a href="#*userdata">*userdata</a>)</small></h3>
Starts a new thread of execution with thread_func as the main routine.
<br><br><code>thread_func:&nbsp;the&nbsp;main&nbsp;function&nbsp;for&nbsp;the&nbsp;new&nbsp;thread.<br>&nbsp;&nbsp;&nbsp;userdata:&nbsp;a&nbsp;pointer&nbsp;to&nbsp;an&nbsp;arbitrary&nbsp;argument.<br></code><br><br>Returns a pointer to pthread_t if OK, otherwise NULL.
<br><br>The function is passed the single argument userdata.
<br><br>The thread can be cancelled by passing the pointer to pthread_t to
<a href="#stop_thread">stop_thread</a>.
<h3><a name="stop_thread"></a><a href="#void"><small>void</small></a> stop_thread<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;the&nbsp;thread&nbsp;to&nbsp;be&nbsp;stopped.<br></code><br><br>No value is returned.
<br><br>The thread to be stopped should have been started with <a href="#start_thread">start_thread</a>.
<h3><a name="pigpio_start"></a><a href="#int"><small>int</small></a> pigpio_start<small>(<a href="#char">char</a> <a href="#*addrStr">*addrStr</a>, <a href="#char">char</a> <a href="#*portStr">*portStr</a>)</small></h3>
Connect to the pigpio daemon.  Reserving command and
notification streams.
<br><br><code>addrStr:&nbsp;specifies&nbsp;the&nbsp;host&nbsp;or&nbsp;IP&nbsp;address&nbsp;of&nbsp;the&nbsp;Pi&nbsp;running&nbsp;the<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pigpio&nbsp;daemon.&nbsp;&nbsp;It&nbsp;may&nbsp;be&nbsp;NULL&nbsp;in&nbsp;which&nbsp;case&nbsp;localhost<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is&nbsp;used&nbsp;unless&nbsp;overridden&nbsp;by&nbsp;the&nbsp;PIGPIO_ADDR&nbsp;environment<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;variable.<br><br>portStr:&nbsp;specifies&nbsp;the&nbsp;port&nbsp;address&nbsp;used&nbsp;by&nbsp;the&nbsp;Pi&nbsp;running&nbsp;the<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pigpio&nbsp;daemon.&nbsp;&nbsp;It&nbsp;may&nbsp;be&nbsp;NULL&nbsp;in&nbsp;which&nbsp;case&nbsp;"8888"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is&nbsp;used&nbsp;unless&nbsp;overridden&nbsp;by&nbsp;the&nbsp;PIGPIO_PORT&nbsp;environment<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;variable.<br></code><h3><a name="pigpio_stop"></a><a href="#void"><small>void</small></a> pigpio_stop<small>(void)</small></h3>
Terminates the connection to the pigpio daemon and releases
resources used by the library.
<h3><a name="set_mode"></a><a href="#int"><small>int</small></a> set_mode<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>, <a href="#unsigned">unsigned</a> <a href="#mode">mode</a>)</small></h3>
Set the GPIO mode.
<br><br><code>gpio:&nbsp;0-53.<br>mode:&nbsp;PI_INPUT,&nbsp;PI_OUTPUT,&nbsp;PI_ALT0,&nbsp;PI_ALT1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PI_ALT2,&nbsp;PI_ALT3,&nbsp;PI_ALT4,&nbsp;PI_ALT5.<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE,
or PI_NOT_PERMITTED.
<h3><a name="get_mode"></a><a href="#int"><small>int</small></a> get_mode<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>)</small></h3>
Get the GPIO mode.
<br><br><code>gpio:&nbsp;0-53.<br></code><br><br>Returns the GPIO mode if OK, otherwise PI_BAD_GPIO.
<h3><a name="set_pull_up_down"></a><a href="#int"><small>int</small></a> set_pull_up_down<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>, <a href="#unsigned">unsigned</a> <a href="#pud">pud</a>)</small></h3>
Set or clear the GPIO pull-up/down resistor.
<br><br><code>gpio:&nbsp;0-53.<br>&nbsp;pud:&nbsp;PI_PUD_UP,&nbsp;PI_PUD_DOWN,&nbsp;PI_PUD_OFF.<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD,
or PI_NOT_PERMITTED.
<h3><a name="gpio_read"></a><a href="#int"><small>int</small></a> gpio_read<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>)</small></h3>
Read the GPIO level.
<br><br><code>gpio:0-53.<br></code><br><br>Returns the GPIO level if OK, otherwise PI_BAD_GPIO.
<h3><a name="gpio_write"></a><a href="#int"><small>int</small></a> gpio_write<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>, <a href="#unsigned">unsigned</a> <a href="#level">level</a>)</small></h3>
Write the GPIO level.
<br><br><code>&nbsp;gpio:&nbsp;0-53.<br>level:&nbsp;0,&nbsp;1.<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL,
or PI_NOT_PERMITTED.
<br><br>Notes
<br><br>If PWM or servo pulses are active on the GPIO they are switched off.
<h3><a name="set_PWM_dutycycle"></a><a href="#int"><small>int</small></a> set_PWM_dutycycle<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>
Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO.
<br><br><code>user_gpio:&nbsp;0-31.<br>dutycycle:&nbsp;0-range&nbsp;(range&nbsp;defaults&nbsp;to&nbsp;255).<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE,
or PI_NOT_PERMITTED.
Notes
<br><br>The <a href="#set_PWM_range">set_PWM_range</a> function may be used to change the
default range of 255.
<h3><a name="get_PWM_dutycycle"></a><a href="#int"><small>int</small></a> get_PWM_dutycycle<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>)</small></h3>
Return the PWM dutycycle in use on a GPIO.
<br><br><code>user_gpio:&nbsp;0-31.<br></code><br><br>Returns 0 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="#get_PWM_range">get_PWM_range</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).
<h3><a name="set_PWM_range"></a><a href="#int"><small>int</small></a> set_PWM_range<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>
Set the range of PWM values to be used on the GPIO.
<br><br><code>user_gpio:&nbsp;0-31.<br>&nbsp;&nbsp;&nbsp;&nbsp;range:&nbsp;25-40000.<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE,
or PI_NOT_PERMITTED.
<br><br>Notes
<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 of the 18 available GPIO frequencies is
<br><br><code>&nbsp;&nbsp;25(#1),&nbsp;&nbsp;&nbsp;&nbsp;50(#2),&nbsp;&nbsp;&nbsp;100(#3),&nbsp;&nbsp;&nbsp;125(#4),&nbsp;&nbsp;&nbsp;&nbsp;200(#5),&nbsp;&nbsp;&nbsp;&nbsp;250(#6),<br>&nbsp;400(#7),&nbsp;&nbsp;&nbsp;500(#8),&nbsp;&nbsp;&nbsp;625(#9),&nbsp;&nbsp;&nbsp;800(#10),&nbsp;&nbsp;1000(#11),&nbsp;&nbsp;1250(#12),<br>2000(#13),&nbsp;2500(#14),&nbsp;4000(#15),&nbsp;5000(#16),&nbsp;10000(#17),&nbsp;20000(#18)<br></code><br><br>The real value set by set_PWM_range is (dutycycle * real range) / range.
<h3><a name="get_PWM_range"></a><a href="#int"><small>int</small></a> get_PWM_range<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>)</small></h3>
Get the range of PWM values being used on the GPIO.
<br><br><code>user_gpio:&nbsp;0-31.<br></code><br><br>Returns the dutycycle range used for the GPIO if OK,
otherwise PI_BAD_USER_GPIO.
<br><br>If a hardware clock or hardware PWM is active on the GPIO the
reported range will be 1000000 (1M).
<h3><a name="get_PWM_real_range"></a><a href="#int"><small>int</small></a> get_PWM_real_range<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>)</small></h3>
Get the real underlying range of PWM values being used on the GPIO.
<br><br><code>user_gpio:&nbsp;0-31.<br></code><br><br>Returns the real range used for the GPIO if OK,
otherwise PI_BAD_USER_GPIO.
<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.
<h3><a name="set_PWM_frequency"></a><a href="#int"><small>int</small></a> set_PWM_frequency<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>
Set the frequency (in Hz) of the PWM to be used on the GPIO.
<br><br><code>user_gpio:&nbsp;0-31.<br>frequency:&nbsp;&gt;=0&nbsp;(Hz).<br></code><br><br>Returns the numerically closest frequency if OK, otherwise
PI_BAD_USER_GPIO or PI_NOT_PERMITTED.
<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).  The
sample rate is set when the pigpio daemon is started.
<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><h3><a name="get_PWM_frequency"></a><a href="#int"><small>int</small></a> get_PWM_frequency<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>)</small></h3>
Get the frequency of PWM being used on the 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="#set_PWM_frequency">set_PWM_frequency</a>.
<br><br>If a hardware clock is active on the GPIO the reported frequency
will be that set by <a href="#hardware_clock">hardware_clock</a>.
<br><br>If hardware PWM is active on the GPIO the reported frequency
will be that set by <a href="#hardware_PWM">hardware_PWM</a>.
<br><br>Returns the frequency (in hertz) used for the GPIO if OK,
otherwise PI_BAD_USER_GPIO.
<h3><a name="set_servo_pulsewidth"></a><a href="#int"><small>int</small></a> set_servo_pulsewidth<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>
Start (500-2500) or stop (0) servo pulses on the GPIO.
<br><br><code>&nbsp;user_gpio:&nbsp;0-31.<br>pulsewidth:&nbsp;0&nbsp;(off),&nbsp;500&nbsp;(anti-clockwise)&nbsp;-&nbsp;2500&nbsp;(clockwise).<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or
PI_NOT_PERMITTED.
<br><br>The selected pulsewidth will continue to be transmitted until
changed by a subsequent call to set_servo_pulsewidth.
<br><br>The pulsewidths 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.
<br><br>You can DAMAGE a servo if you command it to move beyond its limits.
<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>Update&nbsp;Rate&nbsp;(Hz)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;50&nbsp;&nbsp;&nbsp;100&nbsp;&nbsp;200&nbsp;&nbsp;400&nbsp;&nbsp;500<br>1E6/Hz&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20000&nbsp;10000&nbsp;5000&nbsp;2500&nbsp;2000<br></code><br><br>Firstly set the desired PWM frequency using <a href="#set_PWM_frequency">set_PWM_frequency</a>.
<br><br>Then set the PWM range using <a href="#set_PWM_range">set_PWM_range</a> to 1E6/Hz.
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 GPIO 25 at 400Hz
<br><br><code>set_PWM_frequency(25,&nbsp;400);<br>set_PWM_range(25,&nbsp;2500);<br></code><br><br>Thereafter use the <a href="#set_PWM_dutycycle">set_PWM_dutycycle</a> function to move the servo,
e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.<br>
<h3><a name="get_servo_pulsewidth"></a><a href="#int"><small>int</small></a> get_servo_pulsewidth<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>)</small></h3>
Return the servo pulsewidth in use on a GPIO.
<br><br><code>user_gpio:&nbsp;0-31.<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO.
<h3><a name="notify_open"></a><a href="#int"><small>int</small></a> notify_open<small>(void)</small></h3>
Get 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.
<br><br>Pipes are only accessible from the local machine so this function
serves no purpose if you are using the library from a remote machine.
The in-built (socket) notifications provided by <a href="#callback">callback</a>
should be used instead.
<br><br>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.
<h3><a name="notify_begin"></a><a href="#int"><small>int</small></a> notify_begin<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>
Start notifications on a previously opened handle.
<br><br><code>handle:&nbsp;0-31&nbsp;(as&nbsp;returned&nbsp;by&nbsp;<a href="#notify_open">notify_open</a>)<br>&nbsp;&nbsp;bits:&nbsp;a&nbsp;mask&nbsp;indicating&nbsp;the&nbsp;GPIO&nbsp;to&nbsp;be&nbsp;notified.<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 as follows:
<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.
<br><br>PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags
indicate a GPIO which has had a watchdog timeout.
<br><br>PI_NTFY_FLAGS_ALIVE, if bit 6 is set 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.
<h3><a name="notify_pause"></a><a href="#int"><small>int</small></a> notify_pause<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>)</small></h3>
Pause notifications on a previously opened handle.
<br><br><code>handle:&nbsp;0-31&nbsp;(as&nbsp;returned&nbsp;by&nbsp;<a href="#notify_open">notify_open</a>)<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE.
<br><br>Notifications for the handle are suspended until
<a href="#notify_begin">notify_begin</a> is called again.
<h3><a name="notify_close"></a><a href="#int"><small>int</small></a> notify_close<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>)</small></h3>
Stop notifications on a previously opened handle and
release the handle for reuse.
<br><br><code>handle:&nbsp;0-31&nbsp;(as&nbsp;returned&nbsp;by&nbsp;<a href="#notify_open">notify_open</a>)<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE.
<h3><a name="set_watchdog"></a><a href="#int"><small>int</small></a> set_watchdog<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>Only one watchdog may be registered per GPIO.
<br><br>The watchdog may be cancelled by setting timeout to 0.
<br><br>Once a watchdog has been started callbacks for the GPIO will be
triggered every timeout interval after the last GPIO activity.
<br><br>The callback will receive the special level PI_TIMEOUT.
<h3><a name="set_glitch_filter"></a><a href="#int"><small>int</small></a> set_glitch_filter<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="#callback">callback</a>, <a href="#callback_ex">callback_ex</a> and <a href="#wait_for_edge">wait_for_edge</a>.
<br><br>It does not affect levels read by <a href="#gpio_read">gpio_read</a>,
<a href="#read_bank_1">read_bank_1</a>, or <a href="#read_bank_2">read_bank_2</a>.
Each (stable) edge will be timestamped <a href="#steady">steady</a> microseconds
after it was first detected.
<h3><a name="set_noise_filter"></a><a href="#int"><small>int</small></a> set_noise_filter<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="#callback">callback</a>, <a href="#callback_ex">callback_ex</a> and <a href="#wait_for_edge">wait_for_edge</a>.
<br><br>It does not affect levels read by <a href="#gpio_read">gpio_read</a>,
<a href="#read_bank_1">read_bank_1</a>, or <a href="#read_bank_2">read_bank_2</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="read_bank_1"></a><a href="#uint32_t"><small>uint32_t</small></a> read_bank_1<small>(void)</small></h3>
Read the levels of the bank 1 GPIO (GPIO 0-31).
<br><br>The returned 32 bit integer has a bit set if the corresponding
GPIO is logic 1.  GPIO n has bit value (1&lt;&lt;n).
<h3><a name="read_bank_2"></a><a href="#uint32_t"><small>uint32_t</small></a> read_bank_2<small>(void)</small></h3>
Read the levels of the bank 2 GPIO (GPIO 32-53).
<br><br>The returned 32 bit integer has a bit set if the corresponding
GPIO is logic 1.  GPIO n has bit value (1&lt;&lt;(n-32)).
<h3><a name="clear_bank_1"></a><a href="#int"><small>int</small></a> clear_bank_1<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;with&nbsp;1&nbsp;set&nbsp;if&nbsp;the&nbsp;corresponding&nbsp;GPIO&nbsp;is<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;be&nbsp;cleared.<br></code><br><br>Returns 0 if OK, otherwise PI_SOME_PERMITTED.
<br><br>A status of PI_SOME_PERMITTED indicates that the user is not
allowed to write to one or more of the GPIO.
<h3><a name="clear_bank_2"></a><a href="#int"><small>int</small></a> clear_bank_2<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;with&nbsp;1&nbsp;set&nbsp;if&nbsp;the&nbsp;corresponding&nbsp;GPIO&nbsp;is<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;be&nbsp;cleared.<br></code><br><br>Returns 0 if OK, otherwise PI_SOME_PERMITTED.
<br><br>A status of PI_SOME_PERMITTED indicates that the user is not
allowed to write to one or more of the GPIO.
<h3><a name="set_bank_1"></a><a href="#int"><small>int</small></a> set_bank_1<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;with&nbsp;1&nbsp;set&nbsp;if&nbsp;the&nbsp;corresponding&nbsp;GPIO&nbsp;is<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;be&nbsp;set.<br></code><br><br>Returns 0 if OK, otherwise PI_SOME_PERMITTED.
<br><br>A status of PI_SOME_PERMITTED indicates that the user is not
allowed to write to one or more of the GPIO.
<h3><a name="set_bank_2"></a><a href="#int"><small>int</small></a> set_bank_2<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;with&nbsp;1&nbsp;set&nbsp;if&nbsp;the&nbsp;corresponding&nbsp;GPIO&nbsp;is<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;be&nbsp;set.<br></code><br><br>Returns 0 if OK, otherwise PI_SOME_PERMITTED.
<br><br>A status of PI_SOME_PERMITTED indicates that the user is not
allowed to write to one or more of the GPIO.
<h3><a name="hardware_clock"></a><a href="#int"><small>int</small></a> hardware_clock<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;&nbsp;&nbsp;gpio:&nbsp;see&nbsp;description<br>frequency:&nbsp;0&nbsp;(off)&nbsp;or&nbsp;4689-250000000&nbsp;(250M)<br></code><br><br>Returns 0 if OK, otherwise PI_NOT_PERMITTED, 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="hardware_PWM"></a><a href="#int"><small>int</small></a> hardware_PWM<small>(<a href="#unsigned">unsigned</a> <a href="#gpio">gpio</a>, <a href="#unsigned">unsigned</a> <a href="#PWMfreq">PWMfreq</a>, <a href="#uint32_t">uint32_t</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="#wave_send_once">wave_send_once</a>, <a href="#wave_send_repeat">wave_send_repeat</a>,
or <a href="#wave_chain">wave_chain</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 when the pigpio
daemon is started (option -t).
<br><br><code>&nbsp;&nbsp;&nbsp;gpio:&nbsp;see&nbsp;descripton<br>PWMfreq:&nbsp;0&nbsp;(off)&nbsp;or&nbsp;1-125000000&nbsp;(125M)<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_NOT_PERMITTED, 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><h3><a name="get_current_tick"></a><a href="#uint32_t"><small>uint32_t</small></a> get_current_tick<small>(void)</small></h3>
Gets 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.
<h3><a name="get_hardware_revision"></a><a href="#uint32_t"><small>uint32_t</small></a> get_hardware_revision<small>(void)</small></h3>
Get the Pi's hardware revision number.
<br><br>The hardware revision is the last few characters on the Revision line
of /proc/cpuinfo.
<br><br>If the hardware revision can not be found or is not a valid
hexadecimal number the function returns 0.
<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.
<h3><a name="get_pigpio_version"></a><a href="#uint32_t"><small>uint32_t</small></a> get_pigpio_version<small>(void)</small></h3>
Returns the pigpio version.
<h3><a name="wave_clear"></a><a href="#int"><small>int</small></a> wave_clear<small>(void)</small></h3>
This function clears all waveforms and any data added by calls to the
<a href="#wave_add_*">wave_add_*</a> functions.
<br><br>Returns 0 if OK.
<h3><a name="wave_add_new"></a><a href="#int"><small>int</small></a> wave_add_new<small>(void)</small></h3>
This function starts a new empty waveform.  You wouldn't normally need
to call this function as it is automatically called after a waveform is
created with the <a href="#wave_create">wave_create</a> function.
<br><br>Returns 0 if OK.
<h3><a name="wave_add_generic"></a><a href="#int"><small>int</small></a> wave_add_generic<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 solely of a delay.
<h3><a name="wave_add_serial"></a><a href="#int"><small>int</small></a> wave_add_serial<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;number&nbsp;of&nbsp;data&nbsp;bits&nbsp;(1-32)<br>stop_bits:&nbsp;number&nbsp;of&nbsp;stop&nbsp;half&nbsp;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.<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_STOP_BITS, 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, <a href="#data_bits">data_bits</a> data bits,
and <a href="#stop_bits">stop_bits</a>/2 stop bits.
<br><br>It is legal to add serial data streams with different baud rates to
the same waveform.
<br><br><a href="#numBytes">numBytes</a> is the number of bytes of data in str.
<br><br>The bytes required for each character depend upon <a href="#data_bits">data_bits</a>.
<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="wave_create"></a><a href="#int"><small>int</small></a> wave_create<small>(void)</small></h3>
This function creates a waveform from the data provided by the prior
calls to the <a href="#wave_add_*">wave_add_*</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="#wave_add_*">wave_add_*</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="#wave_send_*">wave_send_*</a> to specify the waveform to transmit.
<br><br>Normal usage would be
<br><br>Step 1. <a href="#wave_clear">wave_clear</a> to clear all waveforms and added data.
<br><br>Step 2. <a href="#wave_add_*">wave_add_*</a> calls to supply the waveform data.
<br><br>Step 3. <a href="#wave_create">wave_create</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="#wave_send_*">wave_send_*</a> with the id of the waveform to transmit.
<br><br>A waveform comprises one or 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><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="wave_delete"></a><a href="#int"><small>int</small></a> wave_delete<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><code>wave_id:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;<a href="#wave_create">wave_create</a>.<br></code><br><br>Wave ids are allocated in order, 0, 1, 2, etc.
<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>Returns 0 if OK, otherwise PI_BAD_WAVE_ID.
<h3><a name="wave_send_once"></a><a href="#int"><small>int</small></a> wave_send_once<small>(<a href="#unsigned">unsigned</a> <a href="#wave_id">wave_id</a>)</small></h3>
This function transmits the waveform with id wave_id.  The waveform
is sent once.
<br><br>NOTE: Any hardware PWM started by <a href="#hardware_PWM">hardware_PWM</a> will be cancelled.
<br><br><code>wave_id:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;<a href="#wave_create">wave_create</a>.<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="wave_send_repeat"></a><a href="#int"><small>int</small></a> wave_send_repeat<small>(<a href="#unsigned">unsigned</a> <a href="#wave_id">wave_id</a>)</small></h3>
This function transmits the waveform with id wave_id.  The waveform
cycles until cancelled (either by the sending of a new waveform or
by <a href="#wave_tx_stop">wave_tx_stop</a>).
<br><br>NOTE: Any hardware PWM started by <a href="#hardware_PWM">hardware_PWM</a> will be cancelled.
<br><br><code>wave_id:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;<a href="#wave_create">wave_create</a>.<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="wave_chain"></a><a href="#int"><small>int</small></a> wave_chain<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="#hardware_PWM">hardware_PWM</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;pigpiod_if.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;(pigpio_start(0,&nbsp;0)&lt;0)&nbsp;return&nbsp;-1;<br><br>&nbsp;&nbsp;&nbsp;set_mode(GPIO,&nbsp;PI_OUTPUT);<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;wave_add_generic(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;wave_create();<br>&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;wave_chain((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;(wave_tx_busy())&nbsp;time_sleep(0.1);<br><br>&nbsp;&nbsp;&nbsp;for&nbsp;(i=0;&nbsp;i&lt;WAVES;&nbsp;i++)&nbsp;wave_delete(wid[i]);<br><br>&nbsp;&nbsp;&nbsp;pigpio_stop();<br>}<br></code><h3><a name="wave_tx_busy"></a><a href="#int"><small>int</small></a> wave_tx_busy<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="wave_tx_stop"></a><a href="#int"><small>int</small></a> wave_tx_stop<small>(void)</small></h3>
This function stops the transmission of the current waveform.
<br><br>Returns 0 if OK.
<br><br>This function is intended to stop a waveform started with the repeat mode.
<h3><a name="wave_get_micros"></a><a href="#int"><small>int</small></a> wave_get_micros<small>(void)</small></h3>
This function returns the length in microseconds of the current
waveform.
<h3><a name="wave_get_high_micros"></a><a href="#int"><small>int</small></a> wave_get_high_micros<small>(void)</small></h3>
This function returns the length in microseconds of the longest waveform
created since the pigpio daemon was started.
<h3><a name="wave_get_max_micros"></a><a href="#int"><small>int</small></a> wave_get_max_micros<small>(void)</small></h3>
This function returns the maximum possible size of a waveform in<br>
microseconds.
<h3><a name="wave_get_pulses"></a><a href="#int"><small>int</small></a> wave_get_pulses<small>(void)</small></h3>
This function returns the length in pulses of the current waveform.
<h3><a name="wave_get_high_pulses"></a><a href="#int"><small>int</small></a> wave_get_high_pulses<small>(void)</small></h3>
This function returns the length in pulses of the longest waveform
created since the pigpio daemon was started.
<h3><a name="wave_get_max_pulses"></a><a href="#int"><small>int</small></a> wave_get_max_pulses<small>(void)</small></h3>
This function returns the maximum possible size of a waveform in pulses.
<h3><a name="wave_get_cbs"></a><a href="#int"><small>int</small></a> wave_get_cbs<small>(void)</small></h3>
This function returns the length in DMA control blocks of the current
waveform.
<h3><a name="wave_get_high_cbs"></a><a href="#int"><small>int</small></a> wave_get_high_cbs<small>(void)</small></h3>
This function returns the length in DMA control blocks of the longest
waveform created since the pigpio daemon was started.
<h3><a name="wave_get_max_cbs"></a><a href="#int"><small>int</small></a> wave_get_max_cbs<small>(void)</small></h3>
This function returns the maximum possible size of a waveform in DMA
control blocks.
<h3><a name="gpio_trigger"></a><a href="#int"><small>int</small></a> gpio_trigger<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,
PI_BAD_PULSELEN, or PI_NOT_PERMITTED.
<h3><a name="store_script"></a><a href="#int"><small>int</small></a> store_script<small>(<a href="#char">char</a> <a href="#*script">*script</a>)</small></h3>
This function stores a 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="run_script"></a><a href="#int"><small>int</small></a> run_script<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="#store_script">store_script</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="script_status"></a><a href="#int"><small>int</small></a> script_status<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="#store_script">store_script</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="stop_script"></a><a href="#int"><small>int</small></a> stop_script<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="#store_script">store_script</a>.<br></code><br><br>The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
<h3><a name="delete_script"></a><a href="#int"><small>int</small></a> delete_script<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="#store_script">store_script</a>.<br></code><br><br>The function returns 0 if OK, otherwise PI_BAD_SCRIPT_ID.
<h3><a name="bb_serial_read_open"></a><a href="#int"><small>int</small></a> bb_serial_read_open<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,
or PI_GPIO_IN_USE.
<br><br>The serial data is returned in a cyclic buffer and is read using
bb_serial_read.
<br><br>It is the caller's responsibility to read data from the cyclic buffer
in a timely fashion.
<h3><a name="bb_serial_read"></a><a href="#int"><small>int</small></a> bb_serial_read<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="#bb_serial_read_open">bb_serial_read_open</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="#bb_serial_read_open">bb_serial_read_open</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="bb_serial_read_close"></a><a href="#int"><small>int</small></a> bb_serial_read_close<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="#bb_serial_read_open">bb_serial_read_open</a>.<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_SERIAL_GPIO.
<h3><a name="bb_serial_invert"></a><a href="#int"><small>int</small></a> bb_serial_invert<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 inverts serial logic for big bang serial reads.
<br><br><code>user_gpio:&nbsp;0-31,&nbsp;previously&nbsp;opened&nbsp;with&nbsp;<a href="#bb_serial_read_open">bb_serial_read_open</a>.<br>&nbsp;&nbsp;&nbsp;invert:&nbsp;0-1,&nbsp;1&nbsp;invert,&nbsp;0&nbsp;normal.<br></code><br><br>Returns 0 if OK, otherwise PI_NOT_SERIAL_GPIO or PI_BAD_SER_INVERT.
<h3><a name="i2c_open"></a><a href="#int"><small>int</small></a> i2c_open<small>(<a href="#unsigned">unsigned</a> <a href="#i2c_bus">i2c_bus</a>, <a href="#unsigned">unsigned</a> <a href="#i2c_addr">i2c_addr</a>, <a href="#unsigned">unsigned</a> <a href="#i2c_flags">i2c_flags</a>)</small></h3>
This returns a handle for the device at address i2c_addr on bus i2c_bus.
<br><br><code>&nbsp;&nbsp;i2c_bus:&nbsp;&gt;=0.<br>&nbsp;i2c_addr:&nbsp;0-0x7F.<br>i2c_flags:&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;(1&nbsp;bit)&nbsp;:&nbsp;Start&nbsp;bit<br>P&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(1&nbsp;bit)&nbsp;:&nbsp;Stop&nbsp;bit<br>Rd/Wr&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;(1&nbsp;bit)&nbsp;:&nbsp;Accept&nbsp;and&nbsp;not&nbsp;accept&nbsp;bit.<br><br>Addr&nbsp;&nbsp;(7&nbsp;bits):&nbsp;I2C&nbsp;7&nbsp;bit&nbsp;address.<br>Comm&nbsp;&nbsp;(8&nbsp;bits):&nbsp;Command&nbsp;byte,&nbsp;a&nbsp;data&nbsp;byte&nbsp;which&nbsp;often&nbsp;selects&nbsp;a&nbsp;register.<br>Data&nbsp;&nbsp;(8&nbsp;bits):&nbsp;A&nbsp;data&nbsp;byte.<br>Count&nbsp;(8&nbsp;bits):&nbsp;A&nbsp;data&nbsp;byte&nbsp;containing&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="i2c_close"></a><a href="#int"><small>int</small></a> i2c_close<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="#i2c_open">i2c_open</a>.<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE.
<h3><a name="i2c_write_quick"></a><a href="#int"><small>int</small></a> i2c_write_quick<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="#i2c_open">i2c_open</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;Rd/Wr&nbsp;[A]&nbsp;P<br></code><h3><a name="i2c_write_byte"></a><a href="#int"><small>int</small></a> i2c_write_byte<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="#i2c_open">i2c_open</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;Data&nbsp;[A]&nbsp;P<br></code><h3><a name="i2c_read_byte"></a><a href="#int"><small>int</small></a> i2c_read_byte<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="#i2c_open">i2c_open</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="i2c_write_byte_data"></a><a href="#int"><small>int</small></a> i2c_write_byte_data<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2c_reg">i2c_reg</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>&nbsp;handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>.<br>i2c_reg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;write.<br>&nbsp;&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;Comm&nbsp;[A]&nbsp;Data&nbsp;[A]&nbsp;P<br></code><h3><a name="i2c_write_word_data"></a><a href="#int"><small>int</small></a> i2c_write_word_data<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2c_reg">i2c_reg</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>&nbsp;handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>.<br>i2c_reg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;write.<br>&nbsp;&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;Comm&nbsp;[A]&nbsp;DataLow&nbsp;[A]&nbsp;DataHigh&nbsp;[A]&nbsp;P<br></code><h3><a name="i2c_read_byte_data"></a><a href="#int"><small>int</small></a> i2c_read_byte_data<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2c_reg">i2c_reg</a>)</small></h3>
This reads a single byte from the specified register of the device
associated with handle.
<br><br><code>&nbsp;handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>.<br>i2c_reg:&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;Comm&nbsp;[A]&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[Data]&nbsp;NA&nbsp;P<br></code><h3><a name="i2c_read_word_data"></a><a href="#int"><small>int</small></a> i2c_read_word_data<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2c_reg">i2c_reg</a>)</small></h3>
This reads a single 16 bit word from the specified register of the device
associated with handle.
<br><br><code>&nbsp;handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>.<br>i2c_reg:&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;Comm&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="i2c_process_call"></a><a href="#int"><small>int</small></a> i2c_process_call<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2c_reg">i2c_reg</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 and reads 16 bits of data in return.
<br><br><code>&nbsp;handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>.<br>i2c_reg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;write/read.<br>&nbsp;&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;Comm&nbsp;[A]&nbsp;DataLow&nbsp;[A]&nbsp;DataHigh&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="i2c_write_block_data"></a><a href="#int"><small>int</small></a> i2c_write_block_data<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2c_reg">i2c_reg</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>&nbsp;handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>.<br>i2c_reg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;write.<br>&nbsp;&nbsp;&nbsp;&nbsp;buf:&nbsp;an&nbsp;array&nbsp;with&nbsp;the&nbsp;data&nbsp;to&nbsp;send.<br>&nbsp;&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;Comm&nbsp;[A]&nbsp;Count&nbsp;[A]&nbsp;Data&nbsp;[A]&nbsp;Data&nbsp;[A]&nbsp;...&nbsp;[A]&nbsp;Data&nbsp;[A]&nbsp;P<br></code><h3><a name="i2c_read_block_data"></a><a href="#int"><small>int</small></a> i2c_read_block_data<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2c_reg">i2c_reg</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>&nbsp;handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>.<br>i2c_reg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;read.<br>&nbsp;&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;Comm&nbsp;[A]<br>&nbsp;&nbsp;&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[Count]&nbsp;A&nbsp;[Data]&nbsp;A&nbsp;[Data]&nbsp;A&nbsp;...&nbsp;A&nbsp;[Data]&nbsp;NA&nbsp;P<br></code><h3><a name="i2c_block_process_call"></a><a href="#int"><small>int</small></a> i2c_block_process_call<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2c_reg">i2c_reg</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>&nbsp;handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>.<br>i2c_reg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;write/read.<br>&nbsp;&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;&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;Comm&nbsp;[A]&nbsp;Count&nbsp;[A]&nbsp;Data&nbsp;[A]&nbsp;...<br>&nbsp;&nbsp;&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[Count]&nbsp;A&nbsp;[Data]&nbsp;...&nbsp;A&nbsp;P<br></code><h3><a name="i2c_read_i2c_block_data"></a><a href="#int"><small>int</small></a> i2c_read_i2c_block_data<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2c_reg">i2c_reg</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>&nbsp;handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>.<br>i2c_reg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;read.<br>&nbsp;&nbsp;&nbsp;&nbsp;buf:&nbsp;an&nbsp;array&nbsp;to&nbsp;receive&nbsp;the&nbsp;read&nbsp;data.<br>&nbsp;&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;Comm&nbsp;[A]<br>&nbsp;&nbsp;&nbsp;S&nbsp;Addr&nbsp;Rd&nbsp;[A]&nbsp;[Data]&nbsp;A&nbsp;[Data]&nbsp;A&nbsp;...&nbsp;A&nbsp;[Data]&nbsp;NA&nbsp;P<br></code><h3><a name="i2c_write_i2c_block_data"></a><a href="#int"><small>int</small></a> i2c_write_i2c_block_data<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>, <a href="#unsigned">unsigned</a> <a href="#i2c_reg">i2c_reg</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>&nbsp;handle:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#i2c_open">i2c_open</a>.<br>i2c_reg:&nbsp;0-255,&nbsp;the&nbsp;register&nbsp;to&nbsp;write.<br>&nbsp;&nbsp;&nbsp;&nbsp;buf:&nbsp;the&nbsp;data&nbsp;to&nbsp;write.<br>&nbsp;&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;Comm&nbsp;[A]&nbsp;Data&nbsp;[A]&nbsp;Data&nbsp;[A]&nbsp;...&nbsp;[A]&nbsp;Data&nbsp;[A]&nbsp;P<br></code><h3><a name="i2c_read_device"></a><a href="#int"><small>int</small></a> i2c_read_device<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="#i2c_open">i2c_open</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.
<h3><a name="i2c_write_device"></a><a href="#int"><small>int</small></a> i2c_write_device<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="#i2c_open">i2c_open</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.
<h3><a name="i2c_zip"></a><a href="#int"><small>int</small></a> i2c_zip<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="bb_i2c_open"></a><a href="#int"><small>int</small></a> bb_i2c_open<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="bb_i2c_close"></a><a href="#int"><small>int</small></a> bb_i2c_close<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="#bb_i2c_open">bb_i2c_open</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="#bb_i2c_open">bb_i2c_open</a><br></code><br><br>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_NOT_I2C_GPIO.
<h3><a name="bb_i2c_zip"></a><a href="#int"><small>int</small></a> bb_i2c_zip<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="#bb_i2c_open">bb_i2c_open</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="spi_open"></a><a href="#int"><small>int</small></a> spi_open<small>(<a href="#unsigned">unsigned</a> <a href="#spi_channel">spi_channel</a>, <a href="#unsigned">unsigned</a> <a href="#baud">baud</a>, <a href="#unsigned">unsigned</a> <a href="#spi_flags">spi_flags</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>spi_channel:&nbsp;0-1&nbsp;(0-2&nbsp;for&nbsp;the&nbsp;auxiliary&nbsp;SPI).<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;baud:&nbsp;32K-125M&nbsp;(values&nbsp;above&nbsp;30M&nbsp;are&nbsp;unlikely&nbsp;to&nbsp;work).<br>&nbsp;&nbsp;spi_flags:&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>spi_flags 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="#spi_read">spi_read</a>, <a href="#spi_write">spi_write</a>, and <a href="#spi_xfer">spi_xfer</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="spi_close"></a><a href="#int"><small>int</small></a> spi_close<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="#spi_open">spi_open</a>.<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE.
<h3><a name="spi_read"></a><a href="#int"><small>int</small></a> spi_read<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="#spi_open">spi_open</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="spi_write"></a><a href="#int"><small>int</small></a> spi_write<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="#spi_open">spi_open</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="spi_xfer"></a><a href="#int"><small>int</small></a> spi_xfer<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="#spi_open">spi_open</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="serial_open"></a><a href="#int"><small>int</small></a> serial_open<small>(<a href="#char">char</a> <a href="#*ser_tty">*ser_tty</a>, <a href="#unsigned">unsigned</a> <a href="#baud">baud</a>, <a href="#unsigned">unsigned</a> <a href="#ser_flags">ser_flags</a>)</small></h3>
This function opens a serial device at a specified baud rate
with specified flags.  The device name must start with
/dev/tty or /dev/serial.
<br><br><code>&nbsp;&nbsp;ser_tty:&nbsp;the&nbsp;serial&nbsp;device&nbsp;to&nbsp;open.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;baud:&nbsp;the&nbsp;baud&nbsp;rate&nbsp;in&nbsp;bits&nbsp;per&nbsp;second,&nbsp;see&nbsp;below.<br>ser_flags:&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="serial_close"></a><a href="#int"><small>int</small></a> serial_close<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="#serial_open">serial_open</a>.<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE.
<h3><a name="serial_write_byte"></a><a href="#int"><small>int</small></a> serial_write_byte<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="#serial_open">serial_open</a>.<br></code><br><br>Returns 0 if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or
PI_SER_WRITE_FAILED.
<h3><a name="serial_read_byte"></a><a href="#int"><small>int</small></a> serial_read_byte<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="#serial_open">serial_open</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="serial_write"></a><a href="#int"><small>int</small></a> serial_write<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="#serial_open">serial_open</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="serial_read"></a><a href="#int"><small>int</small></a> serial_read<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 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="#serial_open">serial_open</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_SER_READ_NO_DATA, or PI_SER_WRITE_FAILED.
<br><br>If no data is ready zero is returned.
<h3><a name="serial_data_available"></a><a href="#int"><small>int</small></a> serial_data_available<small>(<a href="#unsigned">unsigned</a> <a href="#handle">handle</a>)</small></h3>
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="#serial_open">serial_open</a>.<br></code><br><br>Returns the number of bytes of data available (&gt;=0) if OK,
otherwise PI_BAD_HANDLE.
<h3><a name="custom_1"></a><a href="#int"><small>int</small></a> custom_1<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="custom_2"></a><a href="#int"><small>int</small></a> custom_2<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 custom_1 in that it returns an array of bytes
rather than just an integer.
<br><br>The return value is an integer indicating the number of returned bytes.
<code>&nbsp;&nbsp;arg1:&nbsp;&gt;=0<br>&nbsp;&nbsp;argc:&nbsp;extra&nbsp;(byte)&nbsp;arguments<br>&nbsp;count:&nbsp;number&nbsp;of&nbsp;extra&nbsp;arguments<br>retBuf:&nbsp;buffer&nbsp;for&nbsp;returned&nbsp;data<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>Note, the number of returned bytes will be retMax or less.
<h3><a name="callback"></a><a href="#int"><small>int</small></a> callback<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#unsigned">unsigned</a> <a href="#edge">edge</a>, <a href="#CBFunc_t">CBFunc_t</a> <a href="#f">f</a>)</small></h3>
This function initialises a new callback.
<br><br><code>user_gpio:&nbsp;0-31.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;edge:&nbsp;RISING_EDGE,&nbsp;FALLING_EDGE,&nbsp;or&nbsp;EITHER_EDGE.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;callback&nbsp;function.<br></code><br><br>The function returns a callback id if OK, otherwise pigif_bad_malloc,
pigif_duplicate_callback, or pigif_bad_callback.
<br><br>The callback is called with the GPIO, edge, and tick, whenever the
GPIO has the identified edge.
<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>edge&nbsp;&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><h3><a name="callback_ex"></a><a href="#int"><small>int</small></a> callback_ex<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#unsigned">unsigned</a> <a href="#edge">edge</a>, <a href="#CBFuncEx_t">CBFuncEx_t</a> <a href="#f">f</a>, <a href="#void">void</a> <a href="#*userdata">*userdata</a>)</small></h3>
This function initialises a new callback.
<br><br><code>user_gpio:&nbsp;0-31.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;edge:&nbsp;RISING_EDGE,&nbsp;FALLING_EDGE,&nbsp;or&nbsp;EITHER_EDGE.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f:&nbsp;the&nbsp;callback&nbsp;function.<br>&nbsp;userdata:&nbsp;a&nbsp;pointer&nbsp;to&nbsp;arbitrary&nbsp;user&nbsp;data.<br></code><br><br>The function returns a callback id if OK, otherwise pigif_bad_malloc,
pigif_duplicate_callback, or pigif_bad_callback.
<br><br>The callback is called with the GPIO, edge, tick, and user, whenever
the GPIO has the identified edge.
<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>edge&nbsp;&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><h3><a name="callback_cancel"></a><a href="#int"><small>int</small></a> callback_cancel<small>(<a href="#unsigned">unsigned</a> <a href="#callback_id">callback_id</a>)</small></h3>
This function cancels a callback identified by its id.
<br><br><code>callback_id:&nbsp;&gt;=0,&nbsp;as&nbsp;returned&nbsp;by&nbsp;a&nbsp;call&nbsp;to&nbsp;<a href="#callback">callback</a>&nbsp;or&nbsp;<a href="#callback_ex">callback_ex</a>.<br></code><br><br>The function returns 0 if OK, otherwise pigif_callback_not_found.
<h3><a name="wait_for_edge"></a><a href="#int"><small>int</small></a> wait_for_edge<small>(<a href="#unsigned">unsigned</a> <a href="#user_gpio">user_gpio</a>, <a href="#unsigned">unsigned</a> <a href="#edge">edge</a>, <a href="#double">double</a> <a href="#timeout">timeout</a>)</small></h3>
This function waits for edge on the GPIO for up to timeout
seconds.
<br><br><code>user_gpio:&nbsp;0-31.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;edge:&nbsp;RISING_EDGE,&nbsp;FALLING_EDGE,&nbsp;or&nbsp;EITHER_EDGE.<br>&nbsp;&nbsp;timeout:&nbsp;&gt;=0.<br></code><br><br>The function returns 1 if the edge occurred, otherwise 0.
<br><br>The function returns when the edge occurs or after the timeout.
<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="*addrStr">*addrStr</a></h3>
A string specifying the host or IP address of the Pi running
the pigpio daemon.  It may be NULL in which case localhost
is used unless overridden by the PIGPIO_ADDR environment
variable.
<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="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="*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="callback_id">callback_id</a></h3>
A &gt;=0, as returned by a call to <a href="#callback">callback</a> or <a href="#callback_ex">callback_ex</a>.  This is
passed to <a href="#callback_cancel">callback_cancel</a> to cancel the callback.
<h3><a name="CBFunc_t">CBFunc_t</a></h3>
<code>typedef&nbsp;void&nbsp;(*CBFunc_t)<br>&nbsp;&nbsp;&nbsp;(unsigned&nbsp;user_gpio,&nbsp;unsigned&nbsp;level,&nbsp;uint32_t&nbsp;tick);<br></code><h3><a name="CBFuncEx_t">CBFuncEx_t</a></h3>
<code>typedef&nbsp;void&nbsp;(*CBFuncEx_t)<br>&nbsp;&nbsp;&nbsp;(unsigned&nbsp;user_gpio,&nbsp;unsigned&nbsp;level,&nbsp;uint32_t&nbsp;tick,&nbsp;void&nbsp;*&nbsp;user);<br></code><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-250000000 (250M)</h3>
The hardware clock frequency.
<h3><a name="count">count</a></h3>
The number of bytes to be transferred in an I2C, SPI, or Serial
command.
<h3><a name="data_bits">data_bits</a>: 1-32</h3>
The number of data bits in each character of serial data.
<br><br><code>#define&nbsp;PI_MIN_WAVE_DATABITS&nbsp;1<br>#define&nbsp;PI_MAX_WAVE_DATABITS&nbsp;32<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></h3>
Used to identify a GPIO level transition of interest.  A rising edge is
a level change from 0 to 1.  A falling edge is a level change from 1 to 0.
<br><br><code>RISING_EDGE&nbsp;&nbsp;0<br>FALLING_EDGE&nbsp;1<br>EITHER_EDGE.&nbsp;2<br></code><h3><a name="errnum">errnum</a></h3>
A negative number indicating a function call failed and the nature
of the error.
<h3><a name="f">f</a></h3>
A function.
<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="#get_hardware_revision">get_hardware_revision</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="gpioPulse_t">gpioPulse_t</a></h3>
<code>typedef&nbsp;struct<br>{<br>uint32_t&nbsp;gpioOn;<br>uint32_t&nbsp;gpioOff;<br>uint32_t&nbsp;usDelay;<br>}&nbsp;gpioPulse_t;<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="handle">handle</a>: &gt;=0</h3>
A number referencing an object opened by one of <a href="#i2c_open">i2c_open</a>, <a href="#notify_open">notify_open</a>,
<a href="#serial_open">serial_open</a>, and <a href="#spi_open">spi_open</a>.
<h3><a name="i2c_addr">i2c_addr</a>: 0-0x7F</h3>
The address of a device on the I2C bus.
<h3><a name="i2c_bus">i2c_bus</a>: &gt;=0</h3>
An I2C bus number.
<h3><a name="i2c_flags">i2c_flags</a>: 0</h3>
Flags which modify an I2C open command.  None are currently defined.
<h3><a name="i2c_reg">i2c_reg</a>: 0-255</h3>
A register of an I2C device.
<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="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="#set_watchdog">set_watchdog</a>.
<br><br><code>PI_TIMEOUT&nbsp;2<br></code><h3><a name="mode">mode</a>: 0-7</h3>
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><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="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="*param">*param</a></h3>
An array of script parameters.
<h3><a name="*portStr">*portStr</a></h3>
A string specifying the port address used by the Pi running
the pigpio daemon.  It may be NULL in which case "8888"
is used unless overridden by the PIGPIO_PORT environment
variable.
<h3><a name="*pth">*pth</a></h3>
A thread identifier, returned by <a href="#start_thread">start_thread</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.
<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>#define&nbsp;PI_HW_PWM_RANGE&nbsp;1000000<br></code><h3><a name="PWMfreq">PWMfreq</a>: 1-125000000 (125M)</h3>
The hardware PWM frequency.
<br><br><code>#define&nbsp;PI_HW_PWM_MIN_FREQ&nbsp;1<br>#define&nbsp;PI_HW_PWM_MAX_FREQ&nbsp;125000000<br></code><h3><a name="range">range</a>: 25-40000</h3>
The permissible dutycycle values are 0-range.
<code>PI_MIN_DUTYCYCLE_RANGE&nbsp;25<br>PI_MAX_DUTYCYCLE_RANGE&nbsp;40000<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="*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="#store_script">store_script</a>.
<h3><a name="SDA">SDA</a></h3>
The user GPIO to use for data when bit banging I2C.
<h3><a name="seconds">seconds</a></h3>
The number of seconds.
<h3><a name="ser_flags">ser_flags</a></h3>
Flags which modify a serial open command.  None are currently defined.
<h3><a name="*ser_tty">*ser_tty</a></h3>
The name of a serial tty device, e.g. /dev/ttyAMA0, /dev/ttyUSB0, /dev/tty1.
<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="spi_channel">spi_channel</a></h3>
A SPI channel, 0-2.
<h3><a name="spi_flags">spi_flags</a></h3>
See <a href="#spi_open">spi_open</a>.
<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="#set_glitch_filter">set_glitch_filter</a>) or triggering
the active part of a noise filter (<a href="#set_noise_filter">set_noise_filter</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>#define&nbsp;PI_MIN_WAVE_HALFSTOPBITS&nbsp;2<br>#define&nbsp;PI_MAX_WAVE_HALFSTOPBITS&nbsp;8<br></code><h3><a name="*str">*str</a></h3>
 An array of characters.
<h3><a name="thread_func">thread_func</a></h3>
A function of type gpioThreadFunc_t used as the main function of a
thread.
<h3><a name="timeout">timeout</a></h3>
A GPIO watchdog timeout in milliseconds.
<code>PI_MIN_WDOG_TIMEOUT&nbsp;0<br>PI_MAX_WDOG_TIMEOUT&nbsp;60000<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="unsigned">unsigned</a></h3>
A whole number &gt;= 0.
<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.
<h3><a name="void">void</a></h3>
Denoting no parameter is required
<h3><a name="wave_add_*">wave_add_*</a></h3>
One of <a href="#wave_add_new">wave_add_new</a>, <a href="#wave_add_generic">wave_add_generic</a>, <a href="#wave_add_serial">wave_add_serial</a>.
<h3><a name="wave_id">wave_id</a></h3>
A number representing a waveform created by <a href="#wave_create">wave_create</a>.
<h3><a name="wave_send_*">wave_send_*</a></h3>
One of <a href="#wave_send_once">wave_send_once</a>, <a href="#wave_send_repeat">wave_send_repeat</a>.
<h3><a name="wVal">wVal</a>: 0-65535 (Hex 0x0-0xFFFF, Octal 0-0177777)</h3>
A 16-bit word value.
<h2>pigpiod_if Error Codes</h2><code><br>typedef&nbsp;enum<br>{<br>&nbsp;&nbsp;&nbsp;pigif_bad_send&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;-2000,<br>&nbsp;&nbsp;&nbsp;pigif_bad_recv&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;-2001,<br>&nbsp;&nbsp;&nbsp;pigif_bad_getaddrinfo&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;-2002,<br>&nbsp;&nbsp;&nbsp;pigif_bad_connect&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;-2003,<br>&nbsp;&nbsp;&nbsp;pigif_bad_socket&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;-2004,<br>&nbsp;&nbsp;&nbsp;pigif_bad_noib&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;-2005,<br>&nbsp;&nbsp;&nbsp;pigif_duplicate_callback&nbsp;=&nbsp;-2006,<br>&nbsp;&nbsp;&nbsp;pigif_bad_malloc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;-2007,<br>&nbsp;&nbsp;&nbsp;pigif_bad_callback&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;-2008,<br>&nbsp;&nbsp;&nbsp;pigif_notify_failed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;-2009,<br>&nbsp;&nbsp;&nbsp;pigif_callback_not_found&nbsp;=&nbsp;-2010,<br>}&nbsp;pigifError_t;<br><br></code>


file_name: pigs
menu_title: pigs
page_title: pigs
pic1: pins.jpg
pic2: meter.jpg
pic3: keypad.jpg
body:
<h2><a name="Introduction">Introduction</a></h2>
The socket and pipe interfaces allow control of the Pi's GPIO by
passing messages to the running pigpio library.
<br><br>The normal way to start the pigpio library would be as a daemon during boot.
<br><br><code>sudo&nbsp;pigpiod<br></code><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 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 I2C, SPI, and serial link wrappers
<br><br>o creating and running scripts on the pigpio daemon
<h3>GPIO</h3>ALL GPIO are identified by their Broadcom number.
<h3>Usage</h3>pigs is a program and internally uses the socket interface to pigpio
whereas /dev/pigpio uses the pipe interface.
<br><br>pigs and the pipe interface share the same commands and are invoked in
a similar fashion from the command line.
<br><br>The pigpio library must be running, either by running a program linked
with the library or starting the pigpio daemon (sudo pigpiod).
<br><br>pigs {command}+
<br><br>echo "{command}+" &gt;/dev/pigpio
<br><br>pigs will show the result of the command on screen.
<br><br>The pigs process returns an exit status (which can be displayed with
the command echo $?).
<br><br><code>PIGS_OK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0<br>PIGS_CONNECT_ERR&nbsp;255<br>PIGS_OPTION_ERR&nbsp;&nbsp;254<br>PIGS_SCRIPT_ERR&nbsp;&nbsp;253<br><br></code><br><br>The results of /dev/pigpio commands need to be read from /dev/pigout,
e.g. cat /dev/pigout (try cat /dev/pigout& so that all subsequent
results are shown on screen).
<br><br>In both cases if an error was detected a message will have been written
to /dev/pigerr (try cat /dev/pigerr&).  This is likely to be more
informative than the message returned by pigs or the error code
returned by the pipe interface.
<br><br>Several commands may be entered on a line.  If present PROC and PARSE must
be the last command on a line.
<br><br>E.g.
<br><br><code>pigs&nbsp;w&nbsp;22&nbsp;1&nbsp;mils&nbsp;1000&nbsp;w&nbsp;22&nbsp;0<br></code><br><br>is equivalent to
<br><br><code>pigs&nbsp;w&nbsp;22&nbsp;1<br>pigs&nbsp;mils&nbsp;1000<br>pigs&nbsp;w&nbsp;22&nbsp;0<br></code><br><br>and
<br><br><code>echo&nbsp;"m&nbsp;4&nbsp;w&nbsp;w&nbsp;4&nbsp;0&nbsp;mils&nbsp;250&nbsp;m&nbsp;4&nbsp;r&nbsp;r&nbsp;4"&nbsp;&gt;/dev/pigpio<br></code><br><br>is equivalent to
<br><br><code>echo&nbsp;"m&nbsp;4&nbsp;w"&nbsp;&nbsp;&nbsp;&nbsp;&gt;/dev/pigpio<br>echo&nbsp;"w&nbsp;4&nbsp;0"&nbsp;&nbsp;&nbsp;&nbsp;&gt;/dev/pigpio<br>echo&nbsp;"mils&nbsp;250"&nbsp;&gt;/dev/pigpio<br>echo&nbsp;"m&nbsp;4&nbsp;r"&nbsp;&nbsp;&nbsp;&nbsp;&gt;/dev/pigpio<br>echo&nbsp;"r&nbsp;4"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&gt;/dev/pigpio<br></code><h3>Notes</h3>The examples from now on will show the pigs interface but the same
commands will also work on the pipe interface.
<br><br>pigs does not show the status of successful commands unless the
command itself returns data.  The status (0) will be returned to
pigs but will be discarded.
<br><br>The status/data of each command sent to the pipe interface should
be read from /dev/pigout.
<br><br>When a command takes a number as a parameter it may be entered as hex
(precede by 0x), octal (precede by 0), or decimal.
<br><br>E.g. 23 is 23 decimal, 0x100 is 256 decimal, 070 is 56 decimal.
<br><br>Some commands can return a variable number of data bytes.  By
default this data is displayed as decimal.  The pigs -a option
can be used to force the display as ASCII and the pigs -x
option can be used to force the display as hex.
<br><br>E.g. assuming the transmitted serial data is the letters ABCDEONM
<br><br><code>$&nbsp;pigs&nbsp;slr&nbsp;4&nbsp;100<br>8&nbsp;65&nbsp;66&nbsp;67&nbsp;68&nbsp;69&nbsp;79&nbsp;78&nbsp;77<br><br>$&nbsp;pigs&nbsp;-a&nbsp;slr&nbsp;4&nbsp;100<br>8&nbsp;ABCDEONM<br><br>$&nbsp;pigs&nbsp;-x&nbsp;slr&nbsp;4&nbsp;100<br>8&nbsp;41&nbsp;42&nbsp;43&nbsp;44&nbsp;45&nbsp;4f&nbsp;4e&nbsp;4d<br></code><h2><a name="Overview">Overview</a></h2>
<table border="0" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td></td><td></td></tr><tr><td>BASIC
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#M/MODES">M/MODES</a> <a href="#g">g</a> <a href="#m">m</a></td><td>Set GPIO mode </td><td><small><a href="cif.html#gpioSetMode">gpioSetMode</a></small></td></tr><tr><td><a href="#MG/MODEG">MG/MODEG</a> <a href="#g">g</a></td><td>Get GPIO mode </td><td><small><a href="cif.html#gpioGetMode">gpioGetMode</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#PUD">PUD</a> <a href="#g">g</a> <a href="#p">p</a></td><td>Set GPIO pull up/down </td><td><small><a href="cif.html#gpioSetPullUpDown">gpioSetPullUpDown</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#R/READ">R/READ</a> <a href="#g">g</a></td><td>Read GPIO level  </td><td><small><a href="cif.html#gpioRead">gpioRead</a></small></td></tr><tr><td><a href="#W/WRITE">W/WRITE</a> <a href="#g">g</a> <a href="#L">L</a></td><td>Write GPIO level </td><td><small><a href="cif.html#gpioWrite">gpioWrite</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>PWM (overrides servo commands on same GPIO)
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#P/PWM">P/PWM</a> <a href="#u">u</a> <a href="#v">v</a></td><td>Set GPIO PWM value      </td><td><small><a href="cif.html#gpioPWM">gpioPWM</a></small></td></tr><tr><td><a href="#PFS">PFS</a> <a href="#u">u</a> <a href="#v">v</a></td><td>Set GPIO PWM frequency  </td><td><small><a href="cif.html#gpioSetPWMfrequency">gpioSetPWMfrequency</a></small></td></tr><tr><td><a href="#PRS">PRS</a> <a href="#u">u</a> <a href="#v">v</a></td><td>Set GPIO PWM range      </td><td><small><a href="cif.html#gpioSetPWMrange">gpioSetPWMrange</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#GDC">GDC</a> <a href="#u">u</a></td><td>Get GPIO PWM dutycycle  </td><td><small><a href="cif.html#gpioGetPWMdutycycle">gpioGetPWMdutycycle</a></small></td></tr><tr><td><a href="#PFG">PFG</a> <a href="#u">u</a></td><td>Get GPIO PWM frequency  </td><td><small><a href="cif.html#gpioGetPWMfrequency">gpioGetPWMfrequency</a></small></td></tr><tr><td><a href="#PRG">PRG</a> <a href="#u">u</a></td><td>Get GPIO PWM range      </td><td><small><a href="cif.html#gpioGetPWMrange">gpioGetPWMrange</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#PRRG">PRRG</a> <a href="#u">u</a></td><td>Get GPIO PWM real range </td><td><small><a href="cif.html#gpioGetPWMrealRange">gpioGetPWMrealRange</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>Servo (overrides PWM commands on same GPIO)
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#S/SERVO">S/SERVO</a> <a href="#u">u</a> <a href="#v">v</a></td><td>Set GPIO servo pulsewidth </td><td><small><a href="cif.html#gpioServo">gpioServo</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#GPW">GPW</a> <a href="#u">u</a></td><td>Get GPIO servo pulsewidth </td><td><small><a href="cif.html#gpioGetServoPulsewidth">gpioGetServoPulsewidth</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>INTERMEDIATE
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#TRIG">TRIG</a> <a href="#u">u</a> <a href="#pl">pl</a> <a href="#L">L</a></td><td>Send a trigger pulse </td><td><small><a href="cif.html#gpioTrigger">gpioTrigger</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#WDOG">WDOG</a> <a href="#u">u</a> <a href="#v">v</a></td><td>Set GPIO watchdog    </td><td><small><a href="cif.html#gpioSetWatchdog">gpioSetWatchdog</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#BR1">BR1</a></td><td>Read bank 1 GPIO               </td><td><small><a href="cif.html#gpioRead_Bits_0_31">gpioRead_Bits_0_31</a></small></td></tr><tr><td><a href="#BR2">BR2</a></td><td>Read bank 2 GPIO               </td><td><small><a href="cif.html#gpioRead_Bits_32_53">gpioRead_Bits_32_53</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#BC1">BC1</a> <a href="#bits">bits</a></td><td>Clear specified GPIO in bank 1 </td><td><small><a href="cif.html#gpioWrite_Bits_0_31_Clear">gpioWrite_Bits_0_31_Clear</a></small></td></tr><tr><td><a href="#BC2">BC2</a> <a href="#bits">bits</a></td><td>Clear specified GPIO in bank 2 </td><td><small><a href="cif.html#gpioWrite_Bits_32_53_Clear">gpioWrite_Bits_32_53_Clear</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#BS1">BS1</a> <a href="#bits">bits</a></td><td>Set specified GPIO in bank 1   </td><td><small><a href="cif.html#gpioWrite_Bits_0_31_Set">gpioWrite_Bits_0_31_Set</a></small></td></tr><tr><td><a href="#BS2">BS2</a> <a href="#bits">bits</a></td><td>Set specified GPIO in bank 2   </td><td><small><a href="cif.html#gpioWrite_Bits_32_53_Set">gpioWrite_Bits_32_53_Set</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>ADVANCED
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#NO">NO</a></td><td>Request a notification </td><td><small><a href="cif.html#gpioNotifyOpen">gpioNotifyOpen</a></small></td></tr><tr><td><a href="#NC">NC</a> <a href="#h">h</a></td><td>Close notification     </td><td><small><a href="cif.html#gpioNotifyClose">gpioNotifyClose</a></small></td></tr><tr><td><a href="#NB">NB</a> <a href="#h">h</a> <a href="#bits">bits</a></td><td>Start notification     </td><td><small><a href="cif.html#gpioNotifyBegin">gpioNotifyBegin</a></small></td></tr><tr><td><a href="#NP">NP</a> <a href="#h">h</a></td><td>Pause notification     </td><td><small><a href="cif.html#gpioNotifyPause">gpioNotifyPause</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#HC">HC</a> <a href="#g">g</a> <a href="#cf">cf</a></td><td>Set hardware clock frequency </td><td><small><a href="cif.html#gpioHardwareClock">gpioHardwareClock</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#HP">HP</a> <a href="#g">g</a> <a href="#pf">pf</a> <a href="#pdc">pdc</a></td><td>Set hardware PWM frequency and dutycycle </td><td><small><a href="cif.html#gpioHardwarePWM">gpioHardwarePWM</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#FG">FG</a> <a href="#u">u</a> <a href="#stdy">stdy</a></td><td>Set a glitch filter on a GPIO  </td><td><small><a href="cif.html#gpioGlitchFilter">gpioGlitchFilter</a></small></td></tr><tr><td><a href="#FN">FN</a> <a href="#u">u</a> <a href="#stdy">stdy</a> <a href="#actv">actv</a></td><td>Set a noise filter on a GPIO   </td><td><small><a href="cif.html#gpioNoiseFilter">gpioNoiseFilter</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#PADS">PADS</a> <a href="#pad">pad</a> <a href="#padma">padma</a></td><td>Set pad drive strength </td><td><small><a href="cif.html#gpioSetPad">gpioSetPad</a></small></td></tr><tr><td><a href="#PADG">PADG</a> <a href="#pad">pad</a></td><td>Get pad drive strength </td><td><small><a href="cif.html#gpioGetPad">gpioGetPad</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#SHELL">SHELL</a> <a href="#name">name</a> <a href="#str">str</a></td><td>Execute a shell command </td><td><small><a href="cif.html#shell">shell</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>Custom
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#CF1">CF1</a> <a href="#uvs">uvs</a></td><td>Custom function 1 </td><td><small><a href="cif.html#gpioCustom1">gpioCustom1</a></small></td></tr><tr><td><a href="#CF2">CF2</a> <a href="#uvs">uvs</a></td><td>Custom function 2 </td><td><small><a href="cif.html#gpioCustom1">gpioCustom1</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>Events
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#EVM">EVM</a> <a href="#h">h</a> <a href="#bits">bits</a></td><td>Set events to monitor </td><td><small><a href="cif.html#eventMonitor">eventMonitor</a></small></td></tr><tr><td><a href="#EVT">EVT</a> <a href="#event">event</a></td><td>Trigger event         </td><td><small><a href="cif.html#eventTrigger">eventTrigger</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>Scripts
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#PROC">PROC</a> <a href="#t">t</a></td><td>Store script                     </td><td><small><a href="cif.html#gpioStoreScript">gpioStoreScript</a></small></td></tr><tr><td><a href="#PROCR">PROCR</a> <a href="#sid">sid</a> <a href="#pars">pars</a></td><td>Run script                       </td><td><small><a href="cif.html#gpioRunScript">gpioRunScript</a></small></td></tr><tr><td><a href="#PROCU">PROCU</a> <a href="#sid">sid</a> <a href="#pars">pars</a></td><td>Set script parameters            </td><td><small><a href="cif.html#gpioUpdateScript">gpioUpdateScript</a></small></td></tr><tr><td><a href="#PROCP">PROCP</a> <a href="#sid">sid</a></td><td>Get script status and parameters </td><td><small><a href="cif.html#gpioScriptStatus">gpioScriptStatus</a></small></td></tr><tr><td><a href="#PROCS">PROCS</a> <a href="#sid">sid</a></td><td>Stop script                      </td><td><small><a href="cif.html#gpioStopScript">gpioStopScript</a></small></td></tr><tr><td><a href="#PROCD">PROCD</a> <a href="#sid">sid</a></td><td>Delete script                    </td><td><small><a href="cif.html#gpioDeleteScript">gpioDeleteScript</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#PARSE">PARSE</a> <a href="#t">t</a></td><td>Validate script                  </td><td><small><a href="cif.html#gpioParseScript">gpioParseScript</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>I2C
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#I2CO">I2CO</a> <a href="#ib">ib</a> <a href="#id">id</a> <a href="#if">if</a></td><td>Open I2C bus and device with flags </td><td><small><a href="cif.html#i2cOpen">i2cOpen</a></small></td></tr><tr><td><a href="#I2CC">I2CC</a> <a href="#h">h</a></td><td>Close I2C handle                   </td><td><small><a href="cif.html#i2cClose">i2cClose</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#I2CWQ">I2CWQ</a> <a href="#h">h</a> <a href="#bit">bit</a></td><td>smb Write Quick: write bit </td><td><small><a href="cif.html#i2cWriteQuick">i2cWriteQuick</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#I2CRS">I2CRS</a> <a href="#h">h</a></td><td>smb Read Byte: read byte   </td><td><small><a href="cif.html#i2cReadByte">i2cReadByte</a></small></td></tr><tr><td><a href="#I2CWS">I2CWS</a> <a href="#h">h</a> <a href="#bv">bv</a></td><td>smb Write Byte: write byte </td><td><small><a href="cif.html#i2cWriteByte">i2cWriteByte</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#I2CRB">I2CRB</a> <a href="#h">h</a> <a href="#r">r</a></td><td>smb Read Byte Data: read byte from register </td><td><small><a href="cif.html#i2cReadByteData">i2cReadByteData</a></small></td></tr><tr><td><a href="#I2CWB">I2CWB</a> <a href="#h">h</a> <a href="#r">r</a> <a href="#bv">bv</a></td><td>smb Write Byte Data: write byte to register </td><td><small><a href="cif.html#i2cWriteByteData">i2cWriteByteData</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#I2CRW">I2CRW</a> <a href="#h">h</a> <a href="#r">r</a></td><td>smb Read Word Data: read word from register </td><td><small><a href="cif.html#i2cReadWordData">i2cReadWordData</a></small></td></tr><tr><td><a href="#I2CWW">I2CWW</a> <a href="#h">h</a> <a href="#r">r</a> <a href="#wv">wv</a></td><td>smb Write Word Data: write word to register </td><td><small><a href="cif.html#i2cWriteWordData">i2cWriteWordData</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#I2CRK">I2CRK</a> <a href="#h">h</a> <a href="#r">r</a></td><td>smb Read Block Data: read data from register </td><td><small><a href="cif.html#i2cReadBlockData">i2cReadBlockData</a></small></td></tr><tr><td><a href="#I2CWK">I2CWK</a> <a href="#h">h</a> <a href="#r">r</a> <a href="#bvs">bvs</a></td><td>smb Write Block Data: write data to register </td><td><small><a href="cif.html#i2cWriteBlockData">i2cWriteBlockData</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#I2CWI">I2CWI</a> <a href="#h">h</a> <a href="#r">r</a> <a href="#bvs">bvs</a></td><td>smb Write I2C Block Data                          </td><td><small><a href="cif.html#i2cWriteI2CBlockData">i2cWriteI2CBlockData</a></small></td></tr><tr><td><a href="#I2CRI">I2CRI</a> <a href="#h">h</a> <a href="#r">r</a> <a href="#num">num</a></td><td>smb Read I2C Block Data: read bytes from register </td><td><small><a href="cif.html#i2cReadI2CBlockData">i2cReadI2CBlockData</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#I2CRD">I2CRD</a> <a href="#h">h</a> <a href="#num">num</a></td><td>i2c Read device  </td><td><small><a href="cif.html#i2cReadDevice">i2cReadDevice</a></small></td></tr><tr><td><a href="#I2CWD">I2CWD</a> <a href="#h">h</a> <a href="#bvs">bvs</a></td><td>i2c Write device </td><td><small><a href="cif.html#i2cWriteDevice">i2cWriteDevice</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#I2CPC">I2CPC</a> <a href="#h">h</a> <a href="#r">r</a> <a href="#wv">wv</a></td><td>smb Process Call: exchange register with word             </td><td><small><a href="cif.html#i2cProcessCall">i2cProcessCall</a></small></td></tr><tr><td><a href="#I2CPK">I2CPK</a> <a href="#h">h</a> <a href="#r">r</a> <a href="#bvs">bvs</a></td><td>smb Block Process Call: exchange data bytes with register </td><td><small><a href="cif.html#i2cBlockProcessCall">i2cBlockProcessCall</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#I2CZ">I2CZ</a> <a href="#h">h</a> <a href="#bvs">bvs</a></td><td>Performs multiple I2C transactions </td><td><small><a href="cif.html#i2cZip">i2cZip</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>I2C BIT BANG
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#BI2CO">BI2CO</a> <a href="#sda">sda</a> <a href="#scl">scl</a> <a href="#b">b</a></td><td>Open bit bang I2C  </td><td><small><a href="cif.html#bbI2COpen">bbI2COpen</a></small></td></tr><tr><td><a href="#BI2CC">BI2CC</a> <a href="#sda">sda</a></td><td>Close bit bang I2C </td><td><small><a href="cif.html#bbI2CClose">bbI2CClose</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#BI2CZ">BI2CZ</a> <a href="#sda">sda</a> <a href="#bvs">bvs</a></td><td>I2C bit bang multiple transactions </td><td><small><a href="cif.html#bbI2CZip">bbI2CZip</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>I2C/SPI SLAVE
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#BSCX">BSCX</a> <a href="#bctl">bctl</a> <a href="#bvs">bvs</a></td><td>BSC I2C/SPI transfer </td><td><small><a href="cif.html#bscXfer">bscXfer</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>SERIAL
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#SERO">SERO</a> <a href="#dev">dev</a> <a href="#b">b</a> <a href="#sef">sef</a></td><td>Open serial device dev at baud b with flags </td><td><small><a href="cif.html#serOpen">serOpen</a></small></td></tr><tr><td><a href="#SERC">SERC</a> <a href="#h">h</a></td><td>Close serial handle                         </td><td><small><a href="cif.html#serClose">serClose</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#SERRB">SERRB</a></td><td>Read byte from serial handle  </td><td><small><a href="cif.html#serReadByte">serReadByte</a></small></td></tr><tr><td><a href="#SERWB">SERWB</a> <a href="#h">h</a> <a href="#bv">bv</a></td><td>Write byte to serial handle   </td><td><small><a href="cif.html#serWriteByte">serWriteByte</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#SERR">SERR</a> <a href="#h">h</a> <a href="#num">num</a></td><td>Read bytes from serial handle </td><td><small><a href="cif.html#serRead">serRead</a></small></td></tr><tr><td><a href="#SERW">SERW</a> <a href="#h">h</a> <a href="#bvs">bvs</a></td><td>Write bytes to serial handle  </td><td><small><a href="cif.html#serWrite">serWrite</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#SERDA">SERDA</a> <a href="#h">h</a></td><td>Check for serial data ready to read </td><td><small><a href="cif.html#serDataAvailable">serDataAvailable</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>SERIAL BIT BANG (read only)
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#SLRO">SLRO</a> <a href="#u">u</a> <a href="#b">b</a> <a href="#db">db</a></td><td>Open GPIO for bit bang serial data     </td><td><small><a href="cif.html#gpioSerialReadOpen">gpioSerialReadOpen</a></small></td></tr><tr><td><a href="#SLRC">SLRC</a> <a href="#u">u</a></td><td>Close GPIO for bit bang serial data    </td><td><small><a href="cif.html#gpioSerialReadClose">gpioSerialReadClose</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#SLRI">SLRI</a> <a href="#u">u</a> <a href="#v">v</a></td><td>Sets bit bang serial data logic levels </td><td><small><a href="cif.html#gpioSerialReadInvert">gpioSerialReadInvert</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#SLR">SLR</a> <a href="#u">u</a> <a href="#num">num</a></td><td>Read bit bang serial data from GPIO    </td><td><small><a href="cif.html#gpioSerialRead">gpioSerialRead</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>SPI
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#SPIO">SPIO</a> <a href="#c">c</a> <a href="#b">b</a> <a href="#spf">spf</a></td><td>SPI open channel at baud b with flags </td><td><small><a href="cif.html#spiOpen">spiOpen</a></small></td></tr><tr><td><a href="#SPIC">SPIC</a> <a href="#h">h</a></td><td>SPI close handle                    </td><td><small><a href="cif.html#spiClose">spiClose</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#SPIR">SPIR</a> <a href="#h">h</a> <a href="#num">num</a></td><td>SPI read bytes from handle          </td><td><small><a href="cif.html#spiRead">spiRead</a></small></td></tr><tr><td><a href="#SPIW">SPIW</a> <a href="#h">h</a> <a href="#bvs">bvs</a></td><td>SPI write bytes to handle           </td><td><small><a href="cif.html#spiWrite">spiWrite</a></small></td></tr><tr><td><a href="#SPIX">SPIX</a> <a href="#h">h</a> <a href="#bvs">bvs</a></td><td>SPI transfer bytes to handle        </td><td><small><a href="cif.html#spiXfer">spiXfer</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>SPI BIT BANG
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#BSPIO">BSPIO</a> <a href="#cs">cs</a> <a href="#miso">miso</a> <a href="#mosi">mosi</a> <a href="#sclk">sclk</a> <a href="#b">b</a> <a href="#spf">spf</a></td><td>Open bit bang SPI      </td><td><small><a href="cif.html#bbSPIOpen">bbSPIOpen</a></small></td></tr><tr><td><a href="#BSPIC">BSPIC</a> <a href="#cs">cs</a></td><td>Close bit bang SPI    </td><td><small><a href="cif.html#bbSPIClose">bbSPIClose</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#BSPIX">BSPIX</a> <a href="#cs">cs</a> <a href="#bvs">bvs</a></td><td>SPI bit bang transfer </td><td><small><a href="cif.html#bbSPIXfer">bbSPIXfer</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>FILES
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#FO">FO</a> <a href="#file">file</a> <a href="#mode">mode</a></td><td>Open a file in mode            </td><td><small><a href="cif.html#fileOpen">fileOpen</a></small></td></tr><tr><td><a href="#FC">FC</a> <a href="#h">h</a></td><td>Close file handle              </td><td><small><a href="cif.html#fileClose">fileClose</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#FR">FR</a> <a href="#h">h</a> <a href="#num">num</a></td><td>Read bytes from file handle    </td><td><small><a href="cif.html#fileRead">fileRead</a></small></td></tr><tr><td><a href="#FW">FW</a> <a href="#h">h</a> <a href="#bvs">bvs</a></td><td>Write bytes to file handle     </td><td><small><a href="cif.html#fileWrite">fileWrite</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#FS">FS</a> <a href="#h">h</a> <a href="#num">num</a> <a href="#from">from</a></td><td>Seek to file handle position   </td><td><small><a href="cif.html#fileSeek">fileSeek</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#FL">FL</a> <a href="#pat">pat</a> <a href="#num">num</a></td><td>List files which match pattern </td><td><small><a href="cif.html#fileList">fileList</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>WAVES
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#WVCLR">WVCLR</a></td><td>Clear all waveforms </td><td><small><a href="cif.html#gpioWaveClear">gpioWaveClear</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#WVNEW">WVNEW</a></td><td>Initialise a new waveform    </td><td><small><a href="cif.html#gpioWaveAddNew">gpioWaveAddNew</a></small></td></tr><tr><td><a href="#WVAG">WVAG</a> <a href="#trips">trips</a></td><td>Add generic pulses to waveform </td><td><small><a href="cif.html#gpioWaveAddGeneric">gpioWaveAddGeneric</a></small></td></tr><tr><td><a href="#WVAS">WVAS</a> <a href="#u">u</a> <a href="#b">b</a> <a href="#db">db</a> <a href="#sb">sb</a> <a href="#o">o</a> <a href="#bvs">bvs</a></td><td>Add serial data to waveform    </td><td><small><a href="cif.html#gpioWaveAddSerial">gpioWaveAddSerial</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#WVCRE">WVCRE</a></td><td>Create a waveform   </td><td><small><a href="cif.html#gpioWaveCreate">gpioWaveCreate</a></small></td></tr><tr><td><a href="#WVCAP">WVCAP</a> <a href="#percent">percent</a></td><td>Create a waveform of fixed size </td><td><small><a href="cif.html#gpioWaveCreatePad">gpioWaveCreatePad</a></small></td></tr><tr><td><a href="#WVDEL">WVDEL</a> <a href="#wid">wid</a></td><td>Delete selected waveform </td><td><small><a href="cif.html#gpioWaveDelete">gpioWaveDelete</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#WVTX">WVTX</a> <a href="#wid">wid</a></td><td>Transmits waveform once       </td><td><small><a href="cif.html#gpioWaveTxSend">gpioWaveTxSend</a></small></td></tr><tr><td><a href="#WVTXM">WVTXM</a> <a href="#wid">wid</a> <a href="#wmde">wmde</a></td><td>Transmits waveform using mode </td><td><small><a href="cif.html#gpioWaveTxSend">gpioWaveTxSend</a></small></td></tr><tr><td><a href="#WVTXR">WVTXR</a> <a href="#wid">wid</a></td><td>Transmits waveform repeatedly </td><td><small><a href="cif.html#gpioWaveTxSend">gpioWaveTxSend</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#WVCHA">WVCHA</a> <a href="#bvs">bvs</a></td><td>Transmits a chain of waveforms </td><td><small><a href="cif.html#gpioWaveChain">gpioWaveChain</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#WVTAT">WVTAT</a></td><td>Returns the current transmitting waveform </td><td><small><a href="cif.html#gpioWaveTxAt">gpioWaveTxAt</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#WVBSY">WVBSY</a></td><td>Check if waveform is being transmitted </td><td><small><a href="cif.html#gpioWaveTxBusy">gpioWaveTxBusy</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#WVHLT">WVHLT</a></td><td>Stop waveform </td><td><small><a href="cif.html#gpioWaveTxStop">gpioWaveTxStop</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#WVSC">WVSC</a> <a href="#ws">ws</a></td><td>Get waveform DMA CB stats    </td><td><small><a href="cif.html#gpioWaveGetCbs">gpioWaveGetCbs</a></small></td></tr><tr><td><a href="#WVSM">WVSM</a> <a href="#ws">ws</a></td><td>Get waveform time stats      </td><td><small><a href="cif.html#gpioWaveGetMicros">gpioWaveGetMicros</a></small></td></tr><tr><td><a href="#WVSP">WVSP</a> <a href="#ws">ws</a></td><td>Get waveform pulse stats     </td><td><small><a href="cif.html#gpioWaveGetPulses">gpioWaveGetPulses</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>UTILITIES
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#H/HELP">H/HELP</a></td><td>Display command help        </td><td><small><a href="cif.html#"></a></small></td></tr><tr><td><a href="#HWVER">HWVER</a></td><td>Get hardware version        </td><td><small><a href="cif.html#gpioHardwareRevision">gpioHardwareRevision</a></small></td></tr><tr><td><a href="#MICS">MICS</a> <a href="#v">v</a></td><td>Microseconds delay          </td><td><small><a href="cif.html#gpioDelay">gpioDelay</a></small></td></tr><tr><td><a href="#MILS">MILS</a> <a href="#v">v</a></td><td>Milliseconds delay          </td><td><small><a href="cif.html#gpioDelay">gpioDelay</a></small></td></tr><tr><td><a href="#PIGPV">PIGPV</a></td><td>Get pigpio library version  </td><td><small><a href="cif.html#gpioVersion">gpioVersion</a></small></td></tr><tr><td><a href="#T/TICK">T/TICK</a></td><td>Get current tick            </td><td><small><a href="cif.html#gpioTick">gpioTick</a></small></td></tr><tr><td></td><td></td><td></td></tr><tr><td>CONFIGURATION
</td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td><a href="#CGI">CGI</a></td><td>Configuration get internals </td><td><small><a href="cif.html#gpioCfgGetInternals">gpioCfgGetInternals</a></small></td></tr><tr><td><a href="#CSI">CSI</a> <a href="#v">v</a></td><td>Configuration set internals </td><td><small><a href="cif.html#gpioCfgSetInternals">gpioCfgSetInternals</a></small></td></tr><tr><td></td><td></td><td></td></tr></tbody></table><h2><a name="Commands">Commands</a></h2>
<h3><a name="BC1">BC1</a>
 <a href="#bits">bits</a> - Clear specified GPIO in bank 1</h3>This command clears (sets low) the GPIO specified by <a href="#bits">bits</a> in bank 1.
Bank 1 consists of GPIO 0-31.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;bc1&nbsp;0x400010&nbsp;#&nbsp;clear&nbsp;GPIO&nbsp;4&nbsp;(1&lt;&lt;4)&nbsp;and&nbsp;22&nbsp;(1&lt;&lt;22)<br><br>$&nbsp;pigs&nbsp;bc1&nbsp;32&nbsp;#&nbsp;clear&nbsp;GPIO&nbsp;5&nbsp;(1&lt;&lt;5)<br>-42<br>ERROR:&nbsp;no&nbsp;permission&nbsp;to&nbsp;update&nbsp;one&nbsp;or&nbsp;more&nbsp;GPIO<br></code><h3><a name="BC2">BC2</a>
 <a href="#bits">bits</a> - Clear specified GPIO in bank 2</h3>This command clears (sets low) the GPIO specified by <a href="#bits">bits</a> in bank 2.
Bank 2 consists of GPIO 32-53.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;bc2&nbsp;0x8000&nbsp;#&nbsp;clear&nbsp;GPIO&nbsp;47&nbsp;(activity&nbsp;LED&nbsp;on&nbsp;A+/B+/Pi2/Pi3)<br><br>$&nbsp;pigs&nbsp;bc2&nbsp;1&nbsp;#&nbsp;clear&nbsp;GPIO&nbsp;32&nbsp;(first&nbsp;in&nbsp;bank&nbsp;2)<br>-42<br>ERROR:&nbsp;no&nbsp;permission&nbsp;to&nbsp;update&nbsp;one&nbsp;or&nbsp;more&nbsp;GPIO<br></code><h3><a name="BI2CC">BI2CC</a>
 <a href="#sda">sda</a> - Close bit bang I2C</h3>This command signals that bit banging I2C on <a href="#sda">sda</a> (and <a href="#scl">scl</a>) is no
longer required.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;bi2cc&nbsp;5<br></code><h3><a name="BI2CO">BI2CO</a>
 <a href="#sda">sda</a> <a href="#scl">scl</a> <a href="#b">b</a> - Open bit bang I2C</h3>This command signals that GPIO <a href="#sda">sda</a> and <a href="#scl">scl</a> are to be used
for bit banging I2C at <a href="#b">b</a> baud.
<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>The baud rate may be between 50 and 500000 bits per second.
<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="BI2CZ">BI2CZ</a>
 <a href="#sda">sda</a> <a href="#bvs">bvs</a> - I2C bit bang multiple transactions</h3>This function executes a sequence of bit banged I2C operations.  The
operations to be performed are specified by the contents of <a href="#bvs">bvs</a>
which contains the concatenated command codes and associated data.
<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><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="BR1">BR1</a>
 - Read bank 1 GPIO</h3>This command read GPIO 0-31 (bank 1) and returns the levels as a
32-bit hexadecimal value.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;br1<br>1001C1CF<br></code><h3><a name="BR2">BR2</a>
 - Read bank 2 GPIO</h3>This command read GPIO 32-53 (bank 2) and returns the levels as a
32-bit hexadecimal value.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;br2<br>003F0000<br></code><h3><a name="BS1">BS1</a>
 <a href="#bits">bits</a> - Set specified GPIO in bank 1</h3>This command sets (sets high) the GPIO specified by <a href="#bits">bits</a> in bank 1.
Bank 1 consists of GPIO 0-31.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;bs1&nbsp;16&nbsp;#&nbsp;set&nbsp;GPIO&nbsp;4&nbsp;(1&lt;&lt;4)<br><br>$&nbsp;pigs&nbsp;bs1&nbsp;1&nbsp;#&nbsp;set&nbsp;GPIO&nbsp;1&nbsp;(1&lt;&lt;0)<br>-42<br>ERROR:&nbsp;no&nbsp;permission&nbsp;to&nbsp;update&nbsp;one&nbsp;or&nbsp;more&nbsp;GPIO<br></code><h3><a name="BS2">BS2</a>
 <a href="#bits">bits</a> - Set specified GPIO in bank 2</h3>This command sets (sets high) the GPIO specified by <a href="#bits">bits</a> in bank 2.
Bank 2 consists of GPIO 32-53.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;bs2&nbsp;0x40&nbsp;#&nbsp;set&nbsp;GPIO&nbsp;38&nbsp;(enable&nbsp;high&nbsp;current&nbsp;mode&nbsp;A+/B+/Pi2/Pi3)<br><br>$&nbsp;pigs&nbsp;bs2&nbsp;1&nbsp;#&nbsp;set&nbsp;GPIO&nbsp;32&nbsp;(first&nbsp;in&nbsp;bank&nbsp;2)<br>-42<br>ERROR:&nbsp;no&nbsp;permission&nbsp;to&nbsp;update&nbsp;one&nbsp;or&nbsp;more&nbsp;GPIO<br></code><h3><a name="BSCX">BSCX</a>
 <a href="#bctl">bctl</a> <a href="#bvs">bvs</a> - BSC I2C/SPI transfer</h3>This command performs a BSC I2C/SPI slave transfer as defined by
<a href="#bctl">bctl</a> with data <a href="#bvs">bvs</a>.
<br><br>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>I can't get SPI to work properly.  I tried with a
control word of 0x303 and swapped MISO and MOSI.
<br><br>The command sets the BSC mode and writes any data <a href="#bvs">bvs</a>
to the BSC transmit FIFO.  It returns the data count (at least 1
for the status word), the status word, followed by any data bytes
read from the BSC receive FIFO.
<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>For I2C use a control word of (I2C address &lt;&lt; 16) + 0x305.
<br><br>E.g. to talk as I2C slave with address 0x13 use 0x130305.
<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>18</td><td>19</td><td>20</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>10</td><td>11</td><td>9</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 control word 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 receieve 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>This example assumes that GPIO 2/3 are connected to GPIO 18/19
(GPIO 10/11 on the BCM2711).
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;bscx&nbsp;0x130305&nbsp;#&nbsp;start&nbsp;BSC&nbsp;as&nbsp;I2C&nbsp;slave&nbsp;0x13<br>1&nbsp;18<br><br>$&nbsp;i2cdetect&nbsp;-y&nbsp;1<br>&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;&nbsp;a&nbsp;&nbsp;b&nbsp;&nbsp;c&nbsp;&nbsp;d&nbsp;&nbsp;e&nbsp;&nbsp;f<br>00:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br>10:&nbsp;--&nbsp;--&nbsp;--&nbsp;13&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br>20:&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br>30:&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br>40:&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br>50:&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br>60:&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br>70:&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--&nbsp;--<br><br>$&nbsp;pigs&nbsp;i2co&nbsp;1&nbsp;0x13&nbsp;0&nbsp;#&nbsp;get&nbsp;handle&nbsp;for&nbsp;device&nbsp;0x13&nbsp;on&nbsp;bus&nbsp;1<br>0<br><br>$&nbsp;pigs&nbsp;i2cwd&nbsp;0&nbsp;90&nbsp;87&nbsp;51&nbsp;9&nbsp;23&nbsp;#&nbsp;write&nbsp;5&nbsp;bytes<br><br>$&nbsp;pigs&nbsp;bscx&nbsp;0x130305&nbsp;#&nbsp;check&nbsp;for&nbsp;data<br>6&nbsp;18&nbsp;90&nbsp;87&nbsp;51&nbsp;9&nbsp;23<br><br>$&nbsp;pigs&nbsp;bscx&nbsp;0x130305&nbsp;11&nbsp;13&nbsp;15&nbsp;17&nbsp;#&nbsp;check&nbsp;for&nbsp;data&nbsp;and&nbsp;send&nbsp;4&nbsp;bytes<br>1&nbsp;262338<br><br>$&nbsp;pigs&nbsp;i2crd&nbsp;0&nbsp;4&nbsp;#&nbsp;read&nbsp;4&nbsp;bytes<br>4&nbsp;11&nbsp;13&nbsp;15&nbsp;17<br><br>$&nbsp;pigs&nbsp;i2cwd&nbsp;0&nbsp;90&nbsp;87&nbsp;51&nbsp;9&nbsp;23&nbsp;#&nbsp;write&nbsp;5&nbsp;bytes<br>$&nbsp;pigs&nbsp;bscx&nbsp;0x130305&nbsp;11&nbsp;13&nbsp;15&nbsp;17&nbsp;#&nbsp;check&nbsp;for&nbsp;data&nbsp;and&nbsp;send&nbsp;4&nbsp;bytes<br>6&nbsp;262338&nbsp;90&nbsp;87&nbsp;51&nbsp;9&nbsp;23<br><br>$&nbsp;pigs&nbsp;i2crd&nbsp;0&nbsp;4<br>4&nbsp;11&nbsp;13&nbsp;15&nbsp;17<br><br>$&nbsp;pigs&nbsp;bscx&nbsp;0x130305&nbsp;22&nbsp;33&nbsp;44&nbsp;55&nbsp;66<br>1&nbsp;327938<br>$&nbsp;pigs&nbsp;i2crd&nbsp;0&nbsp;5<br>5&nbsp;22&nbsp;33&nbsp;44&nbsp;55&nbsp;66<br></code><h3><a name="BSPIC">BSPIC</a>
 <a href="#cs">cs</a> - Close bit bang SPI</h3>This command stops bit banging SPI on a set of GPIO
opened with <a href="#BSPIO">BSPIO</a>.
<br><br>The set of GPIO is specifed by <a href="#cs">cs</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;bspic&nbsp;10<br><br>$&nbsp;pigs&nbsp;bspic&nbsp;10<br>-142<br>ERROR:&nbsp;no&nbsp;bit&nbsp;bang&nbsp;SPI&nbsp;in&nbsp;progress&nbsp;on&nbsp;GPIO<br></code><h3><a name="BSPIO">BSPIO</a>
 <a href="#cs">cs</a> <a href="#miso">miso</a> <a href="#mosi">mosi</a> <a href="#sclk">sclk</a> <a href="#b">b</a> <a href="#spf">spf</a> - Open bit bang SPI</h3>This command starts bit banging SPI on a group of GPIO with slave
select <a href="#cs">cs</a>, MISO <a href="#miso">miso</a>, MOSI <a href="#mosi">mosi</a>, and clock <a href="#sclk">sclk</a>.
<br><br>Data will be transferred at baud <a href="#b">b</a> bits per second (which may
be set in the range 50-250000).
<br><br>The flags <a href="#spf">spf</a> may be used to modify the default behaviour of
mode 0, active low chip select.
<br><br>The flags 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.
<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>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>Upon success 0 is returned.  On error a negative status code
will be returned.
<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>$&nbsp;pigs&nbsp;bspio&nbsp;&nbsp;9&nbsp;11&nbsp;12&nbsp;13&nbsp;50000&nbsp;0<br><br>$&nbsp;pigs&nbsp;bspio&nbsp;10&nbsp;11&nbsp;12&nbsp;13&nbsp;50000&nbsp;0<br><br>$&nbsp;pigs&nbsp;bspio&nbsp;29&nbsp;19&nbsp;20&nbsp;21&nbsp;50000&nbsp;0&nbsp;#&nbsp;GPIO&nbsp;29&nbsp;not&nbsp;avaialble&nbsp;on&nbsp;this&nbsp;Pi<br>-41<br>ERROR:&nbsp;no&nbsp;permission&nbsp;to&nbsp;update&nbsp;GPIO<br></code><h3><a name="BSPIX">BSPIX</a>
 <a href="#cs">cs</a> <a href="#bvs">bvs</a> - SPI bit bang transfer</h3>This command writes bytes <a href="#bvs">bvs</a> to the bit bang SPI device
associated with slave select <a href="#cs">cs</a>.  It returns the same
number of bytes read from the device.
<br><br>Upon success the count of returned bytes followed by the bytes themselves
is returned.  On error a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;bspio&nbsp;5&nbsp;13&nbsp;19&nbsp;12&nbsp;10000&nbsp;0&nbsp;#&nbsp;MCP4251&nbsp;DAC<br>$&nbsp;pigs&nbsp;bspio&nbsp;6&nbsp;13&nbsp;19&nbsp;12&nbsp;20000&nbsp;3&nbsp;#&nbsp;MCP3008&nbsp;ADC<br><br>$&nbsp;pigs&nbsp;bspix&nbsp;5&nbsp;0&nbsp;16&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;set&nbsp;DAC&nbsp;to&nbsp;16<br>2&nbsp;255&nbsp;255<br><br>$&nbsp;pigs&nbsp;bspix&nbsp;5&nbsp;12&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;read&nbsp;back&nbsp;DAC<br>2&nbsp;254&nbsp;16<br><br>$&nbsp;pigs&nbsp;bspix&nbsp;6&nbsp;1&nbsp;128&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;read&nbsp;ADC&nbsp;input&nbsp;0<br>3&nbsp;0&nbsp;3&nbsp;184&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;952<br><br>$&nbsp;pigs&nbsp;bspix&nbsp;5&nbsp;0&nbsp;240&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;set&nbsp;DAC&nbsp;to&nbsp;240<br>2&nbsp;255&nbsp;255<br><br>$&nbsp;pigs&nbsp;bspix&nbsp;5&nbsp;12&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;read&nbsp;back&nbsp;DAC<br>2&nbsp;254&nbsp;240<br><br>$&nbsp;pigs&nbsp;bspix&nbsp;6&nbsp;1&nbsp;128&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;read&nbsp;ADC&nbsp;input&nbsp;0<br>3&nbsp;0&nbsp;0&nbsp;63&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;63<br><br>$&nbsp;pigs&nbsp;bspix&nbsp;5&nbsp;0&nbsp;128&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;set&nbsp;DAC&nbsp;to&nbsp;128<br>2&nbsp;255&nbsp;255<br><br>$&nbsp;pigs&nbsp;bspix&nbsp;5&nbsp;12&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;read&nbsp;back&nbsp;DAC<br>2&nbsp;254&nbsp;128<br><br>$&nbsp;pigs&nbsp;bspix&nbsp;6&nbsp;1&nbsp;128&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;read&nbsp;ADC&nbsp;input&nbsp;0<br>3&nbsp;0&nbsp;1&nbsp;255&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;511<br><br>$&nbsp;pigs&nbsp;bspic&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;close&nbsp;SPI&nbsp;CS&nbsp;5<br>$&nbsp;pigs&nbsp;bspic&nbsp;6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;close&nbsp;SPI&nbsp;CS&nbsp;6<br><br>$&nbsp;pigs&nbsp;bspic&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;try&nbsp;to&nbsp;close&nbsp;SPI&nbsp;CS&nbsp;5&nbsp;again<br>-142<br>ERROR:&nbsp;no&nbsp;bit&nbsp;bang&nbsp;SPI&nbsp;in&nbsp;progress&nbsp;on&nbsp;GPIO<br></code><h3><a name="CF1">CF1</a>
 <a href="#uvs">uvs</a> - Custom function 1</h3>This command calls a user customised function.  The meaning of
any paramaters and the returned value is defined by the
customiser.
<h3><a name="CF2">CF2</a>
 <a href="#uvs">uvs</a> - Custom function 2</h3>This command calls a user customised function.  The meaning of
any paramaters and the returned value is defined by the
customiser.
<h3><a name="CGI">CGI</a>
 - Configuration get internals</h3>This command returns the value of the internal library
configuration settings.
<h3><a name="CSI">CSI</a>
 <a href="#v">v</a> - Configuration set internals</h3>This command sets the value of the internal library
configuration settings to <a href="#v">v</a>.
<h3><a name="EVM">EVM</a>
 <a href="#h">h</a> <a href="#bits">bits</a> - Set events to monitor</h3>This command starts event reporting on handle <a href="#h">h</a> (returned by
a prior call to <a href="#NO">NO</a>).
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>The notification gets reports for each event specified by <a href="#bits">bits</a>.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;evm&nbsp;0&nbsp;-1&nbsp;#&nbsp;Shorthand&nbsp;for&nbsp;events&nbsp;0-31.<br>$&nbsp;pigs&nbsp;evm&nbsp;0&nbsp;0xf0&nbsp;#&nbsp;Get&nbsp;notifications&nbsp;for&nbsp;events&nbsp;4-7.<br><br>$&nbsp;pigs&nbsp;evm&nbsp;1&nbsp;0xf<br>-25<br>ERROR:&nbsp;unknown&nbsp;handle<br></code><h3><a name="EVT">EVT</a>
 <a href="#event">event</a> - Trigger event</h3>This command triggers event <a href="#event">event</a>.
<br><br>One event, number 31, is predefined.  This event is
auto generated on BSC slave activity.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;evt&nbsp;12<br>$&nbsp;pigs&nbsp;evt&nbsp;5<br><br>$&nbsp;pigs&nbsp;evt&nbsp;32<br>-143<br>ERROR:&nbsp;bad&nbsp;event&nbsp;id<br></code><h3><a name="FC">FC</a>
 <a href="#h">h</a> - Close file handle</h3>This command closes a file handle <a href="#h">h</a> previously opened with <a href="#FO">FO</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;fc&nbsp;0&nbsp;#&nbsp;First&nbsp;close&nbsp;okay.<br><br>$&nbsp;pigs&nbsp;fc&nbsp;0&nbsp;#&nbsp;Second&nbsp;fails.<br>-25<br>ERROR:&nbsp;unknown&nbsp;handle<br></code><h3><a name="FG">FG</a>
 <a href="#u">u</a> <a href="#stdy">stdy</a> - Set a glitch filter on a GPIO</h3>Level changes on the GPIO <a href="#u">u</a> are not reported unless the level
has been stable for at least <a href="#stdy">stdy</a> microseconds.  The
level is then reported.  Level changes of less than <a href="#stdy">stdy</a>
microseconds are ignored.
<br><br>The filter only affects callbacks (including pipe notifications).
<br><br>The <a href="#R/READ">R/READ</a>, <a href="#BR1">BR1</a>, and <a href="#BR2">BR2</a> commands are not affected.
<br><br>Note, each (stable) edge will be timestamped <a href="#stdy">stdy</a> microseconds
after it was first detected.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;fg&nbsp;4&nbsp;250<br><br>$&nbsp;pigs&nbsp;fg&nbsp;4&nbsp;1000000<br>-125<br>ERROR:&nbsp;bad&nbsp;filter&nbsp;parameter<br></code><h3><a name="FL">FL</a>
 <a href="#pat">pat</a> <a href="#num">num</a> - List files which match pattern</h3>This command returns a list of the files matching <a href="#pat">pat</a>. Up
to <a href="#num">num</a> bytes may be returned.
<br><br>Upon success the count of returned bytes followed by the matching
files is returned.  On error a negative status code will be returned.
<br><br>A newline (0x0a) character separates each file name.
<br><br>Only files which have a matching entry in /opt/pigpio/access may
be listed.
<br><br>Suppose /opt/pigpio/access contains
<br><br>/sys/bus/w1/devices/28*/w1_slave r
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;-a&nbsp;fl&nbsp;"/sys/bus/w1/devices/28*/w1_slave"&nbsp;5000<br>90&nbsp;/sys/bus/w1/devices/28-000005d34cd2/w1_slave<br>/sys/bus/w1/devices/28-001414abbeff/w1_slave<br><br>$&nbsp;pigs&nbsp;-a&nbsp;fl&nbsp;"/sys/bus/*"&nbsp;5000<br>ERROR:&nbsp;no&nbsp;permission&nbsp;to&nbsp;access&nbsp;file<br>-137<br></code><h3><a name="FN">FN</a>
 <a href="#u">u</a> <a href="#stdy">stdy</a> <a href="#actv">actv</a> - Set a noise filter on a GPIO</h3>Level changes on the GPIO <a href="#u">u</a> are ignored until a level which has
been stable for <a href="#stdy">stdy</a> microseconds is detected.  Level
changes on the GPIO are then reported for <a href="#actv">actv</a> microseconds
after which the process repeats.
<br><br>The filter only affects callbacks (including pipe notifications).
<br><br>The <a href="#R/READ">R/READ</a>, <a href="#BR1">BR1</a>, and <a href="#BR2">BR2</a> commands are not affected.
<br><br>Note, level changes before and after the active period may
be reported.  Your software must be designed to cope with
such reports.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;fn&nbsp;7&nbsp;250&nbsp;1000<br><br>$&nbsp;pigs&nbsp;fn&nbsp;7&nbsp;2500000&nbsp;1000<br>-125<br>ERROR:&nbsp;bad&nbsp;filter&nbsp;parameter<br></code><h3><a name="FO">FO</a>
 <a href="#file">file</a> <a href="#mode">mode</a> - Open a file in mode</h3>This function returns a handle to a file <a href="#file">file</a> opened
in a specified mode <a href="#mode">mode</a>.
<br><br>Upon success a handle (&gt;=0) is returned.  On error a negative status code
will be returned.
<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></td><td>Value</td><td>Meaning</td></tr><tr><td>READ</td><td>1</td><td>open file for reading</td></tr><tr><td>WRITE</td><td>2</td><td>open file for writing</td></tr><tr><td>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></td><td>Value</td><td>Meaning</td></tr><tr><td>APPEND</td><td>4</td><td>All writes append data to the end of the file</td></tr><tr><td>CREATE</td><td>8</td><td>The file is created if it doesn't exist</td></tr><tr><td>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>$&nbsp;ls&nbsp;/ram/*.c<br>/ram/command.c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/ram/pigpiod.c&nbsp;&nbsp;/ram/pigs.c<br>/ram/x_pigpiod_if.c&nbsp;/ram/pig2vcd.c&nbsp;&nbsp;/ram/pigpiod_if2.c<br>/ram/x_pigpio.c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/ram/x_repeat.c&nbsp;/ram/pigpio.c<br>/ram/pigpiod_if.c&nbsp;&nbsp;&nbsp;/ram/x_pigpiod_if2.c<br><br>#&nbsp;assumes&nbsp;/opt/pigpio/access&nbsp;contains&nbsp;the&nbsp;following&nbsp;line<br>#&nbsp;/ram/*.c&nbsp;r<br><br>$&nbsp;pigs&nbsp;fo&nbsp;/ram/pigpio.c&nbsp;1<br>0<br><br>$&nbsp;pigs&nbsp;fo&nbsp;/ram/new.c&nbsp;1<br>-128<br>ERROR:&nbsp;file&nbsp;open&nbsp;failed<br><br>$&nbsp;pigs&nbsp;fo&nbsp;/ram/new.c&nbsp;9<br>1<br><br>$&nbsp;ls&nbsp;/ram/*.c&nbsp;-l<br>-rw-r--r--&nbsp;1&nbsp;joan&nbsp;joan&nbsp;&nbsp;42923&nbsp;Jul&nbsp;10&nbsp;11:22&nbsp;/ram/command.c<br>-rw-------&nbsp;1&nbsp;root&nbsp;root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;Jul&nbsp;10&nbsp;16:54&nbsp;/ram/new.c<br>-rw-r--r--&nbsp;1&nbsp;joan&nbsp;joan&nbsp;&nbsp;&nbsp;2971&nbsp;Jul&nbsp;10&nbsp;11:22&nbsp;/ram/pig2vcd.c<br>-rw-------&nbsp;1&nbsp;joan&nbsp;joan&nbsp;296235&nbsp;Jul&nbsp;10&nbsp;11:22&nbsp;/ram/pigpio.c<br>-rw-r--r--&nbsp;1&nbsp;joan&nbsp;joan&nbsp;&nbsp;&nbsp;9266&nbsp;Jul&nbsp;10&nbsp;11:22&nbsp;/ram/pigpiod.c<br>-rw-r--r--&nbsp;1&nbsp;joan&nbsp;joan&nbsp;&nbsp;37331&nbsp;Jul&nbsp;10&nbsp;11:22&nbsp;/ram/pigpiod_if2.c<br>-rw-r--r--&nbsp;1&nbsp;joan&nbsp;joan&nbsp;&nbsp;33088&nbsp;Jul&nbsp;10&nbsp;11:22&nbsp;/ram/pigpiod_if.c<br>-rw-r--r--&nbsp;1&nbsp;joan&nbsp;joan&nbsp;&nbsp;&nbsp;7990&nbsp;Jul&nbsp;10&nbsp;11:22&nbsp;/ram/pigs.c<br>-rw-r--r--&nbsp;1&nbsp;joan&nbsp;joan&nbsp;&nbsp;19970&nbsp;Jul&nbsp;10&nbsp;11:22&nbsp;/ram/x_pigpio.c<br>-rw-r--r--&nbsp;1&nbsp;joan&nbsp;joan&nbsp;&nbsp;20804&nbsp;Jul&nbsp;10&nbsp;11:22&nbsp;/ram/x_pigpiod_if2.c<br>-rw-r--r--&nbsp;1&nbsp;joan&nbsp;joan&nbsp;&nbsp;19844&nbsp;Jul&nbsp;10&nbsp;11:22&nbsp;/ram/x_pigpiod_if.c<br>-rw-r--r--&nbsp;1&nbsp;joan&nbsp;joan&nbsp;&nbsp;19907&nbsp;Jul&nbsp;10&nbsp;11:22&nbsp;/ram/x_repeat.c<br></code><h3><a name="FR">FR</a>
 <a href="#h">h</a> <a href="#num">num</a> - Read bytes from file handle</h3>This command returns up to <a href="#num">num</a> bytes of data read from the
file associated with handle <a href="#h">h</a>.
<br><br>Upon success the count of returned bytes followed by the bytes themselves
is returned.  On error a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;fr&nbsp;0&nbsp;10<br>5&nbsp;48&nbsp;49&nbsp;128&nbsp;144&nbsp;255<br><br>$&nbsp;pigs&nbsp;fr&nbsp;0&nbsp;10<br>0<br></code><h3><a name="FS">FS</a>
 <a href="#h">h</a> <a href="#num">num</a> <a href="#from">from</a> - Seek to file handle position</h3>This command seeks to a position within the file associated
with handle <a href="#h">h</a>.
<br><br>The number of bytes to move is <a href="#num">num</a>.  Positive offsets
move forward, negative offsets backwards.  The move start
position is determined by <a href="#from">from</a> as follows.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td>From</td></tr><tr><td>0</td><td>start</td></tr><tr><td>1</td><td>current position</td></tr><tr><td>2</td><td>end</td></tr></tbody></table><br><br>Upon success the new byte position within the file (&gt;=0) is
returned.  On error a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;fs&nbsp;0&nbsp;200&nbsp;0&nbsp;#&nbsp;Seek&nbsp;to&nbsp;start&nbsp;of&nbsp;file&nbsp;plus&nbsp;200<br>200<br><br>$&nbsp;pigs&nbsp;fs&nbsp;0&nbsp;0&nbsp;1&nbsp;#&nbsp;Return&nbsp;current&nbsp;position<br>200<br><br>$&nbsp;pigs&nbsp;fs&nbsp;0&nbsp;0&nbsp;2&nbsp;#&nbsp;Seek&nbsp;to&nbsp;end&nbsp;of&nbsp;file,&nbsp;return&nbsp;size<br>296235<br></code><h3><a name="FW">FW</a>
 <a href="#h">h</a> <a href="#bvs">bvs</a> - Write bytes to file handle</h3>This command writes bytes <a href="#bvs">bvs</a> to the file
associated with handle <a href="#h">h</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;fw&nbsp;0&nbsp;23&nbsp;45&nbsp;67&nbsp;89<br></code><h3><a name="GDC">GDC</a>
 <a href="#u">u</a> - Get GPIO PWM dutycycle</h3>This command returns the PWM dutycycle in use on GPIO <a href="#u">u</a>.
<br><br>Upon success the dutycycle is returned.  On error a negative
status code will be returned.
<br><br>For normal PWM the dutycycle will be out of the defined range
for the GPIO (see <a href="#PRG">PRG</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><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;p&nbsp;4&nbsp;129<br>$&nbsp;pigs&nbsp;gdc&nbsp;4<br>129<br><br>pigs&nbsp;gdc&nbsp;5<br>-92<br>ERROR:&nbsp;GPIO&nbsp;is&nbsp;not&nbsp;in&nbsp;use&nbsp;for&nbsp;PWM<br></code><h3><a name="GPW">GPW</a>
 <a href="#u">u</a> - Get GPIO servo pulsewidth</h3>This command returns the servo pulsewidth in use on GPIO <a href="#u">u</a>.
<br><br>Upon success the servo pulsewidth is returned.  On error a negative
status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;s&nbsp;4&nbsp;1235<br>$&nbsp;pigs&nbsp;gpw&nbsp;4<br>1235<br><br>$&nbsp;pigs&nbsp;gpw&nbsp;9<br>-93<br>ERROR:&nbsp;GPIO&nbsp;is&nbsp;not&nbsp;in&nbsp;use&nbsp;for&nbsp;servo&nbsp;pulses<br></code><h3><a name="H/HELP">H/HELP</a>
 - Display command help</h3>This command displays a brief list of the commands and their parameters.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;h<br><br>$&nbsp;pigs&nbsp;help<br></code><h3><a name="HC">HC</a>
 <a href="#g">g</a> <a href="#cf">cf</a> - Set hardware clock frequency</h3>This command sets the hardware clock associated with GPIO <a href="#g">g</a> to
frequency <a href="#cf">cf</a>. Frequencies above 30MHz are unlikely to work.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;hc&nbsp;4&nbsp;5000&nbsp;#&nbsp;start&nbsp;a&nbsp;5&nbsp;KHz&nbsp;clock&nbsp;on&nbsp;GPIO&nbsp;4&nbsp;(clock&nbsp;0)<br><br>$&nbsp;pigs&nbsp;hc&nbsp;5&nbsp;5000000&nbsp;#&nbsp;start&nbsp;a&nbsp;5&nbsp;MHz&nbsp;clcok&nbsp;on&nbsp;GPIO&nbsp;5&nbsp;(clock&nbsp;1)<br>-99<br>ERROR:&nbsp;need&nbsp;password&nbsp;to&nbsp;use&nbsp;hardware&nbsp;clock&nbsp;1<br></code><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><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>4</td><td>clock 0</td><td>All models</td></tr><tr><td>5</td><td>clock 1</td><td>All models but A and B (reserved for system use)</td></tr><tr><td>6</td><td>clock 2</td><td>All models but A and B</td></tr><tr><td>20</td><td>clock 0</td><td>All models but A and B</td></tr><tr><td>21</td><td>clock 1</td><td>All models but A and B Rev.2 (reserved for system use)</td></tr></tbody></table><br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>32</td><td>clock 0</td><td>Compute module only</td></tr><tr><td>34</td><td>clock 0</td><td>Compute module only</td></tr><tr><td>42</td><td>clock 1</td><td>Compute module only (reserved for system use)</td></tr><tr><td>43</td><td>clock 2</td><td>Compute module only</td></tr><tr><td>44</td><td>clock 1</td><td>Compute module only (reserved for system use)</td></tr></tbody></table><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="HP">HP</a>
 <a href="#g">g</a> <a href="#pf">pf</a> <a href="#pdc">pdc</a> - Set hardware PWM frequency and dutycycle</h3>This command sets the hardware PWM associated with GPIO <a href="#g">g</a> to
frequency <a href="#pf">pf</a> with dutycycle <a href="#pdc">pdc</a>. Frequencies above 30MHz
are unlikely to work.
<br><br>NOTE: Any waveform started by <a href="#WVTX">WVTX</a>, <a href="#WVTXR">WVTXR</a>, or <a href="#WVCHA">WVCHA</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 when the pigpio
daemon is started (option -t).
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><code>$&nbsp;pigs&nbsp;hp&nbsp;18&nbsp;100&nbsp;800000&nbsp;#&nbsp;80%&nbsp;dutycycle<br><br>$&nbsp;pigs&nbsp;hp&nbsp;19&nbsp;100&nbsp;200000&nbsp;#&nbsp;20%&nbsp;dutycycle<br><br>$&nbsp;pigs&nbsp;hp&nbsp;19&nbsp;400000000&nbsp;100000<br>-96<br>ERROR:&nbsp;invalid&nbsp;hardware&nbsp;PWM&nbsp;frequency<br></code><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><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>12</td><td>PWM channel 0</td><td>All models but A and B</td></tr><tr><td>13</td><td>PWM channel 1</td><td>All models but A and B</td></tr><tr><td>18</td><td>PWM channel 0</td><td>All models</td></tr><tr><td>19</td><td>PWM channel 1</td><td>All models but A and B</td></tr></tbody></table><br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>40</td><td>PWM channel 0</td><td>Compute module only</td></tr><tr><td>41</td><td>PWM channel 1</td><td>Compute module only</td></tr><tr><td>45</td><td>PWM channel 1</td><td>Compute module only</td></tr><tr><td>52</td><td>PWM channel 0</td><td>Compute module only</td></tr><tr><td>53</td><td>PWM channel 1</td><td>Compute module only</td></tr></tbody></table><br><br>The actual number of steps beween off and fully on is the
integral part of 250M/<a href="#pf">pf</a> (375M/<a href="#pf">pf</a> 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 <a href="#pf">pf</a> of 250 (375 for
the BCM2711). Lower frequencies will have more steps and higher
frequencies will have fewer steps.  <a href="#pdc">pdc</a> is
automatically scaled to take this into account.
<h3><a name="HWVER">HWVER</a>
 - Get hardware version</h3>This command returns the hardware revision of the Pi.
<br><br>The hardware revision is found in the last 4 characters on the revision
line of /proc/cpuinfo.
<br><br>If the hardware revision can not be found or is not a valid hexadecimal
number the command returns 0.
<br><br>The revision number can be used to determine the assignment of GPIO
to pins (see <a href="#g">g</a>).
<br><br>There are currently 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 command returns 2.
<br><br>for "Revision : 000f" the command returns 15.
<br><br>for "Revision : 000g" the command returns 0.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;hwver&nbsp;#&nbsp;On&nbsp;a&nbsp;B+<br>16<br></code><h3><a name="I2CC">I2CC</a>
 <a href="#h">h</a> - Close I2C handle</h3>This command closes an I2C handle <a href="#h">h</a> previously opened with <a href="#I2CO">I2CO</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2cc&nbsp;0&nbsp;#&nbsp;First&nbsp;close&nbsp;okay.<br><br>$&nbsp;pigs&nbsp;i2cc&nbsp;0&nbsp;#&nbsp;Second&nbsp;fails.<br>-25<br>ERROR:&nbsp;unknown&nbsp;handle<br></code><h3><a name="I2CO">I2CO</a>
 <a href="#ib">ib</a> <a href="#id">id</a> <a href="#if">if</a> - Open I2C bus and device with flags</h3>This command returns a handle to access device <a href="#id">id</a> on I2C bus <a href="#ib">ib</a>.
The device is opened with flags <a href="#if">if</a>.
<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>No flags are currently defined.  The parameter <a href="#if">if</a> should be 0.
<br><br>Upon success the next free handle (&gt;=0) is returned.  On error a
negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2co&nbsp;1&nbsp;0x70&nbsp;0&nbsp;#&nbsp;Bus&nbsp;1,&nbsp;device&nbsp;0x70,&nbsp;flags&nbsp;0.<br>0<br><br>$&nbsp;pigs&nbsp;i2co&nbsp;1&nbsp;0x53&nbsp;0&nbsp;#&nbsp;Bus&nbsp;1,&nbsp;device&nbsp;0x53,&nbsp;flags&nbsp;0.<br>1<br></code><h3><a name="I2CPC">I2CPC</a>
 <a href="#h">h</a> <a href="#r">r</a> <a href="#wv">wv</a> - smb Process Call: exchange register with word</h3>This command writes <a href="#wv">wv</a> to register <a href="#r">r</a> of the I2C device
associated with handle <a href="#h">h</a> and returns a 16-bit word read from the
device.
<br><br>Upon success a value between 0 and 65535 will be returned.  On error
a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2cpc&nbsp;0&nbsp;37&nbsp;43210<br>39933<br><br>$&nbsp;pigs&nbsp;i2cpc&nbsp;0&nbsp;256&nbsp;43210<br>ERROR:&nbsp;bad&nbsp;i2c/spi/ser&nbsp;parameter<br>-81<br></code><h3><a name="I2CPK">I2CPK</a>
 <a href="#h">h</a> <a href="#r">r</a> <a href="#bvs">bvs</a> - smb Block Process Call: exchange data bytes with register</h3>This command writes the data bytes <a href="#bvs">bvs</a> to register <a href="#r">r</a> of the I2C device
associated with handle <a href="#h">h</a> and returns a device specific number of bytes.
<br><br>Upon success the count of returned bytes followed by the bytes themselves
is returned.  On error a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2cpk&nbsp;0&nbsp;0&nbsp;0x11&nbsp;0x12<br>6&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0<br></code><h3><a name="I2CRB">I2CRB</a>
 <a href="#h">h</a> <a href="#r">r</a> - smb Read Byte Data: read byte from register</h3>This command returns a single byte read from register <a href="#r">r</a> of the I2C device
associated with handle <a href="#h">h</a>.
<br><br>Upon success a value between 0 and 255 will be returned.  On error
a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2crb&nbsp;0&nbsp;0<br>6<br></code><h3><a name="I2CRD">I2CRD</a>
 <a href="#h">h</a> <a href="#num">num</a> - i2c Read device</h3>This command returns <a href="#num">num</a> bytes read from the I2C device associated with
handle <a href="#h">h</a>.
<br><br>Upon success the count of returned bytes followed by the bytes themselves
is returned.  On error a negative status code will be returned.
<br><br>This command operates on the raw I2C device.  The maximum value of the
parameter <a href="#num">num</a> is dependent on the I2C drivers and the device
itself. pigs imposes a limit of about 8000 bytes.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2crd&nbsp;0&nbsp;16<br>16&nbsp;6&nbsp;24&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;32&nbsp;78<br></code><h3><a name="I2CRI">I2CRI</a>
 <a href="#h">h</a> <a href="#r">r</a> <a href="#num">num</a> - smb Read I2C Block Data: read bytes from register</h3>This command returns <a href="#num">num</a> bytes from register <a href="#r">r</a> of the I2C device
associated with handle <a href="#h">h</a>.
<br><br>Upon success the count of returned bytes followed by the bytes themselves
is returned.  On error a negative status code will be returned.
<br><br>The parameter <a href="#num">num</a> may be 1-32.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2cri&nbsp;0&nbsp;0&nbsp;16<br>16&nbsp;237&nbsp;155&nbsp;155&nbsp;155&nbsp;155&nbsp;155&nbsp;155&nbsp;155&nbsp;155&nbsp;155&nbsp;155&nbsp;155&nbsp;155&nbsp;155&nbsp;155&nbsp;155<br></code><h3><a name="I2CRK">I2CRK</a>
 <a href="#h">h</a> <a href="#r">r</a> - smb Read Block Data: read data from register</h3>This command returns between 1 and 32 bytes read from register <a href="#r">r</a> of
the I2C device associated with handle <a href="#h">h</a>.
<br><br>Upon success the count of returned bytes followed by the bytes themselves
is returned.  On error a negative status code will be returned.
<br><br>The number of bytes of returned data is specific to the device and
register.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2crk&nbsp;0&nbsp;0<br>6&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0<br><br>$&nbsp;pigs&nbsp;i2crk&nbsp;0&nbsp;1<br>24&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;120&nbsp;222&nbsp;105&nbsp;215&nbsp;128&nbsp;87&nbsp;195&nbsp;217&nbsp;0&nbsp;0&nbsp;0&nbsp;0<br></code><h3><a name="I2CRS">I2CRS</a>
 <a href="#h">h</a> - smb Read Byte: read byte</h3>This command returns a single byte read from the I2C device
associated with handle <a href="#h">h</a>.
<br><br>Upon success a value between 0 and 255 will be returned.  On error
a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2crs&nbsp;0<br>0<br></code><h3><a name="I2CRW">I2CRW</a>
 <a href="#h">h</a> <a href="#r">r</a> - smb Read Word Data: read word from register</h3>This command returns a single 16 bit word read from register <a href="#r">r</a> of
the I2C device associated with handle <a href="#h">h</a>.
<br><br>Upon success a value between 0 and 65535 will be returned.  On error
a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2crw&nbsp;0&nbsp;0<br>6150<br></code><h3><a name="I2CWB">I2CWB</a>
 <a href="#h">h</a> <a href="#r">r</a> <a href="#bv">bv</a> - smb Write Byte Data: write byte to register</h3>This command writes a single byte <a href="#bv">bv</a> to register <a href="#r">r</a> of the
I2C device associated with handle <a href="#h">h</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2cwb&nbsp;0&nbsp;10&nbsp;0x54<br></code><h3><a name="I2CWD">I2CWD</a>
 <a href="#h">h</a> <a href="#bvs">bvs</a> - i2c Write device</h3>This command writes a block of bytes <a href="#bvs">bvs</a> to the I2C device
associated with handle <a href="#h">h</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>The number of bytes which may be written in one transaction is
dependent on the I2C drivers and the device itself.  pigs imposes
a limit of about 500 bytes.
<br><br>This command operates on the raw I2C device.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2cwd&nbsp;0&nbsp;0x01&nbsp;0x02&nbsp;0x03&nbsp;0x04<br></code><h3><a name="I2CWI">I2CWI</a>
 <a href="#h">h</a> <a href="#r">r</a> <a href="#bvs">bvs</a> - smb Write I2C Block Data</h3>This command writes between 1 and 32 bytes <a href="#bvs">bvs</a> to register <a href="#r">r</a> of
the I2C device associated with handle <a href="#h">h</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2cwi&nbsp;0&nbsp;4&nbsp;0x01&nbsp;0x04&nbsp;0xc0<br></code><h3><a name="I2CWK">I2CWK</a>
 <a href="#h">h</a> <a href="#r">r</a> <a href="#bvs">bvs</a> - smb Write Block Data: write data to register</h3>This command writes between 1 and 32 bytes <a href="#bvs">bvs</a> to register <a href="#r">r</a> of
the I2C device associated with handle <a href="#h">h</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>pigs&nbsp;i2cwk&nbsp;0&nbsp;4&nbsp;0x01&nbsp;0x04&nbsp;0xc0<br></code><h3><a name="I2CWQ">I2CWQ</a>
 <a href="#h">h</a> <a href="#bit">bit</a> - smb Write Quick: write bit</h3>This command writes a single <a href="#bit">bit</a> to the I2C device associated
with handle <a href="#h">h</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2cwq&nbsp;0&nbsp;1<br></code><h3><a name="I2CWS">I2CWS</a>
 <a href="#h">h</a> <a href="#bv">bv</a> - smb Write Byte: write byte</h3>This command writes a single byte <a href="#bv">bv</a> to the I2C device associated
with handle <a href="#h">h</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2cws&nbsp;0&nbsp;0x12<br><br>$&nbsp;pigs&nbsp;i2cws&nbsp;0&nbsp;0xff<br>-82<br>ERROR:&nbsp;I2C&nbsp;write&nbsp;failed<br></code><h3><a name="I2CWW">I2CWW</a>
 <a href="#h">h</a> <a href="#r">r</a> <a href="#wv">wv</a> - smb Write Word Data: write word to register</h3>This command writes a single 16 bit word <a href="#wv">wv</a> to register <a href="#r">r</a> of
the I2C device associated with handle <a href="#h">h</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;i2cww&nbsp;0&nbsp;0&nbsp;0xffff<br></code><h3><a name="I2CZ">I2CZ</a>
 <a href="#h">h</a> <a href="#bvs">bvs</a> - Performs multiple I2C transactions</h3>This command executes a sequence of I2C operations.  The
operations to be performed are specified by the contents of <a href="#bvs">bvs</a>
which contains the concatenated command codes and associated data.
<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 <a href="#h">h</a>.
The flags default to 0.  The address and flags maintain their
previous value until updated.
<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="M/MODES">M/MODES</a>
 <a href="#g">g</a> <a href="#m">m</a> - Set GPIO mode</h3>This command sets GPIO <a href="#g">g</a> to mode <a href="#m">m</a>, typically input (read)
or output (write).
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>Each GPIO can be configured to be in one of 8 different modes. The modes
are named Input, Output, ALT0, ALT1, ALT2, ALT3, ALT4, and ALT5.
<br><br>To set the mode use the code for the mode.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Mode</td><td>Input</td><td>Output</td><td>ALT0</td><td>ALT1</td><td>ALT2</td><td>ALT3</td><td>ALT4</td><td>ALT5</td></tr><tr><td>Code</td><td>R</td><td>W</td><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td></tr></tbody></table><br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;m&nbsp;4&nbsp;r&nbsp;#&nbsp;Input&nbsp;(read)<br>$&nbsp;pigs&nbsp;m&nbsp;4&nbsp;w&nbsp;#&nbsp;Output&nbsp;(write)<br>$&nbsp;pigs&nbsp;m&nbsp;4&nbsp;0&nbsp;#&nbsp;ALT&nbsp;0<br>$&nbsp;pigs&nbsp;m&nbsp;4&nbsp;5&nbsp;#&nbsp;ALT&nbsp;5<br></code><h3><a name="MG/MODEG">MG/MODEG</a>
 <a href="#g">g</a> - Get GPIO mode</h3>This command returns the current mode of GPIO <a href="#g">g</a>.
<br><br>Upon success the value of the GPIO mode is returned.
On error a negative status code will be returned.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Value</td><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr><tr><td>Mode</td><td>Input</td><td>Output</td><td>ALT5</td><td>ALT4</td><td>ALT0</td><td>ALT1</td><td>ALT2</td><td>ALT3</td></tr></tbody></table><br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;mg&nbsp;4<br>1<br></code><h3><a name="MICS">MICS</a>
 <a href="#v">v</a> - Microseconds delay</h3>This command delays execution for <a href="#v">v</a> microseconds.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>The main use of this command is expected to be within <a href="#Scripts">Scripts</a>.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;mics&nbsp;20&nbsp;#&nbsp;Delay&nbsp;20&nbsp;microseconds.<br>$&nbsp;pigs&nbsp;mics&nbsp;1000000&nbsp;#&nbsp;Delay&nbsp;1&nbsp;second.<br><br>$&nbsp;pigs&nbsp;mics&nbsp;2000000<br>-64<br>ERROR:&nbsp;bad&nbsp;MICS&nbsp;delay&nbsp;(too&nbsp;large)<br></code><h3><a name="MILS">MILS</a>
 <a href="#v">v</a> - Milliseconds delay</h3>This command delays execution for <a href="#v">v</a> milliseconds.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;mils&nbsp;2000&nbsp;#&nbsp;Delay&nbsp;2&nbsp;seconds.<br><br>$&nbsp;pigs&nbsp;mils&nbsp;61000<br>-65<br>ERROR:&nbsp;bad&nbsp;MILS&nbsp;delay&nbsp;(too&nbsp;large)<br></code><h3><a name="NB">NB</a>
 <a href="#h">h</a> <a href="#bits">bits</a> - Start notification</h3>This command starts notifications on handle <a href="#h">h</a> returned by
a prior call to <a href="#NO">NO</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>The notification gets state changes for each GPIO specified by <a href="#bits">bits</a>.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;nb&nbsp;0&nbsp;-1&nbsp;#&nbsp;Shorthand&nbsp;for&nbsp;GPIO&nbsp;0-31.<br>$&nbsp;pigs&nbsp;nb&nbsp;0&nbsp;0xf0&nbsp;#&nbsp;Get&nbsp;notifications&nbsp;for&nbsp;GPIO&nbsp;4-7.<br><br>$&nbsp;pigs&nbsp;nb&nbsp;1&nbsp;0xf<br>-25<br>ERROR:&nbsp;unknown&nbsp;handle<br></code><h3><a name="NC">NC</a>
 <a href="#h">h</a> - Close notification</h3>This command stops notifications on handle <a href="#h">h</a> returned by
a prior call to <a href="#NO">NO</a> and releases the handle for reuse.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;nc&nbsp;0&nbsp;#&nbsp;First&nbsp;call&nbsp;succeeds.<br><br>$&nbsp;pigs&nbsp;nc&nbsp;1&nbsp;#&nbsp;Second&nbsp;call&nbsp;fails.<br>-25<br>ERROR:&nbsp;unknown&nbsp;handle<br></code><h3><a name="NO">NO</a>
 - Request a notification</h3>This command requests a free notification handle.
<br><br>A notification is a method for being notified of GPIO state changes via a pipe.
<br><br>Upon success the command returns a handle greater than or equal to zero.
On error a negative status code will be returned.
<br><br>Notifications for handle x will be available at the pipe named /dev/pigpiox
(where x is the handle number).
<br><br>E.g. if the command returns 15 then the notifications must be read
from /dev/pigpio15.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;no<br>0<br></code><h3><a name="NP">NP</a>
 <a href="#h">h</a> - Pause notification</h3>This command pauses notifications on handle <a href="#h">h</a> returned by
a prior call to <a href="#NO">NO</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>Notifications for the handle are suspended until a new <a href="#NB">NB</a> command
is given for the handle.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;np&nbsp;0<br></code><h3><a name="P/PWM">P/PWM</a>
 <a href="#u">u</a> <a href="#v">v</a> - Set GPIO PWM value</h3>This command starts PWM on GPIO <a href="#u">u</a> with dutycycle <a href="#v">v</a>.  The dutycycle
varies from 0 (off) to range (fully on).  The range defaults to 255.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>This and the servo functionality use the DMA and PWM or PCM peripherals
to control and schedule the pulsewidths and dutycycles.
<br><br>The <a href="#PRS">PRS</a> command may be used to change the default range of 255.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;p&nbsp;4&nbsp;64&nbsp;&nbsp;#&nbsp;Start&nbsp;PWM&nbsp;on&nbsp;GPIO&nbsp;4&nbsp;with&nbsp;25%&nbsp;dutycycle<br>$&nbsp;pigs&nbsp;p&nbsp;4&nbsp;128&nbsp;#&nbsp;50%<br>$&nbsp;pigs&nbsp;p&nbsp;4&nbsp;192&nbsp;#&nbsp;75%<br>$&nbsp;pigs&nbsp;p&nbsp;4&nbsp;255&nbsp;#&nbsp;100%<br></code><h3><a name="PADG">PADG</a>
 <a href="#pad">pad</a> - Get pad drive strength</h3>This command gets the <a href="#pad">pad</a> drive strength <a href="#padma">padma</a> in mA.
<br><br>Returns the pad drive strength if OK.  On error a negative status code
will be returned.
<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>$&nbsp;pigs&nbsp;padg&nbsp;0<br>8<br>$&nbsp;pigs&nbsp;pads&nbsp;0&nbsp;16<br>$&nbsp;pigs&nbsp;padg&nbsp;0<br>16<br>pigs&nbsp;padg&nbsp;3<br>-126<br>ERROR:&nbsp;bad&nbsp;pad&nbsp;number<br></code><h3><a name="PADS">PADS</a>
 <a href="#pad">pad</a> <a href="#padma">padma</a> - Set pad drive strength</h3>This command sets the <a href="#pad">pad</a> drive strength <a href="#padma">padma</a> in mA.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<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>$&nbsp;pigs&nbsp;pads&nbsp;0&nbsp;16<br>$&nbsp;pigs&nbsp;padg&nbsp;0<br>16<br>$&nbsp;pigs&nbsp;pads&nbsp;0&nbsp;17<br>-127<br>ERROR:&nbsp;bad&nbsp;pad&nbsp;drive&nbsp;strength<br></code><h3><a name="PARSE">PARSE</a>
 <a href="#t">t</a> - Validate script</h3>Validates the text <a href="#t">t</a> of a script without storing the script.
<br><br>Upon success nothing is returned.  On error a list of detected
script errors will be given.
<br><br>See <a href="#Scripts">Scripts</a>.
<br><br>This command may be used to find script syntax faults.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;parse&nbsp;tag&nbsp;100&nbsp;w&nbsp;22&nbsp;1&nbsp;mils&nbsp;200&nbsp;w&nbsp;22&nbsp;0&nbsp;mils&nbsp;800&nbsp;jmp&nbsp;100<br><br>$&nbsp;pigs&nbsp;parse&nbsp;tag&nbsp;0&nbsp;w&nbsp;22&nbsp;1&nbsp;mills&nbsp;50&nbsp;w&nbsp;22&nbsp;0&nbsp;dcr&nbsp;p10&nbsp;jp&nbsp;99<br>Unknown&nbsp;command:&nbsp;mills<br>Unknown&nbsp;command:&nbsp;50<br>Bad&nbsp;parameter&nbsp;to&nbsp;dcr<br>Can't&nbsp;resolve&nbsp;tag&nbsp;99<br></code><h3><a name="PFG">PFG</a>
 <a href="#u">u</a> - Get GPIO PWM frequency</h3>This command returns the PWM frequency in Hz used for GPIO <a href="#u">u</a>.
<br><br>Upon success the PWM frequency is returned.  On error a negative
status code will be returned.
<br><br>For normal PWM the frequency will be that defined for the GPIO
by <a href="#PFS">PFS</a>.
<br><br>If a hardware clock is active on the GPIO the reported frequency
will be that set by <a href="#HC">HC</a>.
<br><br>If hardware PWM is active on the GPIO the reported frequency
will be that set by <a href="#HP">HP</a>.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;pfg&nbsp;4<br>800<br><br>$&nbsp;pigs&nbsp;pfg&nbsp;34<br>ERROR:&nbsp;GPIO&nbsp;not&nbsp;0-31<br>-2<br></code><h3><a name="PFS">PFS</a>
 <a href="#u">u</a> <a href="#v">v</a> - Set GPIO PWM frequency</h3>This command sets the PWM frequency <a href="#v">v</a> to be used for GPIO <a href="#u">u</a>.
<br><br>The numerically closest frequency to <a href="#v">v</a> will be selected.
<br><br>Upon success the new frequency is returned.  On error a negative status code
will be returned.
<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).  The
sample rate is set when the pigpio daemon is started.
<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>pigs&nbsp;pfs&nbsp;4&nbsp;0&nbsp;#&nbsp;0&nbsp;selects&nbsp;the&nbsp;lowest&nbsp;frequency.<br>10<br><br>$&nbsp;pigs&nbsp;pfs&nbsp;4&nbsp;1000&nbsp;#&nbsp;Set&nbsp;1000Hz&nbsp;PWM.<br>1000<br><br>$&nbsp;pigs&nbsp;pfs&nbsp;4&nbsp;100000&nbsp;#&nbsp;Very&nbsp;big&nbsp;number&nbsp;selects&nbsp;the&nbsp;highest&nbsp;frequency.<br>8000<br></code><h3><a name="PIGPV">PIGPV</a>
 - Get pigpio library version</h3>This command returns the pigpio library version.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;pigpv<br>17<br></code><h3><a name="PRG">PRG</a>
 <a href="#u">u</a> - Get GPIO PWM range</h3>This command returns the dutycycle range for GPIO <a href="#u">u</a>.
<br><br>Upon success the range is returned.  On error a negative status code
will be returned.
<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>$&nbsp;pigs&nbsp;prg&nbsp;4<br>255<br></code><h3><a name="PROC">PROC</a>
 <a href="#t">t</a> - Store script</h3>This command stores a script <a href="#t">t</a> for later execution.
<br><br>If the script is valid a script id (&gt;=0) is returned which is passed
to the other script commands. On error a negative status code
will be returned.
<br><br>See <a href="#Scripts">Scripts</a>.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;proc&nbsp;tag&nbsp;123&nbsp;w&nbsp;4&nbsp;0&nbsp;mils&nbsp;200&nbsp;w&nbsp;4&nbsp;1&nbsp;mils&nbsp;300&nbsp;dcr&nbsp;p0&nbsp;jp&nbsp;123<br>0<br><br>$&nbsp;pigs&nbsp;proc&nbsp;tag&nbsp;123&nbsp;w&nbsp;4&nbsp;0&nbsp;mils&nbsp;5&nbsp;w&nbsp;4&nbsp;1&nbsp;mils&nbsp;5&nbsp;jmp&nbsp;12<br>ERROR:&nbsp;script&nbsp;has&nbsp;unresolved&nbsp;tag<br>-63<br></code><h3><a name="PROCD">PROCD</a>
 <a href="#sid">sid</a> - Delete script</h3>This command deletes script <a href="#sid">sid</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>See <a href="#Scripts">Scripts</a>.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;procd&nbsp;1<br><br>$&nbsp;pigs&nbsp;procd&nbsp;1<br>ERROR:&nbsp;unknown&nbsp;script&nbsp;id<br>-48<br></code><h3><a name="PROCP">PROCP</a>
 <a href="#sid">sid</a> - Get script status and parameters</h3>This command returns the status of script <a href="#sid">sid</a> as well as the
current value of its 10 parameters.
<br><br>Upon success the script status and parameters are  returned.
On error a negative status code will be returned.
<br><br>The script status may be one of
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>0</td><td>being initialised</td></tr><tr><td>1</td><td>halted</td></tr><tr><td>2</td><td>running</td></tr><tr><td>3</td><td>waiting</td></tr><tr><td>4</td><td>failed</td></tr></tbody></table><br><br>See <a href="#Scripts">Scripts</a>.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;procp&nbsp;0<br>1&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0<br></code><h3><a name="PROCR">PROCR</a>
 <a href="#sid">sid</a> <a href="#pars">pars</a> - Run script</h3>This command runs stored script <a href="#sid">sid</a> passing it up to 10 optional
parameters.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>See <a href="#Scripts">Scripts</a>.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;proc&nbsp;tag&nbsp;123&nbsp;w&nbsp;4&nbsp;0&nbsp;mils&nbsp;200&nbsp;w&nbsp;4&nbsp;1&nbsp;mils&nbsp;300&nbsp;dcr&nbsp;p0&nbsp;jp&nbsp;123<br>0<br><br>$&nbsp;pigs&nbsp;procr&nbsp;0&nbsp;50&nbsp;#&nbsp;Run&nbsp;script&nbsp;0&nbsp;with&nbsp;parameter&nbsp;0&nbsp;of&nbsp;50.<br><br>$&nbsp;pigs&nbsp;procp&nbsp;0<br>2&nbsp;44&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0<br>$&nbsp;pigs&nbsp;procp&nbsp;0<br>2&nbsp;37&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0<br>$&nbsp;pigs&nbsp;procp&nbsp;0<br>2&nbsp;10&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0<br>$&nbsp;pigs&nbsp;procp&nbsp;0<br>2&nbsp;5&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0<br>$&nbsp;pigs&nbsp;procp&nbsp;0<br>2&nbsp;2&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0<br>$&nbsp;pigs&nbsp;procp&nbsp;0<br>1&nbsp;-1&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0<br></code><h3><a name="PROCS">PROCS</a>
 <a href="#sid">sid</a> - Stop script</h3>This command stops a running script <a href="#sid">sid</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>See <a href="#Scripts">Scripts</a>.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;procs&nbsp;0<br><br>$&nbsp;pigs&nbsp;procs&nbsp;1<br>-48<br>ERROR:&nbsp;unknown&nbsp;script&nbsp;id<br></code><h3><a name="PROCU">PROCU</a>
 <a href="#sid">sid</a> <a href="#pars">pars</a> - Set script parameters</h3>This command sets the parameters of a stored script <a href="#sid">sid</a> passing
it up to 10 parameters.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>See <a href="#Scripts">Scripts</a>.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;proc&nbsp;tag&nbsp;0&nbsp;hp&nbsp;18&nbsp;p0&nbsp;p1&nbsp;mils&nbsp;1000&nbsp;jmp&nbsp;0<br>0<br>$&nbsp;pigs&nbsp;procu&nbsp;0&nbsp;50&nbsp;500000<br>$&nbsp;pigs&nbsp;procr&nbsp;0<br>$&nbsp;pigs&nbsp;procu&nbsp;0&nbsp;100<br>$&nbsp;pigs&nbsp;procu&nbsp;0&nbsp;200<br>$&nbsp;pigs&nbsp;procu&nbsp;0&nbsp;200&nbsp;100000<br></code><h3><a name="PRRG">PRRG</a>
 <a href="#u">u</a> - Get GPIO PWM real range</h3>This command returns the real underlying range used by GPIO <a href="#u">u</a>.
<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>On error a negative status code will be returned.
<br><br>See <a href="#PRS">PRS</a>.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;prrg&nbsp;17<br>250<br><br>$&nbsp;pigs&nbsp;pfs&nbsp;17&nbsp;0<br>10<br>$&nbsp;pigs&nbsp;prrg&nbsp;17<br>20000<br><br>$&nbsp;pigs&nbsp;pfs&nbsp;17&nbsp;100000<br>8000<br>$&nbsp;pigs&nbsp;prrg&nbsp;17<br>25<br></code><h3><a name="PRS">PRS</a>
 <a href="#u">u</a> <a href="#v">v</a> - Set GPIO PWM range</h3>This command sets the dutycycle range <a href="#v">v</a> to be used for GPIO <a href="#u">u</a>.
Subsequent uses of command <a href="#P/PWM">P/PWM</a> will use a dutycycle between 0 (off)
and <a href="#v">v</a> (fully on).
<br><br>Upon success the real underlying range used by the GPIO is returned.
On error a negative status code will be returned.
<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><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>#1</td><td>#2</td><td>#3</td><td>#4</td><td>#5</td><td>#6</td><td>#7</td><td>#8</td><td>#9</td></tr><tr><td>25</td><td>50</td><td>100</td><td>125</td><td>200</td><td>250</td><td>400</td><td>500</td><td>625</td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>#10</td><td>#11</td><td>#12</td><td>#13</td><td>#14</td><td>#15</td><td>#16</td><td>#17</td><td>#18</td></tr><tr><td>800</td><td>1000</td><td>1250</td><td>2000</td><td>2500</td><td>4000</td><td>5000</td><td>10000</td><td>20000</td></tr></tbody></table><br><br>The real value set by <a href="#PRS">PRS</a> is (dutycycle * real range) / range.
<br><br>See <a href="#PRRG">PRRG</a>
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;prs&nbsp;18&nbsp;1000<br>250<br></code><h3><a name="PUD">PUD</a>
 <a href="#g">g</a> <a href="#p">p</a> - Set GPIO pull up/down</h3>This command sets the internal pull/up down for GPIO <a href="#g">g</a> to mode <a href="#p">p</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>The mode may be pull-down (D), pull-up (U), or off (O).
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;pud&nbsp;4&nbsp;d&nbsp;#&nbsp;Set&nbsp;pull-down&nbsp;on&nbsp;GPIO&nbsp;4.<br>$&nbsp;pigs&nbsp;pud&nbsp;4&nbsp;u&nbsp;#&nbsp;Set&nbsp;pull-up&nbsp;on&nbsp;GPIO&nbsp;4.<br>$&nbsp;pigs&nbsp;pud&nbsp;4&nbsp;o&nbsp;#&nbsp;No&nbsp;pull-up/down&nbsp;on&nbsp;GPIO&nbsp;4.<br></code><h3><a name="R/READ">R/READ</a>
 <a href="#g">g</a> - Read GPIO level</h3>This reads the current level of GPIO <a href="#g">g</a>.
<br><br>Upon success the current level is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;r&nbsp;17&nbsp;#&nbsp;Get&nbsp;level&nbsp;of&nbsp;GPIO&nbsp;17.<br>0<br><br>$&nbsp;pigs&nbsp;r&nbsp;4&nbsp;#&nbsp;Get&nbsp;level&nbsp;of&nbsp;GPIO&nbsp;4.<br>1<br></code><h3><a name="S/SERVO">S/SERVO</a>
 <a href="#u">u</a> <a href="#v">v</a> - Set GPIO servo pulsewidth</h3>This command starts servo pulses of <a href="#v">v</a> microseconds on GPIO <a href="#u">u</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>The servo pulsewidth may be 0 (off), 500 (most anti-clockwise)
to 2500 (most clockwise).
<br><br>The range supported by servos varies and should probably be determined
by experiment. Generally values between 1000-2000 should be safe.
A value of 1500 should always be safe and represents
the mid-point of rotation.
<br><br>You can DAMAGE a servo if you command it to move beyond its limits.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;SERVO&nbsp;17&nbsp;1500<br></code><br><br>This example causes an on pulse of 1500 microseconds duration to be
transmitted on GPIO 17 at a rate of 50 times per second.
<br><br>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>pigs&nbsp;s&nbsp;17&nbsp;0&nbsp;#&nbsp;Switch&nbsp;servo&nbsp;pulses&nbsp;off.<br></code><h3><a name="SERC">SERC</a>
 <a href="#h">h</a> - Close serial handle</h3>This command closes a serial handle <a href="#h">h</a> previously opened with <a href="#SERO">SERO</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;serc&nbsp;0&nbsp;#&nbsp;First&nbsp;close&nbsp;okay.<br><br>$&nbsp;pigs&nbsp;serc&nbsp;0&nbsp;#&nbsp;Second&nbsp;close&nbsp;gives&nbsp;error.<br>-25<br>ERROR:&nbsp;unknown&nbsp;handle<br></code><h3><a name="SERDA">SERDA</a>
 <a href="#h">h</a> - Check for serial data ready to read</h3>This command returns the number of bytes of data available
to be read from the serial device associated with handle <a href="#h">h</a>.
<br><br>Upon success the count of bytes available to be read is
returned (which may be 0).  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;serda&nbsp;0<br>0<br></code><h3><a name="SERO">SERO</a>
 <a href="#dev">dev</a> <a href="#b">b</a> <a href="#sef">sef</a> - Open serial device dev at baud b with flags</h3>This command opens the serial <a href="#dev">dev</a> at <a href="#b">b</a> bits per second.
<br><br>No flags are currently defined.  <a href="#sef">sef</a> should be set to zero.
<br><br>Upon success a handle (&gt;=0) is returned.  On error a negative status code
will be returned.
<br><br>The device name must start with /dev/tty or /dev/serial.
<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><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;sero&nbsp;/dev/ttyAMA0&nbsp;9600&nbsp;0<br>0<br><br>$&nbsp;pigs&nbsp;sero&nbsp;/dev/tty1&nbsp;38400&nbsp;0<br>1<br></code><h3><a name="SERR">SERR</a>
 <a href="#h">h</a> <a href="#num">num</a> - Read bytes from serial handle</h3>This command returns up to <a href="#num">num</a> bytes of data read from the
serial device associated with handle <a href="#h">h</a>.
<br><br>Upon success the count of returned bytes followed by the bytes themselves
is returned.  On error a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;serr&nbsp;0&nbsp;10<br>5&nbsp;48&nbsp;49&nbsp;128&nbsp;144&nbsp;255<br><br>$&nbsp;pigs&nbsp;serr&nbsp;0&nbsp;10<br>0<br></code><h3><a name="SERRB">SERRB</a>
 - Read byte from serial handle</h3>This command returns a byte of data read from the serial
device associated with handle <a href="#h">h</a>.
<br><br>Upon success a number between 0 and 255 is returned.
On error a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;serrb&nbsp;0<br>23<br>$&nbsp;pigs&nbsp;serrb&nbsp;0<br>45<br></code><h3><a name="SERW">SERW</a>
 <a href="#h">h</a> <a href="#bvs">bvs</a> - Write bytes to serial handle</h3>This command writes bytes <a href="#bvs">bvs</a> to the serial device
associated with handle <a href="#h">h</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;serw&nbsp;0&nbsp;23&nbsp;45&nbsp;67&nbsp;89<br></code><h3><a name="SERWB">SERWB</a>
 <a href="#h">h</a> <a href="#bv">bv</a> - Write byte to serial handle</h3>This command writes a single byte <a href="#bv">bv</a> to the serial device
associated with handle <a href="#h">h</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;serwb&nbsp;0&nbsp;23<br>$&nbsp;pigs&nbsp;serwb&nbsp;0&nbsp;0xf0<br></code><h3><a name="SHELL">SHELL</a>
 <a href="#name">name</a> <a href="#str">str</a> - Execute a shell command</h3>This command uses the system call to execute a shell script <a href="#name">name</a>
with the given string <a href="#str">str</a> as its parameter.
<br><br>The exit status of the system call is returned if OK, otherwise
PI_BAD_SHELL_STATUS.
<br><br><a href="#name">name</a> 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>$&nbsp;pigs&nbsp;shell&nbsp;scr1&nbsp;hello&nbsp;world<br>256<br><br>#&nbsp;pass&nbsp;three&nbsp;parameters,&nbsp;hello,&nbsp;string&nbsp;with&nbsp;spaces,&nbsp;and&nbsp;world<br>$&nbsp;pigs&nbsp;shell&nbsp;scr1&nbsp;"hello&nbsp;'string&nbsp;with&nbsp;spaces'&nbsp;world"<br>256<br><br>#&nbsp;pass&nbsp;one&nbsp;parameter,&nbsp;hello&nbsp;string&nbsp;with&nbsp;spaces&nbsp;world<br>$&nbsp;pigs&nbsp;shell&nbsp;scr1&nbsp;"\"hello&nbsp;string&nbsp;with&nbsp;spaces&nbsp;world\""<br>256<br><br>#&nbsp;non-existent&nbsp;script<br>$&nbsp;pigs&nbsp;shell&nbsp;scr78&nbsp;par1<br>32512<br></code><h3><a name="SLR">SLR</a>
 <a href="#u">u</a> <a href="#num">num</a> - Read bit bang serial data from GPIO</h3>This command returns up to <a href="#num">num</a> bytes of bit bang serial data
read from GPIO <a href="#u">u</a>.
<br><br>Upon success the count of returned bytes followed by the bytes themselves
is returned.  On error a negative status code will be returned.
<br><br>The GPIO <a href="#u">u</a> should have been initialised with the <a href="#SLRO">SLRO</a> command.
<br><br>The bytes returned for each character depend upon the number of
data bits <a href="#db">db</a> specified in the <a href="#SLRO">SLRO</a> command.
<br><br>For <a href="#db">db</a> 1-8 there will be one byte per character.<br>
For <a href="#db">db</a> 9-16 there will be two bytes per character.<br>
For <a href="#db">db</a> 17-32 there will be four bytes per character.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;slr&nbsp;15&nbsp;20<br>6&nbsp;1&nbsp;0&nbsp;23&nbsp;45&nbsp;89&nbsp;0<br></code><h3><a name="SLRC">SLRC</a>
 <a href="#u">u</a> - Close GPIO for bit bang serial data</h3>This command closes GPIO <a href="#u">u</a> for reading bit bang serial data.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;slrc&nbsp;23<br><br>$&nbsp;pigs&nbsp;slrc&nbsp;23<br>-38<br>ERROR:&nbsp;no&nbsp;serial&nbsp;read&nbsp;in&nbsp;progress&nbsp;on&nbsp;GPIO<br></code><h3><a name="SLRI">SLRI</a>
 <a href="#u">u</a> <a href="#v">v</a> - Sets bit bang serial data logic levels</h3>This command sets the logic level for reading bit bang serial data
on GPIO <a href="#u">u</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>The invert parameter <a href="#v">v</a> is 1 for inverted signal, 0 for normal.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;slri&nbsp;17&nbsp;1&nbsp;#&nbsp;invert&nbsp;logic&nbsp;on&nbsp;GPIO&nbsp;17<br><br>$&nbsp;pigs&nbsp;slri&nbsp;23&nbsp;0&nbsp;#&nbsp;use&nbsp;normal&nbsp;logic&nbsp;on&nbsp;GPIO&nbsp;23<br></code><h3><a name="SLRO">SLRO</a>
 <a href="#u">u</a> <a href="#b">b</a> <a href="#db">db</a> - Open GPIO for bit bang serial data</h3>This command opens GPIO <a href="#u">u</a> for reading bit bang serial data
at <a href="#b">b</a> baud and <a href="#db">db</a> data bits.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>The baud rate may be between 50 and 250000 bits per second.
<br><br>The received data is held in a cyclic buffer.
<br><br>It is the user's responsibility to read the data (with <a href="#SLR">SLR</a>)
in a timely fashion.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;slro&nbsp;23&nbsp;19200&nbsp;8<br><br>$&nbsp;pigs&nbsp;slro&nbsp;23&nbsp;19200&nbsp;8<br>-50<br>ERROR:&nbsp;GPIO&nbsp;already&nbsp;in&nbsp;use<br></code><h3><a name="SPIC">SPIC</a>
 <a href="#h">h</a> - SPI close handle</h3>This command closes the SPI handle <a href="#h">h</a> returned by a prior
call to <a href="#SPIO">SPIO</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;spic&nbsp;1<br><br>$&nbsp;pigs&nbsp;spic&nbsp;1<br>-25<br>ERROR:&nbsp;unknown&nbsp;handle<br></code><h3><a name="SPIO">SPIO</a>
 <a href="#c">c</a> <a href="#b">b</a> <a href="#spf">spf</a> - SPI open channel at baud b with flags</h3>This command returns a handle to a SPI device on channel <a href="#c">c</a>.
<br><br>Data will be transferred at <a href="#b">b</a> bits per second.  The flags <a href="#spf">spf</a>
may be used to modify the default behaviour of 4-wire operation,
mode 0, active low chip select.
<br><br>Speeds between 32kbps and 125Mbps are allowed.  Speeds above 30Mbps
are unlikely to work.
<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>The flags 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="#SPIR">SPIR</a>, <a href="#SPIW">SPIW</a>, and <a href="#SPIX">SPIX</a> commands 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 character.<br>
For bits 9-16 there will be two bytes per character.<br>
For bits 17-32 there will be four bytes per character.
<br><br>Multi-byte transfers are made in least significant byte first order.
<br><br>E.g. to transfer 32 11-bit words 64 bytes need to be sent.
<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.
<br><br>Upon success a handle (&gt;=0) is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;spio&nbsp;0&nbsp;100000&nbsp;3&nbsp;#&nbsp;Open&nbsp;channel&nbsp;0&nbsp;at&nbsp;100kbps&nbsp;in&nbsp;mode&nbsp;3.<br>0<br><br>$&nbsp;pigs&nbsp;spio&nbsp;0&nbsp;32000&nbsp;256&nbsp;#&nbsp;Open&nbsp;channel&nbsp;0&nbsp;of&nbsp;auxiliary&nbsp;spi&nbsp;at&nbsp;32kbps.<br>1<br></code><h3><a name="SPIR">SPIR</a>
 <a href="#h">h</a> <a href="#num">num</a> - SPI read bytes from handle</h3>This command returns <a href="#num">num</a> bytes read from the SPI device
associated with handle <a href="#h">h</a>.
<br><br>Upon success the count of returned bytes followed by the bytes themselves
is returned.  On error a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;spir&nbsp;0&nbsp;10&nbsp;#&nbsp;Read&nbsp;10&nbsp;bytes&nbsp;from&nbsp;the&nbsp;SPI&nbsp;device.<br>10&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0&nbsp;0<br></code><h3><a name="SPIW">SPIW</a>
 <a href="#h">h</a> <a href="#bvs">bvs</a> - SPI write bytes to handle</h3>This command writes bytes <a href="#bvs">bvs</a> to the SPI device
associated with handle <a href="#h">h</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;spiw&nbsp;0&nbsp;0x22&nbsp;0x33&nbsp;0xcc&nbsp;0xff<br></code><h3><a name="SPIX">SPIX</a>
 <a href="#h">h</a> <a href="#bvs">bvs</a> - SPI transfer bytes to handle</h3>This command writes bytes <a href="#bvs">bvs</a> to the SPI device
associated with handle <a href="#h">h</a>.  It returns the same
number of bytes read from the device.
<br><br>Upon success the count of returned bytes followed by the bytes themselves
is returned.  On error a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;spix&nbsp;0&nbsp;0x22&nbsp;0x33&nbsp;0xcc&nbsp;0xff<br>4&nbsp;0&nbsp;0&nbsp;0&nbsp;0<br></code><h3><a name="T/TICK">T/TICK</a>
 - Get current tick</h3>This command 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><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;t&nbsp;mils&nbsp;1000&nbsp;t<br>3691823946<br>3692833987<br></code><h3><a name="TRIG">TRIG</a>
 <a href="#u">u</a> <a href="#pl">pl</a> <a href="#L">L</a> - Send a trigger pulse</h3>This command sends a trigger pulse of <a href="#pl">pl</a> microseconds at level <a href="#L">L</a>
to GPIO <a href="#u">u</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br>The GPIO is set to not level at the end of the pulse.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;trig&nbsp;4&nbsp;10&nbsp;1<br><br>$&nbsp;pigs&nbsp;trig&nbsp;4&nbsp;51&nbsp;1<br>-46<br>ERROR:&nbsp;trigger&nbsp;pulse&nbsp;&gt;&nbsp;50&nbsp;microseconds<br></code><h3><a name="W/WRITE">W/WRITE</a>
 <a href="#g">g</a> <a href="#L">L</a> - Write GPIO level</h3>This command sets GPIO <a href="#g">g</a> to level <a href="#L">L</a>.  The level may be 0
(low, off, clear) or 1 (high, on, set).
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;w&nbsp;23&nbsp;0<br>$&nbsp;pigs&nbsp;w&nbsp;23&nbsp;1<br><br>$&nbsp;pigs&nbsp;w&nbsp;23&nbsp;2<br>-5<br>ERROR:&nbsp;level&nbsp;not&nbsp;0-1<br></code><h3><a name="WDOG">WDOG</a>
 <a href="#u">u</a> <a href="#v">v</a> - Set GPIO watchdog</h3>This command sets a watchdog of <a href="#v">v</a> milliseconds on GPIO <a href="#u">u</a>.
<br><br>Upon success nothing is returned.  On error a negative status code
will be returned.
<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>Once a watchdog has been started monitors of the GPIO
will be triggered every timeout interval after the last
GPIO activity.  The watchdog expiry will be indicated by
a special TIMEOUT value.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wdog&nbsp;23&nbsp;90000<br>-15<br>ERROR:&nbsp;timeout&nbsp;not&nbsp;0-60000<br><br>$&nbsp;pigs&nbsp;wdog&nbsp;23&nbsp;9000<br></code><br><br>This example causes a report to be written to any notification pipes
listening on GPIO 23 whenever GPIO 23 changes state or approximately
every 9000 ms.
<h3><a name="WVAG">WVAG</a>
 <a href="#trips">trips</a> - Add generic pulses to waveform</h3>This command adds 1 one or more triplets <a href="#trips">trips</a> of GPIO on, GPIO off,
delay to the existing waveform (if any).
<br><br>Upon success the total number of pulses in the waveform so far is
returned.  On error a negative status code will be returned.
<br><br>The triplets will be added at the start of the existing waveform.  If
they are to start offset from the start then the first triplet should
consist solely of a delay i.e. 0 0 offset.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvag&nbsp;0x10&nbsp;0x80&nbsp;1000&nbsp;0x80&nbsp;0x10&nbsp;9000<br>2<br><br>$&nbsp;pigs&nbsp;wvag&nbsp;0&nbsp;0&nbsp;10000&nbsp;0x10&nbsp;0x80&nbsp;1000&nbsp;0x80&nbsp;0x10&nbsp;9000<br>4<br></code><h3><a name="WVAS">WVAS</a>
 <a href="#u">u</a> <a href="#b">b</a> <a href="#db">db</a> <a href="#sb">sb</a> <a href="#o">o</a> <a href="#bvs">bvs</a> - Add serial data to waveform</h3>This command adds a waveform representing serial data <a href="#bvs">bvs</a> to
GPIO <a href="#u">u</a> at <a href="#b">b</a> baud to the existing waveform (if any).
The serial data starts <a href="#o">o</a> microseconds from the start of the
waveform.
<br><br>Upon success the total number of pulses in the waveform so far is
returned.  On error a negative status code will be returned.
<br><br>The serial data is formatted as one start bit, <a href="#db">db</a> data bits, and
<a href="#sb">sb</a>/2 stop bits.
<br><br>The baud rate may be between 50 and 1000000 bits per second.
<br><br>It is legal to add serial data streams with different baud rates to
the same waveform.
<br><br>The bytes required for each character depend upon <a href="#db">db</a>.
<br><br>For <a href="#db">db</a> 1-8 there will be one byte per character.<br>
For <a href="#db">db</a> 9-16 there will be two bytes per character.<br>
For <a href="#db">db</a> 17-32 there will be four bytes per character.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvas&nbsp;4&nbsp;9600&nbsp;8&nbsp;2&nbsp;0&nbsp;0x30&nbsp;0x31&nbsp;0x32&nbsp;0x33<br>23<br><br>$&nbsp;pigs&nbsp;wvas&nbsp;7&nbsp;38400&nbsp;8&nbsp;2&nbsp;0&nbsp;0x41&nbsp;0x42<br>35<br></code><h3><a name="WVTAT">WVTAT</a>
 - Returns the current transmitting waveform</h3>This command returns the id of the waveform currently
being transmitted.
<br><br>Returns the waveform id or one of the following special
values:
<br><br>9998 - transmitted wave not found<br>
9999 - no wave being transmitted
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvtat<br>9999<br></code><h3><a name="WVBSY">WVBSY</a>
 - Check if waveform is being transmitted</h3>This command checks to see if a waveform is currently being transmitted.
<br><br>Returns 1 if a waveform is currently being transmitted, otherwise 0.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvbsy<br>0<br></code><h3><a name="WVCHA">WVCHA</a>
 <a href="#bvs">bvs</a> - Transmits a chain of waveforms</h3>This command transmits a chain of waveforms.
<br><br>NOTE: Any hardware PWM started by <a href="#HP">HP</a> will
be cancelled.
<br><br>The waves to be transmitted are specified by the contents of
<a href="#bvs">bvs</a> which contains an ordered list of wave_ids and optional
command codes and related data.
<br><br>Upon success 0 is returned.  On error a negative status code
will be returned.
<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>#!/bin/bash<br><br>GPIO=4<br>WAVES=5<br><br>pigs&nbsp;m&nbsp;$GPIO&nbsp;w<br><br>for&nbsp;((i=0;&nbsp;i&lt;$WAVES;&nbsp;i++))<br>do<br>&nbsp;&nbsp;&nbsp;pigs&nbsp;wvag&nbsp;$((1&lt;&lt;GPIO))&nbsp;0&nbsp;20&nbsp;0&nbsp;$((1&lt;&lt;GPIO))&nbsp;$(((i+1)*200))<br>&nbsp;&nbsp;&nbsp;w[i]=$(pigs&nbsp;wvcre)<br>done<br><br>#&nbsp;transmit&nbsp;waves&nbsp;4+3+2<br>#&nbsp;loop&nbsp;start<br>#&nbsp;&nbsp;&nbsp;&nbsp;transmit&nbsp;waves&nbsp;0+0+0<br>#&nbsp;&nbsp;&nbsp;&nbsp;loop&nbsp;start<br>#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;transmit&nbsp;waves&nbsp;0+1<br>#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delay&nbsp;5000us<br>#&nbsp;&nbsp;&nbsp;&nbsp;loop&nbsp;end&nbsp;(repeat&nbsp;30&nbsp;times)<br>#&nbsp;&nbsp;&nbsp;&nbsp;loop&nbsp;start<br>#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;transmit&nbsp;waves&nbsp;2+3+0<br>#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;transmit&nbsp;waves&nbsp;3+1+2<br>#&nbsp;&nbsp;&nbsp;&nbsp;loop&nbsp;end&nbsp;(repeat&nbsp;10&nbsp;times)<br>#&nbsp;loop&nbsp;end&nbsp;(repeat&nbsp;5&nbsp;times)<br>#&nbsp;transmit&nbsp;waves&nbsp;4+4+4<br>#&nbsp;delay&nbsp;20000us<br>#&nbsp;transmit&nbsp;waves&nbsp;0+0+0<br><br>pigs&nbsp;wvcha&nbsp;\<br>&nbsp;&nbsp;&nbsp;${w[4]}&nbsp;${w[3]}&nbsp;${w[2]}&nbsp;\<br>&nbsp;&nbsp;&nbsp;255&nbsp;0&nbsp;\<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${w[0]}&nbsp;${w[0]}&nbsp;${w[0]}&nbsp;\<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255&nbsp;0&nbsp;\<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${w[0]}&nbsp;${w[1]}&nbsp;\<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255&nbsp;2&nbsp;0x88&nbsp;0x13&nbsp;\<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255&nbsp;1&nbsp;30&nbsp;0&nbsp;\<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255&nbsp;0&nbsp;\<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${w[2]}&nbsp;${w[3]}&nbsp;${w[0]}&nbsp;\<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${w[3]}&nbsp;${w[1]}&nbsp;${w[2]}&nbsp;\<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255&nbsp;1&nbsp;10&nbsp;0&nbsp;\<br>&nbsp;&nbsp;&nbsp;255&nbsp;1&nbsp;5&nbsp;0&nbsp;\<br>&nbsp;&nbsp;&nbsp;${w[4]}&nbsp;${w[4]}&nbsp;${w[4]}&nbsp;\<br>&nbsp;&nbsp;&nbsp;255&nbsp;2&nbsp;0x20&nbsp;0x4E&nbsp;\<br>&nbsp;&nbsp;&nbsp;${w[0]}&nbsp;${w[0]}&nbsp;${w[0]}<br><br>while&nbsp;[[&nbsp;$(pigs&nbsp;wvbsy)&nbsp;-eq&nbsp;1&nbsp;]];&nbsp;do&nbsp;sleep&nbsp;0.1;&nbsp;done<br><br>for&nbsp;((i=0;&nbsp;i&lt;$WAVES;&nbsp;i++));&nbsp;do&nbsp;echo&nbsp;${w[i]};&nbsp;pigs&nbsp;wvdel&nbsp;${w[i]};&nbsp;done<br></code><h3><a name="WVCLR">WVCLR</a>
 - Clear all waveforms</h3>This command clears all waveforms.
<br><br>Nothing is returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvclr<br></code><h3><a name="WVCRE">WVCRE</a>
 - Create a waveform</h3>This command creates a waveform from the data provided by the prior
calls to the <a href="#WVAG">WVAG</a> and <a href="#WVAS">WVAS</a> commands.
<br><br>Upon success a wave id (&gt;=0) is returned.  On error a negative status
code will be returned.
<br><br>The data provided by the <a href="#WVAG">WVAG</a> and <a href="#WVAS">WVAS</a> commands is
consumed by this command.
<br><br>As many waveforms may be created as there is space available.
The wave id is passed to <a href="#WVTX">WVTX</a> or <a href="#WVTXR">WVTXR</a> to specify the
waveform to transmit.
<br><br>Normal usage would be
<br><br>Step 1. <a href="#WVCLR">WVCLR</a> to clear all waveforms and added data.
<br><br>Step 2. <a href="#WVAG">WVAG</a>/<a href="#WVAS">WVAS</a> calls to supply the waveform data.
<br><br>Step 3. <a href="#WVCRE">WVCRE</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="#WVTX">WVTX</a> or <a href="#WVTXR">WVTXR</a> with the id of the waveform to transmit.
<br><br>A waveform comprises of one or more pulses.
<br><br>A pulse specifies
<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><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvas&nbsp;4&nbsp;9600&nbsp;0&nbsp;23&nbsp;45&nbsp;67&nbsp;89&nbsp;90<br>37<br>$&nbsp;pigs&nbsp;wvcre<br>0<br><br>$&nbsp;pigs&nbsp;wvcre<br>-69<br>ERROR:&nbsp;attempt&nbsp;to&nbsp;create&nbsp;an&nbsp;empty&nbsp;waveform<br></code><h3><a name="WVCAP">WVCAP</a>
 <a href="#percent">percent</a> - Create a waveform of fixed size</h3>Create a waveform of fixed size. Similar to <a href="#WVCRE">WVCRE</a>, this command creates a waveform but pads the consumed resources to a fixed size, specified as a <a href="#percent">percent</a> of the total resources. Padded waves of equal size can be re-cycled efficiently allowing newly created waves to re-use the resources of deleted waves of the same dimension.
<br><br>Upon success a wave id (&gt;=0) is returned. On error a negative status code will be returned.
<br><br>The data provided by the <a href="#WVAG">WVAG</a> and <a href="#WVAS">WVAS</a> commands are consumed by this command.
<br><br>As many waveforms may be created as there is space available. The wave id is passed to <a href="#WVTX">WVTX</a> or <a href="#WVTXR">WVTXR</a> to specify the waveform to transmit.
<br><br>Normal usage would be
<br><br>Step 1. <a href="#WVCLR">WVCLR</a> to clear all waveforms and added data.
<br><br>Step 2. <a href="#WVAG">WVAG</a>/<a href="#WVAS">WVAS</a> calls to supply the waveform data.
<br><br>Step 3. <a href="#WVCAP">WVCAP</a> to create a waveform of a uniform size.
<br><br>Step 4. <a href="#WVTX">WVTX</a> or <a href="#WVTXR">WVTXR</a> with the id of the waveform to transmit.
<br><br>Repeat steps 2 - 4 as needed.
<br><br>Step 5. Any wave id can now be deleted and another wave of the same size can be created in its place.
<br><br>Example
<br><br><b><small>Example</small></b><br><br><code>#&nbsp;Create&nbsp;a&nbsp;wave&nbsp;that&nbsp;consumes&nbsp;50%&nbsp;of&nbsp;the&nbsp;total&nbsp;resource:<br><br>$&nbsp;pigs&nbsp;wvag&nbsp;16&nbsp;0&nbsp;5000000&nbsp;0&nbsp;16&nbsp;5000000<br>2<br>$&nbsp;pigs&nbsp;wvcap&nbsp;50<br>0<br>$&nbsp;pigs&nbsp;wvtx&nbsp;0<br>11918<br></code><h3><a name="WVDEL">WVDEL</a>
 <a href="#wid">wid</a> - Delete selected waveform</h3>This command deletes the waveform with id <a href="#wid">wid</a>.
<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>Upon success nothing is returned.  On error a negative status code
will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvdel&nbsp;0<br><br>$&nbsp;pigs&nbsp;wvdel&nbsp;0<br>-66<br>ERROR:&nbsp;non&nbsp;existent&nbsp;wave&nbsp;id<br></code><h3><a name="WVHLT">WVHLT</a>
 - Stop waveform</h3>This command aborts the transmission of the current waveform.
<br><br>Nothing is returned.
<br><br>This command is intended to stop a waveform started in the repeat mode.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvhlt<br></code><h3><a name="WVNEW">WVNEW</a>
 - Initialise a new waveform</h3>This clears any existing waveform data ready for the creation of a new
waveform.
<br><br>Nothing is returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvnew<br></code><h3><a name="WVSC">WVSC</a>
 <a href="#ws">ws</a> - Get waveform DMA CB stats</h3>The statistic requested by <a href="#ws">ws</a> is returned.
<br><br><a href="#ws">ws</a> identifies the subcommand as follows.
<br><br>0 Get Cbs<br>
1 Get High Cbs<br>
2 Get Max Cbs
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvas&nbsp;4&nbsp;9600&nbsp;0&nbsp;23&nbsp;45&nbsp;67&nbsp;89&nbsp;90<br>37<br><br>$&nbsp;pigs&nbsp;wvsc&nbsp;0<br>74<br>$&nbsp;pigs&nbsp;wvsc&nbsp;1<br>74<br>$&nbsp;pigs&nbsp;wvsc&nbsp;2<br>25016<br></code><h3><a name="WVSM">WVSM</a>
 <a href="#ws">ws</a> - Get waveform time stats</h3>The statistic requested by <a href="#ws">ws</a> is returned.
<br><br><a href="#ws">ws</a> identifies the subcommand as follows.
<br><br>0 Get Micros<br>
1 Get High Micros<br>
2 Get Max Micros
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvsm&nbsp;0<br>5314<br>$&nbsp;pigs&nbsp;wvsm&nbsp;1<br>5314<br>$&nbsp;pigs&nbsp;wvsm&nbsp;2<br>1800000000<br></code><h3><a name="WVSP">WVSP</a>
 <a href="#ws">ws</a> - Get waveform pulse stats</h3>The statistic requested by <a href="#ws">ws</a> is returned.
<br><br><a href="#ws">ws</a> identifies the subcommand as follows.
<br><br>0 Get Pulses<br>
1 Get High Pulses<br>
2 Get Max Pulses
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvsp&nbsp;0<br>37<br>$&nbsp;pigs&nbsp;wvsp&nbsp;1<br>37<br>$&nbsp;pigs&nbsp;wvsp&nbsp;2<br>12000<br></code><h3><a name="WVTX">WVTX</a>
 <a href="#wid">wid</a> - Transmits waveform once</h3>This command transmits the waveform with id <a href="#wid">wid</a> once.
<br><br>NOTE: Any hardware PWM started by <a href="#HP">HP</a> will be cancelled.
<br><br>Upon success the number of DMA control blocks in the waveform is returned.
On error a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvtx&nbsp;1<br>75<br><br>$&nbsp;pigs&nbsp;wvtx&nbsp;2<br>-66<br>ERROR:&nbsp;non&nbsp;existent&nbsp;wave&nbsp;id<br></code><h3><a name="WVTXM">WVTXM</a>
 <a href="#wid">wid</a> <a href="#wmde">wmde</a> - Transmits waveform using mode</h3>This command transmits the waveform with id <a href="#wid">wid</a> using mode <a href="#wmde">wmde</a>.
<br><br>The mode may be send once (0), send repeatedly (1), send once but
first sync with previous wave (2), or send repeatedly but first
sync with previous wave (3).
<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="#HP">HP</a> will be cancelled.
<br><br>Upon success the number of DMA control blocks in the waveform is returned.
On error a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvtxm&nbsp;1&nbsp;3<br>75<br><br>$&nbsp;pigs&nbsp;wvtxm&nbsp;2&nbsp;0<br>-66<br>ERROR:&nbsp;non&nbsp;existent&nbsp;wave&nbsp;id<br></code><h3><a name="WVTXR">WVTXR</a>
 <a href="#wid">wid</a> - Transmits waveform repeatedly</h3>This command transmits the waveform with id <a href="#wid">wid</a> repeatedly.
<br><br>NOTE: Any hardware PWM started by <a href="#HP">HP</a> will be cancelled.
<br><br>Upon success the number of DMA control blocks in the waveform is returned.
On error a negative status code will be returned.
<br><br><b><small>Example</small></b><br><br><code>$&nbsp;pigs&nbsp;wvtxr&nbsp;1<br>75<br><br>$&nbsp;pigs&nbsp;wvtxr&nbsp;2<br>-66<br>ERROR:&nbsp;non&nbsp;existent&nbsp;wave&nbsp;id<br></code><h2><a name="Parameters">Parameters</a></h2>
<h3><a name="actv">actv</a> - 0-1000000</h3>
The number of microseconds level changes are reported for once
a noise filter has been triggered (by <a href="#stdy">stdy</a> microseconds of
a stable level).
<h3><a name="b">b</a> - baud</h3>
The command expects the baud rate in bits per second for
the transmission of serial data (I2C/SPI/serial link, waves).
<h3><a name="bctl">bctl</a> - BSC control word</h3>
The command expects a BSC control word, see <a href="#BSCX">BSCX</a>.
<h3><a name="bit">bit</a> - bit value (0-1)</h3>
The command expects 0 or 1.
<h3><a name="bits">bits</a> - a bit mask</h3>
A mask is used to select one or more GPIO.  A GPIO is selected
if bit (1&lt;&lt;GPIO) is set in the mask.
<br><br>E.g. a mask of 6 (binary 110) select GPIO 1 and 2, a mask of
0x103 (binary 100000011) selects GPIO 0, 1, and 8.
<h3><a name="bv">bv</a> - a byte value (0-255)</h3>
The command expects a byte value.
<h3><a name="bvs">bvs</a> - byte values (0-255)</h3>
The command expects one or more byte values.
<h3><a name="c">c</a> - SPI channel (0-1)</h3>
The command expects a SPI channel.
<h3><a name="cf">cf</a> - hardware clock frequency (4689-250M, 13184-375M for the BCM2711)</h3>
The command expects a frequency.
<h3><a name="cs">cs</a> - GPIO (0-31)</h3>
The GPIO used for the slave select signal when bit banging SPI.
<h3><a name="db">db</a> - serial data bits (1-32)</h3>
The command expects the number of data bits per serial character.
<h3><a name="dev">dev</a> - a tty serial device (/dev/tty* or /dev/serial*)</h3>
The command expects the name of a tty serial device, e.g.
<br><br><code>/dev/ttyAMA0<br>/dev/ttyUSB0<br>/dev/tty0<br>/dev/serial0<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="file">file</a> - a file name</h3>
The file name must match an entry in /opt/pigpio/access.
<h3><a name="from">from</a> - 0-2</h3>
Position to seek from <a href="#FS">FS</a>.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td>From</td></tr><tr><td>0</td><td>start</td></tr><tr><td>1</td><td>current position</td></tr><tr><td>2</td><td>end</td></tr></tbody></table><h3><a name="g">g</a> - GPIO (0-53)</h3>
The command expects a GPIO.
<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="#HWVER">HWVER</a>.
<br><br>The user GPIO are marked with an X in the following table.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td><td>11</td><td>12</td><td>13</td><td>14</td><td>15</td></tr><tr><td>Type 1</td><td>X</td><td>X</td><td>-</td><td>-</td><td>X</td><td>-</td><td>-</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>-</td><td>-</td><td>X</td><td>X</td></tr><tr><td>Type 2</td><td>-</td><td>-</td><td>X</td><td>X</td><td>X</td><td>-</td><td>-</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>-</td><td>-</td><td>X</td><td>X</td></tr><tr><td>Type 3</td><td></td><td></td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td>16</td><td>17</td><td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td><td>25</td><td>26</td><td>27</td><td>28</td><td>29</td><td>30</td><td>31</td></tr><tr><td>Type 1</td><td>-</td><td>X</td><td>X</td><td>-</td><td>-</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td></tr><tr><td>Type 2</td><td>-</td><td>X</td><td>X</td><td>-</td><td>-</td><td>-</td><td>X</td><td>X</td><td>X</td><td>X</td><td>-</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td></tr><tr><td>Type 3</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>X</td><td>-</td><td>-</td><td>-</td><td>-</td></tr></tbody></table><br><br>You are not prevented from writing to unsafe GPIO.  The consequences
of doing so range from no effect, to a crash, or corrupted data.
<h3><a name="h">h</a> - handle (&gt;=0)</h3>
The command expects a handle.
<br><br>A handle is a number referencing an object opened by one of <a href="#FO">FO</a>,
<a href="#I2CO">I2CO</a>, <a href="#NO">NO</a>, <a href="#SERO">SERO</a>, <a href="#SPIO">SPIO</a>.
<h3><a name="ib">ib</a> - I2C bus (&gt;=0)</h3>
The command expects an I2C bus number.
<h3><a name="id">id</a> - I2C device (0-0x7F)</h3>
The command expects the address of an I2C device.
<h3><a name="if">if</a> - I2C flags (0)</h3>
The command expects an I2C flags value.  No flags are currently defined.
<h3><a name="L">L</a> - level (0-1)</h3>
The command expects a GPIO level.
<h3><a name="m">m</a> - mode (RW540123)</h3>
The command expects a mode character.
<br><br>Each GPIO can be configured to be in one of 8 different modes. The modes
are named Input, Output, ALT0, ALT1, ALT2, ALT3, ALT4, and ALT5.
<br><br>To set the mode use the code for the mode.
<br><br>The value is returned by the mode get command.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Mode</td><td>Input</td><td>Output</td><td>ALT0</td><td>ALT1</td><td>ALT2</td><td>ALT3</td><td>ALT4</td><td>ALT5</td></tr><tr><td>Code</td><td>R</td><td>W</td><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td></tr><tr><td>Value</td><td>0</td><td>1</td><td>4</td><td>5</td><td>6</td><td>7</td><td>3</td><td>2</td></tr></tbody></table><h3><a name="miso">miso</a> - GPIO (0-31)</h3>
The GPIO used for the MISO signal when bit banging SPI.
<h3><a name="mode">mode</a> - file open mode</h3>
One of the following values.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td>Value</td><td>Meaning</td></tr><tr><td>READ</td><td>1</td><td>open file for reading</td></tr><tr><td>WRITE</td><td>2</td><td>open file for writing</td></tr><tr><td>RW</td><td>3</td><td>open file for reading and writing</td></tr></tbody></table><br><br>The following values can be or'd into the mode.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td></td><td>Value</td><td>Meaning</td></tr><tr><td>APPEND</td><td>4</td><td>All writes append data to the end of the file</td></tr><tr><td>CREATE</td><td>8</td><td>The file is created if it doesn't exist</td></tr><tr><td>TRUNC</td><td>16</td><td>The file is truncated</td></tr></tbody></table><h3><a name="mosi">mosi</a> - GPIO (0-31)</h3>
The GPIO used for the MOSI signal when bit banging SPI.
<h3><a name="name">name</a> - the name of a script</h3>
Only alphanumeric characters, '-' and '_' are allowed in the name.
<h3><a name="num">num</a> - maximum number of bytes to return (1-)</h3>
The command expects the maximum number of bytes to return.
<br><br>For the I2C and SPI commands the requested number of bytes will always
be returned.
<br><br>For the serial and file commands the smaller of the number of
bytes available to be read (which may be zero) and <a href="#num">num</a> bytes
will be returned.
<h3><a name="o">o</a> - offset (&gt;=0)</h3>
Serial data is stored offset microseconds from the start of the waveform.
<h3><a name="p">p</a> - PUD (ODU)</h3>
The command expects a PUD character.
<br><br>Each GPIO can be configured to use or not use an internal pull up or
pull down resistor.  This is useful to provide a default state for inputs.
<br><br>A pull up will default the input to 1 (high).
<br><br>A pull down will default the input to 0 (low).
<br><br>To set the pull up down state use the command character for the state.
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Pull Up Down</td><td>Off</td><td>Pull Down</td><td>Pull Up</td></tr><tr><td>Command Character</td><td>O</td><td>D</td><td>U</td></tr></tbody></table><br><br>There is no mechanism to read the pull up down state.
<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="padma">padma</a> - 1-16</h3>
The mA which may be drawn from each GPIO whilst still guaranteeing the
high and low levels.
<h3><a name="pars">pars</a> - script parameters</h3>
The command expects 0 to 10 numbers as parameters to be passed to the script.
<h3><a name="pat">pat</a> - a file name pattern</h3>
A file path which may contain wildcards.  To be accessible the path
must match an entry in /opt/pigpio/access.
<h3><a name="pdc">pdc</a> - hardware PWM dutycycle (0-1000000)</h3>
The command expects a dutycycle.
<h3><a name="percent">percent</a> - percent (1-100)</h3>
The percent of wave resources to allocate to a wave.  It can be useful
to create waves of fixed sizes to prevent wave fragmentation (where
there are plenty of resources but not a large enough contiguous space).
<h3><a name="pf">pf</a> - hardware PWM frequency (1-125M, 1-187.5M for the BCM2711)</h3>
The command expects a frequency.
<h3><a name="pl">pl</a> - pulse length (1-100)</h3>
The command expects a pulse length in microseconds.
<h3><a name="r">r</a> - register (0-255)</h3>
The command expects an I2C register number.
<h3><a name="sb">sb</a> - serial stop (half) bits (2-8)</h3>
The command expects the number of stop (half) bits per serial character.
<h3><a name="scl">scl</a> - user GPIO (0-31)</h3>
The command expects the number of the GPIO to be used for SCL
when bit banging I2C.
<h3><a name="sclk">sclk</a> - user GPIO (0-31)</h3>
The GPIO used for the SCLK signal when bit banging SPI.
<h3><a name="sda">sda</a> - user GPIO (0-31)</h3>
The command expects the number of the GPIO to be used for SDA
when bit banging I2C.
<h3><a name="sef">sef</a> - serial flags (32 bits)</h3>
The command expects a flag value.  No serial flags are currently defined.
<h3><a name="sid">sid</a> - script id (&gt;= 0)</h3>
The command expects a script id as returned by a call to <a href="#PROC">PROC</a>.
<h3><a name="spf">spf</a> - SPI flags (32 bits)</h3>
See <a href="#SPIO">SPIO</a> and <a href="#BSPIO">BSPIO</a>.
<h3><a name="stdy">stdy</a> - 0-300000</h3>
The number of microseconds level changes must be stable for
before reporting the level changed (<a href="#FG">FG</a>) or triggering
the active part of a noise filter (<a href="#FN">FN</a>).
<h3><a name="str">str</a> - a string</h3>
The command expects a string.
<h3><a name="t">t</a> - a string</h3>
The command expects a string.
<h3><a name="trips">trips</a> - triplets</h3>
The command expects 1 or more triplets of GPIO on, GPIO off, delay.
<br><br>E.g. 0x400000 0 100000 0 0x400000 900000 defines two pulses as follows
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>GPIO on</td><td>GPIO off</td><td>delay</td></tr><tr><td>0x400000 (GPIO 22)</td><td>0 (None)</td><td>100000 (1/10th s)</td></tr><tr><td>0 (None)</td><td>0x400000 (GPIO 22)</td><td>900000 (9/10th s)</td></tr></tbody></table><h3><a name="u">u</a> - user GPIO (0-31)</h3>
The command expects the number of a user GPIO.
<br><br>A number of commands are restricted to GPIO in bank 1,
in particular the PWM commands, the servo command,
the watchdog command, and the notification command.
<br><br>It is your responsibility to ensure that the PWM and servo commands
are only used on safe GPIO.
<br><br>See <a href="#g">g</a>
<h3><a name="uvs">uvs</a> - values</h3>
The command expects an arbitrary number of &gt;=0 values (possibly none).
Any after the first two must be &lt;= 255.
<h3><a name="v">v</a> - value</h3>
The command expects a number.
<h3><a name="wid">wid</a> - wave id (&gt;=0)</h3>
The command expects a wave id.
<br><br>When a waveform is created it is given an id (0, 1, 2, ...).
<h3><a name="wmde">wmde</a> - mode (0-3)</h3>
The command expects a wave transmission mode.
<br><br>0 = send once<br>
1 = send repeatedly<br>
2 = send once but first sync with previous wave<br>
3 = send repeatedly but first sync with previous wave<br>
<h3><a name="ws">ws</a> - wave stats sucommand (0-2)</h3>
The command expects a subcommand.
<br><br>0 = current value.<br>
1 = highest value so far.<br>
2 = maximum possible value.
<h3><a name="wv">wv</a> - word value (0-65535)</h3>
The command expects a word value.
<h2><a name="Scripts">Scripts</a></h2>
Scripts are programs to be stored and executed by the pigpio daemon.
They are intended to mitigate any performance problems associated with
the pigpio daemon server/client model.
<h3>Example</h3>A trivial example might be useful.  Suppose you want to toggle a GPIO
on and off as fast as possible.
<br><br>From the command line you could write
<br><br><code>for&nbsp;((i=0;&nbsp;i&lt;1000;i++));&nbsp;do&nbsp;pigs&nbsp;w&nbsp;22&nbsp;1&nbsp;w&nbsp;22&nbsp;0;&nbsp;done<br></code><br><br>Timing that you will see it takes about 14 seconds, or roughly
70 toggles per second.
<br><br>Using the pigpio Python module you could use code such as
<br><br><code>#!/usr/bin/env&nbsp;python<br><br>import&nbsp;time<br><br>import&nbsp;pigpio<br><br>PIN=4<br><br>TOGGLE=10000<br><br>pi&nbsp;=&nbsp;pigpio.pi()&nbsp;#&nbsp;Connect&nbsp;to&nbsp;local&nbsp;Pi.<br><br>s&nbsp;=&nbsp;time.time()<br><br>for&nbsp;i&nbsp;in&nbsp;range(TOGGLE):<br>&nbsp;&nbsp;&nbsp;pi.write(PIN,&nbsp;1)<br>&nbsp;&nbsp;&nbsp;pi.write(PIN,&nbsp;0)<br><br>e&nbsp;=&nbsp;time.time()<br><br>print("pigpio&nbsp;did&nbsp;{}&nbsp;toggles&nbsp;per&nbsp;second".format(int(TOGGLE/(e-s))))<br><br>pi.stop()<br></code><br><br>Timing that shows a speed improvement to roughly 800 toggles per second.
<br><br>Now let's use a script.
<br><br><code>pigs&nbsp;proc&nbsp;tag&nbsp;999&nbsp;w&nbsp;22&nbsp;1&nbsp;w&nbsp;22&nbsp;0&nbsp;dcr&nbsp;p0&nbsp;jp&nbsp;999<br></code><br><br>Ignore the details for now.
<br><br>Let's time the script running.
<br><br>Again, ignore the details for now.
<br><br><code>time&nbsp;(pigs&nbsp;procr&nbsp;0&nbsp;10000000;&nbsp;while&nbsp;a=$(pigs&nbsp;procp&nbsp;0);&nbsp;[[&nbsp;${a::1}&nbsp;-eq&nbsp;2&nbsp;]];\<br>&nbsp;do&nbsp;sleep&nbsp;0.2;&nbsp;done)<br></code><br><br>The script takes roughly 12 seconds to complete, or 800,000 toggles per second.
<br><br>That is the advantage of a stored script.
<br><br>Some details.
<br><br><code>pigs&nbsp;proc&nbsp;tag&nbsp;999&nbsp;w&nbsp;22&nbsp;1&nbsp;w&nbsp;22&nbsp;0&nbsp;dcr&nbsp;p0&nbsp;jp&nbsp;999<br></code><br><br>proc introduces a script.  Everything after proc is part of the script.<br>
tag 999 names the current position in the script.<br>
w 22 1 writes 1 to GPIO 22.<br>
w 22 0 writes 0 to GPIO 22.<br>
dcr p0 decrements parameter 0.<br>
jp 999 jumps to tag 999 if the result is positive.
<br><br><code>time&nbsp;(pigs&nbsp;procr&nbsp;0&nbsp;10000000;&nbsp;while&nbsp;a=$(pigs&nbsp;procp&nbsp;0);&nbsp;[[&nbsp;${a::1}&nbsp;-eq&nbsp;2&nbsp;]];\<br>&nbsp;do&nbsp;sleep&nbsp;0.2;&nbsp;done)<br></code><br><br>pigs procr 0 10000000 starts script 0 with parameter 0 of 10 million.
<br><br>The rest is bash apart from
<br><br>pigs procp 0 asks for the status and parameters of script 0.
The status will be 2 while the script is running and 1 when it is complete.
<h3>Virtual machine</h3>A script runs within a virtual machine with
<br><br>a 32 bit accumulator A.<br>
a flags register F.<br>
a program counter PC.
<br><br>Each script has
<br><br>10 parameters named 0 through 9.<br>
150 variables named 0 through 149.<br>
50 labels which are named by any unique number.
<h3>Commands</h3>Many pigpio commands may be used within a script.  However
some commands do not work within the script model as designed and
are not permitted.
<br><br>The following commands are not permitted within a script:
<br><br>File - FL FO FR FW
<br><br>I2C - BI2CZ I2CPK I2CRD I2CRI I2CRK I2CWD I2CWI I2CWK I2CZ
<br><br>Misc - BSCX CF1 CF2 SHELL
<br><br>Script control - PARSE PROC PROCD PROCP PROCR PROCS PROCU
<br><br>Serial - SERO SERR SERW SLR
<br><br>SPI - BSPIO BSPIX SPIR SPIW SPIX
<br><br>Waves - WVAG WVAS WVCHA WVGO WVGOR
<br><br>The following commands are only permitted within a script:
<br><br><table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td>Command</td><td>Description</td><td>Definition</td></tr><tr><td>ADD x</td><td>Add x to accumulator</td><td>A+=x; F=A</td></tr><tr><td>AND x</td><td>And x with accumulator</td><td>A&=x; F=A</td></tr><tr><td>CALL L</td><td>Call subroutine at tag L</td><td>push(PC+1); PC=L</td></tr><tr><td>CMP x</td><td>Compare x with accumulator</td><td>F=A-x</td></tr><tr><td>DCR y</td><td>Decrement register</td><td>--*y; F=*y</td></tr><tr><td>DCRA</td><td>Decrement accumulator</td><td>--A; F=A</td></tr><tr><td>DIV x</td><td>Divide x into accumulator</td><td>A/=x; F=A</td></tr><tr><td>EVTWT</td><td>Wait for an event to occur</td><td>A=wait(x); F=A</td></tr><tr><td>HALT</td><td>Halt</td><td>Halt</td></tr><tr><td>INR y</td><td>Increment register</td><td>++*y; F=*y</td></tr><tr><td>INRA</td><td>Increment accumulator</td><td>++A; F=A</td></tr><tr><td>JM L</td><td>Jump if minus to tag L</td><td>if (F&lt;0) PC=L</td></tr><tr><td>JMP L</td><td>Jump to tag L</td><td>PC=L</td></tr><tr><td>JNZ L</td><td>Jump if non-zero to tag L</td><td>if (F) PC=L</td></tr><tr><td>JP L</td><td>Jump if positive to tag L</td><td>if (F&gt;=0) PC=L</td></tr><tr><td>JZ L</td><td>Jump if zero to tag L</td><td>if (!F) PC=L</td></tr><tr><td>LD y x</td><td>Load register with x</td><td>*y=x</td></tr><tr><td>LDA x</td><td>Load accumulator with x</td><td>A=x</td></tr><tr><td>MLT x</td><td>Multiply x with accumulator</td><td>A*=x; F=A</td></tr><tr><td>MOD x</td><td>Modulus x with accumulator</td><td>A%=x; F=A</td></tr><tr><td>OR x</td><td>Or x with accumulator</td><td>A|=x; F=A</td></tr><tr><td>POP y</td><td>Pop register</td><td>y=pop()</td></tr><tr><td>POPA</td><td>Pop accumulator</td><td>A=pop()</td></tr><tr><td>PUSH y</td><td>Push register</td><td>push(y)</td></tr><tr><td>PUSHA</td><td>Push accumulator</td><td>push(A)</td></tr><tr><td>RET</td><td>Return from subroutine</td><td>PC=pop()</td></tr><tr><td>RL y x</td><td>Rotate left register x bits</td><td>*y&lt;&lt;=x; F=*y</td></tr><tr><td>RLA x</td><td>Rotate left accumulator x bits</td><td>A&lt;&lt;=x; F=A</td></tr><tr><td>RR y x</td><td>Rotate right register x bits</td><td>*y&gt;&gt;=x; F=*y</td></tr><tr><td>RRA x</td><td>Rotate right accumulator x bits</td><td>A&gt;&gt;=x; F=A</td></tr><tr><td>STA y</td><td>Store accumulator in register</td><td>y=A</td></tr><tr><td>SUB x</td><td>Subtract x from accumulator</td><td>A-=x; F=A</td></tr><tr><td>SYS str</td><td>Run external script (/opt/pigpio/cgi/str)</td><td>system(str); F=A</td></tr><tr><td>TAG L</td><td>Label the current script position</td><td>N/A</td></tr><tr><td>WAIT x</td><td>Wait for a GPIO in x to change state</td><td>A=wait(x); F=A</td></tr><tr><td>X y1 y2</td><td>Exchange contents of registers y1 and y2</td><td>t=*y1;*y1=*y2;*y2=t</td></tr><tr><td>XA y</td><td>Exchange contents of accumulator and register</td><td>t=A;A=*y;*y=t</td></tr><tr><td>XOR x</td><td>Xor x with accumulator</td><td>A^=x; F=A</td></tr></tbody></table><br><br>x may be a constant, a parameter (p0-p9), or a variable (v0-v149).
<br><br>y may be a parameter (p0-p9), or a variable (v0-v149).  If p or v isn't
specified y is assumed to be a variable.
<br><br>The EVTWT command parameter is a bit-mask with 1 set for events of interest.
<br><br>The WAIT command parameter is a bit-mask with 1 set for GPIO of interest.
<br><br>The SYS script receives two unsigned parameters: the accumulator A and
the current GPIO levels.
<br><br>


