I²C - KeirRice/PolarTable GitHub Wiki
I²C
I²C goes by many names and is pronounced "I squared C"
- Inter-Integrated Circuit
- Inter-IC
- IIC
- I2C
- TWI
- Two-wire interface
Most of the time I just use I2C because it's easier to type.
About
Its a communications protocol for integrated circuit chips to send messages between each other. It only uses two wires and is addressable, so you can have many devices sharing a common bus.
The wires are labelled SDA (Serial Data) and SCL (Serial Clock).
Arduino
Arduino has support for I2C on dedicated pins on the newer models. The older models have it on pins A4 (SDA) and A5 (SCL).
The Arduino I2C header runs at 5 volts
Libraries
Once you are connected up, take a look at the Wire
library and examples.
Also, check out this scanner by Rob Tillaart
Raspberry Pi
The Raspberry Pi has I2C support on its GPIO header. Starting from the pin closest to the P1 end, the first pin is 3.3V out, then SDA, then SCL.
The Raspberry Pi I2C header runs at 3.3 volts
You have to specifically enable the I2C bus in the Raspberry Pi configuration and install a bunch of tools to get it up and running. There are heaps of tutorials around to cover this part.
Once you are wired up and configured run i2cdetect -y 1
to scan the bus for devices.
Python
The goto python library for this seems to be smbus
but it's pretty low level. The is also a higher level pure python version called smbus2
, though I had trouble installing it. (Try running an upgrade on setuptools before you install it.)
Voltage
All devices on the bus need to be running at the same logic voltage level. If you connect a 5V device to a 3.3V device you will burn it. To avoid this you can install a bi-directional logic level converter between the high and low sides.