Update .gitignore and remove cruft from DOC directory.

This commit is contained in:
Guy McSwain 2020-04-30 12:51:32 -05:00
parent 67af06f176
commit 348ad4cb25
67 changed files with 5 additions and 60419 deletions

6
.gitignore vendored
View File

@ -12,5 +12,9 @@ __pycache__
build
dist
*.egg-info
wavepad_jitter.py
# DOC files
DOC/dbase/pigpio.sqlite.*
DOC/tmp
DOC/MAN
DOC/HTML/*.html

File diff suppressed because one or more lines are too long

View File

@ -1,121 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links." />
<meta name="keywords" content="raspberry, pi, C, Python, GPIO, library, shell, command, utilities, module, SPI, I2C, serial" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>pigpio library</title>
<link rel="stylesheet" type="text/css" href="scripts/index.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<table style="padding:0px; border:0px; margin:0px; width:780px; background-color:#e0e0e0;">
<td style="background:#EAF2E6 url('images/sidebar.gif') repeat-y; width:35px; height:100%"></td>
<td>
<table>
<div style="background:url('images/topbar.gif') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"><a href="index.html"><img src="images/pigpio-logo.gif" border="0" /></a>pigpio library</div>
</table>
<table><div>
<td><img src="images/rf-tx.jpg" width="250"></td>
<td><img src="images/rpi.jpg" width="250"></td>
<td><img src="images/speaker.jpg" width="250"></td>
</div></table>
<table>
<td style="vertical-align: top; background-color: #98bf21;"><a class="l1" href="index.html">pigpio</a>
<a class="l1" href="cif.html">pigpio C I/F</a>
<a class="l1" href="pigpiod.html">pigpiod</a>
<a class="l1" href="pdif2.html">pigpiod C I/F</a>
<a class="l1" href="python.html">Python</a>
<a class="l1" href="pigs.html">pigs</a>
<a class="l1" href="piscope.html">piscope</a>
<a class="l1" href="misc.html">Misc</a>
<a class="l1" href="examples.html">Examples</a>
<a class="l1" href="download.html">Download</a>
<a class="l1" href="faq.html">FAQ</a>
<a class="l1" href="sitemap.html">Site Map</a>
</td>
<td><center><h2>Download & Install</h2></center>
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 (V75)<br></h3>
<code>wget https://github.com/joan2937/pigpio/archive/v75.zip<br>
unzip v75.zip<br>
cd pigpio-75<br>
make<br>
sudo make install<br></code><br>
<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>
</td>
</table>
<div style="vertical-align: center; text-align: center; background-color:#98bf21; font-size:0.8em; height:30px"><a class="l2" href="index.html">[pigpio]</a>
<a class="l2" href="cif.html">[pigpio C I/F]</a>
<a class="l2" href="pigpiod.html">[pigpiod]</a>
<a class="l2" href="pdif2.html">[pigpiod C I/F]</a>
<a class="l2" href="python.html">[Python]</a>
<a class="l2" href="pigs.html">[pigs]</a>
<a class="l2" href="piscope.html">[piscope]</a>
<a class="l2" href="misc.html">[Misc]</a>
<a class="l2" href="examples.html">[Examples]</a>
<a class="l2" href="download.html">[Download]</a>
<a class="l2" href="faq.html">[FAQ]</a>
<a class="l2" href="sitemap.html">[Site Map]</a>
</div>
<table><tr>
<td style="width: 200px"><div style="text-align: left;"><small>&copy; 2012-2020</small></div></td>
<td style="width: 350px"><div style="text-align: center;">e-mail: pigpio @ abyz.me.uk</div></td>
<td style="width: 200px"><div style="text-align: right;"><small>Updated: 30/04/2020</small></div></td>
</tr></table>
</td>
</table>
</body>
</html>

View File

@ -1,205 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links." />
<meta name="keywords" content="raspberry, pi, C, Python, GPIO, library, shell, command, utilities, module, SPI, I2C, serial" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>pigpio library</title>
<link rel="stylesheet" type="text/css" href="scripts/index.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<table style="padding:0px; border:0px; margin:0px; width:780px; background-color:#e0e0e0;">
<td style="background:#EAF2E6 url('images/sidebar.gif') repeat-y; width:35px; height:100%"></td>
<td>
<table>
<div style="background:url('images/topbar.gif') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"><a href="index.html"><img src="images/pigpio-logo.gif" border="0" /></a>pigpio library</div>
</table>
<table><div>
<td><img src="images/keypad.jpg" width="250"></td>
<td><img src="images/ldr-cap.jpg" width="250"></td>
<td><img src="images/meter.jpg" width="250"></td>
</div></table>
<table>
<td style="vertical-align: top; background-color: #98bf21;"><a class="l1" href="index.html">pigpio</a>
<a class="l1" href="cif.html">pigpio C I/F</a>
<a class="l1" href="pigpiod.html">pigpiod</a>
<a class="l1" href="pdif2.html">pigpiod C I/F</a>
<a class="l1" href="python.html">Python</a>
<a class="l1" href="pigs.html">pigs</a>
<a class="l1" href="piscope.html">piscope</a>
<a class="l1" href="misc.html">Misc</a>
<a class="l1" href="examples.html">Examples</a>
<a class="l1" href="download.html">Download</a>
<a class="l1" href="faq.html">FAQ</a>
<a class="l1" href="sitemap.html">Site Map</a>
</td>
<td><center><h2>LDR Example</h2></center>
<p>The following code shows a method of reading analogue sensors on
the digital input only Pi.&nbsp; A Light Dependent Resistor (LDR)
varies its resistance according to the incident light
intensisty.</p>
<h3>SETUP</h3>
<img src="images/LDR-fritz.png" alt="fritzing diagram" style=
"width: 200px; height: 300px;" align="left" hspace="10">The LDR
used is a Cadmium Sulphide device with a 1MOhm dark resistance and
2-4KOhm at 100 lux.&nbsp; The capacitor is a 104
ceramic.<span itemprop="name"><br>
<br>
One end of the capacitor is connected to Pi ground.<br>
<br>
One end of the LDR is connected to Pi 3V3.<br>
<br>
The other ends of the capacitor and LDR are connected to a spare
gpio.</span><br>
<p>Here P1-1 is used for 3V3, P1-20 is used for ground, and gpio 18
(P1-12) is used for the gpio.<br clear="all"></p>
<p><img src="images/LDR-photo.jpg" style=
"width: 500px; height: 667px;" alt="photo of set-up"></p>
<h3>CODE</h3>
<code>#include &lt;stdio.h&gt;<br>
<br>
#include &lt;pigpio.h&gt;<br>
<br>
/*
-----------------------------------------------------------------------<br>
<br>
&nbsp;&nbsp; 3V3 ----- Light Dependent Resistor --+-- Capacitor
----- Ground<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+-- gpio<br>
<br>
<br>
&nbsp; cc -o LDR LDR.c -lpigpio -lpthread -lrt<br>
&nbsp; sudo ./LDR<br>
<br>
*/<br>
<br>
#define LDR 18<br>
<br>
/* forward declaration */<br>
<br>
void alert(int pin, int level, uint32_t tick);<br>
<br>
int main (int argc, char *argv[])<br>
{<br>
&nbsp;&nbsp; if (gpioInitialise()&lt;0) return 1;<br>
<br>
&nbsp;&nbsp; gpioSetAlertFunc(LDR, alert); /* call alert when LDR
changes state */<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp; while (1)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioSetMode(LDR, PI_OUTPUT); /*
drain capacitor */<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioWrite(LDR, PI_OFF);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioDelay(200); /* 50 micros is
enough, 200 is overkill */<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioSetMode(LDR, PI_INPUT); /* start
capacitor recharge */<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioDelay(10000); /* nominal 100
readings per second */<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; gpioTerminate();<br>
}<br>
<br>
void alert(int pin, int level, uint32_t tick)<br>
{<br>
&nbsp;&nbsp; static uint32_t inited = 0;<br>
&nbsp;&nbsp; static uint32_t lastTick, firstTick;<br>
<br>
&nbsp;&nbsp; uint32_t diffTick;<br>
<br>
&nbsp;&nbsp; if (inited)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diffTick = tick - lastTick;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastTick = tick;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (level == 1) printf("%u %d\ ",
tick-firstTick, diffTick);<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; else<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inited = 1;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; firstTick = tick;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastTick = firstTick;<br>
&nbsp;&nbsp; }<br>
}<br></code>
<h3>BUILD</h3>
<code>cc -o LDR LDR.c -lpigpio -lrt -lpthread<br></code>
<h3>RUN</h3>
<code>sudo ./LDR &gt;LDR.dat &amp;</code><br>
<br>
While the program is running you can capture the waveform using the
notification feature built in to pigpio.&nbsp; Issue the following
commands on the Pi.<br>
<br>
<code>pigs no<br>
pig2vcd&nbsp; &lt;/dev/pigpio0 &gt;LDR.vcd &amp;<br>
pigs nb 0 0x40000 # set bit for gpio 18<br></code>
<p>Change the light falling on the LDR for a few seconds (e.g.
shine a torch on it or shade it with your hands).<br></p>
<code>pigs nc 0</code><br>
<p>The file LDR.vcd will contain the captured waveform, which can
be viewed using GTKWave.</p>
<p>Overview</p>
<img src="images/LDR-wave-1.png" style=
"width: 600px; height: 100px;" alt="LDR waveform 1"><br>
<p>Reading circa every 10ms<br></p>
<img src="images/LDR-wave-2.png" style=
"width: 600px; height: 100px;" alt="LDR waveform 2"><br>
<p>One reading, circa 400us<br></p>
<img src="images/LDR-wave-3.png" style=
"width: 600px; height: 100px;" alt="LDR waveform 3"><br>
<p>The file LDR.dat will contain pairs of timestamps and recharge
time (in us).&nbsp; The following&nbsp; script will convert the
timestamps into seconds.<span style=
"font-style: italic;"><br></span></p>
<p><code>awk '{print $1/1000000, $2}' LDR.dat
&gt;LDR-secs.dat</code></p>
<p>Gnuplot is a useful tool to graph data.<br></p>
plot [14:24] 'LDR-secs.dat' with lines title 'LDR'
<p>Gnuplot readings 14-24 seconds<br></p>
<p><img src="images/LDR-gnup-1.png" style=
"width: 600px; height: 321px;" alt="gnuplot 1"></p>
plot [18:21] 'LDR-secs.dat' with lines title 'LDR'<br>
<br>
Gnuplot readings 18-21 seconds
<p><img src="images/LDR-gnup-2.png" style=
"width: 600px; height: 321px;" alt="Gnuplot 2"></p>
</td>
</table>
<div style="vertical-align: center; text-align: center; background-color:#98bf21; font-size:0.8em; height:30px"><a class="l2" href="index.html">[pigpio]</a>
<a class="l2" href="cif.html">[pigpio C I/F]</a>
<a class="l2" href="pigpiod.html">[pigpiod]</a>
<a class="l2" href="pdif2.html">[pigpiod C I/F]</a>
<a class="l2" href="python.html">[Python]</a>
<a class="l2" href="pigs.html">[pigs]</a>
<a class="l2" href="piscope.html">[piscope]</a>
<a class="l2" href="misc.html">[Misc]</a>
<a class="l2" href="examples.html">[Examples]</a>
<a class="l2" href="download.html">[Download]</a>
<a class="l2" href="faq.html">[FAQ]</a>
<a class="l2" href="sitemap.html">[Site Map]</a>
</div>
<table><tr>
<td style="width: 200px"><div style="text-align: left;"><small>&copy; 2012-2020</small></div></td>
<td style="width: 350px"><div style="text-align: center;">e-mail: pigpio @ abyz.me.uk</div></td>
<td style="width: 200px"><div style="text-align: right;"><small>Updated: 30/04/2020</small></div></td>
</tr></table>
</td>
</table>
</body>
</html>

View File

@ -1,308 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links." />
<meta name="keywords" content="raspberry, pi, C, Python, GPIO, library, shell, command, utilities, module, SPI, I2C, serial" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>pigpio library</title>
<link rel="stylesheet" type="text/css" href="scripts/index.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<table style="padding:0px; border:0px; margin:0px; width:780px; background-color:#e0e0e0;">
<td style="background:#EAF2E6 url('images/sidebar.gif') repeat-y; width:35px; height:100%"></td>
<td>
<table>
<div style="background:url('images/topbar.gif') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"><a href="index.html"><img src="images/pigpio-logo.gif" border="0" /></a>pigpio library</div>
</table>
<table><div>
<td><img src="images/driver.jpg" width="250"></td>
<td><img src="images/imu-3.jpg" width="250"></td>
<td><img src="images/ir-motion.jpg" width="250"></td>
</div></table>
<table>
<td style="vertical-align: top; background-color: #98bf21;"><a class="l1" href="index.html">pigpio</a>
<a class="l1" href="cif.html">pigpio C I/F</a>
<a class="l1" href="pigpiod.html">pigpiod</a>
<a class="l1" href="pdif2.html">pigpiod C I/F</a>
<a class="l1" href="python.html">Python</a>
<a class="l1" href="pigs.html">pigs</a>
<a class="l1" href="piscope.html">piscope</a>
<a class="l1" href="misc.html">Misc</a>
<a class="l1" href="examples.html">Examples</a>
<a class="l1" href="download.html">Download</a>
<a class="l1" href="faq.html">FAQ</a>
<a class="l1" href="sitemap.html">Site Map</a>
</td>
<td><center><h2>IR Remote Example</h2></center>
<p>The following code shows one way to read an infrared remote
control device (the sort used in TVs and stereo systems).</p>
<h3>SETUP</h3>
<img alt="fritzing diagram" style="width: 200px; height: 317px;"
src="images/ir-fritz.png" align="left" hspace="10">The device used
is a <span itemprop="name">SFH5110 (IR Receiver for remote control,
carrier 38 kHz).<br>
<br></span> Pin 1 (left from front) may be connected to any spare
gpio.&nbsp; Here it's connected via a 4K7 current limiting
resistor.&nbsp; This isn't really needed as the device has an
internal 23K resistor in-line.&nbsp; It does no harm though.<br>
<br>
Pin 2 should be connected to a Pi ground pin.<br>
<br>
Pin 3 should be connected to a Pi 5V pin.<br>
<p>Here pin 1 to gpio7 (P1-26) via a 4K7 resistor, pin 2 to ground
(P1-14), and pin 3 to 5V (P1-2).<br clear="all"></p>
<p><img src="images/ir-photo.jpg" style=
"width: 500px; height: 500px;" alt="photo of set-up"></p>
<h3>CODE</h3>
<code>#include &lt;stdio.h&gt;<br>
<br>
#include &lt;pigpio.h&gt;<br>
<br>
#define IR_PIN 7<br>
<br>
#define OUTSIDE_CODE 0<br>
#define INSIDE_CODE&nbsp; 1<br>
<br>
#define MIN_MESSAGE_GAP 3000<br>
#define MAX_MESSAGE_END 3000<br>
<br>
#define MAX_TRANSITIONS 500<br>
<br>
/*<br>
&nbsp;&nbsp; using the FNV-1a
hash&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp; from
http://isthe.com/chongo/tech/comp/fnv/#FNV-param<br>
*/<br>
<br>
#define FNV_PRIME_32 16777619<br>
#define FNV_BASIS_32 2166136261U<br>
<br>
static volatile uint32_t ir_hash = 0;<br>
<br>
typedef struct<br>
{<br>
&nbsp;&nbsp; int state;<br>
&nbsp;&nbsp; int count;<br>
&nbsp;&nbsp; int level;<br>
&nbsp;&nbsp; uint16_t micros[MAX_TRANSITIONS];<br>
} decode_t;<br>
<br>
/* forward declarations */<br>
<br>
void&nbsp;&nbsp;&nbsp;&nbsp; alert(int gpio, int level, uint32_t
tick);<br>
uint32_t getHash(decode_t * decode);<br>
void&nbsp;&nbsp;&nbsp;&nbsp; updateState(decode_t * decode, int
level, uint32_t micros);<br>
<br>
int main(int argc, char * argv[])<br>
{<br>
&nbsp;&nbsp; if (gpioInitialise()&lt;0)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1 ;<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; /* IR pin as input */<br>
<br>
&nbsp;&nbsp; gpioSetMode(IR_PIN, PI_INPUT);<br>
<br>
&nbsp;&nbsp; /* 5ms max gap after last pulse */<br>
<br>
&nbsp;&nbsp; gpioSetWatchdog(IR_PIN, 5);<br>
<br>
&nbsp;&nbsp; /* monitor IR level changes */<br>
<br>
&nbsp;&nbsp; gpioSetAlertFunc(IR_PIN, alert);<br>
<br>
&nbsp;&nbsp; while (1)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (ir_hash)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* non-zero means
new decode */<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("ir code is
%u\ ", ir_hash);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ir_hash = 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioDelay(100000); /* check remote
10 times per second */<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; gpioTerminate();<br>
}<br>
<br>
void alert(int gpio, int level, uint32_t tick)<br>
{<br>
&nbsp;&nbsp; static int inited = 0;<br>
<br>
&nbsp;&nbsp; static decode_t activeHigh, activeLow;<br>
<br>
&nbsp;&nbsp; static uint32_t lastTick;<br>
<br>
&nbsp;&nbsp; uint32_t diffTick;<br>
<br>
&nbsp;&nbsp; if (!inited)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inited = 1;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; activeHigh.state = OUTSIDE_CODE;
activeHigh.level = PI_LOW;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; activeLow.state&nbsp; =
OUTSIDE_CODE; activeLow.level&nbsp; = PI_HIGH;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastTick = tick;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; diffTick = tick - lastTick;<br>
<br>
&nbsp;&nbsp; if (level != PI_TIMEOUT) lastTick = tick;<br>
<br>
&nbsp;&nbsp; updateState(&amp;activeHigh, level, diffTick);<br>
&nbsp;&nbsp; updateState(&amp;activeLow, level, diffTick);<br>
}<br>
<br>
void updateState(decode_t * decode, int level, uint32_t micros)<br>
{<br>
&nbsp;&nbsp; /*<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; We are dealing with active high as
well as active low<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; remotes.&nbsp; Abstract the common
functionality.<br>
&nbsp;&nbsp; */<br>
<br>
&nbsp;&nbsp; if (decode-&gt;state == OUTSIDE_CODE)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (level == decode-&gt;level)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (micros &gt;
MIN_MESSAGE_GAP)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
decode-&gt;state = INSIDE_CODE;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
decode-&gt;count = 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; else<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (micros &gt; MAX_MESSAGE_END)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* end of message
*/<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* ignore if last
code not consumed */<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!ir_hash)
ir_hash = getHash(decode);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; decode-&gt;state =
OUTSIDE_CODE;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if
(decode-&gt;count &lt; (MAX_TRANSITIONS-1))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if (level != PI_TIMEOUT)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
decode-&gt;micros[decode-&gt;count++] = micros;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp; }<br>
}<br>
<br>
int compare(unsigned int oldval, unsigned int newval)<br>
{<br>
&nbsp;&nbsp; if&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (newval &lt; (oldval
* 0.75)) {return 1;}<br>
&nbsp;&nbsp; else if (oldval &lt; (newval * 0.75)) {return 2;}<br>
&nbsp;&nbsp;
else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{return 4;}<br>
}<br>
<br>
uint32_t getHash(decode_t * decode)<br>
{<br>
&nbsp;&nbsp; /* use FNV-1a */<br>
<br>
&nbsp;&nbsp; uint32_t hash;<br>
&nbsp;&nbsp; int i, value;<br>
<br>
&nbsp;&nbsp; if (decode-&gt;count &lt; 6) {return 0;}<br>
<br>
&nbsp;&nbsp; hash = FNV_BASIS_32;<br>
<br>
&nbsp;&nbsp; for (i=0; i&lt;(decode-&gt;count-2); i++)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value =
compare(decode-&gt;micros[i], decode-&gt;micros[i+2]);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hash = hash ^ value;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hash = (hash * FNV_PRIME_32);<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; return hash;<br>
}<br></code>
<h3>BUILD</h3>
<code>cc -o ir_remote ir_remote.c -lpigpio -lrt
-lpthread<br></code>
<h3>RUN</h3>
<code>sudo ./ir_remote</code><br>
<p>A hash code is formed from the level transitions detected during
a remote key press.&nbsp; This is likely to be unique over multiple
remotes and keys.</p>
<p>While the program is running you can capture the waveform using
the notification feature built in to pigpio.&nbsp; Issue the
following commands on the Pi.</p>
<code>pigs no<br>
pig2vcd&nbsp; &lt;/dev/pigpio0 &gt;ir.vcd &amp;<br>
pigs nb 0 0x80 # set bits for gpios 7 (0x80)<br></code>
<p>Press a few different remotes and keys.&nbsp; Then enter<br></p>
<code>pigs nc 0</code><br>
<p>The file ir.vcd will contain the captured waveform, which can be
viewed using GTKWave.</p>
<p>Overview</p>
<img src="images/ir-wave-1.png" style=
"width: 600px; height: 100px;" alt="ir remote waveform 1"><br>
<p>Remote A typical waveform</p>
<img src="images/ir-wave-2.png" style=
"width: 600px; height: 100px;" alt="ir remote waveform 2"><br>
<p>Remote B typical waveform</p>
<img style="width: 600px; height: 100px;" alt=
"ir remote waveform 3" src="images/ir-wave-3.png">
</td>
</table>
<div style="vertical-align: center; text-align: center; background-color:#98bf21; font-size:0.8em; height:30px"><a class="l2" href="index.html">[pigpio]</a>
<a class="l2" href="cif.html">[pigpio C I/F]</a>
<a class="l2" href="pigpiod.html">[pigpiod]</a>
<a class="l2" href="pdif2.html">[pigpiod C I/F]</a>
<a class="l2" href="python.html">[Python]</a>
<a class="l2" href="pigs.html">[pigs]</a>
<a class="l2" href="piscope.html">[piscope]</a>
<a class="l2" href="misc.html">[Misc]</a>
<a class="l2" href="examples.html">[Examples]</a>
<a class="l2" href="download.html">[Download]</a>
<a class="l2" href="faq.html">[FAQ]</a>
<a class="l2" href="sitemap.html">[Site Map]</a>
</div>
<table><tr>
<td style="width: 200px"><div style="text-align: left;"><small>&copy; 2012-2020</small></div></td>
<td style="width: 350px"><div style="text-align: center;">e-mail: pigpio @ abyz.me.uk</div></td>
<td style="width: 200px"><div style="text-align: right;"><small>Updated: 30/04/2020</small></div></td>
</tr></table>
</td>
</table>
</body>
</html>

