A little curiosity. A whole lot of making.Robotics, CNC & connected ideas
robodatech.
Arduino sample library

I2C Scan 35

Find I2C device addresses for sensors, displays, and expanders.

Open in compiler →
/*
  Roboda verified Arduino sample 0859
  Feature: I2C Scan
  Generated for online build, classroom practice, and hardware upload testing.
*/

#include <Wire.h>

void setup() {
  Wire.begin();
  Serial.begin(9600);
}

void loop() {
  for (byte address = 1; address < 127; address++) {
    Wire.beginTransmission(address);
    if (Wire.endTransmission() == 0) {
      Serial.print("I2C device at 0x");
      Serial.println(address, HEX);
    }
  }
  delay(3000);
}

How it works

Discover I2C addresses on the board SDA/SCL bus.

  1. Wire SDA and SCL using the board-specific map.
  2. Share GND between all I2C devices.
  3. Run the scanner and open Serial Monitor.
  4. Use the printed address in later sensor/display sketches.

Connections

PinConnect toNote
SDA / SCLI2C sensor, OLED, RTC, or expanderUse the board-specific SDA/SCL pins from the mapping table.

Good ideas start here.

Robotics lessons, build notes and useful updates. Subscribe by entering your email.