pigpio library
pigpio pigpio C I/F pigpiod pigpiod C I/F Python pigs piscope Misc Examples Download Site Map

The pigpio library

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.

pigpio is written in C but may be used by other languages.  In particular the pigpio daemon offers a socket and pipe interface to the underlying library.

Features

  • sampling and time-stamping of GPIO 0-31 between 100,000 and 1,000,000 times per second.

  • provision of PWM on any number of the user GPIO simultaneously.

  • provision of servo pulses on any number of the user GPIO simultaneously.

  • callbacks when any of GPIO 0-31 change state (callbacks receive the time of the event accurate to a few microseconds).

  • notifications via pipe when any of GPIO 0-31 change state.

  • callbacks at timed intervals.

  • reading/writing all of the GPIO 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 GPIO.

  • creating and running scripts on the pigpio daemon.

Download

Interfaces

The library provides a number of control interfaces

  • 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

  • the pig2vcd utility which converts notifications into the value change dump (VCD) format (useful for viewing digital waveforms with GTKWave).

piscope

piscope is a digital waveform viewer.

piscope is a GTK+3 application and uses pigpio to provide raw gpio 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.

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

Type 1 - Model B (original model)

  • 26 pin header (P1).
  • Hardware revision numbers of 2 and 3.
  • User GPIO 0-1, 4, 7-11, 14-15, 17-18, 21-25.

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

27 13 14 - Ground

21 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).
  • Hardware revision numbers of 4, 5, 6 (B), 7, 8, 9 (A), and 13, 14, 15 (B).
  • User GPIO 2-4, 7-11, 14-15, 17-18, 22-25, 27-31.

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, Pi2B, Pi3B

  • 40 pin expansion header (J8).
  • Hardware revision numbers of 16 or greater.
  • User GPIO 2-27 (0 and 1 are reserved).

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.

For all types of Pi it is safe to read 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.

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.

|pigpio| |pigpio C I/F| |pigpiod| |pigpiod C I/F| |Python| |pigs| |piscope| |Misc| |Examples| |Download| |Site Map|
© 2012-2016
e-mail: pigpio @ abyz.co.uk
Updated: 17/03/2016