🛠 Scanner le bus I2C depuis le microcontrôleur
Objectives
The Arduino header of the LattePanda 3 Delta exposes an I2C bus (official ADC and I2C tutorials exist in the IO_Playability documentation). Rather than assuming a specific sensor, this tutorial writes a native I2C scanner in C++ on the ATmega32U4: it scans all 7-bit addresses and reports the devices present on the internal serial port. This is an essential diagnostic tool before connecting any sensor, and it once again demonstrates the dual nature of the board: the bus is on the Arduino side, not the PC side.
Hardware
- LattePanda 3 Delta + Arduino IDE (board "Arduino Leonardo")
- 1 I2C sensor module or peripheral of your choice (the scanner will identify it by its address)
- 4.7 kΩ pull-up resistors on SDA and SCL if the module does not already have them (Gravity/DFRobot modules usually include them)
- Dupont cables to the I2C pins of the Arduino header (labeled SDA/SCL on the official pinout diagram on the
io_playabilitypage)
Complete Code
Arduino IDE sketch (board "Arduino Leonardo"):
// Scanner I2C pour l'ATmega32U4 embarqué de la LattePanda 3 Delta.
#include <Wire.h>
void setup {
Serial.begin(9600);
while (!Serial) {} // attendre le port série USB
Wire.begin; // maître I2C
Serial.println("Scan I2C : 0x08 -> 0x77");
}
void loop {
byte trouve = 0;
for (byte addr = 8; addr < 120; addr++) {
Wire.beginTransmission(addr);
if (Wire.endTransmission == 0) { // 0 = ACK reçu
Serial.print("Périphérique trouvé à 0x");
Serial.println(addr, HEX);
trouve++;
}
}
if (trouve == 0) Serial.println("Aucun périphérique I2C.");
Serial.println("---");
delay(5000); // refaire un scan toutes les 5 s
}
The lines are displayed in the IDE's serial monitor or on the MCU's COM port from the SoC (see the serial bridge tutorial).
Expected Verification
With a module connected, the scan displays its address (for example, address 0x3C for many OLED screens — the actual address depends on the module). With nothing connected but SDA/SCL left floating, many addresses may respond falsely: this is the classic symptom of missing pull-up resistors.
Common Errors
- SDA/SCL swapped: nothing responds; swap the two wires.
- No pull-up: the bus floats and the scan outputs garbage; add 4.7 kΩ resistors or use a module with built-in pull-ups.
- Logic level: >
- Wrong pins: do not connect SDA/SCL to just any pin on the two 50-pin blocks; follow the official pinout on the
io_playabilitypage. - Confusion with the SoC: the bus controlled here is the Arduino's; the Celeron N5105 does not expose user-accessible I2C in the same way.
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton.pyPythonservo.pyPythonanalogique.pyPythonrespiration.pyPythonneopixel.pyPython