Mini GPIO board for Raspberry Pi

This is a simple add-on board for the Raspberry Pi with three LEDs and a push-button switch. A sample bit of Python code is shown below to flash the LEDs in response to the switch being pressed. There’s also the option to add a low-cost DHT11 temperature/humidity sensor to build a simple datalogger.
mini gpio

Here’s a little bit of code you can use to test the board. Use a text editor to enter the code and save it in a file called led_flasher.py which you can then run by typing sudo python led_flasher.py

import RPi.GPIO as GPIO
import time
 
def led_on_and_pause(pin):
    GPIO.output(pin, GPIO.HIGH) # LED on
    if (GPIO.input(9) == GPIO.LOW):
        time.sleep(0.2) # switch pressed
    else:
        time.sleep(1) # switch NOT pressed
    GPIO.output(pin, GPIO.LOW) # LED off
 
# Note: the switch requires use of the
# Pi's internal pull-up resistors hence the
# GPIO.PUD_UP in the setup code below.
 
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT) # red
GPIO.setup(22, GPIO.OUT) # yellow
GPIO.setup(10, GPIO.OUT) # green
GPIO.setup(9, GPIO.IN, GPIO.PUD_UP) # switch
 
for i in range(100):
    led_on_and_pause(17) # red
    led_on_and_pause(22) # yellow
    led_on_and_pause(10) # green
 
GPIO.cleanup()
If you’ve got one of the blue DHT11 temperature/humidity sensors attached to your board, you should look at Adafruit’s excellent tutorial – the DHT11 on your board is wired to GPIO pin BCM4 as suggested by Adafruit, so you can skip the wiring instructions!