Skip to content

I²C Documentation

Introduction

Inter-Integrated Circuit (I²C) is a synchronous, multi-master, multi-slave, packet-switched serial communication protocol. It allows multiple devices to communicate over just two wires: SDA (data) and SCL (clock).

It is commonly used for connecting sensors, EEPROMs, and other peripherals to microcontrollers.

How It Works

  • Two-wire bus: SDA carries the data, SCL carries the clock.
  • Addressed communication: Each device has a unique 7- or 10-bit address.
  • Master/slave model: The master generates the clock and initiates communication; slaves respond.
  • Data transfer: Each byte is followed by an acknowledgment (ACK) bit.

Diagram – Basic I²C Connection

TODO

Use Cases

  • Reading sensor data (IMUs, temperature, pressure)
  • Writing configuration to peripherals (EEPROM, DACs)
  • Communication between microcontroller boards (e.g., Arduino ↔ Pixhawk)

Common Pitfalls / Gotchas

  • Pull-up resistors required: Typically 4.7kΩ or 10kΩ on SDA and SCL.
  • Bus length: Keep wires short to avoid signal degradation.
  • Address conflicts: Two devices cannot share the same address.
  • Clock stretching: Some devices may delay the clock; ensure your master supports it.

Tools to Debug

  • Logic analyzer to decode SDA/SCL signals.
  • Oscilloscope for checking waveform integrity.
  • Arduino serial monitor or debug prints to verify data.

References

Pixhawk User Guide: Click me

Codes inspired from the Internet

Onboarding Tutorial (ESP32 or STM32)

Goal: Read a simple sensor (e.g., temperature or rangefinder) via I²C and print the data over serial.

Materials

  • ESP32 or STM32 development board
  • I²C sensor (e.g., TFMini Rangefinder, MPU6050, BMP280)
  • Breadboard + jumper wires
  • Pull-up resistors (4.7kΩ or 10kΩ) if required

Steps

  1. Connect SDA → SDA and SCL → SCL between the board and sensor.
  2. Add pull-up resistors if your sensor board does not include them.
  3. Flash the ESP32/STM32 with an example I²C read program.
  4. Open the serial monitor to verify that data is being received correctly.
// Example Arduino-style pseudo-code
#include <Wire.h>

void setup() {
  Wire.begin(); // join I2C bus as master
  Serial.begin(115200);
}

void loop() {
  Wire.beginTransmission(0x68); // device address
  Wire.write(0x00); // register
  Wire.endTransmission();

  Wire.requestFrom(0x68, 2); // read 2 bytes
  while (Wire.available()) {
    int data = Wire.read();
    Serial.println(data);
  }

  delay(500);
}

Mini Challenges

  • Connect a second I²C sensor and read both simultaneously.
  • Change the I²C address of a sensor (if configurable) and update your code.
  • Use the I²C bus to control a small actuator or LED array.