Having brought my RPi.GPIO documentation (almost) up-to-date with the previous blog post, I realised it was time to update my RPi.GPIO Quick Reference ‘cheat sheet’ as well. It’s quite a useful reference. Page 1 gives you the basic RPi.GPIO commands and usage. I like to take one of these the Jams in case someone needs help and I can’t remember the necessary commands. Page 2 has a Raspberry Pi GPIO pinout diagram for all versions (except compute module). This part has been updated to add the pinouts for the B+ (and A+). Page 3 gives a list of links to all 13 of my RPi.GPIO tutorial pages (including yesterday’s).
I had to redo parts of it from scratch because I couldn’t find the main source file. But it didn’t take too long.
Here’s what page 1 looks like…
# RPi.GPIO Basics cheat sheet - Don't try to run this. It'll fail! # Alex Eames http://RasPi.TV # http://RasPi.TV/?p=4320 # RPi.GPIO Official Documentation # http://sourceforge.net/p/raspberry-gpio-python/wiki/Home/ import RPi.GPIO as GPIO # import RPi.GPIO module # choose BOARD or BCM GPIO.setmode(GPIO.BCM) # BCM for GPIO numbering GPIO.setmode(GPIO.BOARD) # BOARD for P1 pin numbering # Set up Inputs GPIO.setup(port_or_pin, GPIO.IN) # set port/pin as an input GPIO.setup(port_or_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # input with pull-down GPIO.setup(port_or_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # input with pull-up # Set up Outputs GPIO.setup(port_or_pin, GPIO.OUT) # set port/pin as an output GPIO.setup(port_or_pin, GPIO.OUT, initial=1) # set initial value option (1 or 0) # Switch Outputs GPIO.output(port_or_pin, 1) # set an output port/pin value to 1/GPIO.HIGH/True GPIO.output(port_or_pin, 0) # set an output port/pin value to 0/GPIO.LOW/False # Read status of inputs OR outputs i = GPIO.input(port_or_pin) # read status of pin/port and assign to variable i if GPIO.input(port_or_pin): # use input status directly in program logic # Clean up on exit GPIO.cleanup() # What Raspberry Pi revision are we running? GPIO.RPI_REVISION # 0 = Compute Module, 1 = Rev 1, 2 = Rev 2, 3 = Model B+ # What version of RPi.GPIO are we running? GPIO.VERSION # What Python version are we running? import sys; sys.version
Page 2 is the pinouts for all Pi models
Page 3 is an Index of Tutorial Links
RPi.GPIO Basics series
- How to check what RPi.GPIO version you have
- How to check what Raspberry Pi board Revision you have
- How to Exit GPIO programs cleanly, avoid warnings and protect your Pi
- Setting up RPi.GPIO, numbering systems and inputs
- Setting up and using outputs with RPi.GPIO
- Using inputs and outputs at the same time with RPi.GPIO, and pull-ups/pull-downs
- RPi.GPIO cheat sheet
RPi.GPIO more advanced
Interrupts (needs RPi.GPIO 0.5.2+)
- Background and simple interrupt: How to use interrupts with Python on the Raspberry Pi and RPi.GPIO
- Threaded callback: How to use interrupts with Python on the Raspberry Pi and RPi.GPIO – part 2
- Multiple threaded callback: How to use interrupts with Python on the Raspberry Pi and RPi.GPIO – part 3
- Edge Detection: Detecting both rising and falling edges with RPi.GPIO
From 0.5.2a onwards, RPi.GPIO has software PWM. Below are two links. One describes its basic usage and the other is a practical application for dimming LEDs and controlling motor speed.
- PWM: RPi.GPIO 0.5.2a now has software PWM – How to use it
- PWM practical: How to use soft PWM in RPi.GPIO 0.5.2a pt 2 – led dimming and motor speed control
Hope this is useful for you.
The download here http://raspi.tv/download/RPi.GPIO-Cheat-Sheet.pdf