In Part 1 I showed you how to set up a Slice of Pi/O add on board for the Raspberry Pi, which we then tested in Part 2 by getting an LED to light up using one of the additional outputs the board supplies.
In Part 3, I’ll show you the Slice of Pi/O being used to its full potential – using all 16 outputs to drive LEDs as a prototype for my sports scoreboard project.
- 1 x large breadboard (830-point or similar)
- 16 x LEDs
- 16 x resistors for the LEDs
- 1 x 10k resistor for the switch
- 1 x 4-pin header (optional)
- 2 x 8-pin headers (optional)
- 1 x Tactile switch
- 20 x male-to-male jumper wires
Check out Part 2 if you want to use the same items that I use here.
Before we start
As always, turn off your Pi (you can use sudo halt from Terminal, or just do it the GUI way)
Solder the headers
If you want to solder your power and GPIO jumpers directly to the Slice of Pi/O, then technically you can skip this step. However, I like to add the headers to the breakout holes of my Slice of Pi/O to make prototyping easier.
I’ll use the 4-pin header as an example. Your 4-pin header should look like this:

4-pin header

Enter the 4-pin header here

View from the back

Soldering the 4-pin header

GPIO headers added as well
All we have done here is:
- Link up the PWR and GND pins to the breadboard power lanes
- Added 16 LEDs to the centre split on the board (positive leg upwards)
- Linked the positive LED legs to each MCP23017 output in order
- Linked the negative LED legs to the GND supply with a suitable resistor in line
- Added a tactile switch linked to GPIO 25 to act as our ‘goal’ button

What it should look like
The Python code
#! /usr/bin/python
#Imports
import smbus
import sys
import getopt
import time
import RPi.GPIO as GPIO
#Set GPIO mode
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
#Set GPIO pin for switch
TEAM1 = 25
#Set GPIO name and input/output
GPIO.setup(TEAM1, GPIO.IN) #Team 1 score button
#Bus thing??
bus = smbus.SMBus(0) #for revision 2 board...use 1
#Set the address (can check using i2cdetect -y 0 )
address = 0x20
# Set all banks to outputs
bus.write_byte_data(address,0x00,0x00) # Set all of bank A to outputs
bus.write_byte_data(address,0x01,0x00) # Set all of bank B to outputs
#gives each MCP pin a name
led0 = 0
led1 = 1
led2 = 2
led3 = 4
led4 = 8
led5 = 16
led6 = 32
led7 = 64
led8 = 128
#Banks
bank0 = 0
bank1 = 1
def set_led(data,bank): #means bank1 or bank0...simple
#print "set_led bank=" + str(bank) + " data=" + str(data)
if bank == 1:
bus.write_byte_data(address,0x12,data)
else:
bus.write_byte_data(address,0x13,data)
return
def main():
set_led(led0,bank0) #clear LEDs
set_led(led0,bank1) #clear LEDs
count = 0 #initially start 'count' at zero aka no LEDs lit
while 1:
if ( GPIO.input(TEAM1) == True): #aka if button clicked
count = count + 1
if ( count == 1):
set_led(led1,bank0)
time.sleep(1)
if ( count == 2):
set_led(led2,bank0)
time.sleep(1)
if ( count == 3):
set_led(led3,bank0)
time.sleep(1)
if ( count == 4):
set_led(led4,bank0)
time.sleep(1)
if ( count == 5):
set_led(led5,bank0)
time.sleep(1)
if ( count == 6):
set_led(led6,bank0)
time.sleep(1)
if ( count == 7):
set_led(led7,bank0)
time.sleep(1)
if ( count == 8):
set_led(led8,bank0)
time.sleep(1)
if ( count == 9):
set_led(led0,bank0) # turn off other bank
set_led(led8,bank1)
time.sleep(1)
if ( count == 10):
set_led(led7,bank1)
time.sleep(1)
if ( count == 11):
set_led(led6,bank1)
time.sleep(1)
if ( count == 12):
set_led(led5,bank1)
time.sleep(1)
if ( count == 13):
set_led(led4,bank1)
time.sleep(1)
if ( count == 14):
set_led(led3,bank1)
time.sleep(1)
if ( count == 15):
set_led(led2,bank1)
time.sleep(1)
if ( count == 16):
set_led(led1,bank1)
time.sleep(1)
if ( count == 17): #end 'game over' sequence
set_led(led2,bank1)
time.sleep(0.3)
set_led(led3,bank1)
time.sleep(0.3)
set_led(led4,bank1)
time.sleep(0.3)
set_led(led5,bank1)
time.sleep(0.3)
set_led(led6,bank1)
time.sleep(0.3)
set_led(led7,bank1)
time.sleep(0.3)
set_led(led8,bank1)
time.sleep(0.3)
set_led(led0,bank1)
set_led(led8,bank0)
time.sleep(0.3)
set_led(led7,bank0)
time.sleep(0.3)
set_led(led6,bank0)
time.sleep(0.3)
set_led(led5,bank0)
time.sleep(0.3)
set_led(led4,bank0)
time.sleep(0.3)
set_led(led3,bank0)
time.sleep(0.3)
set_led(led2,bank0)
time.sleep(0.3)
set_led(led1,bank0)
time.sleep(0.3)
set_led(led0,bank0)
time.sleep(0.3)
if __name__ == "__main__":
main()
The End Result
Considerations
You might be thinking “Why doesn’t the Average Man keep the previous LEDs lit after each goal”…
Good question, and one I did look in to.
From the Google research I did, it seems that this chip has a limitation on the amount of current it can handle, and powering 16 LEDs at once would most likely cause something to go ‘pop’. I’m not entirely educated on that part yet, but I’m looking into transistors to make use of an external power supply for the LEDs.
So if you decide to take this and modify it for your own use, keep this in mind.
Part 3 Complete!
Whilst I will be continuing this project over time, this series of posts will end here as you now have the knowledge and starter code to help you on your way with whatever you will build on the Slice of Pi/O.
I’ll post an update later in the year once I complete the project. I would love to hear from anyone who has used this to help them, to see what projects people are using this for.
Here’s a little hint of what one of my next blogs might cover….

2 x MCP23017 chips…watch this space…
If you have any questions, just ask.
Average Man
Thanks for the info on the pinouts. Very helpfull. I have a suggestion that may help you display your 40 goals.
How about 9 green LEDs to represent units and 7 red to represent tens. Then you can display upto 79 goals. Or use 3 red to display upto 39 and have 4 pins spare for something else.