Python Library – PIGPIO
PIGPIO
Website
Informatie (ENG):
pigpio is a C library for the Raspberry which allows control of the general purpose input outputs (gpios).
Features
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
sampling and time-stamping of gpios 0-31 between 100,000 and 1,000,000 times per second. provision of PWM on any number of the user gpios simultaneously. provision of servo pulses on any number of the user gpios simultaneously. callbacks when any of gpios 0-31 change state (callbacks receive the time of the event accurate to a few microseconds). notifications via pipe when any of gpios 0-31 change state. callbacks at timed intervals. reading/writing all of the gpios in a bank (0-31, 32-53) as a single operation. individually setting gpio modes, reading and writing. socket and pipe interfaces for the bulk of the functionality in addition to the underlying C library calls. the construction of arbitrary waveforms to give precise timing of output gpio level changes (accurate to a few microseconds). software serial links using any user gpio. rudimentary permission control through the socket and pipe interfaces so users can be prevented from "updating" inappropriate gpios. creating and running scripts on the pigpio daemon. |
Interfaces
The library provides a number of control interfaces
1 2 3 4 5 |
the C function interface the /dev/pigpio pipe interface the socket interface (used by the pigs utility and the Python module) |
Utilities
A number of utility programs are provided
1 2 3 4 5 6 7 |
the pigpiod daemon. the Python module. the pigs command line utility. the pig2vcd utility which converts notifications into the value change dump (VCD) format (useful for viewing digital waveforms with GTKWave). |
gpios
ALL gpios are identified by their Broadcom number. See elinux.org
There are 54 gpios in total, arranged in two banks.
Bank 1 contains gpios 0-31. Bank 2 contains gpios 32-54.
A user should only manipulate gpios in bank 1.
There are at least three types of board.
Type 1
1 2 3 4 5 |
26 pin header (P1). Hardware revision numbers of 2 and 3. User gpios 0-1, 4, 7-11, 14-15, 17-18, 21-25. |
Type 2
1 2 3 4 5 |
26 pin header (P1) and an additional 8 pin header (P5). Hardware revision numbers of 4, 5, 6, and 15. User gpios 2-4, 7-11, 14-15, 17-18, 22-25, 27-31. |
Type 3
1 2 3 4 5 |
40 pin expansion header (J8). Hardware revision numbers of 16 or greater. User gpios 2-27 (0 and 1 are reserved). |
It is safe to read all the gpios. 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.
Installation
Remove or rename any existing pigpio zip or tar files depending on your download method. Remove or rename any existing PIGPIO or pigpio-master directory (saving any of your own files in that directory first).
If the pigpio daemon is running it should be killed (sudo killall pigpiod) before make install and restarted afterwards (sudo pigpiod).
The initial part of the make, the compilation of pigpio.c, takes 100 seconds on early model Pis. Be patient. The overall install takes just over 3 minutes.
Download and install (V55)
Method 1
1 2 3 4 5 6 7 |
rm pigpio.zip sudo rm -rf PIGPIO wget abyz.co.uk/rpi/pigpio/pigpio.zip unzip pigpio.zip cd PIGPIO make -j4 sudo make install |
Method 2
1 2 3 4 5 6 7 |
rm pigpio.tar sudo rm -rf PIGPIO wget abyz.co.uk/rpi/pigpio/pigpio.tar tar xf pigpio.tar cd PIGPIO make -j4 sudo make install |
Method 3
1 2 3 4 5 6 7 |
rm master.zip sudo rm -rf pigpio-master wget https://github.com/joan2937/pigpio/archive/master.zip unzip master.zip cd pigpio-master make -j4 sudo make install |
To check the library
These tests make extensive use of GPIO 25 (pin 22). Make sure nothing, or only a LED, is connected to the GPIO before running the tests. Most tests are statistical in nature and so may on occasion fail. Repeated failures on the same test or many failures in a group of tests indicate a problem.
1 2 3 4 5 6 7 8 |
sudo ./x_pigpio # check C I/F sudo pigpiod # start daemon ./x_pigpiod_if2 # check C I/F to daemon ./x_pigpio.py # check Python I/F to daemon ./x_pigs # check pigs I/F to daemon ./x_pipe # check pipe I/F to daemon |
To compile, link, and run a C program
1 2 |
gcc -Wall -pthread -o foobar foobar.c -lpigpio -lrt sudo ./foobar |
To start the pigpio daemon
sudo pigpiod
To stop the pigpio daemon
sudo killall pigpiod
github
git clone https://github.com/joan2937/pigpio
Raspbian (raspberrypi.org image)
This may not be the most recent version. You can check the version with the command pigpiod -v.
1 2 |
sudo apt-get update sudo apt-get install pigpio python-pigpio python3-pigpio |
Installatie vanaf Github
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
--2016-09-14 10:24:49-- https://github.com/joan2937/pigpio/archive/master.zip Resolving github.com (github.com)... 192.30.253.113 Connecting to github.com (github.com)|192.30.253.113|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://codeload.github.com/joan2937/pigpio/zip/master [following] --2016-09-14 10:24:50-- https://codeload.github.com/joan2937/pigpio/zip/master Resolving codeload.github.com (codeload.github.com)... 192.30.253.121 Connecting to codeload.github.com (codeload.github.com)|192.30.253.121|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [application/zip] Saving to: ‘master.zip’ master.zip [ <=> ] 377.86K 945KB/s in 0.4s 2016-09-14 10:24:51 (945 KB/s) - ‘master.zip’ saved [386927] |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
Archive: master.zip f9e24d568bab974bd353d8bfa7453de2acd66fa0 creating: pigpio-master/ creating: pigpio-master/EXAMPLES/ creating: pigpio-master/EXAMPLES/C/ creating: pigpio-master/EXAMPLES/C/COUNTER_1/ inflating: pigpio-master/EXAMPLES/C/COUNTER_1/README inflating: pigpio-master/EXAMPLES/C/COUNTER_1/freq_count_1.c creating: pigpio-master/EXAMPLES/C/COUNTER_2/ inflating: pigpio-master/EXAMPLES/C/COUNTER_2/README inflating: pigpio-master/EXAMPLES/C/COUNTER_2/freq_count_2.c creating: pigpio-master/EXAMPLES/C/HALL_EFFECT_SENSOR/ extracting: pigpio-master/EXAMPLES/C/HALL_EFFECT_SENSOR/README inflating: pigpio-master/EXAMPLES/C/HALL_EFFECT_SENSOR/hall.c creating: pigpio-master/EXAMPLES/C/I2C_SNIFFER/ inflating: pigpio-master/EXAMPLES/C/I2C_SNIFFER/README inflating: pigpio-master/EXAMPLES/C/I2C_SNIFFER/pig2i2c.c creating: pigpio-master/EXAMPLES/C/IR_RECEIVER/ inflating: pigpio-master/EXAMPLES/C/IR_RECEIVER/README inflating: pigpio-master/EXAMPLES/C/IR_RECEIVER/ir_hasher.c inflating: pigpio-master/EXAMPLES/C/IR_RECEIVER/ir_hasher.h inflating: pigpio-master/EXAMPLES/C/IR_RECEIVER/test_ir_hasher.c creating: pigpio-master/EXAMPLES/C/PCF8591_YL-40/ inflating: pigpio-master/EXAMPLES/C/PCF8591_YL-40/PCF8591.c extracting: pigpio-master/EXAMPLES/C/PCF8591_YL-40/README creating: pigpio-master/EXAMPLES/C/POT_CAP_RECHARGE/ inflating: pigpio-master/EXAMPLES/C/POT_CAP_RECHARGE/README inflating: pigpio-master/EXAMPLES/C/POT_CAP_RECHARGE/pot_cap_charge.c creating: pigpio-master/EXAMPLES/C/ROTARY_ENCODER/ inflating: pigpio-master/EXAMPLES/C/ROTARY_ENCODER/README inflating: pigpio-master/EXAMPLES/C/ROTARY_ENCODER/rotary_encoder.c inflating: pigpio-master/EXAMPLES/C/ROTARY_ENCODER/rotary_encoder.h inflating: pigpio-master/EXAMPLES/C/ROTARY_ENCODER/test_rotary_encoder.c creating: pigpio-master/EXAMPLES/C/WIEGAND_CODE/ inflating: pigpio-master/EXAMPLES/C/WIEGAND_CODE/README inflating: pigpio-master/EXAMPLES/C/WIEGAND_CODE/test_wiegand.c inflating: pigpio-master/EXAMPLES/C/WIEGAND_CODE/wiegand.c inflating: pigpio-master/EXAMPLES/C/WIEGAND_CODE/wiegand.h creating: pigpio-master/EXAMPLES/CPP/ creating: pigpio-master/EXAMPLES/CPP/IR_RECEIVER/ inflating: pigpio-master/EXAMPLES/CPP/IR_RECEIVER/README inflating: pigpio-master/EXAMPLES/CPP/IR_RECEIVER/ir_hasher.cpp inflating: pigpio-master/EXAMPLES/CPP/IR_RECEIVER/ir_hasher.hpp inflating: pigpio-master/EXAMPLES/CPP/IR_RECEIVER/test_ir_hasher.cpp creating: pigpio-master/EXAMPLES/CPP/ROTARY_ENCODER/ inflating: pigpio-master/EXAMPLES/CPP/ROTARY_ENCODER/README inflating: pigpio-master/EXAMPLES/CPP/ROTARY_ENCODER/rotary_encoder.cpp inflating: pigpio-master/EXAMPLES/CPP/ROTARY_ENCODER/rotary_encoder.hpp inflating: pigpio-master/EXAMPLES/CPP/ROTARY_ENCODER/test_rotary_encoder.cpp creating: pigpio-master/EXAMPLES/CPP/WIEGAND_CODE/ inflating: pigpio-master/EXAMPLES/CPP/WIEGAND_CODE/README inflating: pigpio-master/EXAMPLES/CPP/WIEGAND_CODE/test_wiegand.cpp inflating: pigpio-master/EXAMPLES/CPP/WIEGAND_CODE/wiegand.cpp inflating: pigpio-master/EXAMPLES/CPP/WIEGAND_CODE/wiegand.hpp creating: pigpio-master/EXAMPLES/Python/ creating: pigpio-master/EXAMPLES/Python/DHT11_SENSOR/ inflating: pigpio-master/EXAMPLES/Python/DHT11_SENSOR/README inflating: pigpio-master/EXAMPLES/Python/DHT11_SENSOR/dht11.py creating: pigpio-master/EXAMPLES/Python/DHT22_AM2302_SENSOR/ inflating: pigpio-master/EXAMPLES/Python/DHT22_AM2302_SENSOR/DHT22.py inflating: pigpio-master/EXAMPLES/Python/DHT22_AM2302_SENSOR/README creating: pigpio-master/EXAMPLES/Python/GPIO_STATUS/ extracting: pigpio-master/EXAMPLES/Python/GPIO_STATUS/README inflating: pigpio-master/EXAMPLES/Python/GPIO_STATUS/gpio_status.py creating: pigpio-master/EXAMPLES/Python/HALL_EFFECT_SENSOR/ extracting: pigpio-master/EXAMPLES/Python/HALL_EFFECT_SENSOR/README inflating: pigpio-master/EXAMPLES/Python/HALL_EFFECT_SENSOR/hall.py creating: pigpio-master/EXAMPLES/Python/I2C_SNIFFER/ inflating: pigpio-master/EXAMPLES/Python/I2C_SNIFFER/I2C_sniffer.py inflating: pigpio-master/EXAMPLES/Python/I2C_SNIFFER/README creating: pigpio-master/EXAMPLES/Python/IR_RECEIVER/ inflating: pigpio-master/EXAMPLES/Python/IR_RECEIVER/README inflating: pigpio-master/EXAMPLES/Python/IR_RECEIVER/ir_hasher.py creating: pigpio-master/EXAMPLES/Python/MORSE_CODE/ inflating: pigpio-master/EXAMPLES/Python/MORSE_CODE/README inflating: pigpio-master/EXAMPLES/Python/MORSE_CODE/morse_code.py creating: pigpio-master/EXAMPLES/Python/PCF8591_YL-40/ inflating: pigpio-master/EXAMPLES/Python/PCF8591_YL-40/PCF8591.py extracting: pigpio-master/EXAMPLES/Python/PCF8591_YL-40/README creating: pigpio-master/EXAMPLES/Python/PIGPIO_BENCHMARK/ extracting: pigpio-master/EXAMPLES/Python/PIGPIO_BENCHMARK/README inflating: pigpio-master/EXAMPLES/Python/PIGPIO_BENCHMARK/bench_1.py creating: pigpio-master/EXAMPLES/Python/ROTARY_ENCODER/ extracting: pigpio-master/EXAMPLES/Python/ROTARY_ENCODER/README inflating: pigpio-master/EXAMPLES/Python/ROTARY_ENCODER/rotary_encoder.py creating: pigpio-master/EXAMPLES/Python/SONAR_RANGER/ inflating: pigpio-master/EXAMPLES/Python/SONAR_RANGER/README inflating: pigpio-master/EXAMPLES/Python/SONAR_RANGER/sonar_trigger_echo.py creating: pigpio-master/EXAMPLES/Python/VIRTUAL_WIRE/ inflating: pigpio-master/EXAMPLES/Python/VIRTUAL_WIRE/README inflating: pigpio-master/EXAMPLES/Python/VIRTUAL_WIRE/vw.py creating: pigpio-master/EXAMPLES/Python/WIEGAND_CODE/ inflating: pigpio-master/EXAMPLES/Python/WIEGAND_CODE/README inflating: pigpio-master/EXAMPLES/Python/WIEGAND_CODE/wiegand.py creating: pigpio-master/EXAMPLES/Shell/ creating: pigpio-master/EXAMPLES/Shell/GPIOTEST/ inflating: pigpio-master/EXAMPLES/Shell/GPIOTEST/README inflating: pigpio-master/EXAMPLES/Shell/GPIOTEST/gpiotest inflating: pigpio-master/MakeRemote inflating: pigpio-master/Makefile inflating: pigpio-master/README inflating: pigpio-master/README.md inflating: pigpio-master/UNLICENCE inflating: pigpio-master/command.c inflating: pigpio-master/command.h inflating: pigpio-master/custom.cext inflating: pigpio-master/pig2vcd.1 inflating: pigpio-master/pig2vcd.c inflating: pigpio-master/pigpio.3 inflating: pigpio-master/pigpio.c inflating: pigpio-master/pigpio.h inflating: pigpio-master/pigpio.py inflating: pigpio-master/pigpiod.1 inflating: pigpio-master/pigpiod.c inflating: pigpio-master/pigpiod_if.3 inflating: pigpio-master/pigpiod_if.c inflating: pigpio-master/pigpiod_if.h inflating: pigpio-master/pigpiod_if2.3 inflating: pigpio-master/pigpiod_if2.c inflating: pigpio-master/pigpiod_if2.h inflating: pigpio-master/pigs.1 inflating: pigpio-master/pigs.c inflating: pigpio-master/setup.py creating: pigpio-master/util/ inflating: pigpio-master/util/Findpigpio.cmake inflating: pigpio-master/util/pigpiod inflating: pigpio-master/util/readme.md inflating: pigpio-master/x_pigpio.c inflating: pigpio-master/x_pigpio.py inflating: pigpio-master/x_pigpiod_if.c inflating: pigpio-master/x_pigpiod_if2.c inflating: pigpio-master/x_pigs inflating: pigpio-master/x_pipe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
gcc -O3 -Wall -pthread -fpic -c -o pigpio.o pigpio.c gcc -O3 -Wall -pthread -fpic -c -o command.o command.c gcc -O3 -Wall -pthread -fpic -c -o pigpiod_if.o pigpiod_if.c gcc -O3 -Wall -pthread -fpic -c -o pigpiod_if2.o pigpiod_if2.c gcc -O3 -Wall -pthread -c -o x_pigpio.o x_pigpio.c gcc -O3 -Wall -pthread -c -o x_pigpiod_if.o x_pigpiod_if.c gcc -O3 -Wall -pthread -c -o x_pigpiod_if2.o x_pigpiod_if2.c gcc -O3 -Wall -pthread -c -o pig2vcd.o pig2vcd.c gcc -O3 -Wall -pthread -c -o pigpiod.o pigpiod.c gcc -O3 -Wall -pthread -c -o pigs.o pigs.c gcc -shared -o libpigpiod_if.so pigpiod_if.o command.o strip --strip-unneeded libpigpiod_if.so size libpigpiod_if.so gcc -shared -o libpigpiod_if2.so pigpiod_if2.o command.o text data bss dec hex filename 57743 4156 49244 111143 1b227 libpigpiod_if.so gcc -o pig2vcd pig2vcd.o gcc -o pigs pigs.o command.o strip --strip-unneeded libpigpiod_if2.so size libpigpiod_if2.so text data bss dec hex filename 65705 4144 1844 71693 1180d libpigpiod_if2.so gcc -o x_pigpiod_if x_pigpiod_if.o -L. -lpigpiod_if -pthread -lrt gcc -o x_pigpiod_if2 x_pigpiod_if2.o -L. -lpigpiod_if2 -pthread -lrt gcc -shared -o libpigpio.so pigpio.o command.o strip --strip-unneeded libpigpio.so size libpigpio.so text data bss dec hex filename 230808 5144 593824 829776 ca950 libpigpio.so gcc -o x_pigpio x_pigpio.o -L. -lpigpio -pthread -lrt gcc -o pigpiod pigpiod.o -L. -lpigpio -pthread -lrt |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
install -m 0755 -d /opt/pigpio/cgi install -m 0755 -d /usr/local/include install -m 0644 pigpio.h /usr/local/include install -m 0644 pigpiod_if.h /usr/local/include install -m 0644 pigpiod_if2.h /usr/local/include install -m 0755 -d /usr/local/lib install -m 0755 libpigpio.so /usr/local/lib install -m 0755 libpigpiod_if.so /usr/local/lib install -m 0755 libpigpiod_if2.so /usr/local/lib install -m 0755 -d /usr/local/bin install -m 0755 -s pig2vcd /usr/local/bin install -m 0755 -s pigpiod /usr/local/bin install -m 0755 -s pigs /usr/local/bin if which python2; then python2 setup.py install; fi /usr/bin/python2 running install running build running build_py creating build creating build/lib.linux-armv7l-2.7 copying pigpio.py -> build/lib.linux-armv7l-2.7 running install_lib copying build/lib.linux-armv7l-2.7/pigpio.py -> /usr/local/lib/python2.7/dist-packages byte-compiling /usr/local/lib/python2.7/dist-packages/pigpio.py to pigpio.pyc running install_egg_info Writing /usr/local/lib/python2.7/dist-packages/pigpio-1.32.egg-info if which python3; then python3 setup.py install; fi /usr/bin/python3 running install running build running build_py creating build/lib copying pigpio.py -> build/lib running install_lib copying build/lib/pigpio.py -> /usr/local/lib/python3.4/dist-packages byte-compiling /usr/local/lib/python3.4/dist-packages/pigpio.py to pigpio.cpython-34.pyc running install_egg_info Writing /usr/local/lib/python3.4/dist-packages/pigpio-1.32.egg-info install -m 0755 -d /usr/local/man/man1 install -m 0644 *.1 /usr/local/man/man1 install -m 0755 -d /usr/local/man/man3 install -m 0644 *.3 /usr/local/man/man3 ldconfig |
Download PIGPIO @ abyz.co.uk
Download PIGPIO @ github.com
[#/python/libraries/pigpio” ]