View File

@ -1,309 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links." />
<meta name="keywords" content="raspberry, pi, C, Python, GPIO, library, shell, command, utilities, module, SPI, I2C, serial" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>pigpio library</title>
<link rel="stylesheet" type="text/css" href="scripts/index.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<table style="padding:0px; border:0px; margin:0px; width:780px; background-color:#e0e0e0;">
<td style="background:#EAF2E6 url('images/sidebar.gif') repeat-y; width:35px; height:100%"></td>
<td>
<table>
<div style="background:url('images/topbar.gif') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"><a href="index.html"><img src="images/pigpio-logo.gif" border="0" /></a>pigpio library</div>
</table>
<table><div>
<td><img src="images/stepper.jpg" width="250"></td>
<td><img src="images/transistors.jpg" width="250"></td>
<td><img src="images/wires.jpg" width="250"></td>
</div></table>
<table>
<td style="vertical-align: top; background-color: #98bf21;"><a class="l1" href="index.html">pigpio</a>
<a class="l1" href="cif.html">pigpio C I/F</a>
<a class="l1" href="pigpiod.html">pigpiod</a>
<a class="l1" href="pdif2.html">pigpiod C I/F</a>
<a class="l1" href="python.html">Python</a>
<a class="l1" href="pigs.html">pigs</a>
<a class="l1" href="piscope.html">piscope</a>
<a class="l1" href="misc.html">Misc</a>
<a class="l1" href="examples.html">Examples</a>
<a class="l1" href="download.html">Download</a>
<a class="l1" href="faq.html">FAQ</a>
<a class="l1" href="sitemap.html">Site Map</a>
</td>
<td><center><h2>Arduino Motor Shield</h2></center>
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>
</td>
</table>
<div style="vertical-align: center; text-align: center; background-color:#98bf21; font-size:0.8em; height:30px"><a class="l2" href="index.html">[pigpio]</a>
<a class="l2" href="cif.html">[pigpio C I/F]</a>
<a class="l2" href="pigpiod.html">[pigpiod]</a>
<a class="l2" href="pdif2.html">[pigpiod C I/F]</a>
<a class="l2" href="python.html">[Python]</a>
<a class="l2" href="pigs.html">[pigs]</a>
<a class="l2" href="piscope.html">[piscope]</a>
<a class="l2" href="misc.html">[Misc]</a>
<a class="l2" href="examples.html">[Examples]</a>
<a class="l2" href="download.html">[Download]</a>
<a class="l2" href="faq.html">[FAQ]</a>
<a class="l2" href="sitemap.html">[Site Map]</a>
</div>
<table><tr>
<td style="width: 200px"><div style="text-align: left;"><small>&copy; 2012-2020</small></div></td>
<td style="width: 350px"><div style="text-align: center;">e-mail: pigpio @ abyz.me.uk</div></td>
<td style="width: 200px"><div style="text-align: right;"><small>Updated: 30/04/2020</small></div></td>
</tr></table>
</td>
</table>
</body>
</html>

View File

@ -1,240 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links." />
<meta name="keywords" content="raspberry, pi, C, Python, GPIO, library, shell, command, utilities, module, SPI, I2C, serial" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>pigpio library</title>
<link rel="stylesheet" type="text/css" href="scripts/index.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<table style="padding:0px; border:0px; margin:0px; width:780px; background-color:#e0e0e0;">
<td style="background:#EAF2E6 url('images/sidebar.gif') repeat-y; width:35px; height:100%"></td>
<td>
<table>
<div style="background:url('images/topbar.gif') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"><a href="index.html"><img src="images/pigpio-logo.gif" border="0" /></a>pigpio library</div>
</table>
<table><div>
<td><img src="images/msp430.jpg" width="250"></td>
<td><img src="images/leds.jpg" width="250"></td>
<td><img src="images/ldr.jpg" width="250"></td>
</div></table>
<table>
<td style="vertical-align: top; background-color: #98bf21;"><a class="l1" href="index.html">pigpio</a>
<a class="l1" href="cif.html">pigpio C I/F</a>
<a class="l1" href="pigpiod.html">pigpiod</a>
<a class="l1" href="pdif2.html">pigpiod C I/F</a>
<a class="l1" href="python.html">Python</a>
<a class="l1" href="pigs.html">pigs</a>
<a class="l1" href="piscope.html">piscope</a>
<a class="l1" href="misc.html">Misc</a>
<a class="l1" href="examples.html">Examples</a>
<a class="l1" href="download.html">Download</a>
<a class="l1" href="faq.html">FAQ</a>
<a class="l1" href="sitemap.html">Site Map</a>
</td>
<td><center><h2>Rotary Encoder Example</h2></center>
<p>The following code shows one way to read an incremental
mechanical rotary enoder (the sort used for volume control in audio
systems).&nbsp; These rotary encoders have two switches A and B
which return a quadrature output, i.e. they are 90 degrees out of
phase.</p>
<h3>SETUP</h3>
<img alt="fritzing diagram" style="width: 200px; height: 300px;"
src="images/re-fritz.png" align="left" hspace="10">The common
(centre) terminal should be connected to a Pi ground.
<p>The A and B terminals may be connected to any spare gpios.</p>
<p>Here A to gpio18 (P1-12), common to ground (P1-20), B to gpio7
(P1-26).<br clear="all"></p>
<p><img src="images/re-photo.jpg" style=
"width: 400px; height: 300px;" alt="photo of set-up"></p>
<h3>CODE</h3>
<code>#include &lt;stdio.h&gt;<br>
<br>
#include &lt;pigpio.h&gt;<br>
<br>
/*<br>
&nbsp;&nbsp; Rotary encoder connections:<br>
<br>
&nbsp;&nbsp; Encoder A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - gpio
18&nbsp;&nbsp; (pin P1-12)<br>
&nbsp;&nbsp; Encoder B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - gpio
7&nbsp;&nbsp;&nbsp; (pin P1-26)<br>
&nbsp;&nbsp; Encoder Common - Pi ground (pin P1-20)<br>
*/<br>
<br>
#define ENCODER_A 18<br>
#define ENCODER_B&nbsp; 7<br>
<br>
static volatile int encoderPos;<br>
<br>
/* forward declaration */<br>
<br>
void encoderPulse(int gpio, int lev, uint32_t tick);<br>
<br>
int main(int argc, char * argv[])<br>
{<br>
&nbsp;&nbsp; int pos=0;<br>
<br>
&nbsp;&nbsp; if (gpioInitialise()&lt;0) return 1;<br>
<br>
&nbsp;&nbsp; gpioSetMode(ENCODER_A, PI_INPUT);<br>
&nbsp;&nbsp; gpioSetMode(ENCODER_B, PI_INPUT);<br>
<br>
&nbsp;&nbsp; /* pull up is needed as encoder common is grounded
*/<br>
<br>
&nbsp;&nbsp; gpioSetPullUpDown(ENCODER_A, PI_PUD_UP);<br>
&nbsp;&nbsp; gpioSetPullUpDown(ENCODER_B, PI_PUD_UP);<br>
<br>
&nbsp;&nbsp; encoderPos = pos;<br>
<br>
&nbsp;&nbsp; /* monitor encoder level changes */<br>
<br>
&nbsp;&nbsp; gpioSetAlertFunc(ENCODER_A, encoderPulse);<br>
&nbsp;&nbsp; gpioSetAlertFunc(ENCODER_B, encoderPulse);<br>
<br>
&nbsp;&nbsp; while (1)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (pos != encoderPos)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos =
encoderPos;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("pos=%d\ ",
pos);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioDelay(20000); /* check pos 50
times per second */<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; gpioTerminate();<br>
}<br>
<br>
void encoderPulse(int gpio, int level, uint32_t tick)<br>
{<br>
&nbsp;&nbsp; /*<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+---------+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+---------+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
&nbsp;&nbsp; A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
&nbsp;&nbsp;
+---------+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+---------+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +-----
1<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+---------+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+---------+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
&nbsp;&nbsp; B&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
&nbsp;&nbsp; ----+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+---------+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+---------+&nbsp; 1<br>
<br>
&nbsp;&nbsp; */<br>
<br>
&nbsp;&nbsp; static int levA=0, levB=0, lastGpio = -1;<br>
<br>
&nbsp;&nbsp; if (gpio == ENCODER_A) levA = level; else levB =
level;<br>
<br>
&nbsp;&nbsp; if (gpio != lastGpio) /* debounce */<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastGpio = gpio;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ((gpio == ENCODER_A) &amp;&amp;
(level == 0))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!levB)
++encoderPos;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if ((gpio == ENCODER_B)
&amp;&amp; (level == 1))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (levA)
--encoderPos;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp; }<br>
}<br></code>
<h3>BUILD</h3>
<code>cc -o rotary_encoder rotary_encoder.c -lpigpio -lrt
-lpthread<br></code>
<h3>RUN</h3>
<code>sudo ./rotary_encoder</code><br>
<p>While the program is running you can capture the waveform using
the notification feature built in to pigpio.&nbsp; Issue the
following commands on the Pi.</p>
<code>pigs no<br>
pig2vcd&nbsp; &lt;/dev/pigpio0 &gt;re.vcd &amp;<br>
pigs nb 0 0x40080 # set bits for gpios 7 (0x80) and 18
(0x40000)<br></code>
<p>Twiddle the rotary encoder forwards and backwards for a few
seconds.&nbsp; Then enter<br></p>
<code>pigs nc 0</code><br>
<p>The file re.vcd will contain the captured waveform, which can be
viewed using GTKWave.</p>
<br>
Overview<br>
<br>
<img src="images/re-wave-1.png" style=
"width: 600px; height: 100px;" alt=
"rotary encoder waveform overview"><br>
<br>
Detail of switch bounce.&nbsp; Contact A bounces for circa 700 us
before completing the level transition<br>
<br>
<img src="images/re-wave-2.png" style=
"width: 600px; height: 100px;" alt=
"rotary encoder waveform detail"><br>
</td>
</table>
<div style="vertical-align: center; text-align: center; background-color:#98bf21; font-size:0.8em; height:30px"><a class="l2" href="index.html">[pigpio]</a>
<a class="l2" href="cif.html">[pigpio C I/F]</a>
<a class="l2" href="pigpiod.html">[pigpiod]</a>
<a class="l2" href="pdif2.html">[pigpiod C I/F]</a>
<a class="l2" href="python.html">[Python]</a>
<a class="l2" href="pigs.html">[pigs]</a>
<a class="l2" href="piscope.html">[piscope]</a>
<a class="l2" href="misc.html">[Misc]</a>
<a class="l2" href="examples.html">[Examples]</a>
<a class="l2" href="download.html">[Download]</a>
<a class="l2" href="faq.html">[FAQ]</a>
<a class="l2" href="sitemap.html">[Site Map]</a>
</div>
<table><tr>
<td style="width: 200px"><div style="text-align: left;"><small>&copy; 2012-2020</small></div></td>
<td style="width: 350px"><div style="text-align: center;">e-mail: pigpio @ abyz.me.uk</div></td>
<td style="width: 200px"><div style="text-align: right;"><small>Updated: 30/04/2020</small></div></td>
</tr></table>
</td>
</table>
</body>
</html>

View File

