So, in this project I used the MCP23017 (as many of you know) it’s a great little chip that can add a lot of functionality to your Raspberry Pi. I wrote this python module for talking to the chip, and if anybody wants to use it, feel free.

First, create an instance of the class, and then it has get_bit, set_bit, get_port, set_port, and so on. It needs the i2c drivers, and the python-smubus modules.

import mcp23017chip = mcp23017.mcp23017_IO(0, 0x20, 0x00, 0xFF) #I2c Buss, chip address, Port A Direction, port B direction

print chip.get_port(chip.PortA)
print chip.get_bit(chip.PortA, 1) #It starts counting at 0, so that’s the 2nd bit.

chip.set_bit(chip.PortB, 2, True)
chip.set_port(chip.PortB, 0xFF)

If somebody can use it, awesome.

Leave a Reply

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