I2C Scanner example sketch Scans the I2C bus on the SDA/SCL header pins every 5 s and prints every address from 0x08 to 0x77 that answers.
Each address is probed with PhyduinoWire::beginTransmission() and PhyduinoWire::endTransmission() with no data; 0 means a device answered.
- Wiring
- One or more I2C devices on SDA, SCL, 3.3 V and GND.
- Output
- Serial Monitor at 115200 baud, for example:
Device at 0x3C
1 device(s) found.
- Note
- The board has no I2C pull-up resistors, only the RP2040's weak internal ones. Add 4.7 kOhm resistors to 3.3 V for long wires or 400 kHz.
}
int found = 0;
for (uint8_t address = 0x08; address < 0x78; address++) {
Wire.beginTransmission(address);
if (
Wire.endTransmission() == 0) {
found++;
}
}
Serial.println(
" device(s) found.");
}
SerialUSBClass Serial
USB serial port, the one the Serial Monitor uses.
Arduino Wire (I2C) on the SDA/SCL header pins.
PhyduinoWire Wire
I2C on the header SDA / SCL pins.
void loop(void)
Written by the sketch: runs over and over after setup(), on core 0.
void setup(void)
Written by the sketch: runs once after reset, on core 0.
void delay(unsigned long)
Waits a number of milliseconds.