This is an old revision of the document!
Table of Contents
What's this I²C Thing?
I²C, prounounced I-Squared-C, is short for the “Inter-Integrated-Circuit bus”. It was invented in 1982 by Philips, although the patent is now expired.
More than you'll ever need to know is on the I²C Wikipedia page.
Sometimes it is also known as the “two-wire” bus, which is also descriptive, because it has two signal wires. Those two wires are called “SCL” and “SDA, for “serial clock” and “serial data.”
Some basic facts about I²C:
- It was originally intended to stay on the same PC board, but works over a few feet of cable
- It runs at 100Kbps or 400Kbps
- Devices only pull SDA and SCL low
- Pullup resistors are required on SDA and SCL, but most boards have the installed already.
- Each “slave” device has an address, and each slave on the bus must have a unique address.
- Addresses are 7 bits long, therefore there are only 128 possible addresses.
- Some devices have pins that can chose from several addresses. Others are limited to one per bus because the address can't be changed.
I²C Protocol
The I²C standard defines the basic signalling on the two wires for sending data back and forth to the device. The primitives available are:
- Claim the bus and start a transaction: pull SDA low while leaving SCL high
- Stop and release the bus: release SDA to go high, while leaving SCL high
- Send a byte (and get an acknowlegement)
- Read a byte
These get combined in various ways depending on the device. Reading the datasheet is a must while writing software for an I2C device.
I²C in FRC
Since the introduction of the RoboRio, there has been an easy way to use I²C for FIRST robots. The connector on the Rio looks like this. The connector has four pins. In addition to SCL and SDA, there is a pin for 3.3v power, and a pin for the common ground for signal and power. This means that no external power source is needed or recommended for attaching an I2C device.
Around 2018-2019 we started to see packaged color and distance sensors from Rev Robotics and others.
For 2020 Rev introduced a cable to make using one of them easy with the RoboRio.
Software for I²C devices: start with Arduino
Nearly every I²C device has unique requirements from the software to communicate with it. Fortunately, the success of the Arduino family of microcontroller boards means that almost every interesting I²C device has example code ready to use with the arduino board and software. This is often the best place to find such examples.
I²C in other maker/hobby wiring
QWIIC
Sparkfun has many sensor boards and controllers that use a tiny 4-pin connector they call QWIIC. It carries the SDA and SCL signals, ground, and +3.3v power.
(picture)
Adafruit wants to call the same thing STEMMA-QT.