@ -1,219 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links." />
<meta name="keywords" content="raspberry, pi, C, Python, GPIO, library, shell, command, utilities, module, SPI, I2C, serial" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>pigpio library</title>
<link rel="stylesheet" type="text/css" href="scripts/index.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<table style="padding:0px; border:0px; margin:0px; width:780px; background-color:#e0e0e0;">
<td style="background:#EAF2E6 url('images/sidebar.gif') repeat-y; width:35px; height:100%"></td>
<td>
<table>
<div style="background:url('images/topbar.gif') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"><a href="index.html"><img src="images/pigpio-logo.gif" border="0" /></a>pigpio library</div>
</table>
<table><div>
<td><img src="images/nano.jpg" width="250"></td>
<td><img src="images/pot.jpg" width="250"></td>
<td><img src="images/remote-1.jpg" width="250"></td>
</div></table>
<table>
<td style="vertical-align: top; background-color: #98bf21;"><a class="l1" href="index.html">pigpio</a>
<a class="l1" href="cif.html">pigpio C I/F</a>
<a class="l1" href="pigpiod.html">pigpiod</a>
<a class="l1" href="pdif2.html">pigpiod C I/F</a>
<a class="l1" href="python.html">Python</a>
<a class="l1" href="pigs.html">pigs</a>
<a class="l1" href="piscope.html">piscope</a>
<a class="l1" href="misc.html">Misc</a>
<a class="l1" href="examples.html">Examples</a>
<a class="l1" href="download.html">Download</a>
<a class="l1" href="faq.html">FAQ</a>
<a class="l1" href="sitemap.html">Site Map</a>
</td>
<td><center><h2>Sonar Ranger Example</h2></center>
<p>The following code shows a method of reading a class of sonar
rangers.&nbsp; These rangers requires a trigger pulse.&nbsp;
Shortly after receiving a trigger they transmit a noise pulse and
set the echo line high.&nbsp; When the echo is received the echo
line is set low.<br></p>
<h3>SETUP</h3>
<img src="images/son-fritz.png" alt="fritzing diagram" style=
"width: 200px; height: 600px;" align="left" hspace="10"><br>
<br>
<br>
<br>
<br>
The ranger used is a SRF05 (check the pinouts, there are many
variants).<br>
<br>
The fritzing diagram shows the back of the ranger, i.e. pin 1 is
the rightmost.<br>
<br>
Pin 1 is 5V.<br>
Pin 2 is the trigger line.<br>
Pin 3 is the echo line.<br>
Pin 4 is out (unused).<br>
Pin 5 is ground.<br>
<br clear="all">
<p><img src="images/son-photo.jpg" style=
"width: 500px; height: 376px;" alt="photo of set-up"></p>
<h3>CODE</h3>
<code>#include &lt;stdio.h&gt;<br>
<br>
#include &lt;pigpio.h&gt;<br>
<br>
/*<br>
<br>
P1&nbsp; Name&nbsp; gpio&nbsp;&nbsp;&nbsp; used for<br>
<br>
&nbsp;2&nbsp; 5V&nbsp;&nbsp;&nbsp; ---&nbsp;&nbsp;&nbsp;&nbsp;
5V<br>
&nbsp;6&nbsp; GND&nbsp;&nbsp; ---&nbsp;&nbsp;&nbsp;&nbsp;
Ground<br>
24&nbsp; CE0&nbsp;&nbsp; 8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Sonar echo<br>
26&nbsp; CE1&nbsp;&nbsp; 7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Sonar trigger<br>
<br>
*/<br>
<br>
#define SONAR_TRIGGER 7<br>
#define SONAR_ECHO&nbsp;&nbsp;&nbsp; 8<br>
<br>
/* forward prototypes */<br>
<br>
void sonarTrigger(void);<br>
<br>
void sonarEcho(int gpio, int level, uint32_t tick);<br>
<br>
int main(int argc, char *argv[])<br>
{<br>
&nbsp;&nbsp; if (gpioInitialise()&lt;0) return 1;<br>
<br>
&nbsp;&nbsp; gpioSetMode(SONAR_TRIGGER, PI_OUTPUT);<br>
&nbsp;&nbsp; gpioWrite&nbsp; (SONAR_TRIGGER, PI_OFF);<br>
<br>
&nbsp;&nbsp; gpioSetMode(SONAR_ECHO,&nbsp;&nbsp;&nbsp;
PI_INPUT);<br>
<br>
&nbsp;&nbsp; /* update sonar 20 times a second, timer #0 */<br>
<br>
&nbsp;&nbsp; gpioSetTimerFunc(0, 50, sonarTrigger); /* every 50ms
*/<br>
<br>
&nbsp;&nbsp; /* monitor sonar echos */<br>
<br>
&nbsp;&nbsp; gpioSetAlertFunc(SONAR_ECHO, sonarEcho);<br>
<br>
&nbsp;&nbsp; while (1) sleep(1);<br>
<br>
&nbsp;&nbsp; gpioTerminate();<br>
<br>
&nbsp;&nbsp; return 0;<br>
}<br>
<br>
void sonarTrigger(void)<br>
{<br>
&nbsp;&nbsp; /* trigger a sonar reading */<br>
<br>
&nbsp;&nbsp; gpioWrite(SONAR_TRIGGER, PI_ON);<br>
<br>
&nbsp;&nbsp; gpioDelay(10); /* 10us trigger pulse */<br>
<br>
&nbsp;&nbsp; gpioWrite(SONAR_TRIGGER, PI_OFF);<br>
}<br>
<br>
void sonarEcho(int gpio, int level, uint32_t tick)<br>
{<br>
&nbsp;&nbsp; static uint32_t startTick, firstTick=0;<br>
<br>
&nbsp;&nbsp; int diffTick;<br>
<br>
&nbsp;&nbsp; if (!firstTick) firstTick = tick;<br>
<br>
&nbsp;&nbsp; if (level == PI_ON)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; startTick = tick;<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; else if (level == PI_OFF)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diffTick = tick - startTick;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%u %u\ ", tick-firstTick,
diffTick);<br>
&nbsp;&nbsp; }<br>
}<br></code>
<h3>BUILD</h3>
<code>cc -o sonar sonar.c -lpigpio -lrt -lpthread<br></code>
<h3>RUN</h3>
<code>sudo ./sonar &gt;sonar.dat &amp;</code><br>
<br>
While the program is running you can capture the waveform using the
notification feature built in to pigpio.&nbsp; Issue the following
commands on the Pi.<br>
<br>
<code>pigs no<br>
pig2vcd&nbsp; &lt;/dev/pigpio0 &gt;sonar.vcd &amp;<br>
pigs nb 0 0x180 # set bits for gpios 7 and 8<br></code>
<p>Move an object in front of the sonar ranger for a few
seconds.<br></p>
<code>pigs nc 0</code><br>
<p>The file sonar.vcd will contain the captured waveform, which can
be viewed using GTKWave.</p>
<p>Overview</p>
<img src="images/son-wave-1.png" style=
"width: 600px; height: 100px;" alt="LDR waveform 1"><br>
<p>Reading circa every 10ms<br></p>
<img src="images/son-wave-2.png" style=
"width: 600px; height: 100px;" alt="Sonar waveform 2"><br>
<p>One reading, circa 400us<br></p>
<img src="images/son-wave-3.png" style=
"width: 600px; height: 100px;" alt="Sonar waveform 3"><br>
<p>another</p>
<img style="width: 600px; height: 100px;" alt="Sonar waveform 4"
src="images/son-wave-4.png"><br>
<p>The file sonar.dat will contain pairs of timestamps and echo
length (in us).&nbsp; The following&nbsp; script will convert the
timestamps into seconds.<span style=
"font-style: italic;"><br></span></p>
<p><code>awk '{print $1/1000000, $2}' sonar.dat
&gt;sonar-secs.dat</code></p>
<p>Gnuplot is a useful tool to graph data.<br></p>
plot 'sonar-secs.dat' title 'Sonar'<br>
<p><img src="images/son-gnup-1.png" style=
"width: 600px; height: 321px;" alt="gnuplot 1"><br>
&nbsp;plot [10:25] 'sonar-secs.dat' title 'Sonar'<br></p>
<p><img src="images/son-gnup-2.png" style=
"width: 600px; height: 321px;" alt="gnuplot 1"></p>
</td>
</table>
<div style="vertical-align: center; text-align: center; background-color:#98bf21; font-size:0.8em; height:30px"><a class="l2" href="index.html">[pigpio]</a>
<a class="l2" href="cif.html">[pigpio C I/F]</a>
<a class="l2" href="pigpiod.html">[pigpiod]</a>
<a class="l2" href="pdif2.html">[pigpiod C I/F]</a>
<a class="l2" href="python.html">[Python]</a>
<a class="l2" href="pigs.html">[pigs]</a>
<a class="l2" href="piscope.html">[piscope]</a>
<a class="l2" href="misc.html">[Misc]</a>
<a class="l2" href="examples.html">[Examples]</a>
<a class="l2" href="download.html">[Download]</a>
<a class="l2" href="faq.html">[FAQ]</a>
<a class="l2" href="sitemap.html">[Site Map]</a>
</div>
<table><tr>
<td style="width: 200px"><div style="text-align: left;"><small>&copy; 2012-2020</small></div></td>
<td style="width: 350px"><div style="text-align: center;">e-mail: pigpio @ abyz.me.uk</div></td>
<td style="width: 200px"><div style="text-align: right;"><small>Updated: 30/04/2020</small></div></td>
</tr></table>
</td>
</table>
</body>
</html>

View File

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

View File

@ -1,516 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links." />
<meta name="keywords" content="raspberry, pi, C, Python, GPIO, library, shell, command, utilities, module, SPI, I2C, serial" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>pigpio library</title>
<link rel="stylesheet" type="text/css" href="scripts/index.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<table style="padding:0px; border:0px; margin:0px; width:780px; background-color:#e0e0e0;">
<td style="background:#EAF2E6 url('images/sidebar.gif') repeat-y; width:35px; height:100%"></td>
<td>
<table>
<div style="background:url('images/topbar.gif') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"><a href="index.html"><img src="images/pigpio-logo.gif" border="0" /></a>pigpio library</div>
</table>
<table><div>
<td><img src="images/faq1.jpg" width="250"></td>
<td><img src="images/faq2.jpg" width="250"></td>
<td><img src="images/faq3.jpg" width="250"></td>
</div></table>
<table>
<td style="vertical-align: top; background-color: #98bf21;"><a class="l1" href="index.html">pigpio</a>
<a class="l1" href="cif.html">pigpio C I/F</a>
<a class="l1" href="pigpiod.html">pigpiod</a>
<a class="l1" href="pdif2.html">pigpiod C I/F</a>
<a class="l1" href="python.html">Python</a>
<a class="l1" href="pigs.html">pigs</a>
<a class="l1" href="piscope.html">piscope</a>
<a class="l1" href="misc.html">Misc</a>
<a class="l1" href="examples.html">Examples</a>
<a class="l1" href="download.html">Download</a>
<a class="l1" href="faq.html">FAQ</a>
<a class="l1" href="sitemap.html">Site Map</a>
</td>
<td><center><h2>Frequently Asked Questions</h2></center>
<a href="#Are_my_GPIO_broken">Are my GPIO broken?</a><br>
<br>
<a href="#Audio_is_broken">Audio is broken</a><br>
<br>
<a href="#Cant_initialise_pigpio_library">Can´t initialise pigpio
library</a><br>
<br>
<a href="#Cant_lock_varrunpigpio.pid">Can´t lock
var/run/pigpio.pid</a><br>
<br>
<a href="#Hello_World">Hello World!</a><br>
<br>
<a href="#make_fails">Clock skew, make fails</a><br>
<br>
<a href="#Have_I_fried_my_GPIO">Have I fried my GPIO?</a><br>
<br>
<a href="#How_do_I_debounce_inputs">How do I debounce
inputs?</a><br>
<br>
<a href="#How_fast_is_SPI">How fast is SPI?</a><br>
<br>
<a href="#Library_update_fails">Library update didn't work</a><br>
<br>
<a href="#make_fails">make fails with clock skew</a><br>
<br>
<a href="#Porting_pigpio">Porting pigpio to another CPU/SoC</a><br>
<br>
<a href="#Sound_isnt_working">Sound isn't working</a><br>
<br>
<a href="#Library_update_fails">Symbol not found</a><br>
<br>
<a href="#What_is_I2C">What is I2C?</a><br>
<br>
<a href="#What_is_Serial">What is Serial?</a><br>
<br>
<a href="#What_is_SPI">What is SPI?</a><br>
<br>
<a href="#Which_library">Which library should I use?</a><br>
<br>
<h3><a name="Are_my_GPIO_broken" id="Are_my_GPIO_broken"></a>Are my
GPIO broken?</h3>
<p>See <a href="#Have_I_fried_my_GPIO">Have I fried my
GPIO?</a><br></p>
<h3><a name="Audio_is_broken" id="Audio_is_broken"></a>Audio is
broken</h3>
<p>See <a href="#Sound_isnt_working">Sound isn't
working</a><br></p>
<h3><a name="Cant_lock_varrunpigpio.pid" id=
"Cant_lock_varrunpigpio.pid"></a>Can´t lock
/var/run/pigpio.pid</h3>
<p>See <a href=
"#Cant_initialise_pigpio_library">Can´t_initialise_pigpio_library</a><br>
</p>
<h3><a name="Cant_initialise_pigpio_library" id=
"Cant_initialise_pigpio_library"></a>Can´t initialise pigpio
library</h3>
<p>This message means the pigpio daemon is already running.<br></p>
<p>The default daemon is called pigpiod and may be removed as
follows.<br></p>
Check that it is running with the command
<p><code>ps aux | grep pigpiod</code></p>
<p>Kill the daemon with<br></p>
<p><code>sudo killall pigpiod</code></p>
<p>If your own program is acting as the daemon it may be removed as
follows.</p>
<p>Find its process id (<span style=
"font-style: italic;">pid</span>).<br></p>
<p><code>cat /var/run/pigpio.pid</code><br></p>
<p>Kill the program with<br></p>
<p><code>sudo kill -9 <span style=
"font-style: italic;">pid</span></code><br></p>
If the above doesn't work do the following and try starting the
daemon again
<p><code>sudo rm /var/run/pigpio.pid<br></code></p>
<p>To start the daemon do</p>
<p><code>sudo pigpiod</code></p>
<h3><a name="Have_I_fried_my_GPIO" id=
"Have_I_fried_my_GPIO"></a>Have I fried my GPIO?</h3>
<p>If you think you have damaged one or more GPIO you can carry out
a diagnostic test.</p>
<p>The test is a command line script called <a rel="nofollow"
class="external text" href=
"http://abyz.me.uk/rpi/pigpio/code/gpiotest.zip">gpiotest</a></p>
For the duration of the test nothing must be connected to the GPIO
(no LEDs, wires, ribbon cables etc.).
<p>The test checks that each GPIO may be read and written and that
the internal resistor pull-ups and pull-downs are functional.</p>
<p>A <a rel="nofollow" class="external text" href=
"https://www.youtube.com/watch?v=sCJFLKWaxHo&amp;feature=youtu.be">video</a>
showing what happens to the GPIO during a test.</p>
<p>A test with all GPIO okay.</p>
<pre>This program checks the Pi's (user) gpios.
The program reads and writes all the gpios. Make sure NOTHING
is connected to the gpios during this test.
The program uses the pigpio daemon which must be running.
To start the daemon use the command sudo pigpiod.
Press the ENTER key to continue or ctrl-C to abort...
Testing...
Skipped non-user gpios: 0 1 28 29 30 31
Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18<br> 19 20 21 22 23 24 25 26 27
Failed user gpios: None
</pre>
<p>A test showing failed GPIO.</p>
<pre>This program checks the Pi's (user) gpios.
The program reads and writes all the gpios. Make sure NOTHING
is connected to the gpios during this test.
The program uses the pigpio daemon which must be running.
To start the daemon use the command sudo pigpiod.
Press the ENTER key to continue or ctrl-C to abort...
Testing...
Write 1 to gpio 17 failed.
Pull up on gpio 17 failed.
Write 1 to gpio 18 failed.
Pull up on gpio 18 failed.
Write 0 to gpio 23 failed.
Pull down on gpio 23 failed.
Write 0 to gpio 24 failed.
Pull down on gpio 24 failed.
Write 1 to gpio 27 failed.
Pull up on gpio 27 failed.
Skipped non-user gpios: 0 1 28 29 30 31
Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18<br> 19 20 21 22 23 24 25 26 27
Failed user gpios: 17 18 23 24 27
</pre>
<h3><a name="How_do_I_debounce_inputs" id=
"How_do_I_debounce_inputs"></a>How do I debounce inputs?</h3>
<p>Some devices like mechanical switches can generate multiple
interrupts as they bounce between on and off.&nbsp; It is possible
to debounce the inputs in hardware by the correct use of resistors
and capacitors.<br></p>
<p>In software use the glitch filter which ignores all events
shorter than a set number of microseconds.&nbsp; C <a href=
"cif.html#gpioGlitchFilter">gpioGlitchFilter</a>, Python <a href=
"python.html#set_glitch_filter">set_glitch_filter</a>.<br></p>
<h3><a name="How_fast_is_SPI" id="How_fast_is_SPI"></a>How fast is
SPI?</h3>
The SPI throughput in samples per second depends on a number of
factors.<br>
<br>
<ul>
<li>The SPI bit rate (transfer rate in bits per second)</li>
</ul>
<ul>
<li>The number of bytes transferred per sample (a 12 bit ADC sample
may require 3 bytes to transfer)</li>
</ul>
<ul>
<li>The driver used</li>
</ul>
<p>Two of those factors are fixed, the variable is the driver
used.</p>
<p>The pigpio driver is considerably faster than the Linux SPI
driver as is demonstrated by the following graphs.<br></p>
<p>Each graph shows the SPI bit rate in bits per second along the
horizontal axis.&nbsp; The samples per second achieved is shown on
the vertical axis.&nbsp; Each graph contains plots assuming 1 to 5
bytes per transfer.<br></p>
<p>The source code used for the tests is <a href=
"code/spi-driver-speed.c">spi-driver-speed.c</a> and <a href=
"code/spi-pigpio-speed.c">spi-pigpio-speed.c</a><br></p>
<p><img alt="spi-lnx-pibr1.png" src="images/spi-lnx-pibr1.png"></p>
<hr>
<p><img alt="spi-pig-pibr1.png" src="images/spi-pig-pibr1.png"></p>
<hr>
<p><img alt="spi-lnx-pi3b.png" src="images/spi-lnx-pi3b.png"></p>
<hr>
<p><img alt="spi-pig-pi3b.png" src="images/spi-pig-pi3b.png"></p>
<h3><a name="Library_update_fails" id=
"Library_update_fails"></a>Library update didn't work</h3>
<p>pigpio places files in the following locations<br></p>
<p>/usr/local/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)<br>
/usr/local/lib (libpigpio.so, libpigpiod_if.so,
libpigpiod_if2.so)<br>
/usr/local/bin (pig2vcd, pigpiod, pigs)<br>
/usr/local/man (man pages)<br></p>
The raspberrypi.org image containing pigpio uses different
locations.<br>
<p>/usr/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)<br>
/usr/lib (libpigpio.so, libpigpiod_if.so, libpigpiod_if2.so)<br>
/usr/bin (pig2vcd, pigpiod, pigs)<br>
/usr/man (man pages)<br></p>
<p>Mostly this doesn't matter as the /usr/local directories will
generally be earlier in the search path.&nbsp; The pigpio built
includes, binaries, and manuals are normally found first.<br></p>
<p>However the wrong libraries may be linked during the
compilation.&nbsp; If this is the case remove the /usr/lib entries
for libpigpio.so , libpigpiod_if.so, and libpigpiod_if2.so</p>
<h3><a name="Hello_World" id="Hello_World"></a>Hello World!</h3>
<p>The following examples show how to use the various components of
the pigpio library.</p>
<p>Each example shows how to read the level of a GPIO.</p>
<h4>C</h4>
read_cif.c
<pre>
#include &lt;stdio.h&gt;
#include &lt;pigpio.h&gt;
int main(int argc, char *argv[])
{
int GPIO=4;
int level;
if (gpioInitialise() &lt; 0) return 1;
level = gpioRead(GPIO);
printf("GPIO %d is %d\n", GPIO, level);
gpioTerminate();
}
</pre>
<p>Build</p>
<code>gcc -pthread -o read_cif read_cif.c -lpigpio</code>
<p>Run</p>
<code>sudo ./read_cif</code>
<h4>C via pigpio daemon</h4>
read_pdif.c
<pre>
#include &lt;stdio.h&gt;
#include &lt;pigpiod_if2.h&gt;
int main(int argc, char *argv[])
{
int pi;
int GPIO=4;
int level;
pi = pigpio_start(0, 0); /* Connect to local Pi. */
if (pi &lt; 0)
{
printf("Can't connect to pigpio daemon\n");
return 1;
}
level = gpio_read(pi, GPIO);
printf("GPIO %d is %d\n", GPIO, level);
pigpio_stop(pi); /* Disconnect from local Pi. */
return 0;
}
</pre>
<p>Build</p>
<code>gcc -pthread -o read_pdif read_pdif.c -lpigpiod_if2</code>
<p>Run</p>
<code>./read_pdif</code>
<h4>Python</h4>
read_gpio.py
<pre>
#!/usr/bin/env python
import pigpio
GPIO=4
pi = pigpio.pi()
if not pi.connected:
exit()
level = pi.read(GPIO)
print("GPIO {} is {}".format(GPIO, level))
pi.stop()
</pre>
<p>Run</p>
<code>python read_gpio.py</code>
<h4>pigs</h4>
<pre>
pigs r 4
</pre>
<h4>pipe I/F</h4>
<pre>
echo "r 4" &gt;/dev/pigpio
cat /dev/pigout
</pre>
<h3><a name="make_fails" id="make_fails"></a>make fails with clock
skew</h3>
<p>If make fails with one of the following messages it is probably
because the Pi's clock is wrong.<br></p>
<p><code>make: Warning: File 'xxx' has modification time x s in the
future<br>
make: warning: Clock skew detected. Your build may be
incomplete.</code></p>
<p>make uses the current time to work out which files need to be
rebuilt (a file is rebuilt if it depends on other files which have
a later time-stamp).<br></p>
<p>The solution is to make sure the system clock is correct.&nbsp;
If the Pi is networked this will not normally be a problem.<br></p>
<p>To set the date and time use the date command as in the
following example.</p>
<p><code>sudo date -d "2017-03-01 18:47:00"</code></p>
<h3><a name="Porting_pigpio" id="Porting_pigpio"></a>Porting pigpio
to another CPU/SoC</h3>
<h3><a name="Sound_isnt_working" id="Sound_isnt_working"></a>Sound
isn't working</h3>
<p>The Pi contains two pieces of hardware, a PWM peripheral and a
PCM peripheral, to generate sound.&nbsp; The PWM peripheral is
normally used and generates medium quality audio out of the
headphone jack.&nbsp; The PCM peripheral may be used by add-ons
such as HATs and generates high quality audio.<br></p>
<p>pigpio uses at least one of these peripherals during normal
operation (for timing DMA transfers).&nbsp; pigpio will use both
peripherals if waves or the hardware PWM function is used.<br></p>
<p>By default pigpio uses the PCM peripheral leaving the PWM
peripheral free for medium quality audio.<br></p>
<p>You can change the default with a configuration option.&nbsp;
For C use <a href="cif.html#gpioCfgClock">gpioCfgClock</a>, for the
<a href="pigpiod.html">pigpio daemon</a> use the -t option.</p>
<h3><a name="What_is_I2C" id="What_is_I2C"></a>What is I2C?</h3>
<p>I2C is a data link between the Pi (master) and one or more
slaves.</p>
<p>Data may be sent and received but the Pi initiates all
transfers.<br></p>
<p>I2C is a medium speed link.&nbsp; On the Pi the default speed is
100 kbps, but 400 kbps also works.<br></p>
<p>I2C is implemented as a bus with two lines called<br></p>
<ul>
<li>SDA - for data</li>
<li>SCL - for a clock</li>
</ul>
On the Pi bus 1 is used which uses GPIO 2 (pin 3) for SDA and GPIO
3 (pin 5) for SCL.<br>
<br>
Only one slave device may be communicated with at a time.&nbsp;
Each message from the Pi includes the slave to be addressed and
whether a read or write is to be performed.<br>
<br>
When the Pi (master) wishes to talk to a slave it begins by issuing
a start sequence on the I2C bus. A start sequence is one of two
special sequences defined for the I2C bus, the other being the stop
sequence. The start sequence and stop sequence are special in that
these are the only places where the SDA (data line) is allowed to
change while the SCL (clock line) is high. When data is being
transferred, SDA must remain stable and not change whilst SCL is
high. The start and stop sequences mark the beginning and end of a
transaction with the slave device.<br>
<br>
<img style="width: 600px;" alt="I2C start and stop sequences" src=
"images/faq-i2c-ss.png"><br>
<br>
Data is transferred in 8-bit bytes. The bytes are placed on the SDA
line starting with the most significant bit. The SCL line is then
pulsed high, then low. For every byte transferred, the device
receiving the data sends back an acknowledge bit, so there are
actually 9 SCL clock pulses to transfer each 8-bit byte of data. If
the receiving device sends back a low ACK bit, then it has received
the data and is ready to accept another byte. If it sends back a
high then it is indicating it cannot accept any further data and
the master should terminate the transfer by sending a stop
sequence.<br>
<br>
<p><img style="width: 600px;" alt="I2C waveform" src=
"images/faq-i2c.jpg"><br></p>
<h3><a name="What_is_Serial" id="What_is_Serial"></a>What is
Serial?</h3>
<p>Serial is a data link between the Pi and one other
device.<br></p>
<p>Data may be sent and received.&nbsp; Either the Pi or the device
can initiate a transfer.<br></p>
<p>Serial is a low to medium speed link.&nbsp; On the Pi speeds of
50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600,
19200, 38400, 57600, 115200, and 230400 bps may be used.<br></p>
<p>Serial is implemented with one line for transmit called TXD and
one line for receive called RXD.<br></p>
<p>If only receive or transmit are required the other line need not
be connected.<br></p>
<p>The Pi uses GPIO 14 (pin 8) for TXD and GPIO 15 (pin 10) for
RXD.<br></p>
<p>Data is normally transmitted in 8-bit bytes with a start bit,
eight data bits, no parity, and one stop bit.&nbsp; This is
represented as 8N1.&nbsp; The number of transmitted bits per second
(bps) is called the baud rate.&nbsp;&nbsp; The time for each bit,
<span style="font-style: italic;">1 / baud rate</span> seconds, is
referred to as the bit period.<br></p>
<p>The lines are in the high state when no data is being
transmitted.&nbsp; The start of a byte is signalled by the line
going low for one bit period (the start bit).&nbsp; The data bits
are then sent least significant bit firsts (low if the bit is 0,
high if the bit is 1).&nbsp; The data bits are followed by the
optional parity bit.&nbsp; Finally the line is set high for at
least the number of stop bit periods.&nbsp; The line will stay high
if there are no more bytes to be transmitted.<br></p>
<p><img style="width: 600px;" alt="Serial waveform" src=
"images/faq-serial.jpg"><br></p>
<h3><a name="What_is_SPI" id="What_is_SPI"></a>What is SPI?</h3>
<p>SPI is a data link between the Pi (master) and one or more
slaves.</p>
<p>Data may be sent and received but the Pi initiates all
transfers.<br></p>
<p>SPI is a medium to high speed link.&nbsp; On the Pi speeds of 32
kbps to 8 Mbps may be used.<br></p>
<p>SPI is implemented as a bus with three lines called<br></p>
<ul>
<li>MOSI - for data from the Pi to the slave</li>
<li>MISO - for data from the slave to the Pi</li>
<li>SCLK - for a clock</li>
</ul>
Only one slave device may be communicated with at a time.&nbsp; An
additional line per slave called slave select is used to identify
the slave to be addressed.
<p>The Pi has two SPI buses<br></p>
<ol>
<li>the main SPI bus
<ul>
<li>MOSI GPIO 10 (pin 19)</li>
<li>MISO GPIO 9 (pin 21)</li>
<li>SCLK GPIO 11 (pin 23)</li>
<li>Slave selects</li>
<li style="list-style: none; display: inline">
<ul>
<li>CE0 GPIO 8 (pin 24)</li>
<li>CE1 GPIO 7 (pin 26)</li>
</ul>
</li>
</ul>
</li>
<li>the auxiliary SPI bus
<ul>
<li>MOSI GPIO 20 (pin 38)</li>
<li>MISO GPIO 19 (pin 35)</li>
<li>SCLK GPIO 21 (pin 40)</li>
<li>Slave selects</li>
<li style="list-style: none; display: inline">
<ul>
<li>CE0 GPIO 18 (pin 12)</li>
<li>CE1 GPIO 17 (pin 11)</li>
<li>CE2 GPIO 16 (pin 36)<br></li>
</ul>
</li>
</ul>
</li>
</ol>
<p><img style="width: 600px;" alt="SPI waveform" src=
"images/faq-spi.jpg"><br></p>
<p><br></p>
<h3><a name="Which_library" id="Which_library"></a>Which library
should I use?</h3>
<p><br></p>
</td>
</table>
<div style="vertical-align: center; text-align: center; background-color:#98bf21; font-size:0.8em; height:30px"><a class="l2" href="index.html">[pigpio]</a>
<a class="l2" href="cif.html">[pigpio C I/F]</a>
<a class="l2" href="pigpiod.html">[pigpiod]</a>
<a class="l2" href="pdif2.html">[pigpiod C I/F]</a>
<a class="l2" href="python.html">[Python]</a>
<a class="l2" href="pigs.html">[pigs]</a>
<a class="l2" href="piscope.html">[piscope]</a>
<a class="l2" href="misc.html">[Misc]</a>
<a class="l2" href="examples.html">[Examples]</a>
<a class="l2" href="download.html">[Download]</a>
<a class="l2" href="faq.html">[FAQ]</a>
<a class="l2" href="sitemap.html">[Site Map]</a>
</div>
<table><tr>
<td style="width: 200px"><div style="text-align: left;"><small>&copy; 2012-2020</small></div></td>
<td style="width: 350px"><div style="text-align: center;">e-mail: pigpio @ abyz.me.uk</div></td>
<td style="width: 200px"><div style="text-align: right;"><small>Updated: 30/04/2020</small></div></td>
</tr></table>
</td>
</table>
</body>
</html>

