pigpio
raw JSON → 1.78 verified Fri May 01 auth: no python
pigpio is a Python module for controlling the Raspberry Pi's GPIO pins. It provides both local and remote GPIO control via the pigpio daemon. Current version is 1.78, with infrequent releases.
pip install pigpio Common errors
error Can't connect to pigpio on localhost ↓
cause pigpio daemon not running or not accessible.
fix
Run 'sudo pigpiod' to start the daemon.
error ImportError: No module named pigpio ↓
cause pigpio Python module not installed.
fix
pip install pigpio
error AttributeError: module 'pigpio' has no attribute 'pi' ↓
cause Using an older version of pigpio that uses a different API.
fix
Upgrade to latest pigpio: pip install --upgrade pigpio
Warnings
gotcha pigpio requires the pigpio daemon to be running before the Python script can connect. If daemon is not running, pi.connected returns False. ↓
fix Start the daemon: sudo pigpiod
deprecated Passing a hostname to pigpio.pi() or using pi.serial() may be deprecated in future versions. Use pi = pigpio.pi() for local connection. ↓
fix Use pigpio.pi() without arguments for local connection.
gotcha GPIO numbers are Broadcom (BCM) pin numbers, not physical pin numbers. Common mistake is to use physical pin numbers. ↓
fix Always use BCM GPIO numbers (e.g., GPIO 17 is physical pin 11).
Imports
- pi wrong
import pigpio pi = pigpio.pi('localhost')correctimport pigpio pi = pigpio.pi()
Quickstart
import pigpio
import time
pi = pigpio.pi()
if not pi.connected:
print("Failed to connect to pigpio daemon")
exit(1)
pi.set_mode(17, pigpio.OUTPUT)
pi.write(17, 1)
time.sleep(1)
pi.write(17, 0)
pi.stop()