pigpio is a library for the Raspberry which allows control of the General Purpose Input Outputs (GPIO).  pigpio works on all versions of the Pi.

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. sudo pigpiod -d 5 -e 8 to specify primary 5, secondary 8.

Download

Features

General

The pigpio library is written in the C programming language.

The pigpio daemon offers a socket and pipe interface to the underlying C library.

A C library and a Python module allow control of the GPIO via the pigpio daemon.

There is third party support for a number of other languages

piscope

piscope is a logic analyser (digital waveform viewer).

piscope is a GTK+3 application and uses pigpio to provide raw GPIO level data.  piscope may be run on a Pi or on any machine capable of compiling a GTK+3 application.

GPIO

ALL GPIO are identified by their Broadcom number.  See elinux.org

There are 54 GPIO in total, arranged in two banks.

Bank 1 contains GPIO 0-31.  Bank 2 contains GPIO 32-53.

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.

There are several types of board, each with different expansion headers, giving physical access to different GPIO. 

Type 1 - Model B (original model)


GPIO pin pin GPIO
3V3 - 1 2 - 5V
SDA 0
3 4 - 5V
SCL 1
5 6 - Ground

4 7 8 14 TXD
Ground - 9 10 15 RXD
ce1 17 11 12 18 ce0

21 13 14 - Ground

22 15 16 23
3V3 -
17 18 24
MOSI 10 19 20 - Ground
MISO 9 21 22 25
SCLK 11 23 24 8 CE0
Ground - 25 26 7 CE1

Type 2 - Model A, B (revision 2)

26 pin header (P1) and an additional 8 pin header (P5).

GPIO pin pin GPIO
3V3 - 1 2 - 5V
SDA 2 3 4 - 5V
SCL 3 5 6 - Ground

4 7 8 14 TXD
Ground - 9 10 15 RXD
ce1 17 11 12 18 ce0

27 13 14 - Ground

22 15 16 23
3V3 -
17 18 24
MOSI 10 19 20 - Ground
MISO 9 21 22 25
SCLK 11 23 24 8 CE0
Ground - 25 26 7 CE1


GPIO pin pin GPIO
5V
- 1 2 - 3V3
SDA
28 3 4 29 SCL

30 5 6 31
Ground
-
7 8 -
Ground

Type 3 - Model A+, B+, Pi Zero, Pi Zero W, Pi2B, Pi3B, Pi4B


GPIO pin pin GPIO
3V3 - 1 2 - 5V
SDA 2 3 4 - 5V
SCL 3 5 6 - Ground

4 7 8 14 TXD
Ground - 9 10 15 RXD
ce1 17 11 12 18 ce0

27 13 14 - Ground

22 15 16 23
3V3 -
17 18 24
MOSI 10 19 20 - Ground
MISO 9 21 22 25
SCLK 11 23 24 8 CE0
Ground - 25 26 7 CE1
ID_SD 0 27 28 1 ID_SC

5 29 30 - Ground

6 31 32 12

13 33 34 - Ground
miso 19 35 36 16 ce2

26 37 38 20 mosi
Ground - 39 40 21 sclk

Compute Module

All 54 GPIO may be physically accessed.  Some are reserved for system use - refer to the Compute Module documentation.

Only GPIO 0-31 are supported for hardware timed sampling, PWM, servo pulses, alert callbacks, waves, and software serial links.

Other Languages

There are several third party projects which provide wrappers for pigpio.

Some I am aware of are:


The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals.  This use was inspired by Richard Hirst's servoblaster kernel module.