Skip to main content

I²C Bus

I²C (Inter-Integrated Circuit, pronounced "I-squared-C" or "I-two-C") is the other universal peripheral bus. Where SPI is fast and one-slave-at-a-time, I²C is slower but lets many chips share just two wires while each gets its own address. It's the standard interface for OLED screens (SSD1306, SH1106), IMUs (ICM-20600, LSM6DS), magnetometers (LIS3MDL, MLX90393), ADCs (ADS1115), magnetic-rotary sensors (AS5600), battery chargers, RTCs and a long etcetera.

Wiring and addressing​

Only two signals (plus power and ground):

SignalRole
SDABidirectional data line.
SCLClock driven by the master.

Both lines are open-drain — every device on the bus pulls the line low to signal, and an external pull-up resistor (typically 2.2–10 kΩ) brings it back high. Most breakout boards already include the pull-ups; if you assemble a bus from raw chips, add them once on the bus, not per device.

Each device answers to a 7-bit address. Many chips have one or two pins that select between two or four possible addresses (so you can put two of the same sensor on one bus). The full address space is therefore tight — collisions across two devices that hard-code the same address need an address-changing strap, separate I²C bus, or a multiplexer.

How NodeBlue exposes I²C​

Unlike SPI there is no master/slave NodeBlue module for I²C — the bus is configured inside each I²C-using module. Every I²C peripheral exposes the same two parameters:

ParameterDescription
I²C PortWhich hardware I²C bus the chip is on (Wire, Wire1, Wire2 — depending on the board).
I²C FrequencyBus clock in Hz: 100 kHz (standard), 400 kHz (fast, the safe default), 1 MHz (fast-mode-plus — supported by many modern devices but not all).

The frequency the slowest device on a bus tolerates is the maximum the bus can run at; mixing a 100 kHz-only chip with a 1 MHz-capable one means the whole bus drops to 100 kHz.

Example: a magnetic-angle sensor​

The nAS5600 module (a 12-bit hall-effect rotary sensor) wants:

  • I²C Port — usually the default Wire.
  • I²C Frequency — 400 kHz works fine.
  • ... plus its application-level parameters (range, dead-zone, filter…).

Nothing else: you don't add a wrapper "nI2CMaster" — the AS5600 module is itself the I²C participant.

Discovering devices: nI2CScan​

When a device isn't responding the first useful question is "is it actually on the bus at all?" NodeBlue ships a small diagnostic module — nI2CScan — that sweeps every address on the chosen bus and reports which ones reply. Wire its Start input to a Button (or to a Software Timer set to one-shot), watch its Msg output in the serial console.

ParameterDescription
I²C PortSame Wire / Wire1 selection as any I²C device.
I²C FrequencySpeed to scan at. Drop to 100 kHz when a device is misbehaving — sometimes bus speed is the culprit.

The scanner is the fastest way to diagnose three classes of problem:

Scanner resultLikely cause
Nothing answersWiring (SDA/SCL swapped, no power, no ground), missing pull-ups, wrong I²C Port.
One device replies but at an unexpected addressAddress-select strap is the other way round — check the chip's address-selection pins.
Two devices share an addressMove one to a different I²C bus, or change one's address-select strap.

Pull-ups, levels and a few gotchas​

  • Pull-up resistors are mandatory. Without them the lines never go high and nothing works. Most breakout boards include them already.
  • Total bus capacitance sets a practical wire-length limit: roughly 30 cm at 100 kHz, 10 cm at 400 kHz, less at higher speeds. Stacking many breakouts on a single bus is fine; running a long ribbon to a remote sensor is not.
  • Voltage mixing. Most modern boards are 3.3 V; some I²C peripherals are 5 V-only. Use a bidirectional level shifter (e.g. a small board with two MOSFETs) — the open-drain nature of I²C makes this much simpler than for SPI.
  • One sensor module per slave instance. If you have two identical sensors on the same bus at different addresses, you'd add two modules of that type, one per address (when the module exposes an address-selection parameter), or use a separate Wire / Wire1 bus for each.

With SPI and I²C covered, you have the buses every sensor and display module uses internally. Next, the sensors themselves: IMUs, temperature, magnetic angle, load cells, and friends.