View File

@ -1,716 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links." />
<meta name="keywords" content="raspberry, pi, C, Python, GPIO, library, shell, command, utilities, module, SPI, I2C, serial" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>pigpio library</title>
<link rel="stylesheet" type="text/css" href="scripts/index.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<table style="padding:0px; border:0px; margin:0px; width:780px; background-color:#e0e0e0;">
<td style="background:#EAF2E6 url('images/sidebar.gif') repeat-y; width:35px; height:100%"></td>
<td>
<table>
<div style="background:url('images/topbar.gif') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"><a href="index.html"><img src="images/pigpio-logo.gif" border="0" /></a>pigpio library</div>
</table>
<table><div>
<td><img src="images/rpi.jpg" width="250"></td>
<td><img src="images/servo.jpg" width="250"></td>
<td><img src="images/motor.jpg" width="250"></td>
</div></table>
<table>
<td style="vertical-align: top; background-color: #98bf21;"><a class="l1" href="index.html">pigpio</a>
<a class="l1" href="cif.html">pigpio C I/F</a>
<a class="l1" href="pigpiod.html">pigpiod</a>
<a class="l1" href="pdif2.html">pigpiod C I/F</a>
<a class="l1" href="python.html">Python</a>
<a class="l1" href="pigs.html">pigs</a>
<a class="l1" href="piscope.html">piscope</a>
<a class="l1" href="misc.html">Misc</a>
<a class="l1" href="examples.html">Examples</a>
<a class="l1" href="download.html">Download</a>
<a class="l1" href="faq.html">FAQ</a>
<a class="l1" href="sitemap.html">Site Map</a>
</td>
<td><center><h2>The pigpio library</h2></center>
pigpio is a library for the Raspberry which allows control of the
General Purpose Input Outputs (GPIO).&nbsp; pigpio works on all
versions of the Pi.
<p><b>At the moment pigpio on the Pi4B is experimental. I am not
sure if the DMA channels being used are safe. The Pi4B defaults are
primary channel 7, secondary channel 6. If these channels do not
work you will have to experiment. You can set the channels used by
the pigpio daemon by invoking it with the -d and -e options, e.g.
<small>sudo pigpiod -d 5 -e 8</small> to specify primary 5,
secondary 8.</b></p>
<p><a href="download.html">Download</a><br></p>
<h3>Features<br></h3>
<ul>
<li>
<p>hardware timed sampling and time-stamping of GPIO 0-31 every 5
us<br></p>
</li>
<li>
<p>hardware timed PWM on all of GPIO 0-31<br></p>
</li>
<li>
<p>hardware timed servo pulses on all of GPIO 0-31</p>
</li>
<li>
<p>callbacks on GPIO 0-31 level change (time accurate to a few
us)</p>
</li>
<li>
<p>notifications via pipe on GPIO 0-31 level change<br></p>
</li>
<li>
<p>callbacks at timed intervals</p>
</li>
<li>
<p>reading/writing all of the GPIO in a bank (0-31, 32-53) as a
single operation</p>
</li>
<li>
<p>GPIO reading, writing, modes, and internal pulls<br></p>
</li>
<li>
<p>socket and pipe interfaces for the bulk of the functionality</p>
</li>
<li>
<p>waveforms to generate GPIO level changes (time accurate to a few
us)</p>
</li>
<li>
<p>software serial links using any user GPIO</p>
</li>
<li>
<p>rudimentary permission control through the socket and pipe
interfaces<br></p>
</li>
<li>creating and running scripts on the pigpio daemon</li>
</ul>
<h3>General</h3>
The pigpio <a href="cif.html">library</a> is written in the C
programming language.<br>
<br>
The <a href="pigpiod.html">pigpio daemon</a> offers a <a href=
"sif.html">socket</a> and <a href="pif.html">pipe</a> interface to
the underlying C library.<br>
<br>
A <a href="pdif2.html">C library</a> and a <a href=
"python.html">Python module</a> allow control of the GPIO via the
pigpio daemon.<br>
<br>
There is third party support for a number of <a href=
"index.html#Other_Languages">other languages</a>.&nbsp;
<h3>piscope</h3>
<p><a href="piscope.html">piscope</a> is a logic analyser (digital
waveform viewer).<br></p>
piscope is a GTK+3 application and uses pigpio to provide raw GPIO
level data.&nbsp; piscope may be run on a Pi or on any machine
capable of compiling a GTK+3 application.
<h3><a name="GPIO" id="GPIO"></a>GPIO</h3>
<p><span style="font-weight: bold;">ALL GPIO</span> are identified
by their <span style="font-weight: bold;">Broadcom
number</span>.&nbsp; See <a href=
"http://elinux.org/RPi_Low-level_peripherals#General_Purpose_Input.2FOutput_.28GPIO.29">
elinux.org</a><br></p>
There are 54 GPIO in total, arranged in two banks.<br>
<p>Bank 1 contains GPIO 0-31.&nbsp; Bank 2 contains GPIO
32-53.<br></p>
For all types of Pi it is safe to read all the GPIO. If you try to
write a system GPIO or change its mode you can crash the Pi or
corrupt the data on the SD card.<br>
<br>
There are several types of board, each with different expansion
headers, giving physical access to different GPIO.&nbsp;
<ul>
<li><a href="#Type_1">Type 1</a> - Model B (original model)</li>
<li><a href="#Type_2">Type 2</a> - Model A, B (revision 2)</li>
<li><a href="#Type_3">Type 3</a> - Model A+, B+, Pi Zero, Pi2B,
Pi3B</li>
<li><a href="#CM">Compute Module</a> - Compute Module</li>
</ul>
<h4><a name="Type_1" id="Type_1"></a>Type 1 - Model B (original
model)</h4>
<ul>
<li>26 pin header (P1).</li>
</ul>
<ul>
<li>Hardware revision numbers of 2 and 3.</li>
</ul>
<ul>
<li>User GPIO 0-1, 4, 7-11, 14-15, 17-18, 21-25.</li>
</ul>
<table summary="" style="width: 60%; text-align: left;"
cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
<br></td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">3V3</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">5V</td>
</tr>
<tr>
<td style="text-align: center;">SDA</td>
<td style="text-align: center;">0<br></td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">5V</td>
</tr>
<tr>
<td style="text-align: center;">SCL</td>
<td style="text-align: center;">1<br></td>
<td style="text-align: center;">5</td>
<td style="text-align: center;">6</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">14</td>
<td style="text-align: center;">TXD</td>
</tr>
<tr>
<td style="text-align: center;">Ground</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">9</td>
<td style="text-align: center;">10</td>
<td style="text-align: center;">15</td>
<td style="text-align: center;">RXD</td>
</tr>
<tr>
<td style="text-align: center;">ce1</td>
<td style="text-align: center;">17</td>
<td style="text-align: center;">11</td>
<td style="text-align: center;">12</td>
<td style="text-align: center;">18</td>
<td style="text-align: center;">ce0</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">21</td>
<td style="text-align: center;">13</td>
<td style="text-align: center;">14</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">22</td>
<td style="text-align: center;">15</td>
<td style="text-align: center;">16</td>
<td style="text-align: center;">23</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">3V3</td>
<td style="text-align: center;">-<br></td>
<td style="text-align: center;">17</td>
<td style="text-align: center;">18</td>
<td style="text-align: center;">24</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">MOSI</td>
<td style="text-align: center;">10</td>
<td style="text-align: center;">19</td>
<td style="text-align: center;">20</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;">MISO</td>
<td style="text-align: center;">9</td>
<td style="text-align: center;">21</td>
<td style="text-align: center;">22</td>
<td style="text-align: center;">25</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">SCLK</td>
<td style="text-align: center;">11</td>
<td style="text-align: center;">23</td>
<td style="text-align: center;">24</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">CE0</td>
</tr>
<tr>
<td style="text-align: center;">Ground</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">25</td>
<td style="text-align: center;">26</td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">CE1</td>
</tr>
</tbody>
</table>
<br>
<h4><a name="Type_2" id="Type_2"></a>Type 2 - Model A, B (revision
2)</h4>
26 pin header (P1) and an additional 8 pin header (P5).
<ul>
<li>Hardware revision numbers of 4, 5, 6 (B), 7, 8, 9 (A), and 13,
14, 15 (B).</li>
</ul>
<ul>
<li>User GPIO 2-4, 7-11, 14-15, 17-18, 22-25, 27-31.<br></li>
</ul>
<table summary="" style="width: 60%; text-align: left;"
cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
<br></td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">3V3</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">5V</td>
</tr>
<tr>
<td style="text-align: center;">SDA</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">5V</td>
</tr>
<tr>
<td style="text-align: center;">SCL</td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">5</td>
<td style="text-align: center;">6</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">14</td>
<td style="text-align: center;">TXD</td>
</tr>
<tr>
<td style="text-align: center;">Ground</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">9</td>
<td style="text-align: center;">10</td>
<td style="text-align: center;">15</td>
<td style="text-align: center;">RXD</td>
</tr>
<tr>
<td style="text-align: center;">ce1</td>
<td style="text-align: center;">17</td>
<td style="text-align: center;">11</td>
<td style="text-align: center;">12</td>
<td style="text-align: center;">18</td>
<td style="text-align: center;">ce0</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">27</td>
<td style="text-align: center;">13</td>
<td style="text-align: center;">14</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">22</td>
<td style="text-align: center;">15</td>
<td style="text-align: center;">16</td>
<td style="text-align: center;">23</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">3V3</td>
<td style="text-align: center;">-<br></td>
<td style="text-align: center;">17</td>
<td style="text-align: center;">18</td>
<td style="text-align: center;">24</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">MOSI</td>
<td style="text-align: center;">10</td>
<td style="text-align: center;">19</td>
<td style="text-align: center;">20</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;">MISO</td>
<td style="text-align: center;">9</td>
<td style="text-align: center;">21</td>
<td style="text-align: center;">22</td>
<td style="text-align: center;">25</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">SCLK</td>
<td style="text-align: center;">11</td>
<td style="text-align: center;">23</td>
<td style="text-align: center;">24</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">CE0</td>
</tr>
<tr>
<td style="text-align: center;">Ground</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">25</td>
<td style="text-align: center;">26</td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">CE1</td>
</tr>
</tbody>
</table>
<br>
<table summary="" style="width: 60%; text-align: left;"
cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
<br></td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">5V<br></td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">3V3</td>
</tr>
<tr>
<td style="text-align: center;">SDA<br></td>
<td style="text-align: center;">28</td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">29</td>
<td style="text-align: center;">SCL</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">30</td>
<td style="text-align: center;">5</td>
<td style="text-align: center;">6</td>
<td style="text-align: center;">31</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">Ground<br></td>
<td style="text-align: center;">-<br></td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">-<br></td>
<td style="text-align: center;">Ground</td>
</tr>
</tbody>
</table>
<br>
<h4><a name="Type_3" id="Type_3"></a>Type 3 - Model A+, B+, Pi
Zero, Pi Zero W, Pi2B, Pi3B, Pi4B<br></h4>
<ul>
<li>40 pin expansion header (J8).</li>
</ul>
<ul>
<li>Hardware revision numbers of 16 or greater.</li>
</ul>
<ul>
<li>User GPIO 2-27 (0 and 1 are reserved).<br></li>
</ul>
<table summary="" style="width: 60%; text-align: left;"
cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
<br></td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style="font-weight: bold; text-align: center;">pin</td>
<td style=
"vertical-align: top; font-weight: bold; text-align: center;">
GPIO</td>
<td style="font-weight: bold; text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">3V3</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">5V</td>
</tr>
<tr>
<td style="text-align: center;">SDA</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">5V</td>
</tr>
<tr>
<td style="text-align: center;">SCL</td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">5</td>
<td style="text-align: center;">6</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">14</td>
<td style="text-align: center;">TXD</td>
</tr>
<tr>
<td style="text-align: center;">Ground</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">9</td>
<td style="text-align: center;">10</td>
<td style="text-align: center;">15</td>
<td style="text-align: center;">RXD</td>
</tr>
<tr>
<td style="text-align: center;">ce1</td>
<td style="text-align: center;">17</td>
<td style="text-align: center;">11</td>
<td style="text-align: center;">12</td>
<td style="text-align: center;">18</td>
<td style="text-align: center;">ce0</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">27</td>
<td style="text-align: center;">13</td>
<td style="text-align: center;">14</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">22</td>
<td style="text-align: center;">15</td>
<td style="text-align: center;">16</td>
<td style="text-align: center;">23</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">3V3</td>
<td style="text-align: center;">-<br></td>
<td style="text-align: center;">17</td>
<td style="text-align: center;">18</td>
<td style="text-align: center;">24</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">MOSI</td>
<td style="text-align: center;">10</td>
<td style="text-align: center;">19</td>
<td style="text-align: center;">20</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;">MISO</td>
<td style="text-align: center;">9</td>
<td style="text-align: center;">21</td>
<td style="text-align: center;">22</td>
<td style="text-align: center;">25</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;">SCLK</td>
<td style="text-align: center;">11</td>
<td style="text-align: center;">23</td>
<td style="text-align: center;">24</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">CE0</td>
</tr>
<tr>
<td style="text-align: center;">Ground</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">25</td>
<td style="text-align: center;">26</td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">CE1</td>
</tr>
<tr>
<td style="text-align: center;">ID_SD</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">27</td>
<td style="text-align: center;">28</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">ID_SC</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">5</td>
<td style="text-align: center;">29</td>
<td style="text-align: center;">30</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">6</td>
<td style="text-align: center;">31</td>
<td style="text-align: center;">32</td>
<td style="text-align: center;">12</td>
<td style="text-align: center;"><br></td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">13</td>
<td style="text-align: center;">33</td>
<td style="text-align: center;">34</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">Ground</td>
</tr>
<tr>
<td style="text-align: center;">miso</td>
<td style="text-align: center;">19</td>
<td style="text-align: center;">35</td>
<td style="text-align: center;">36</td>
<td style="text-align: center;">16</td>
<td style="text-align: center;">ce2</td>
</tr>
<tr>
<td style="text-align: center;"><br></td>
<td style="text-align: center;">26</td>
<td style="text-align: center;">37</td>
<td style="text-align: center;">38</td>
<td style="text-align: center;">20</td>
<td style="text-align: center;">mosi</td>
</tr>
<tr>
<td style="text-align: center;">Ground</td>
<td style="text-align: center;">-</td>
<td style="text-align: center;">39</td>
<td style="text-align: center;">40</td>
<td style="text-align: center;">21</td>
<td style="text-align: center;">sclk</td>
</tr>
</tbody>
</table>
<br>
<h4><a name="CM" id="CM"></a>Compute Module</h4>
<p>All 54 GPIO may be physically accessed.&nbsp; Some are reserved
for system use - refer to the Compute Module documentation.<br></p>
<p>Only GPIO 0-31 are supported for hardware timed sampling, PWM,
servo pulses, alert callbacks, waves, and software serial
links.<br></p>
<h3><a name="Other_Languages" id="Other_Languages"></a>Other
Languages</h3>
<p>There are several third party projects which provide wrappers
for pigpio.<br></p>
<p>Some I am aware of are:<br></p>
<ul>
<li><a href="https://github.com/skvamme/pigpio">Erlang</a>
(skvamme)</li>
<li><a href="https://github.com/mattjlewis/pigpioj">Java</a> JNI
wrapper around the pigpio C library (mattlewis)</li>
<li><a href="https://github.com/mattjlewis/diozero">Java</a> via
diozero, a high level wrapper around pigpio, Pi4J, wiringPi etc
(mattlewis)</li>
<li><a href="https://github.com/nkolban/jpigpio">Java</a>
(nkolban)</li>
<li><a href=
"https://github.com/unosquare/pigpio-dotnet">.NET/mono</a>
(unosquare)</li>
<li><a href="https://github.com/fivdi/pigpio">Node.js</a>
(fivdi)</li>
<li><a href="https://metacpan.org/pod/RPi::PIGPIO">Perl</a> (Gligan
Calin Horea)</li>
<li><a href=
"https://github.com/nak1114/ruby-extension-pigpio">Ruby</a>
(Nak)</li>
<li><a href=
"https://github.com/vasmalltalk/pigpio-vast">Smalltalk</a>(Instantiations)</li>
<li><a href=
"https://github.com/UBogun/Xojo-pigpio">Xojo</a>(UBogun)</li>
</ul>
<hr style="width: 100%; height: 2px;">
<p><font size="-2">The PWM and servo pulses are timed using the DMA
and PWM/PCM peripherals.&nbsp; This use was inspired by Richard
Hirst's <a href="https://github.com/richardghirst/PiBits" target=
"_blank">servoblaster</a> kernel module.</font></p>
</td>
</table>
<div style="vertical-align: center; text-align: center; background-color:#98bf21; font-size:0.8em; height:30px"><a class="l2" href="index.html">[pigpio]</a>
<a class="l2" href="cif.html">[pigpio C I/F]</a>
<a class="l2" href="pigpiod.html">[pigpiod]</a>
<a class="l2" href="pdif2.html">[pigpiod C I/F]</a>
<a class="l2" href="python.html">[Python]</a>
<a class="l2" href="pigs.html">[pigs]</a>
<a class="l2" href="piscope.html">[piscope]</a>
<a class="l2" href="misc.html">[Misc]</a>
<a class="l2" href="examples.html">[Examples]</a>
<a class="l2" href="download.html">[Download]</a>
<a class="l2" href="faq.html">[FAQ]</a>
<a class="l2" href="sitemap.html">[Site Map]</a>
</div>
<table><tr>
<td style="width: 200px"><div style="text-align: left;"><small>&copy; 2012-2020</small></div></td>
<td style="width: 350px"><div style="text-align: center;">e-mail: pigpio @ abyz.me.uk</div></td>
<td style="width: 200px"><div style="text-align: right;"><small>Updated: 30/04/2020</small></div></td>
</tr></table>
</td>
</table>
</body>
</html>

