See Can´t_initialise_pigpio_library
This message means the pigpio daemon is already running.
The default daemon is called pigpiod and may be removed as
follows.
ps aux | grep pigpiod
Kill the daemon with
sudo killall pigpiod
If your own program is acting as the daemon it may be removed as follows.
Find its process id (pid).
cat /var/run/pigpio.pid
Kill the program with
sudo kill -9 pid
sudo rm /var/run/pigpio.pid
To start the daemon do
sudo pigpiod
If you think you have damaged one or more GPIO you can carry out a diagnostic test.
The test is a command line script called gpiotest
For the duration of the test nothing must be connected to the GPIO (no LEDs, wires, ribbon cables etc.).The test checks that each GPIO may be read and written and that the internal resistor pull-ups and pull-downs are functional.
A video showing what happens to the GPIO during a test.
A test with all GPIO okay.
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
19 20 21 22 23 24 25 26 27 Failed user gpios: None
A test showing failed GPIO.
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
19 20 21 22 23 24 25 26 27 Failed user gpios: 17 18 23 24 27
Some devices like mechanical switches can generate multiple
interrupts as they bounce between on and off. It is possible
to debounce the inputs in hardware by the correct use of resistors
and capacitors.
In software use the glitch filter which ignores all events
shorter than a set number of microseconds. C gpioGlitchFilter, Python set_glitch_filter.
Two of those factors are fixed, the variable is the driver used.
The pigpio driver is considerably faster than the Linux SPI
driver as is demonstrated by the following graphs.
Each graph shows the SPI bit rate in bits per second along the
horizontal axis. The samples per second achieved is shown on
the vertical axis. Each graph contains plots assuming 1 to 5
bytes per transfer.
The source code used for the tests is spi-driver-speed.c and spi-pigpio-speed.c
pigpio places files in the following locations
/usr/local/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
/usr/local/lib (libpigpio.so, libpigpiod_if.so,
libpigpiod_if2.so)
/usr/local/bin (pig2vcd, pigpiod, pigs)
/usr/local/man (man pages)
/usr/include (pigpio.h, pigpiod_if.h, pigpiod_if2.h)
/usr/lib (libpigpio.so, libpigpiod_if.so, libpigpiod_if2.so)
/usr/bin (pig2vcd, pigpiod, pigs)
/usr/man (man pages)
Mostly this doesn't matter as the /usr/local directories will
generally be earlier in the search path. The pigpio built
includes, binaries, and manuals are normally found first.
However the wrong libraries may be linked during the compilation. If this is the case remove the /usr/lib entries for libpigpio.so , libpigpiod_if.so, and libpigpiod_if2.so
The following examples show how to use the various components of the pigpio library.
Each example shows how to read the level of a GPIO.
#include <stdio.h> #include <pigpio.h> int main(int argc, char *argv[]) { int GPIO=4; int level; if (gpioInitialise() < 0) return 1; level = gpioRead(GPIO); printf("GPIO %d is %d\n", GPIO, level); gpioTerminate(); }
Build
gcc -pthread -o read_cif read_cif.c -lpigpio
Run
sudo ./read_cif
#include <stdio.h> #include <pigpiod_if2.h> int main(int argc, char *argv[]) { int pi; int GPIO=4; int level; pi = pigpio_start(0, 0); /* Connect to local Pi. */ if (pi < 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; }
Build
gcc -pthread -o read_pdif read_pdif.c -lpigpiod_if2
Run
./read_pdif
#!/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()
Run
python read_gpio.py
pigs r 4
echo "r 4" >/dev/pigpio cat /dev/pigout
If make fails with one of the following messages it is probably
because the Pi's clock is wrong.
make: Warning: File 'xxx' has modification time x s in the
future
make: warning: Clock skew detected. Your build may be
incomplete.
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).
The solution is to make sure the system clock is correct.
If the Pi is networked this will not normally be a problem.
To set the date and time use the date command as in the following example.
sudo date -d "2017-03-01 18:47:00"
The Pi contains two pieces of hardware, a PWM peripheral and a
PCM peripheral, to generate sound. The PWM peripheral is
normally used and generates medium quality audio out of the
headphone jack. The PCM peripheral may be used by add-ons
such as HATs and generates high quality audio.
pigpio uses at least one of these peripherals during normal
operation (for timing DMA transfers). pigpio will use both
peripherals if waves or the hardware PWM function is used.
By default pigpio uses the PCM peripheral leaving the PWM
peripheral free for medium quality audio.
You can change the default with a configuration option. For C use gpioCfgClock, for the pigpio daemon use the -t option.
I2C is a data link between the Pi (master) and one or more slaves.
Data may be sent and received but the Pi initiates all
transfers.
I2C is a medium speed link. On the Pi the default speed is
100 kbps, but 400 kbps also works.
I2C is implemented as a bus with two lines called
Serial is a data link between the Pi and one other
device.
Data may be sent and received. Either the Pi or the device
can initiate a transfer.
Serial is a low to medium speed link. 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.
Serial is implemented with one line for transmit called TXD and
one line for receive called RXD.
If only receive or transmit are required the other line need not
be connected.
The Pi uses GPIO 14 (pin 8) for TXD and GPIO 15 (pin 10) for
RXD.
Data is normally transmitted in 8-bit bytes with a start bit,
eight data bits, no parity, and one stop bit. This is
represented as 8N1. The number of transmitted bits per second
(bps) is called the baud rate. The time for each bit,
1 / baud rate seconds, is
referred to as the bit period.
The lines are in the high state when no data is being
transmitted. The start of a byte is signalled by the line
going low for one bit period (the start bit). The data bits
are then sent least significant bit firsts (low if the bit is 0,
high if the bit is 1). The data bits are followed by the
optional parity bit. Finally the line is set high for at
least the number of stop bit periods. The line will stay high
if there are no more bytes to be transmitted.
SPI is a data link between the Pi (master) and one or more slaves.
Data may be sent and received but the Pi initiates all
transfers.
SPI is a medium to high speed link. On the Pi speeds of 32
kbps to 8 Mbps may be used.
SPI is implemented as a bus with three lines called
The Pi has two SPI buses