Here we define some terms related to I2C.
- SDA - Serial DAta line. This is the line the 1's and 0's go down to communicate data.
- SCL - Serial CLock line. This is a square wave clock signal that is used to coordinate when to read the SDA line.
- VCC - The supply voltage for power, typically 3.3V or 5V.
- GND - Ground
- Address - Each I2C device has a specific numerical address.
- Pull Up Resistors - Resistors required between SCL and VCC as well as between SDA and VCC.
Here is a simple diagram showing the general arrangement of an I2C bus with several devices attached.
There are two main items that are important here:
- Pull up resistors between SCL/SDA and VCC
- Unique addresses for each device
Most I2C issues relate to something wrong with these two factors.
Only one set of pull up resistors are needed for the entire I2C bus. A stand alone device, like an iPhone, will have taken care of this internally. In that case, the microcontroller and all the I2C devices are self contained within the iPhone itself. But for maker applications, the microcontroller and I2C devices are typically provided as separate items. In that case, where are the pull up resistors? It depends, but in general:
- Adafruit I2C breakouts include pull up resistors.
- Mix mode breakouts may or may not include pull up resistors.
- Raspberry Pi's include pull up resistors on their I2C pins.
It's OK to have more than one pull up resistor. That would happen if you chained more than one Adafruit I2C breakout together, since each includes pull ups. The resistors will act in parallel and thus reduce the overall pull up resistance. But I2C can work with a range of pull up values, so this is generally not an issue.
Each device on the I2C bus needs a unique address. How do you determine what the address is for any given breakout? The datasheet is the main source, but it can be a bit buried. Sometimes the address will be mentioned on the product page or in the associated learn guide. Some breakouts will print the address on the PCB itself. The source code for the sensor's library is another option, but again, can be a bit buried. That's why there's this convenient list of nothing but I2C addresses:
But it requires manually updating, so may not be 100% complete.
But also, don't worry - you don't need to know the address to perform an I2C scan. It just helps to know what to expect from the scan results.
By convention, I2C addresses are reported in hexadecimal notation. That is what the leading
0x indicates. We won't discuss hex notation here, just keep in mind that when you see
0x77, it is not the same as