Skip to main content

i2c

Communicate with I2C devices like sensors, displays, and expanders using the two-wire serial interface.

Overview

The i2c node enables communication with I2C (Inter-Integrated Circuit) devices. I2C is a multi-device bus protocol using just two wires (SDA and SCL) to connect multiple sensors, displays, EEPROM, and other peripherals to your Raspberry Pi.

127
Max Devices
2
Wires (SDA+SCL)
400kHz
Fast Mode
3.3V
Logic Level

Raspberry Pi I2C Pins

I2C Bus 1 (Default)

SDA (Data) GPIO 2 (Pin 3)
SCL (Clock) GPIO 3 (Pin 5)

Enable I2C

sudo raspi-config
# Interface Options → I2C → Enable

# Or add to /boot/config.txt:
dtparam=i2c_arm=on

Properties

Property Type Required Default Description
address number Yes - Device I2C address (0x00-0x7F)
bus number No 1 I2C bus number
command string No "read" "read", "write", "scan"
register number No - Register address to read/write
count number No 1 Number of bytes to read

Inputs

Read Operation
{
  "payload": {
    "command": "read",
    "register": 0x00,
    "count": 2
  }
}
Write Operation
{
  "payload": {
    "command": "write",
    "register": 0x01,
    "data": [0x80, 0x03]
  }
}

Outputs

Read Response
{
  "payload": {
    "data": [0x1A, 0x3C],
    "buffer": "<Buffer 1a 3c>"
  },
  "address": 104,
  "register": 0
}
Scan Response
{
  "payload": [35, 60, 104],
  "devices": ["0x23", "0x3C", "0x68"]
}

Common I2C Devices

Device Address Type Notes
BME280 0x76 / 0x77 Temp/Humidity/Pressure SDO pin selects address
SSD1306 0x3C / 0x3D OLED Display 128x64 / 128x32 pixels
MPU6050 0x68 / 0x69 Accelerometer/Gyroscope AD0 pin selects address
BH1750 0x23 / 0x5C Light Sensor ADDR pin selects address
PCF8574 0x20-0x27 GPIO Expander 8 extra I/O pins
ADS1115 0x48-0x4B ADC 16-bit, 4 channels

Example: Scan I2C Bus

Find all connected I2C devices and their addresses.

[
  {
    "id": "scan-trigger",
    "type": "inject",
    "payload": "{ "command": "scan" }",
    "payloadType": "json"
  },
  {
    "id": "i2c-scan",
    "type": "i2c",
    "bus": 1,
    "address": ""
  },
  {
    "id": "display",
    "type": "debug",
    "name": "I2C Devices"
  }
]

Tip: Run i2cdetect -y 1 in terminal to verify I2C devices.

Troubleshooting

No devices detected
  • Enable I2C: sudo raspi-config → Interface Options → I2C
  • Check wiring: SDA to SDA, SCL to SCL
  • Verify power: Most devices need 3.3V
  • Install tools: sudo apt install i2c-tools
Permission denied errors
sudo usermod -a -G i2c $USER
sudo reboot
Intermittent communication failures
  • Add 4.7kΩ pull-up resistors on SDA and SCL
  • Keep wires short (<30cm for best reliability)
  • Use shielded cable for noisy environments
  • Reduce I2C speed if using long wires

Related Nodes