Controlling LEDs With The Ciseco Slice of Pi/O - Part

When I'm not playing with my Raspberry Pi, I like to play roller/ice hockey with my now-disbanded team.

One thing we struggle to keep track of is the score, and this week I decided the Raspberry Pi would be the solution. In my head this was something as simple as a wooden board, with a couple of heavy duty buttons to register new goals, and some way of displaying the score.

Being new to the Pi and Python, I decided that this needed to be something primitive and simple. Any form of complex LCD screen/LED matrix to show 'actual numbers' for the score was out of the question this early in my Raspberry career.

I decided that I would create a simple grid of scores, with an LED lighting up the current score for each team.

Considering that our goalies have been known to let in up to 20 pucks in a game, I needed around 40 GPIO pins to drive LEDs for each score.
That wasn't going to happen with a standard Raspberry Pi with just 8 general GPIO pins. You can make other pins act as GPIO, and you can also add a P5 header (I'll do a separate blog on that), but even then I still wouldn't have enough.

After some research it looked like the Ciseco 'Slice of Pi/O board' could solve my problem. The board is a variation of their 'Slice of Pi' board, and comes with an MCP23017 chip as part of the self-solder kit:

The Ciseco Slice of PI/O


The MCP23017 is...well...it's a chip - I told you earlier I'm new to this. One thing I do know is that it gives you 16 additional inputs/outputs via the I2C - that sounded like a step in the right direction for my project (40...16...close enough...), so as always I jumped right in and ordered one. (You'll probably want to know more about the chip - go HERE if you do)

Building the Slice of Pi/O


The Slice of Pi/O comes as a kit so you will need basic soldering skills here.
The build instructions on Ciseco's website are very good so I won't cover that part. It is however worth mentioning that for my project example, following the Ciseco guide, I used the power jumper on the 3.3V line and soldered the pads for address 0x20 as shown in the image below, taken from the guide:

Setting the address to 0x20

System configuration


OK, board soldered - now to make sure the Pi has the necessary 'brains' to make it work, as this isn't enabled as standard. Using Google I managed to find excellent instructions for this part (Thanks raspberrypi-spy) . You need to do the following in Terminal:

Edit the modules file


Type this in Terminal and press 'enter':

sudo nano /etc/modules


Now just add these lines:
i2c-bcm2708

i2c-dev

To save those new lines, use Ctrl+X, then hit Y, then press Enter. Sorted.

Edit the modules blacklist file

Type this in Terminal and press 'enter':

sudo nano /etc/modprobe.d/raspi-blacklist.conf


There should be 2 lines of text in this file already, and we need to put a # in front of them to 'turn them off' as such (to stop the Pi from blacklisting these). You should end up with them looking like this:

#blacklist spi-bcm2708

#blacklist i2c-bcm2708

To save those line changes, use Ctrl+X, then hit Y, then press Enter again. Happy days.

Install I2C utilities


Final bit of code to mess around with now - nearly there. Type this in Terminal and press 'enter':

sudo apt-get install python-smbus i2c-tools

Let it do its thing - wait for Terminal to finish. Once that's complete, reboot your Pi using:

sudo reboot

Test It!


It's not that I'm lacking confidence or anything...but it's good practice to do a little test now to make sure your Pi has the I2C utilities working and recognises the MCP23017 chip connected to your Slice of Pi/O.

It's as easy as typing a line of code:

If you're a bit old school have a Rev 1 Raspberry, type this in Terminal:

sudo i2cdetect -y 0

If you're lucky enough to have the more recent Rev2 board, pop this in Terminal instead:

sudo i2cdetect -y 1

If you soldered the same address pad/pin as me (0x20), you should get this:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

(I will cover the use of other addresses in a future blog when I start daisy-chaining these chips)

Part 1 complete!


That's the Pi and Slice of Pi/O set up and ready, minus some physical testing with an LED. If you've managed to get it all working, give yourselves a tap on the back and crack open a beer - you've achieved something today!

I'll cover some physical (LED) testing in Part 2 as well as going through a simple Python script to show the MCP23017 outputs in action.

Thanks to raspberrypi-spy.co.uk for their excellent tutorial - the best on the web for this board!

Continue reading here: Raspberry Pi Touchscreen Display Case Options

Was this article helpful?

+1 0