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)