🛠 Scanner le bus I²C de l'UNO (A4/A5)

Arduino UNO R3 · avance · Schéma : IMG-uno-r3-avance-2-scanner-bus-i2c.svg — UNO R3 avec un module I²C (afficheur OLED) sur le bus A4 (SDA) / A5 (SCL), pull-up R1/R2 notées, broches SDA/SCL près de AREF mises en évidence.

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials