Raspberry Pi with the IO Expander

A month ago my Raspberry Pi arrived and since then I have been wanting to control external devices with it. Like any other newbie, I was eager to do something with it as soon as possible and spent hours and hours reading and trying out sample codes from experienced Pi users from the internet. After all the countless hours of reading forums and looking at step by step tutorials I am still not confident to directly connect LEDs and buttons to my Pi as I am afraid to fry it up to smokes.
Raspberry Pi with the IO Expander
Until I read about the MCP23017 IO Expander from Nathan Chantrell and SKPANG, which from my readings will protect my Pi and give me peace of mind while experimenting with it, so I bought one (Slice of PI/O). Unfortunately, most examples I found are for output only and not so many for input (I guess I just got lazy).  With quite a lot of trial and error, I finally figured out how to accept external input using Python with Smbus (i2c).  This is the reason why I made this blog,  I want to share what I have learned to those like me who has zero knowledge of the Linux operating system, the Python programming language and even in using the i2c to interface the Pi with other devices.  I hope this will help minimize the number of hours that will be spent looking for a basic example of programming the GPIO (input and output) of the Raspberry Pi with the MCP23017 IO expander.
Requirements
Hardware:
– Raspberry Pi version 2
– MCP23017 IO Expander add-on
– breadboard
– 9 pcs LEDs
– 9 pcs 470ohm resistors
– 5 pcs micro switches
– 5 pcs 10Kohm resistors
– connecting wires or ribbon cable
(please see setup photo)
Raspberry Pi with the IO Expander
Software:
– Raspbian Wheezy (latest version) from raspberrypi.org
– Python-pygame (sudo apt-get install python-pygame)
– MCP23017 IO Expander driver (i2ctools, smbus and etc). (How to?)

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top