Our crew is replaceable. Your package isn't.

I2C

Thu 21 April 2016

I2C (Inter-Integrated Circuit), pronounced I-squared-C, is a multi-master, multi-slave, single-ended, serial computer bus invented by Philips Semiconductor (now NXP Semiconductors). It is typically used for attaching lower-speed peripheral ICs to processors and microcontrollers in short-distance, intra-board communication. Alternatively I2C is spelled I2C (pronounced I-two-C) or IIC (pronounced I-I-C).

Addressing is based of a 7-bit addressing system, where each data packet looks like:

If you have everything setup correctly, you should be able to see what is on your i2c bus by typing:

[kevin@raspberrypi ~]$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Note that something is attached to the 0x20 address.

Then a simple program might look like:

import Adafruit_GPIO as GPIO

io = GPIO.MCP23017(0x20)

for i in range(0,16):
    io.setup(i,GPIO.OUT) # set all pins to output
    pins = {1:1,3:0,5:1} # set pins 1&5 True and pin 3 False
    io.output_pins(pins)

References

on the top