🛠 Scanner le bus I²C de l'UNO (A4/A5)
Objectives
Master the I²C bus standardized by the R3 connectors: SDA on A4, SCL on A5, and the dedicated SDA/SCL pins added next to AREF on the UNO R3 (along with IOREF and 3.3 V — this addition defined the shield standard). You will write an address scanner, an essential diagnostic tool before writing any sensor driver.
Hardware
- 1 Arduino UNO R3 + USB-B cable
- 1 or more I²C modules (SSD1306 OLED address 0x3C, sensors, PCF8574...)
- Wires: SDA→A4 (or the SDA pin near AREF), SCL→A5, VCC 5 V or 3.3 V (note: the UNO's 3.3 V is limited to 50 mA), GND
- Serious modules provide their own pull-ups; without them, the bus does not work (I²C is open-drain).
Complete Code
// Scanner I²C : interroge les adresses 8..127 et liste les réponses.
#include <Wire.h>
void setup {
Wire.begin; // maître, broches A4/A5 par défaut sur UNO
Serial.begin(115200);
Serial.println(F("Scanneur I2C — bus A4(SDA)/A5(SCL)"));
}
void loop {
uint8_t trouves = 0;
for (uint8_t addr = 8; addr <= 127; addr++) {
Wire.beginTransmission(addr);
uint8_t err = Wire.endTransmission;
if (err == 0) { // 0 = ACK reçu, périphérique présent
Serial.print(F("Périphérique à l'adresse 0x"));
Serial.println(addr, HEX);
trouves++;
} else if (err == 4) {
// Erreur sur la phase d'écriture : on ignore sans bloquer.
}
}
if (trouves == 0) Serial.println(F("Aucun périphérique — vérifiez SDA/SCL et les pull-up"));
Serial.println(F("--- nouvelle passe (Ctrl+Shift+M pour arrêter le moniteur) ---"));
delay(5000);
}
Expected Verification
Each connected module appears with its address (OLED: 0x3C, PCF8574: 0x20/0x27, etc.). Diagnostic test: disconnect SCL — the scan finds nothing anymore; swap SDA/SCL on a shield — nothing either. This is your bus multimeter.
Common Errors
- Forgetting the pull-ups (4.7–10 kΩ to 3.3 V or 5 V): floating lines, random or missing ACKs. Many modules include them (JP1 jumper on some), others do not.
- Powering a 3.3 V peripheral with 5 V: the ATmega is at 5 V, a 3.3 V peripheral back-powering the bus can draw more than the 50 mA limit of the 3.3 V pin.
- Confusing 7-bit and 8-bit addresses: datasheets sometimes give the write address (0x78) where Wire expects 0x3C.
- Two peripherals on the same bus with the same address: the scan sees only one, the second is silent — change the address (A0 pins on many modules).
- Connecting I²C to pins other than A4/A5 (or the dedicated R3 pins): Wire on the UNO is hardwired to port C of the ATmega328P.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-poussoir.inoArduinopwm-fade.inoArduinocapteur-lumiere-ldr.inoArduinoservo-balayage.inoArduinoruban-neopixel.inoArduino