View File

@ -1,88 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links." />
<meta name="keywords" content="raspberry, pi, C, Python, GPIO, library, shell, command, utilities, module, SPI, I2C, serial" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>pigpio library</title>
<link rel="stylesheet" type="text/css" href="scripts/index.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<table style="padding:0px; border:0px; margin:0px; width:780px; background-color:#e0e0e0;">
<td style="background:#EAF2E6 url('images/sidebar.gif') repeat-y; width:35px; height:100%"></td>
<td>
<table>
<div style="background:url('images/topbar.gif') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"><a href="index.html"><img src="images/pigpio-logo.gif" border="0" /></a>pigpio library</div>
</table>
<table><div>
<td><img src="images/msp430.jpg" width="250"></td>
<td><img src="images/motor.jpg" width="250"></td>
<td><img src="images/leds.jpg" width="250"></td>
</div></table>
<table>
<td style="vertical-align: top; background-color: #98bf21;"><a class="l1" href="index.html">pigpio</a>
<a class="l1" href="cif.html">pigpio C I/F</a>
<a class="l1" href="pigpiod.html">pigpiod</a>
<a class="l1" href="pdif2.html">pigpiod C I/F</a>
<a class="l1" href="python.html">Python</a>
<a class="l1" href="pigs.html">pigs</a>
<a class="l1" href="piscope.html">piscope</a>
<a class="l1" href="misc.html">Misc</a>
<a class="l1" href="examples.html">Examples</a>
<a class="l1" href="download.html">Download</a>
<a class="l1" href="faq.html">FAQ</a>
<a class="l1" href="sitemap.html">Site Map</a>
</td>
<td><center><h2>Miscellaneous</h2></center>
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>.
</td>
</table>
<div style="vertical-align: center; text-align: center; background-color:#98bf21; font-size:0.8em; height:30px"><a class="l2" href="index.html">[pigpio]</a>
<a class="l2" href="cif.html">[pigpio C I/F]</a>
<a class="l2" href="pigpiod.html">[pigpiod]</a>
<a class="l2" href="pdif2.html">[pigpiod C I/F]</a>
<a class="l2" href="python.html">[Python]</a>
<a class="l2" href="pigs.html">[pigs]</a>
<a class="l2" href="piscope.html">[piscope]</a>
<a class="l2" href="misc.html">[Misc]</a>
<a class="l2" href="examples.html">[Examples]</a>
<a class="l2" href="download.html">[Download]</a>
<a class="l2" href="faq.html">[FAQ]</a>
<a class="l2" href="sitemap.html">[Site Map]</a>
</div>
<table><tr>
<td style="width: 200px"><div style="text-align: left;"><small>&copy; 2012-2020</small></div></td>
<td style="width: 350px"><div style="text-align: center;">e-mail: pigpio @ abyz.me.uk</div></td>
<td style="width: 200px"><div style="text-align: right;"><small>Updated: 30/04/2020</small></div></td>
</tr></table>
</td>
</table>
</body>
</html>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,85 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links." />
<meta name="keywords" content="raspberry, pi, C, Python, GPIO, library, shell, command, utilities, module, SPI, I2C, serial" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>pigpio library</title>
<link rel="stylesheet" type="text/css" href="scripts/index.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<table style="padding:0px; border:0px; margin:0px; width:780px; background-color:#e0e0e0;">
<td style="background:#EAF2E6 url('images/sidebar.gif') repeat-y; width:35px; height:100%"></td>
<td>
<table>
<div style="background:url('images/topbar.gif') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"><a href="index.html"><img src="images/pigpio-logo.gif" border="0" /></a>pigpio library</div>
</table>
<table><div>
<td><img src="images/switches.jpg" width="250"></td>
<td><img src="images/uln2003a.jpg" width="250"></td>
<td><img src="images/yl-40.jpg" width="250"></td>
</div></table>
<table>
<td style="vertical-align: top; background-color: #98bf21;"><a class="l1" href="index.html">pigpio</a>
<a class="l1" href="cif.html">pigpio C I/F</a>
<a class="l1" href="pigpiod.html">pigpiod</a>
<a class="l1" href="pdif2.html">pigpiod C I/F</a>
<a class="l1" href="python.html">Python</a>
<a class="l1" href="pigs.html">pigs</a>
<a class="l1" href="piscope.html">piscope</a>
<a class="l1" href="misc.html">Misc</a>
<a class="l1" href="examples.html">Examples</a>
<a class="l1" href="download.html">Download</a>
<a class="l1" href="faq.html">FAQ</a>
<a class="l1" href="sitemap.html">Site Map</a>
</td>
<td><center><h2>Pipe Interface</h2></center>
pigpio provides a pipe interface to many of its functions.<br>
<br>
The pipe interface is available whenever pigpio is running, either
because it has been started as a daemon, or it has been linked in
to a running user program.&nbsp; The pipe interface can be disabled
by the program which initialises the library.&nbsp; pigpiod offers
the -f option to disable the pipe interface.&nbsp; User programs
should call <a href=
"http://abyz.me.uk/rpi/pigpio/cif.html#gpioCfgInterfaces">gpioCfgInterfaces</a>
if they wish to disable the pipe interface.<br>
<br>
pigpio listens for commands on pipe /dev/pigpio.&nbsp; The commands
consist of a command identifier with, depending on the command,
zero, one, or two parameters.&nbsp; The result, if any, may be read
from pipe /dev/pigout.&nbsp; If any errors are detected a message
will be written to pipe /dev/pigerr.<br>
<br>
<br>
The format of the commands is identical to those used by <a href=
"pigs.html">pigs</a>.
</td>
</table>
<div style="vertical-align: center; text-align: center; background-color:#98bf21; font-size:0.8em; height:30px"><a class="l2" href="index.html">[pigpio]</a>
<a class="l2" href="cif.html">[pigpio C I/F]</a>
<a class="l2" href="pigpiod.html">[pigpiod]</a>
<a class="l2" href="pdif2.html">[pigpiod C I/F]</a>
<a class="l2" href="python.html">[Python]</a>
<a class="l2" href="pigs.html">[pigs]</a>
<a class="l2" href="piscope.html">[piscope]</a>
<a class="l2" href="misc.html">[Misc]</a>
<a class="l2" href="examples.html">[Examples]</a>
<a class="l2" href="download.html">[Download]</a>
<a class="l2" href="faq.html">[FAQ]</a>
<a class="l2" href="sitemap.html">[Site Map]</a>
</div>
<table><tr>
<td style="width: 200px"><div style="text-align: left;"><small>&copy; 2012-2020</small></div></td>
<td style="width: 350px"><div style="text-align: center;">e-mail: pigpio @ abyz.me.uk</div></td>
<td style="width: 200px"><div style="text-align: right;"><small>Updated: 30/04/2020</small></div></td>
</tr></table>
</td>
</table>
</body>
</html>

View File

@ -1,83 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links." />
<meta name="keywords" content="raspberry, pi, C, Python, GPIO, library, shell, command, utilities, module, SPI, I2C, serial" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>pigpio library</title>
<link rel="stylesheet" type="text/css" href="scripts/index.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<table style="padding:0px; border:0px; margin:0px; width:780px; background-color:#e0e0e0;">
<td style="background:#EAF2E6 url('images/sidebar.gif') repeat-y; width:35px; height:100%"></td>
<td>
<table>
<div style="background:url('images/topbar.gif') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"><a href="index.html"><img src="images/pigpio-logo.gif" border="0" /></a>pigpio library</div>
</table>
<table><div>
<td><img src="images/wheel.jpg" width="250"></td>
<td><img src="images/srf04.jpg" width="250"></td>
<td><img src="images/servo.jpg" width="250"></td>
</div></table>
<table>
<td style="vertical-align: top; background-color: #98bf21;"><a class="l1" href="index.html">pigpio</a>
<a class="l1" href="cif.html">pigpio C I/F</a>
<a class="l1" href="pigpiod.html">pigpiod</a>
<a class="l1" href="pdif2.html">pigpiod C I/F</a>
<a class="l1" href="python.html">Python</a>
<a class="l1" href="pigs.html">pigs</a>
<a class="l1" href="piscope.html">piscope</a>
<a class="l1" href="misc.html">Misc</a>
<a class="l1" href="examples.html">Examples</a>
<a class="l1" href="download.html">Download</a>
<a class="l1" href="faq.html">FAQ</a>
<a class="l1" href="sitemap.html">Site Map</a>
</td>
<td><center><h2>pig2vcd</h2></center>pig2vcd is a utility which reads notifications on stdin and writes the
output as a Value Change Dump (VCD) file on stdout.
<br><br>The VCD file can be viewed using GTKWave.
<h3>Notifications</h3>Notifications consist of 12 bytes with the following binary format.
<br><br><code>typedef&nbsp;struct<br>{<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;seqno;<br>&nbsp;&nbsp;&nbsp;uint16_t&nbsp;flags;<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;tick;<br>&nbsp;&nbsp;&nbsp;uint32_t&nbsp;level;<br>}&nbsp;gpioReport_t;<br></code><br><br>seqno: starts at 0 each time the handle is opened and then increments by one for each report.
<br><br>flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE. If bit 5 is set (PI_NTFY_FLAGS_WDOG) then bits 0-4 of the flags indicate a gpio which has had a watchdog timeout; if bit 6 is set (PI_NTFY_FLAGS_ALIVE) this indicates a keep alive signal on the pipe/socket and is sent once a minute in the absence of other notification activity.
<br><br>tick: the number of microseconds since system boot. It wraps around after 1h12m.
<br><br>level: indicates the level of each gpio. If bit 1&lt;&lt;x is set then gpio x is high. pig2vcd takes these notifications and outputs a text format VCD.
<h3>VCD format</h3>The VCD starts with a header.
<br><br><code>$date&nbsp;2013-05-31&nbsp;18:49:36&nbsp;$end<br>$version&nbsp;pig2vcd&nbsp;V1&nbsp;$end<br>$timescale&nbsp;1&nbsp;us&nbsp;$end<br>$scope&nbsp;module&nbsp;top&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;A&nbsp;0&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;B&nbsp;1&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;C&nbsp;2&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;D&nbsp;3&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;E&nbsp;4&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;F&nbsp;5&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;G&nbsp;6&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;H&nbsp;7&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;I&nbsp;8&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;J&nbsp;9&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;K&nbsp;10&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;L&nbsp;11&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;M&nbsp;12&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;N&nbsp;13&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;O&nbsp;14&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;P&nbsp;15&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;Q&nbsp;16&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;R&nbsp;17&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;S&nbsp;18&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;T&nbsp;19&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;U&nbsp;20&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;V&nbsp;21&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;W&nbsp;22&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;X&nbsp;23&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;Y&nbsp;24&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;Z&nbsp;25&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;a&nbsp;26&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;b&nbsp;27&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;c&nbsp;28&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;d&nbsp;29&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;e&nbsp;30&nbsp;$end<br>$var&nbsp;wire&nbsp;1&nbsp;f&nbsp;31&nbsp;$end<br>$upscope&nbsp;$end<br>$enddefinitions&nbsp;$end<br></code><br><br>The header defines gpio identifiers and their name. Each gpio identifier
must be unique. pig2vcd arbitrarily uses 'A' through 'Z' for gpios 0
through 25, and 'a' through 'f' for gpios 26 through 31.
The corresponding names are 0 through 31.<br>
<br><br>The VCD file may be edited to give a frendlier name, e.g. 8 could be
changed to ENCODER_A if an encoder switch A is connected to gpio 8.
<br><br>Following the header pig2vcd takes notifications and outputs a timestamp
followed by a list of one or more gpios which have changed state.
The timestamp consists of a '#' followed by the microsecond tick.
The state lines contain the new state followed by the gpio identifier.
<br><br><code>#1058747<br>0H<br>0I<br>#1059012<br>1H<br>#1079777<br>1I<br>#1079782<br>0I<br>#1079852<br>1I<br>#1079857<br>0I<br>0H<br>#1165113<br>1H<br>#1165118<br>0H<br>#1165153<br>1H<br></code></td>
</table>
<div style="vertical-align: center; text-align: center; background-color:#98bf21; font-size:0.8em; height:30px"><a class="l2" href="index.html">[pigpio]</a>
<a class="l2" href="cif.html">[pigpio C I/F]</a>
<a class="l2" href="pigpiod.html">[pigpiod]</a>
<a class="l2" href="pdif2.html">[pigpiod C I/F]</a>
<a class="l2" href="python.html">[Python]</a>
<a class="l2" href="pigs.html">[pigs]</a>
<a class="l2" href="piscope.html">[piscope]</a>
<a class="l2" href="misc.html">[Misc]</a>
<a class="l2" href="examples.html">[Examples]</a>
<a class="l2" href="download.html">[Download]</a>
<a class="l2" href="faq.html">[FAQ]</a>
<a class="l2" href="sitemap.html">[Site Map]</a>
</div>
<table><tr>
<td style="width: 200px"><div style="text-align: left;"><small>&copy; 2012-2020</small></div></td>
<td style="width: 350px"><div style="text-align: center;">e-mail: pigpio @ abyz.me.uk</div></td>
<td style="width: 200px"><div style="text-align: right;"><small>Updated: 30/04/2020</small></div></td>
</tr></table>
</td>
</table>
</body>
</html>

