Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Extend your GPIOs on Raspberry Pi with MCP23017 & MCP23008.

Extend your GPIOs on Raspberry Pi with MCP23017 & MCP23008.

Ratings: (0)|Views: 503|Likes:
Published by S Bera
It's very easy to extend the GPIOs capability on Raspberry Pi using MCP23017 & MCP23008 on I2C and running a 4*16 LCD panel on MCP23008
It's very easy to extend the GPIOs capability on Raspberry Pi using MCP23017 & MCP23008 on I2C and running a 4*16 LCD panel on MCP23008

More info:

Published by: S Bera on Sep 14, 2013
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





I2C – the extension of GPIOs
The Raspberry Pi has 26 ports out of which a handful GPIOs left to dogreat works. But to further impress your nephew with your fancRaspberry Pi here's how you can connect additional micro controllers toextend the GPIOs capability by any numbers !Even the clumsy LCD panel which has eaten away half a dozen of GPIOscan straight away be shifted to the additional micro controllers leavingthe Raspberry Pi with only 2 wires to control all these countless GPIOsprecisely yet very economically.The new mantra is I2C , just two wires - SDA and SCL (Pin-3 & Pin-5) will control all these additional devices. The small help that I've borrowed from Adfruit.com is in the form of a GPL python script tomanage these extended GPIOs.
System set up:
To use I2C on Raspi you need to enable a few things in Wheezy Raspbian as by default it is not enabled. This is a fairly easy process. First you need to edit the modules file using :$ sudo nano /etc/modules#and add the following two linesi2c-bcm2708i2c-dev Save the file and exit nano and open the next file$ sudo nano /etc/modprobe.d/raspi-blacklist.conf Put a # symbol at the beginning of the two lines so that they look likethis:#blacklist spi-bcm2708#blacklist i2c-bcm2708save and exit nano.Now install the necessary softwares to manipulate the I2C bus.$ sudo apt-get update #this updates your Raspberry Pi$ sudo apt-get install python-smbus i2c-tools #instals smbus & i2c tools
So far so good. Relax now ! As the next step is going to be little messy but berest assured that soon you will have enough knowledge to expand your Raspi with as high as 8 16 64 or whatever you like no of GPIOs and thencontrolling these extended GPIOs by only two wires from your Raspi !Once the softwares are installed reboot your Raspi so that these effects takeplace permanently.$ sudo rebootHowever, my nephew likes to use the Raspi like a TV and he simply switchesit off and then switches on and it works glitch free !
Two package MCP23008 ( 18 pins DIL ) and MCP23017 (28pin DIL) is taken for our exercise. Together they comes for around Rs:200from kit's n spares. Connect them as shown in the drawing:
Once you have connected the hardware double check the wiring.Make sure the 5 volt is going to the correct pins else it will heat up themicroprocessor and damage it eventually. Also ensure the reset pins (6 or 18 )are connected with the +5V rail. Open a shell prompt from a remoteconnection or from the local and issue the following command.$ sudo i2cdetect -y 0or$ sudo i2cdetect -y 1If your Raspi is version 1 then use 0 else 1 and watch for the following screenappears at the terminal prompt.
Congratulations ! Pat your back , your cute Raspi has successfully detected thehardware at 0x20 address. Now it's only a matter of time to issue commandsto control it. Theaddress is 0×20 because all
the three address pins (A0,A1,A2) are set low. If you set only A0 high (connected to +5 volt) the address wouldhave become 0×21.This signifies one fundamental issue with the I2C communications - You canconnect any number of devices on the I2C bus (Pin-3 & Pin-5) but all devicesshould have a unique address. So how you set A0, A1 and A2 is going to definedifferent address for the different devices. You may try that feats here to gainmore confidences now.
There is a command line testing for I2C on Raspi. Connect a few LEDs on the pins as shown in Fig-1 and issue the following commands.$ sudo i2cset 0x20 0x00 0x00 #this will switch on the LED on A0$ sudo i2cset 0x20 0x00 0x01 #this will switch off the LED on A0The command line program is easy ,provided you understand the binary andhex conversion of all the numbers, bits and not talk of the impressivedatasheet that comes with each micro processors. However, Adafruit.com hasan excellent library by which we can manipulate these GPIOs in a far morelucid way.Open a terminal window and write the following python scripts. However, allthe program files including the Adafruit library is available at this location.Download it and then expand them all in a fixed location.https://docs.google.com/file/d/0B3E3LcSKoM-6YUZZbndXYVR1VTA/edit?usp=sharing$sudo nano mcp23017.py 
 from Adafruit_MCP230xx import * import timemcp = Adafruit_MCP230XX(address = 0x20, num_gpios = 16) # for MCP23017 #mcp = Adafruit_MCP230XX(address = 0x20, num_gpios = 8) # for MCP23008# Set pins 0, 1 and 2,3,15 to output (you can set all pins 0..15 this way)mcp.config(0, mcp.OUTPUT)

Activity (2)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->