This is an old revision of the document!

IP Selctor with the MCP23008 and MCP23017

Preparing the RPi for I2C:
Open the file:

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

Comment out:

#blacklist i2c-bcm2708

Open the file:

$ sudo nano /etc/modules



Load modules:

$ sudo modprobe i2c_bcm2708
$ sudo modprobe i2c-dev

Check the i2c modules:

$ lsmod

Module                  Size  Used by
i2c_dev                 3792  0 
i2c_bcm2708             3408  0 

Install some programs:

$ sudo apt-get update
$ sudo apt-get install i2c-tools
$ sudo apt-get install python-smbus

Check the address:

$ sudo i2cdetect -y 1
$ sudo i2cdump -y 1 0x20

Download Adafruit libraries:

$ wget


$ unzip


# Set IP Address with MCP23008
from Adafruit_MCP230xx import *
# Use busnum = 0 for older Raspberry Pi's (256MB)
# Use busnum = 1 for new Raspberry Pi's (512MB with mounting holes)
mcp = Adafruit_MCP230XX(busnum = 1, address = 0x20, num_gpios = 8)
# Set pins to input with the pullup resistor enabled
for i in range(0,8):
  mcp.pullup(i, 1)
# Read pins and display the results
#bitshift output, third bit is the output
for i in range(0,8):
  print "%d: %x" % (i, mcp.input(i) >> i)
  meineIP = meineIP +  mcp.input(i)
print meineIP