View File

@ -1,114 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links." />
<meta name="keywords" content="raspberry, pi, C, Python, GPIO, library, shell, command, utilities, module, SPI, I2C, serial" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>pigpio library</title>
<link rel="stylesheet" type="text/css" href="scripts/index.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<table style="padding:0px; border:0px; margin:0px; width:780px; background-color:#e0e0e0;">
<td style="background:#EAF2E6 url('images/sidebar.gif') repeat-y; width:35px; height:100%"></td>
<td>
<table>
<div style="background:url('images/topbar.gif') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"><a href="index.html"><img src="images/pigpio-logo.gif" border="0" /></a>pigpio library</div>
</table>
<table><div>
<td><img src="images/breadboard.jpg" width="250"></td>
<td><img src="images/caps.jpg" width="250"></td>
<td><img src="images/driver.jpg" width="250"></td>
</div></table>
<table>
<td style="vertical-align: top; background-color: #98bf21;"><a class="l1" href="index.html">pigpio</a>
<a class="l1" href="cif.html">pigpio C I/F</a>
<a class="l1" href="pigpiod.html">pigpiod</a>
<a class="l1" href="pdif2.html">pigpiod C I/F</a>
<a class="l1" href="python.html">Python</a>
<a class="l1" href="pigs.html">pigs</a>
<a class="l1" href="piscope.html">piscope</a>
<a class="l1" href="misc.html">Misc</a>
<a class="l1" href="examples.html">Examples</a>
<a class="l1" href="download.html">Download</a>
<a class="l1" href="faq.html">FAQ</a>
<a class="l1" href="sitemap.html">Site Map</a>
</td>
<td><center><h2>pigpio Daemon</h2></center>pigpiod is a utility which launches the pigpio library as a daemon.<br>
<br>
Once launched the pigpio library runs in the background accepting commands from the pipe and socket interfaces.<br>
<br>
The pigpiod utility requires sudo privileges to launch the library but thereafter the pipe and socket commands may be issued by normal users.<br>
<br>
pigpiod accepts the following configuration options<br>
<br>
<table border="1" cellpadding="2" cellspacing="2"><tbody><tr><td><b>-a value</b></td><td>DMA memory allocation mode</td><td>0=AUTO, 1=PMAP, 2=MBOX</td><td>Default AUTO
</td></tr><tr><td><b>-b value</b></td><td>GPIO sample buffer size in milliseconds</td><td>100-10000</td><td>Default 120
</td></tr><tr><td><b>-c value</b></td><td>Library internal settings</td><td></td><td>Default 0
</td></tr><tr><td><b>-d value</b></td><td>Primary DMA channel</td><td>0-14</td><td>Default 14
</td></tr><tr><td><b>-e value</b></td><td>Secondary DMA channel</td><td>0-14</td><td>Default 6. Preferably use one of DMA channels 0 to 6 for the secondary channel
</td></tr><tr><td><b>-f</b></td><td>Disable fifo interface</td><td></td><td>Default enabled
</td></tr><tr><td><b>-g</b></td><td>Run in foreground (do not fork)</td><td></td><td>Default disabled
</td></tr><tr><td><b>-k</b></td><td>Disable local and remote socket interface</td><td></td><td>Default enabled
</td></tr><tr><td><b>-l</b></td><td>Disable remote socket interface</td><td></td><td>Default enabled
</td></tr><tr><td><b>-m</b></td><td>Disable alerts (sampling)</td><td></td><td>Default enabled
</td></tr><tr><td><b>-n IP address</b></td><td>Allow IP address to use the socket interface</td><td>Name (e.g. paul) or dotted quad (e.g. 192.168.1.66)</td><td>If the -n option is not used all addresses are allowed (unless overridden by the -k or -l options). Multiple -n options are allowed. If -k has been used -n has no effect. If -l has been used only -n localhost has any effect
</td></tr><tr><td><b>-p value</b></td><td>Socket port</td><td>1024-32000</td><td>Default 8888
</td></tr><tr><td><b>-s value</b></td><td>Sample rate</td><td>1, 2, 4, 5, 8, or 10 microseconds</td><td>Default 5
</td></tr><tr><td><b>-t value</b></td><td>Clock peripheral</td><td>0=PWM 1=PCM</td><td>Default PCM. pigpio uses one or both of PCM and PWM. If PCM is used then PWM is available for audio. If PWM is used then PCM is available for audio. If waves or hardware PWM are used neither PWM nor PCM will be available for audio.
</td></tr><tr><td><b>-v -V</b></td><td>Display pigpio version and exit</td><td></td><td>
</td></tr><tr><td><b>-x mask</b></td><td>GPIO which may be updated</td><td>A 54 bit mask with (1&lt;&lt;n) set if the user may update GPIO #n</td><td>Default is the set of user GPIO for the board revision. Use -x -1 to allow all GPIO
</td></tr></tbody></table><h3>Example</h3><code>sudo&nbsp;pigpiod&nbsp;-s&nbsp;2&nbsp;-b&nbsp;200&nbsp;-f<br></code><br><br>Launch the pigpio library with a sample rate of 2 microseconds and a 200 millisecond buffer. Disable the fifo interface.
<h3>Permissions</h3>pigpio provides a rudimentary permissions system for commands issued via the socket and pipe interfaces.
<br><br>All GPIO may be read.
<br><br>Only the user GPIO for the board type or those specified by the -x option may be updated.
<br><br><code>Type&nbsp;1&nbsp;boards&nbsp;0x03E6CF93&nbsp;(26&nbsp;pin&nbsp;header)<br>Type&nbsp;2&nbsp;boards&nbsp;0xFBC6CF9C&nbsp;(26&nbsp;pin&nbsp;+&nbsp;8&nbsp;pin&nbsp;header)<br>Type&nbsp;3&nbsp;boards&nbsp;0x0FFFFFFC&nbsp;(40&nbsp;pin&nbsp;header)<br></code><br><br>In this context an update includes the following:
<br><br>GPIO mode set<br>
GPIO pull/up down<br>
GPIO write<br>
GPIO set PWM (including range and frequency)<br>
GPIO set servo
<br><br>In addition the bank clear and set commands, and the wave commands will only
affect updateable GPIO.
<h3>Exceptions</h3>The following exceptions are made for particular models.
<br><br><b>Models A and B</b><br><br>The green activity LED (GPIO 16) may be written.<br>
<br><b>Models A+ and B+</b><br><br>The green activity LED (GPIO 47) may be written.<br>
The red power LED (GPIO 35) may be written.<br>
The high USB power mode (GPIO 38) may be written.<br>
<br><b>Pi Zero</b><br><br>The green activity LED (GPIO 47) may be written.<br>
<br><b>Pi2B</b><br><br>The green activity LED (GPIO 47) may be written.<br>
The red power LED (GPIO 35) may be written.<br>
The high USB power mode (GPIO 38) may be written.<br>
<br><b>Pi3B</b><br><br>The green activity LED and the red power LED are not writable.<br>
The USB power mode is fixed at 1.2 amps (high power).<br>
<h3>DMA Channels</h3>The secondary channel is only used for the transmission of waves.
<br><br>If possible use one of channels 0 to 6 for the secondary channel (a full channel).
<br><br>A full channel only requires one DMA control block regardless of the length of a pulse delay. Channels 7 to 14 (lite channels) require one DMA control block for each 16383 microseconds of delay. I.e. a 10 second pulse delay requires one control block on a full channel and 611 control blocks on a lite channel.
<br><br></td>
</table>
<div style="vertical-align: center; text-align: center; background-color:#98bf21; font-size:0.8em; height:30px"><a class="l2" href="index.html">[pigpio]</a>
<a class="l2" href="cif.html">[pigpio C I/F]</a>
<a class="l2" href="pigpiod.html">[pigpiod]</a>
<a class="l2" href="pdif2.html">[pigpiod C I/F]</a>
<a class="l2" href="python.html">[Python]</a>
<a class="l2" href="pigs.html">[pigs]</a>
<a class="l2" href="piscope.html">[piscope]</a>
<a class="l2" href="misc.html">[Misc]</a>
<a class="l2" href="examples.html">[Examples]</a>
<a class="l2" href="download.html">[Download]</a>
<a class="l2" href="faq.html">[FAQ]</a>
<a class="l2" href="sitemap.html">[Site Map]</a>
</div>
<table><tr>
<td style="width: 200px"><div style="text-align: left;"><small>&copy; 2012-2020</small></div></td>
<td style="width: 350px"><div style="text-align: center;">e-mail: pigpio @ abyz.me.uk</div></td>
<td style="width: 200px"><div style="text-align: right;"><small>Updated: 30/04/2020</small></div></td>
</tr></table>
</td>
</table>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -1,269 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links." />
<meta name="keywords" content="raspberry, pi, C, Python, GPIO, library, shell, command, utilities, module, SPI, I2C, serial" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>pigpio library</title>
<link rel="stylesheet" type="text/css" href="scripts/index.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<table style="padding:0px; border:0px; margin:0px; width:780px; background-color:#e0e0e0;">
<td style="background:#EAF2E6 url('images/sidebar.gif') repeat-y; width:35px; height:100%"></td>
<td>
<table>
<div style="background:url('images/topbar.gif') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"><a href="index.html"><img src="images/pigpio-logo.gif" border="0" /></a>pigpio library</div>
</table>
<table><div>
<td><img src="images/pisc-1.jpg" width="250"></td>
<td><img src="images/pisc-2.jpg" width="250"></td>
<td><img src="images/pisc-3.jpg" width="250"></td>
</div></table>
<table>
<td style="vertical-align: top; background-color: #98bf21;"><a class="l1" href="index.html">pigpio</a>
<a class="l1" href="cif.html">pigpio C I/F</a>
<a class="l1" href="pigpiod.html">pigpiod</a>
<a class="l1" href="pdif2.html">pigpiod C I/F</a>
<a class="l1" href="python.html">Python</a>
<a class="l1" href="pigs.html">pigs</a>
<a class="l1" href="piscope.html">piscope</a>
<a class="l1" href="misc.html">Misc</a>
<a class="l1" href="examples.html">Examples</a>
<a class="l1" href="download.html">Download</a>
<a class="l1" href="faq.html">FAQ</a>
<a class="l1" href="sitemap.html">Site Map</a>
</td>
<td><center><h2>piscope</h2></center>
<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>
</td>
</table>
<div style="vertical-align: center; text-align: center; background-color:#98bf21; font-size:0.8em; height:30px"><a class="l2" href="index.html">[pigpio]</a>
<a class="l2" href="cif.html">[pigpio C I/F]</a>
<a class="l2" href="pigpiod.html">[pigpiod]</a>
<a class="l2" href="pdif2.html">[pigpiod C I/F]</a>
<a class="l2" href="python.html">[Python]</a>
<a class="l2" href="pigs.html">[pigs]</a>
<a class="l2" href="piscope.html">[piscope]</a>
<a class="l2" href="misc.html">[Misc]</a>
<a class="l2" href="examples.html">[Examples]</a>
<a class="l2" href="download.html">[Download]</a>
<a class="l2" href="faq.html">[FAQ]</a>
<a class="l2" href="sitemap.html">[Site Map]</a>
</div>
<table><tr>
<td style="width: 200px"><div style="text-align: left;"><small>&copy; 2012-2020</small></div></td>
<td style="width: 350px"><div style="text-align: center;">e-mail: pigpio @ abyz.me.uk</div></td>
<td style="width: 200px"><div style="text-align: right;"><small>Updated: 30/04/2020</small></div></td>
</tr></table>
</td>
</table>
</body>
</html>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,85 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="description" content="Raspberry Pi Reg. C GPIO library and Python GPIO module and shell command utilities to control the GPIO, including SPI, I2C, and serial links." />
<meta name="keywords" content="raspberry, pi, C, Python, GPIO, library, shell, command, utilities, module, SPI, I2C, serial" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>pigpio library</title>
<link rel="stylesheet" type="text/css" href="scripts/index.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<table style="padding:0px; border:0px; margin:0px; width:780px; background-color:#e0e0e0;">
<td style="background:#EAF2E6 url('images/sidebar.gif') repeat-y; width:35px; height:100%"></td>
<td>
<table>
<div style="background:url('images/topbar.gif') repeat-x; height: 70px; font-size:1.5em; vertical-align: top;"><a href="index.html"><img src="images/pigpio-logo.gif" border="0" /></a>pigpio library</div>
</table>
<table><div>
<td><img src="images/ir-rx.jpg" width="250"></td>
<td><img src="images/imu-2.jpg" width="250"></td>
<td><img src="images/caps.jpg" width="250"></td>
</div></table>
<table>
<td style="vertical-align: top; background-color: #98bf21;"><a class="l1" href="index.html">pigpio</a>
<a class="l1" href="cif.html">pigpio C I/F</a>
<a class="l1" href="pigpiod.html">pigpiod</a>
<a class="l1" href="pdif2.html">pigpiod C I/F</a>
<a class="l1" href="python.html">Python</a>
<a class="l1" href="pigs.html">pigs</a>
<a class="l1" href="piscope.html">piscope</a>
<a class="l1" href="misc.html">Misc</a>
<a class="l1" href="examples.html">Examples</a>
<a class="l1" href="download.html">Download</a>
<a class="l1" href="faq.html">FAQ</a>
<a class="l1" href="sitemap.html">Site Map</a>
</td>
<td><center><h2>Site Map</h2></center><a href="index.html">pigpio</a><br>
<a href="cif.html">pigpio C I/F</a><br>
<a href="pigpiod.html">pigpiod</a><br>
<a href="pdif2.html">pigpiod C I/F</a><br>
<a href="python.html">Python</a><br>
<a href="pigs.html">pigs</a><br>
<a href="piscope.html">piscope</a><br>
<a href="misc.html">Misc</a><br>
----<a href="sif.html">Socket I/F</a><br>
----<a href="pif.html">Pipe I/F</a><br>
----<a href="pdif.html">pigpiod_if</a><br>
----<a href="pig2vcd.html">pig2vcd</a><br>
<a href="examples.html">Examples</a><br>
----<a href="ex_rotary_encoder.html">Rotary Encoder</a><br>
----<a href="ex_ir_remote.html">IR Remote</a><br>
----<a href="ex_LDR.html">Light Dependent Resitor</a><br>
----<a href="ex_sonar_ranger.html">Sonar Ranger</a><br>
----<a href="ex_motor_shield.html">Arduino Motor Shield</a><br>
<a href="download.html">Download</a><br>
<a href="faq.html">FAQ</a><br>
<a href="sitemap.html">Site Map</a><br>
</td>
</table>
<div style="vertical-align: center; text-align: center; background-color:#98bf21; font-size:0.8em; height:30px"><a class="l2" href="index.html">[pigpio]</a>
<a class="l2" href="cif.html">[pigpio C I/F]</a>
<a class="l2" href="pigpiod.html">[pigpiod]</a>
<a class="l2" href="pdif2.html">[pigpiod C I/F]</a>
<a class="l2" href="python.html">[Python]</a>
<a class="l2" href="pigs.html">[pigs]</a>
<a class="l2" href="piscope.html">[piscope]</a>
<a class="l2" href="misc.html">[Misc]</a>
<a class="l2" href="examples.html">[Examples]</a>
<a class="l2" href="download.html">[Download]</a>
<a class="l2" href="faq.html">[FAQ]</a>
<a class="l2" href="sitemap.html">[Site Map]</a>
</div>
<table><tr>
<td style="width: 200px"><div style="text-align: left;"><small>&copy; 2012-2020</small></div></td>
<td style="width: 350px"><div style="text-align: center;">e-mail: pigpio @ abyz.me.uk</div></td>
<td style="width: 200px"><div style="text-align: right;"><small>Updated: 30/04/2020</small></div></td>
</tr></table>
</td>
</table>
</body>
</html>

View File

@ -1,2 +0,0 @@
Placeholder directory for man pages.

View File

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

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,57 +0,0 @@
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 (V75)<br></h3>
<code>wget https://github.com/joan2937/pigpio/archive/v75.zip<br>
unzip v75.zip<br>
cd pigpio-75<br>
make<br>
sudo make install<br></code><br>
<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>

View File

