🛠 Scanner les deux bus I2C de la Due (Wire sur 20/21, Wire1 sur 70/71)

Arduino Due · intermediaire · Schéma : IMG-due-intermediaire-2-scanner-deux-bus-i2c.svg — Arduino Due avec deux bus I2C distincts : Wire/TWI1 sur les broches 20 (SDA) et 21 (SCL) près de AREF, Wire1/TWI0 sur le connecteur 4 broches 70/71 près du RESET, résistances de pull-up 4,7 kΩ annotées.

Objectives

The Due has TWO hardware I2C controllers, with a numbering pitfall documented in the core: the Wire object corresponds to the TWI1 controller (pins 20 = SDA, 21 = SCL, near AREF) while Wire1 corresponds to TWI0 (pins 70/71, small 4-pin connector near RESET). This tutorial writes a scanner that sweeps both buses and reports the 7-bit addresses that respond — the basis of all I2C sensor troubleshooting.

Hardware

Complete code

// Scanner Wire (TWI1: 20/21) et Wire1 (TWI0: 70/71)
#include <Wire.h>

uint8_t scanner(TwoWire &w, const char *nom) {
  uint8_t trouves = 0;
  SerialUSB.print(nom); SerialUSB.print(" : ");
  for (uint8_t a = 1; a < 127; a++) {
    w.beginTransmission(a);
    if (w.endTransmission == 0) {       // 0 = ACK reçu
      SerialUSB.print("0x"); SerialUSB.print(a, HEX); SerialUSB.print(" ");
      trouves++;
    }
  }
  if (!trouves) SerialUSB.print("(aucun) ");
  SerialUSB.println;
  return trouves;
}

void setup {
  SerialUSB.begin(115200);
  delay(1500);                             // laisser le CDC s'énumérer
  SerialUSB.println("=== Scan I2C Due ===");
  Wire.begin;    // TWI1 -> broches 20 (SDA) / 21 (SCL)
  Wire1.begin;   // TWI0 -> broches 70 / 71 (connecteur pres RESET)
  scanner(Wire,  "Wire  (TWI1, broches 20/21)");
  scanner(Wire1, "Wire1 (TWI0, broches 70/71)");
  SerialUSB.println("Fin de scan.");
}

void loop { }

Expected verification

With a module on the classic I2C connector (20/21), the "Wire" line displays its address (e.g., 0x68 for a DS3231, 0x3C for a SSD1306) and the "Wire1" line displays (none). Moving the module to the 4-pin connector 70/71 reverses the results. With no peripheral connected, both lines display (none).

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials