The module provides access to the Pi's gpios with the principal features
- PWM may be output to all gpios (PWM is used to position servos, control motor speed, control LED brightness etc).
- Callbacks for fast reaction to changes in gpio levels.
- Reading/writing of individual gpios or all gpios in one operation.
- Setting gpio modes.
- Setting gpio pull-up down state.
To download and install cut & paste the following into a Pi terminal window (all steps should be complete in less than 3 minutes).
Code: Select all
wget abyz.co.uk/rpi/pigpio/pigpio.zip
unzip pigpio.zip
cd PIGPIO
make
make install
Test
The Python module requires the services of the pigpio daemon. As a quick test. Start the daemon.
sudo pigpiod
Start Python.
python
Enter the following code (you can cut & paste but do not use the SELECT ALL button as that corrupts the formatting).
Code: Select all
import pigpio
pigpio.start()
for g in range(0,32):
print("gpio {} is {}".format(g, pigpio.read(g)))
pigpio.stop()
To exit Python type exit() or ctrl-D.
A script to show the status of the first 32 gpios with updates is at http://abyz.co.uk/rpi/pigpio/code/gpio_status_py.zip.
Documentation
You can use help(pigpio) within python or refer to the on-line documentation at http://abyz.co.uk/rpi/pigpio/python.html
Remote Processing
There are almost certainly performance advantages in running the Python code on a networked machine separate to the Pi. The pigpio daemon must still be running on the Pi.
The simplest method is to copy the setup.py and pigpio.py files from the PIGPIO directory to a temporary directory on the remote machine. Then move to the temporary directory and enter.
On Linux
sudo python setup.py install
On Windows something like
c:\python33\python setup.py install
On the remote machine you need to specify the address of the Pi (either by hostname or IP address).
On Linux something like
export PIGPIO_ADDR=myPi
On Windows something like
set PIGPIO_ADDR=myPi
Alternatively, rather than pigpio.start(), you could use pigpio.start('myPi').
I don't know what needs to be done on a Mac.
Performance Comparison
The following table gives an idea of the performance gains to be had from running remotely. In each test each of 14 gpios were raising 8000 measurable events per second for a total of 112,000 events per second. The 000's EPS column show the number of events captured by the Python module. My pretty poor desktop caught them all, my pretty poor laptop nearly all, and the Pi's were obviously swamped.
Code: Select all
000's Python O/S Machine
EPS version
113 2.7 Debian remote Desktop
113 2.7 Windows(XP) remote Desktop
113 3.3 Debian remote Desktop
113 3.3 Windows(XP) remote Desktop
99.2 3.3 Debian remote Laptop
98.9 2.7 Debian remote Laptop
90.6 2.7 Windows(Vista) remote Laptop
78.3 3.3 Windows(Vista) remote Laptop
9.69 2.7 Raspbian local Pi
8.58 2.7 Debian local Pi
6.49 3.2 Raspbian local Pi
6.25 3.2 Debian local Pi