@ -1,141 +0,0 @@
<p>The following code shows a method of reading analogue sensors on
the digital input only Pi.&nbsp; A Light Dependent Resistor (LDR)
varies its resistance according to the incident light
intensisty.</p>
<h3>SETUP</h3>
<img src="images/LDR-fritz.png" alt="fritzing diagram" style=
"width: 200px; height: 300px;" align="left" hspace="10">The LDR
used is a Cadmium Sulphide device with a 1MOhm dark resistance and
2-4KOhm at 100 lux.&nbsp; The capacitor is a 104
ceramic.<span itemprop="name"><br>
<br>
One end of the capacitor is connected to Pi ground.<br>
<br>
One end of the LDR is connected to Pi 3V3.<br>
<br>
The other ends of the capacitor and LDR are connected to a spare
gpio.</span><br>
<p>Here P1-1 is used for 3V3, P1-20 is used for ground, and gpio 18
(P1-12) is used for the gpio.<br clear="all"></p>
<p><img src="images/LDR-photo.jpg" style=
"width: 500px; height: 667px;" alt="photo of set-up"></p>
<h3>CODE</h3>
<code>#include &lt;stdio.h&gt;<br>
<br>
#include &lt;pigpio.h&gt;<br>
<br>
/*
-----------------------------------------------------------------------<br>
<br>
&nbsp;&nbsp; 3V3 ----- Light Dependent Resistor --+-- Capacitor
----- Ground<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+-- gpio<br>
<br>
<br>
&nbsp; cc -o LDR LDR.c -lpigpio -lpthread -lrt<br>
&nbsp; sudo ./LDR<br>
<br>
*/<br>
<br>
#define LDR 18<br>
<br>
/* forward declaration */<br>
<br>
void alert(int pin, int level, uint32_t tick);<br>
<br>
int main (int argc, char *argv[])<br>
{<br>
&nbsp;&nbsp; if (gpioInitialise()&lt;0) return 1;<br>
<br>
&nbsp;&nbsp; gpioSetAlertFunc(LDR, alert); /* call alert when LDR
changes state */<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp; while (1)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioSetMode(LDR, PI_OUTPUT); /*
drain capacitor */<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioWrite(LDR, PI_OFF);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioDelay(200); /* 50 micros is
enough, 200 is overkill */<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioSetMode(LDR, PI_INPUT); /* start
capacitor recharge */<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioDelay(10000); /* nominal 100
readings per second */<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; gpioTerminate();<br>
}<br>
<br>
void alert(int pin, int level, uint32_t tick)<br>
{<br>
&nbsp;&nbsp; static uint32_t inited = 0;<br>
&nbsp;&nbsp; static uint32_t lastTick, firstTick;<br>
<br>
&nbsp;&nbsp; uint32_t diffTick;<br>
<br>
&nbsp;&nbsp; if (inited)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diffTick = tick - lastTick;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastTick = tick;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (level == 1) printf("%u %d\ ",
tick-firstTick, diffTick);<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; else<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inited = 1;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; firstTick = tick;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastTick = firstTick;<br>
&nbsp;&nbsp; }<br>
}<br></code>
<h3>BUILD</h3>
<code>cc -o LDR LDR.c -lpigpio -lrt -lpthread<br></code>
<h3>RUN</h3>
<code>sudo ./LDR &gt;LDR.dat &amp;</code><br>
<br>
While the program is running you can capture the waveform using the
notification feature built in to pigpio.&nbsp; Issue the following
commands on the Pi.<br>
<br>
<code>pigs no<br>
pig2vcd&nbsp; &lt;/dev/pigpio0 &gt;LDR.vcd &amp;<br>
pigs nb 0 0x40000 # set bit for gpio 18<br></code>
<p>Change the light falling on the LDR for a few seconds (e.g.
shine a torch on it or shade it with your hands).<br></p>
<code>pigs nc 0</code><br>
<p>The file LDR.vcd will contain the captured waveform, which can
be viewed using GTKWave.</p>
<p>Overview</p>
<img src="images/LDR-wave-1.png" style=
"width: 600px; height: 100px;" alt="LDR waveform 1"><br>
<p>Reading circa every 10ms<br></p>
<img src="images/LDR-wave-2.png" style=
"width: 600px; height: 100px;" alt="LDR waveform 2"><br>
<p>One reading, circa 400us<br></p>
<img src="images/LDR-wave-3.png" style=
"width: 600px; height: 100px;" alt="LDR waveform 3"><br>
<p>The file LDR.dat will contain pairs of timestamps and recharge
time (in us).&nbsp; The following&nbsp; script will convert the
timestamps into seconds.<span style=
"font-style: italic;"><br></span></p>
<p><code>awk '{print $1/1000000, $2}' LDR.dat
&gt;LDR-secs.dat</code></p>
<p>Gnuplot is a useful tool to graph data.<br></p>
plot [14:24] 'LDR-secs.dat' with lines title 'LDR'
<p>Gnuplot readings 14-24 seconds<br></p>
<p><img src="images/LDR-gnup-1.png" style=
"width: 600px; height: 321px;" alt="gnuplot 1"></p>
plot [18:21] 'LDR-secs.dat' with lines title 'LDR'<br>
<br>
Gnuplot readings 18-21 seconds
<p><img src="images/LDR-gnup-2.png" style=
"width: 600px; height: 321px;" alt="Gnuplot 2"></p>

View File

@ -1,244 +0,0 @@
<p>The following code shows one way to read an infrared remote
control device (the sort used in TVs and stereo systems).</p>
<h3>SETUP</h3>
<img alt="fritzing diagram" style="width: 200px; height: 317px;"
src="images/ir-fritz.png" align="left" hspace="10">The device used
is a <span itemprop="name">SFH5110 (IR Receiver for remote control,
carrier 38 kHz).<br>
<br></span> Pin 1 (left from front) may be connected to any spare
gpio.&nbsp; Here it's connected via a 4K7 current limiting
resistor.&nbsp; This isn't really needed as the device has an
internal 23K resistor in-line.&nbsp; It does no harm though.<br>
<br>
Pin 2 should be connected to a Pi ground pin.<br>
<br>
Pin 3 should be connected to a Pi 5V pin.<br>
<p>Here pin 1 to gpio7 (P1-26) via a 4K7 resistor, pin 2 to ground
(P1-14), and pin 3 to 5V (P1-2).<br clear="all"></p>
<p><img src="images/ir-photo.jpg" style=
"width: 500px; height: 500px;" alt="photo of set-up"></p>
<h3>CODE</h3>
<code>#include &lt;stdio.h&gt;<br>
<br>
#include &lt;pigpio.h&gt;<br>
<br>
#define IR_PIN 7<br>
<br>
#define OUTSIDE_CODE 0<br>
#define INSIDE_CODE&nbsp; 1<br>
<br>
#define MIN_MESSAGE_GAP 3000<br>
#define MAX_MESSAGE_END 3000<br>
<br>
#define MAX_TRANSITIONS 500<br>
<br>
/*<br>
&nbsp;&nbsp; using the FNV-1a
hash&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp; from
http://isthe.com/chongo/tech/comp/fnv/#FNV-param<br>
*/<br>
<br>
#define FNV_PRIME_32 16777619<br>
#define FNV_BASIS_32 2166136261U<br>
<br>
static volatile uint32_t ir_hash = 0;<br>
<br>
typedef struct<br>
{<br>
&nbsp;&nbsp; int state;<br>
&nbsp;&nbsp; int count;<br>
&nbsp;&nbsp; int level;<br>
&nbsp;&nbsp; uint16_t micros[MAX_TRANSITIONS];<br>
} decode_t;<br>
<br>
/* forward declarations */<br>
<br>
void&nbsp;&nbsp;&nbsp;&nbsp; alert(int gpio, int level, uint32_t
tick);<br>
uint32_t getHash(decode_t * decode);<br>
void&nbsp;&nbsp;&nbsp;&nbsp; updateState(decode_t * decode, int
level, uint32_t micros);<br>
<br>
int main(int argc, char * argv[])<br>
{<br>
&nbsp;&nbsp; if (gpioInitialise()&lt;0)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1 ;<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; /* IR pin as input */<br>
<br>
&nbsp;&nbsp; gpioSetMode(IR_PIN, PI_INPUT);<br>
<br>
&nbsp;&nbsp; /* 5ms max gap after last pulse */<br>
<br>
&nbsp;&nbsp; gpioSetWatchdog(IR_PIN, 5);<br>
<br>
&nbsp;&nbsp; /* monitor IR level changes */<br>
<br>
&nbsp;&nbsp; gpioSetAlertFunc(IR_PIN, alert);<br>
<br>
&nbsp;&nbsp; while (1)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (ir_hash)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* non-zero means
new decode */<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("ir code is
%u\ ", ir_hash);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ir_hash = 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gpioDelay(100000); /* check remote
10 times per second */<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; gpioTerminate();<br>
}<br>
<br>
void alert(int gpio, int level, uint32_t tick)<br>
{<br>
&nbsp;&nbsp; static int inited = 0;<br>
<br>
&nbsp;&nbsp; static decode_t activeHigh, activeLow;<br>
<br>
&nbsp;&nbsp; static uint32_t lastTick;<br>
<br>
&nbsp;&nbsp; uint32_t diffTick;<br>
<br>
&nbsp;&nbsp; if (!inited)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inited = 1;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; activeHigh.state = OUTSIDE_CODE;
activeHigh.level = PI_LOW;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; activeLow.state&nbsp; =
OUTSIDE_CODE; activeLow.level&nbsp; = PI_HIGH;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastTick = tick;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; diffTick = tick - lastTick;<br>
<br>
&nbsp;&nbsp; if (level != PI_TIMEOUT) lastTick = tick;<br>
<br>
&nbsp;&nbsp; updateState(&amp;activeHigh, level, diffTick);<br>
&nbsp;&nbsp; updateState(&amp;activeLow, level, diffTick);<br>
}<br>
<br>
void updateState(decode_t * decode, int level, uint32_t micros)<br>
{<br>
&nbsp;&nbsp; /*<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; We are dealing with active high as
well as active low<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; remotes.&nbsp; Abstract the common
functionality.<br>
&nbsp;&nbsp; */<br>
<br>
&nbsp;&nbsp; if (decode-&gt;state == OUTSIDE_CODE)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (level == decode-&gt;level)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (micros &gt;
MIN_MESSAGE_GAP)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
decode-&gt;state = INSIDE_CODE;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
decode-&gt;count = 0;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; else<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (micros &gt; MAX_MESSAGE_END)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* end of message
*/<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* ignore if last
code not consumed */<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!ir_hash)
ir_hash = getHash(decode);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; decode-&gt;state =
OUTSIDE_CODE;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if
(decode-&gt;count &lt; (MAX_TRANSITIONS-1))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if (level != PI_TIMEOUT)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
decode-&gt;micros[decode-&gt;count++] = micros;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp; }<br>
}<br>
<br>
int compare(unsigned int oldval, unsigned int newval)<br>
{<br>
&nbsp;&nbsp; if&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (newval &lt; (oldval
* 0.75)) {return 1;}<br>
&nbsp;&nbsp; else if (oldval &lt; (newval * 0.75)) {return 2;}<br>
&nbsp;&nbsp;
else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{return 4;}<br>
}<br>
<br>
uint32_t getHash(decode_t * decode)<br>
{<br>
&nbsp;&nbsp; /* use FNV-1a */<br>
<br>
&nbsp;&nbsp; uint32_t hash;<br>
&nbsp;&nbsp; int i, value;<br>
<br>
&nbsp;&nbsp; if (decode-&gt;count &lt; 6) {return 0;}<br>
<br>
&nbsp;&nbsp; hash = FNV_BASIS_32;<br>
<br>
&nbsp;&nbsp; for (i=0; i&lt;(decode-&gt;count-2); i++)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value =
compare(decode-&gt;micros[i], decode-&gt;micros[i+2]);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hash = hash ^ value;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hash = (hash * FNV_PRIME_32);<br>
&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp; return hash;<br>
}<br></code>
<h3>BUILD</h3>
<code>cc -o ir_remote ir_remote.c -lpigpio -lrt
-lpthread<br></code>
<h3>RUN</h3>
<code>sudo ./ir_remote</code><br>
<p>A hash code is formed from the level transitions detected during
a remote key press.&nbsp; This is likely to be unique over multiple
remotes and keys.</p>
<p>While the program is running you can capture the waveform using
the notification feature built in to pigpio.&nbsp; Issue the
following commands on the Pi.</p>
<code>pigs no<br>
pig2vcd&nbsp; &lt;/dev/pigpio0 &gt;ir.vcd &amp;<br>
pigs nb 0 0x80 # set bits for gpios 7 (0x80)<br></code>
<p>Press a few different remotes and keys.&nbsp; Then enter<br></p>
<code>pigs nc 0</code><br>
<p>The file ir.vcd will contain the captured waveform, which can be
viewed using GTKWave.</p>
<p>Overview</p>
<img src="images/ir-wave-1.png" style=
"width: 600px; height: 100px;" alt="ir remote waveform 1"><br>
<p>Remote A typical waveform</p>
<img src="images/ir-wave-2.png" style=
"width: 600px; height: 100px;" alt="ir remote waveform 2"><br>
<p>Remote B typical waveform</p>
<img style="width: 600px; height: 100px;" alt=
"ir remote waveform 3" src="images/ir-wave-3.png">

View File

@ -1,245 +0,0 @@
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>

View File

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

View File

@ -1,155 +0,0 @@
<p>The following code shows a method of reading a class of sonar
rangers.&nbsp; These rangers requires a trigger pulse.&nbsp;
Shortly after receiving a trigger they transmit a noise pulse and
set the echo line high.&nbsp; When the echo is received the echo
line is set low.<br></p>
<h3>SETUP</h3>
<img src="images/son-fritz.png" alt="fritzing diagram" style=
"width: 200px; height: 600px;" align="left" hspace="10"><br>
<br>
<br>
<br>
<br>
The ranger used is a SRF05 (check the pinouts, there are many
variants).<br>
<br>
The fritzing diagram shows the back of the ranger, i.e. pin 1 is
the rightmost.<br>
<br>
Pin 1 is 5V.<br>
Pin 2 is the trigger line.<br>
Pin 3 is the echo line.<br>
Pin 4 is out (unused).<br>
Pin 5 is ground.<br>
<br clear="all">
<p><img src="images/son-photo.jpg" style=
"width: 500px; height: 376px;" alt="photo of set-up"></p>
<h3>CODE</h3>
<code>#include &lt;stdio.h&gt;<br>
<br>
#include &lt;pigpio.h&gt;<br>
<br>
/*<br>
<br>
P1&nbsp; Name&nbsp; gpio&nbsp;&nbsp;&nbsp; used for<br>
<br>
&nbsp;2&nbsp; 5V&nbsp;&nbsp;&nbsp; ---&nbsp;&nbsp;&nbsp;&nbsp;
5V<br>
&nbsp;6&nbsp; GND&nbsp;&nbsp; ---&nbsp;&nbsp;&nbsp;&nbsp;
Ground<br>
24&nbsp; CE0&nbsp;&nbsp; 8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Sonar echo<br>
26&nbsp; CE1&nbsp;&nbsp; 7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Sonar trigger<br>
<br>
*/<br>
<br>
#define SONAR_TRIGGER 7<br>
#define SONAR_ECHO&nbsp;&nbsp;&nbsp; 8<br>
<br>
/* forward prototypes */<br>
<br>
void sonarTrigger(void);<br>
<br>
void sonarEcho(int gpio, int level, uint32_t tick);<br>
<br>
int main(int argc, char *argv[])<br>
{<br>
&nbsp;&nbsp; if (gpioInitialise()&lt;0) return 1;<br>
<br>
&nbsp;&nbsp; gpioSetMode(SONAR_TRIGGER, PI_OUTPUT);<br>
&nbsp;&nbsp; gpioWrite&nbsp; (SONAR_TRIGGER, PI_OFF);<br>
<br>
&nbsp;&nbsp; gpioSetMode(SONAR_ECHO,&nbsp;&nbsp;&nbsp;
PI_INPUT);<br>
<br>
&nbsp;&nbsp; /* update sonar 20 times a second, timer #0 */<br>
<br>
&nbsp;&nbsp; gpioSetTimerFunc(0, 50, sonarTrigger); /* every 50ms
*/<br>
<br>
&nbsp;&nbsp; /* monitor sonar echos */<br>
<br>
&nbsp;&nbsp; gpioSetAlertFunc(SONAR_ECHO, sonarEcho);<br>
<br>
&nbsp;&nbsp; while (1) sleep(1);<br>
<br>
&nbsp;&nbsp; gpioTerminate();<br>
<br>
&nbsp;&nbsp; return 0;<br>
}<br>
<br>
void sonarTrigger(void)<br>
{<br>
&nbsp;&nbsp; /* trigger a sonar reading */<br>
<br>
&nbsp;&nbsp; gpioWrite(SONAR_TRIGGER, PI_ON);<br>
<br>
&nbsp;&nbsp; gpioDelay(10); /* 10us trigger pulse */<br>
<br>
&nbsp;&nbsp; gpioWrite(SONAR_TRIGGER, PI_OFF);<br>
}<br>
<br>
void sonarEcho(int gpio, int level, uint32_t tick)<br>
{<br>
&nbsp;&nbsp; static uint32_t startTick, firstTick=0;<br>
<br>
&nbsp;&nbsp; int diffTick;<br>
<br>
&nbsp;&nbsp; if (!firstTick) firstTick = tick;<br>
<br>
&nbsp;&nbsp; if (level == PI_ON)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; startTick = tick;<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; else if (level == PI_OFF)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diffTick = tick - startTick;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%u %u\ ", tick-firstTick,
diffTick);<br>
&nbsp;&nbsp; }<br>
}<br></code>
<h3>BUILD</h3>
<code>cc -o sonar sonar.c -lpigpio -lrt -lpthread<br></code>
<h3>RUN</h3>
<code>sudo ./sonar &gt;sonar.dat &amp;</code><br>
<br>
While the program is running you can capture the waveform using the
notification feature built in to pigpio.&nbsp; Issue the following
commands on the Pi.<br>
<br>
<code>pigs no<br>
pig2vcd&nbsp; &lt;/dev/pigpio0 &gt;sonar.vcd &amp;<br>
pigs nb 0 0x180 # set bits for gpios 7 and 8<br></code>
<p>Move an object in front of the sonar ranger for a few
seconds.<br></p>
<code>pigs nc 0</code><br>
<p>The file sonar.vcd will contain the captured waveform, which can
be viewed using GTKWave.</p>
<p>Overview</p>
<img src="images/son-wave-1.png" style=
"width: 600px; height: 100px;" alt="LDR waveform 1"><br>
<p>Reading circa every 10ms<br></p>
<img src="images/son-wave-2.png" style=
"width: 600px; height: 100px;" alt="Sonar waveform 2"><br>
<p>One reading, circa 400us<br></p>
<img src="images/son-wave-3.png" style=
"width: 600px; height: 100px;" alt="Sonar waveform 3"><br>
<p>another</p>
<img style="width: 600px; height: 100px;" alt="Sonar waveform 4"
src="images/son-wave-4.png"><br>
<p>The file sonar.dat will contain pairs of timestamps and echo
length (in us).&nbsp; The following&nbsp; script will convert the
timestamps into seconds.<span style=
"font-style: italic;"><br></span></p>
<p><code>awk '{print $1/1000000, $2}' sonar.dat
&gt;sonar-secs.dat</code></p>
<p>Gnuplot is a useful tool to graph data.<br></p>
plot 'sonar-secs.dat' title 'Sonar'<br>
<p><img src="images/son-gnup-1.png" style=
"width: 600px; height: 321px;" alt="gnuplot 1"><br>
&nbsp;plot [10:25] 'sonar-secs.dat' title 'Sonar'<br></p>
<p><img src="images/son-gnup-2.png" style=
"width: 600px; height: 321px;" alt="gnuplot 1"></p>

View File

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

View File

@ -1,452 +0,0 @@
<a href="#Are_my_GPIO_broken">Are my GPIO broken?</a><br>
<br>
<a href="#Audio_is_broken">Audio is broken</a><br>
<br>
<a href="#Cant_initialise_pigpio_library">Can´t initialise pigpio
library</a><br>
<br>
<a href="#Cant_lock_varrunpigpio.pid">Can´t lock
var/run/pigpio.pid</a><br>
<br>
<a href="#Hello_World">Hello World!</a><br>
<br>
<a href="#make_fails">Clock skew, make fails</a><br>
<br>
<a href="#Have_I_fried_my_GPIO">Have I fried my GPIO?</a><br>
<br>
<a href="#How_do_I_debounce_inputs">How do I debounce
inputs?</a><br>
<br>
<a href="#How_fast_is_SPI">How fast is SPI?</a><br>
<br>
<a href="#Library_update_fails">Library update didn't work</a><br>
<br>
<a href="#make_fails">make fails with clock skew</a><br>
<br>
<a href="#Porting_pigpio">Porting pigpio to another CPU/SoC</a><br>
<br>
<a href="#Sound_isnt_working">Sound isn't working</a><br>
<br>
<a href="#Library_update_fails">Symbol not found</a><br>
<br>
<a href="#What_is_I2C">What is I2C?</a><br>
<br>
<a href="#What_is_Serial">What is Serial?</a><br>
<br>
<a href="#What_is_SPI">What is SPI?</a><br>
<br>
<a href="#Which_library">Which library should I use?</a><br>
<br>
<h3><a name="Are_my_GPIO_broken" id="Are_my_GPIO_broken"></a>Are my
GPIO broken?</h3>
<p>See <a href="#Have_I_fried_my_GPIO">Have I fried my
GPIO?</a><br></p>
<h3><a name="Audio_is_broken" id="Audio_is_broken"></a>Audio is
broken</h3>
<p>See <a href="#Sound_isnt_working">Sound isn't
working</a><br></p>
<h3><a name="Cant_lock_varrunpigpio.pid" id=
"Cant_lock_varrunpigpio.pid"></a>Can´t lock
/var/run/pigpio.pid</h3>
<p>See <a href=
"#Cant_initialise_pigpio_library">Can´t_initialise_pigpio_library</a><br>
</p>
<h3><a name="Cant_initialise_pigpio_library" id=
"Cant_initialise_pigpio_library"></a>Can´t initialise pigpio
library</h3>
<p>This message means the pigpio daemon is already running.<br></p>
<p>The default daemon is called pigpiod and may be removed as
follows.<br></p>
Check that it is running with the command
<p><code>ps aux | grep pigpiod</code></p>
<p>Kill the daemon with<br></p>
<p><code>sudo killall pigpiod</code></p>
<p>If your own program is acting as the daemon it may be removed as
follows.</p>
<p>Find its process id (<span style=
"font-style: italic;">pid</span>).<br></p>
<p><code>cat /var/run/pigpio.pid</code><br></p>
<p>Kill the program with<br></p>
<p><code>sudo kill -9 <span style=
"font-style: italic;">pid</span></code><br></p>
If the above doesn't work do the following and try starting the
daemon again
<p><code>sudo rm /var/run/pigpio.pid<br></code></p>
<p>To start the daemon do</p>
<p><code>sudo pigpiod</code></p>
<h3><a name="Have_I_fried_my_GPIO" id=
"Have_I_fried_my_GPIO"></a>Have I fried my GPIO?</h3>
<p>If you think you have damaged one or more GPIO you can carry out
a diagnostic test.</p>
<p>The test is a command line script called <a rel="nofollow"
class="external text" href=
"http://abyz.me.uk/rpi/pigpio/code/gpiotest.zip">gpiotest</a></p>
For the duration of the test nothing must be connected to the GPIO
(no LEDs, wires, ribbon cables etc.).
<p>The test checks that each GPIO may be read and written and that
the internal resistor pull-ups and pull-downs are functional.</p>
<p>A <a rel="nofollow" class="external text" href=
"https://www.youtube.com/watch?v=sCJFLKWaxHo&amp;feature=youtu.be">video</a>
showing what happens to the GPIO during a test.</p>
<p>A test with all GPIO okay.</p>
<pre>This program checks the Pi's (user) gpios.
The program reads and writes all the gpios. Make sure NOTHING
is connected to the gpios during this test.
The program uses the pigpio daemon which must be running.
To start the daemon use the command sudo pigpiod.
Press the ENTER key to continue or ctrl-C to abort...
Testing...
Skipped non-user gpios: 0 1 28 29 30 31
Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18<br> 19 20 21 22 23 24 25 26 27
Failed user gpios: None
</pre>
<p>A test showing failed GPIO.</p>
<pre>This program checks the Pi's (user) gpios.
The program reads and writes all the gpios. Make sure NOTHING
is connected to the gpios during this test.
The program uses the pigpio daemon which must be running.
To start the daemon use the command sudo pigpiod.
Press the ENTER key to continue or ctrl-C to abort...
Testing...
Write 1 to gpio 17 failed.
Pull up on gpio 17 failed.
Write 1 to gpio 18 failed.
Pull up on gpio 18 failed.
Write 0 to gpio 23 failed.
Pull down on gpio 23 failed.
Write 0 to gpio 24 failed.
Pull down on gpio 24 failed.
Write 1 to gpio 27 failed.
Pull up on gpio 27 failed.
Skipped non-user gpios: 0 1 28 29 30 31
Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18<br> 19 20 21 22 23 24 25 26 27
Failed user gpios: 17 18 23 24 27
</pre>
<h3><a name="How_do_I_debounce_inputs" id=
"How_do_I_debounce_inputs"></a>How do I debounce inputs?</h3>
<p>Some devices like mechanical switches can generate multiple
interrupts as they bounce between on and off.&nbsp; It is possible
to debounce the inputs in hardware by the correct use of resistors
and capacitors.<br></p>
<p>In software use the glitch filter which ignores all events
shorter than a set number of microseconds.&nbsp; C <a href=
"cif.html#gpioGlitchFilter">gpioGlitchFilter</a>, Python <a href=
"python.html#set_glitch_filter">set_glitch_filter</a>.<br></p>
<h3><a name="How_fast_is_SPI" id="How_fast_is_SPI"></a>How fast is
SPI?</h3>
The SPI throughput in samples per second depends on a number of
factors.<br>
<br>
<ul>
<li>The SPI bit rate (transfer rate in bits per second)</li>
</ul>
<ul>
<li>The number of bytes transferred per sample (a 12 bit ADC sample
may require 3 bytes to transfer)</li>
</ul>
<ul>
<li>The driver used</li>
</ul>
<p>Two of those factors are fixed, the variable is the driver
used.</p>
<p>The pigpio driver is considerably faster than the Linux SPI
driver as is demonstrated by the following graphs.<br></p>
<p>Each graph shows the SPI bit rate in bits per second along the
horizontal axis.&nbsp; The samples per second achieved is shown on
the vertical axis.&nbsp; Each graph contains plots assuming 1 to 5
bytes per transfer.<br></p>
<p>The source code used for the tests is <a href=
"code/spi-driver-speed.c">spi-driver-speed.c</a> and <a href=
"code/spi-pigpio-speed.c">spi-pigpio-speed.c</a><br></p>
<p><img alt="spi-lnx-pibr1.png" src="images/spi-lnx-pibr1.png"></p>
<hr>
<p><img alt="spi-pig-pibr1.png" src="images/spi-pig-pibr1.png"></p>
<hr>
<p><img alt="spi-lnx-pi3b.png" src="images/spi-lnx-pi3b.png"></p>
<hr>
<p><img alt="spi-pig-pi3b.png" src="images/spi-pig-pi3b.png"></p>
<h3><a name="Library_update_fails" id=
"Library_update_fails"></a>Library update didn't work</h3>
<p>pigpio places files in the following locations<br></p>
<p>/usr/local/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)<br>
/usr/local/lib (libpigpio.so, libpigpiod_if.so,
libpigpiod_if2.so)<br>
/usr/local/bin (pig2vcd, pigpiod, pigs)<br>
/usr/local/man (man pages)<br></p>
The raspberrypi.org image containing pigpio uses different
locations.<br>
<p>/usr/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)<br>
/usr/lib (libpigpio.so, libpigpiod_if.so, libpigpiod_if2.so)<br>
/usr/bin (pig2vcd, pigpiod, pigs)<br>
/usr/man (man pages)<br></p>
<p>Mostly this doesn't matter as the /usr/local directories will
generally be earlier in the search path.&nbsp; The pigpio built
includes, binaries, and manuals are normally found first.<br></p>
<p>However the wrong libraries may be linked during the
compilation.&nbsp; If this is the case remove the /usr/lib entries
for libpigpio.so , libpigpiod_if.so, and libpigpiod_if2.so</p>
<h3><a name="Hello_World" id="Hello_World"></a>Hello World!</h3>
<p>The following examples show how to use the various components of
the pigpio library.</p>
<p>Each example shows how to read the level of a GPIO.</p>
<h4>C</h4>
read_cif.c
<pre>
#include &lt;stdio.h&gt;
#include &lt;pigpio.h&gt;
int main(int argc, char *argv[])
{
int GPIO=4;
int level;
if (gpioInitialise() &lt; 0) return 1;
level = gpioRead(GPIO);
printf("GPIO %d is %d\n", GPIO, level);
gpioTerminate();
}
</pre>
<p>Build</p>
<code>gcc -pthread -o read_cif read_cif.c -lpigpio</code>
<p>Run</p>
<code>sudo ./read_cif</code>
<h4>C via pigpio daemon</h4>
read_pdif.c
<pre>
#include &lt;stdio.h&gt;
#include &lt;pigpiod_if2.h&gt;
int main(int argc, char *argv[])
{
int pi;
int GPIO=4;
int level;
pi = pigpio_start(0, 0); /* Connect to local Pi. */
if (pi &lt; 0)
{
printf("Can't connect to pigpio daemon\n");
return 1;
}
level = gpio_read(pi, GPIO);
printf("GPIO %d is %d\n", GPIO, level);
pigpio_stop(pi); /* Disconnect from local Pi. */
return 0;
}
</pre>
<p>Build</p>
<code>gcc -pthread -o read_pdif read_pdif.c -lpigpiod_if2</code>
<p>Run</p>
<code>./read_pdif</code>
<h4>Python</h4>
read_gpio.py
<pre>
#!/usr/bin/env python
import pigpio
GPIO=4
pi = pigpio.pi()
if not pi.connected:
exit()
level = pi.read(GPIO)
print("GPIO {} is {}".format(GPIO, level))
pi.stop()
</pre>
<p>Run</p>
<code>python read_gpio.py</code>
<h4>pigs</h4>
<pre>
pigs r 4
</pre>
<h4>pipe I/F</h4>
<pre>
echo "r 4" &gt;/dev/pigpio
cat /dev/pigout
</pre>
<h3><a name="make_fails" id="make_fails"></a>make fails with clock
skew</h3>
<p>If make fails with one of the following messages it is probably
because the Pi's clock is wrong.<br></p>
<p><code>make: Warning: File 'xxx' has modification time x s in the
future<br>
make: warning: Clock skew detected. Your build may be
incomplete.</code></p>
<p>make uses the current time to work out which files need to be
rebuilt (a file is rebuilt if it depends on other files which have
a later time-stamp).<br></p>
<p>The solution is to make sure the system clock is correct.&nbsp;
If the Pi is networked this will not normally be a problem.<br></p>
<p>To set the date and time use the date command as in the
following example.</p>
<p><code>sudo date -d "2017-03-01 18:47:00"</code></p>
<h3><a name="Porting_pigpio" id="Porting_pigpio"></a>Porting pigpio
to another CPU/SoC</h3>
<h3><a name="Sound_isnt_working" id="Sound_isnt_working"></a>Sound
isn't working</h3>
<p>The Pi contains two pieces of hardware, a PWM peripheral and a
PCM peripheral, to generate sound.&nbsp; The PWM peripheral is
normally used and generates medium quality audio out of the
headphone jack.&nbsp; The PCM peripheral may be used by add-ons
such as HATs and generates high quality audio.<br></p>
<p>pigpio uses at least one of these peripherals during normal
operation (for timing DMA transfers).&nbsp; pigpio will use both
peripherals if waves or the hardware PWM function is used.<br></p>
<p>By default pigpio uses the PCM peripheral leaving the PWM
peripheral free for medium quality audio.<br></p>
<p>You can change the default with a configuration option.&nbsp;
For C use <a href="cif.html#gpioCfgClock">gpioCfgClock</a>, for the
<a href="pigpiod.html">pigpio daemon</a> use the -t option.</p>
<h3><a name="What_is_I2C" id="What_is_I2C"></a>What is I2C?</h3>
<p>I2C is a data link between the Pi (master) and one or more
slaves.</p>
<p>Data may be sent and received but the Pi initiates all
transfers.<br></p>
<p>I2C is a medium speed link.&nbsp; On the Pi the default speed is
100 kbps, but 400 kbps also works.<br></p>
<p>I2C is implemented as a bus with two lines called<br></p>
<ul>
<li>SDA - for data</li>
<li>SCL - for a clock</li>
</ul>
On the Pi bus 1 is used which uses GPIO 2 (pin 3) for SDA and GPIO
3 (pin 5) for SCL.<br>
<br>
Only one slave device may be communicated with at a time.&nbsp;
Each message from the Pi includes the slave to be addressed and
whether a read or write is to be performed.<br>
<br>
When the Pi (master) wishes to talk to a slave it begins by issuing
a start sequence on the I2C bus. A start sequence is one of two
special sequences defined for the I2C bus, the other being the stop
sequence. The start sequence and stop sequence are special in that
these are the only places where the SDA (data line) is allowed to
change while the SCL (clock line) is high. When data is being
transferred, SDA must remain stable and not change whilst SCL is
high. The start and stop sequences mark the beginning and end of a
transaction with the slave device.<br>
<br>
<img style="width: 600px;" alt="I2C start and stop sequences" src=
"images/faq-i2c-ss.png"><br>
<br>
Data is transferred in 8-bit bytes. The bytes are placed on the SDA
line starting with the most significant bit. The SCL line is then
pulsed high, then low. For every byte transferred, the device
receiving the data sends back an acknowledge bit, so there are
actually 9 SCL clock pulses to transfer each 8-bit byte of data. If
the receiving device sends back a low ACK bit, then it has received
the data and is ready to accept another byte. If it sends back a
high then it is indicating it cannot accept any further data and
the master should terminate the transfer by sending a stop
sequence.<br>
<br>
<p><img style="width: 600px;" alt="I2C waveform" src=
"images/faq-i2c.jpg"><br></p>
<h3><a name="What_is_Serial" id="What_is_Serial"></a>What is
Serial?</h3>
<p>Serial is a data link between the Pi and one other
device.<br></p>
<p>Data may be sent and received.&nbsp; Either the Pi or the device
can initiate a transfer.<br></p>
<p>Serial is a low to medium speed link.&nbsp; On the Pi speeds of
50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600,
19200, 38400, 57600, 115200, and 230400 bps may be used.<br></p>
<p>Serial is implemented with one line for transmit called TXD and
one line for receive called RXD.<br></p>
<p>If only receive or transmit are required the other line need not
be connected.<br></p>
<p>The Pi uses GPIO 14 (pin 8) for TXD and GPIO 15 (pin 10) for
RXD.<br></p>
<p>Data is normally transmitted in 8-bit bytes with a start bit,
eight data bits, no parity, and one stop bit.&nbsp; This is
represented as 8N1.&nbsp; The number of transmitted bits per second
(bps) is called the baud rate.&nbsp;&nbsp; The time for each bit,
<span style="font-style: italic;">1 / baud rate</span> seconds, is
referred to as the bit period.<br></p>
<p>The lines are in the high state when no data is being
transmitted.&nbsp; The start of a byte is signalled by the line
going low for one bit period (the start bit).&nbsp; The data bits
are then sent least significant bit firsts (low if the bit is 0,
high if the bit is 1).&nbsp; The data bits are followed by the
optional parity bit.&nbsp; Finally the line is set high for at
least the number of stop bit periods.&nbsp; The line will stay high
if there are no more bytes to be transmitted.<br></p>
<p><img style="width: 600px;" alt="Serial waveform" src=
"images/faq-serial.jpg"><br></p>
<h3><a name="What_is_SPI" id="What_is_SPI"></a>What is SPI?</h3>
<p>SPI is a data link between the Pi (master) and one or more
slaves.</p>
<p>Data may be sent and received but the Pi initiates all
transfers.<br></p>
<p>SPI is a medium to high speed link.&nbsp; On the Pi speeds of 32
kbps to 8 Mbps may be used.<br></p>
<p>SPI is implemented as a bus with three lines called<br></p>
<ul>
<li>MOSI - for data from the Pi to the slave</li>
<li>MISO - for data from the slave to the Pi</li>
<li>SCLK - for a clock</li>
</ul>
Only one slave device may be communicated with at a time.&nbsp; An
additional line per slave called slave select is used to identify
the slave to be addressed.
<p>The Pi has two SPI buses<br></p>
<ol>
<li>the main SPI bus
<ul>
<li>MOSI GPIO 10 (pin 19)</li>
<li>MISO GPIO 9 (pin 21)</li>
<li>SCLK GPIO 11 (pin 23)</li>
<li>Slave selects</li>
<li style="list-style: none; display: inline">
<ul>
<li>CE0 GPIO 8 (pin 24)</li>
<li>CE1 GPIO 7 (pin 26)</li>
</ul>
</li>
</ul>
</li>
<li>the auxiliary SPI bus
<ul>
<li>MOSI GPIO 20 (pin 38)</li>
<li>MISO GPIO 19 (pin 35)</li>
<li>SCLK GPIO 21 (pin 40)</li>
<li>Slave selects</li>
<li style="list-style: none; display: inline">
<ul>
<li>CE0 GPIO 18 (pin 12)</li>
<li>CE1 GPIO 17 (pin 11)</li>
<li>CE2 GPIO 16 (pin 36)<br></li>
</ul>
</li>
</ul>
</li>
</ol>
<p><img style="width: 600px;" alt="SPI waveform" src=
"images/faq-spi.jpg"><br></p>
<p><br></p>
<h3><a name="Which_library" id="Which_library"></a>Which library
should I use?</h3>
<p><br></p>

View File

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

View File

@ -1,24 +0,0 @@
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 diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -1,205 +0,0 @@
<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 diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff