🛠 Télémétrie série robuste vers le Traceur série

Arduino UNO R3 · intermediaire · Schéma : IMG-uno-r3-intermediaire-2-telemetrie-serie-robuste.svg — UNO R3 reliée en USB à un PC, écran affichant des courbes (Traceur série), annotation du quirk DTR de réinitialisation.

Objectives

Send data from the UNO to the PC properly: pace sampling with micros/millis instead of delay, save SRAM with the F macro, and above all, understand the DTR auto-reset quirk — the UNO resets every time the serial port is opened, and its bootloader "intercepts the first bytes" sent after connection.

Hardware

Complete Code

// Échantillonnage non bloquant 20 Hz sur A0, format Traceur série.
const uint32_t PERIODE_US = 50000;  // 50 ms = 20 Hz
uint32_t precedent = 0;

void setup {
  Serial.begin(115200);
  while (!Serial) { }   // attend l'ouverture du port (utile sur les cartes USB natives)
  Serial.println(F("pret"));  // F : la chaîne vit en flash, pas en SRAM (2 Ko seulement !)
}

void loop {
  uint32_t maintenant = micros;
  if (maintenant - precedent >= PERIODE_US) {
    precedent = maintenant;
    int a0 = analogRead(A0);
    int a1 = analogRead(A1);
    // Le Traceur série trace une courbe par valeur séparée par tabulation :
    Serial.print(a0); Serial.print("\t"); Serial.println(a1);
  }
  // ... ici on peut faire autre chose : le delay ne bloque plus la boucle.
}

Expected Verification

Tools > Serial Plotter: two continuous and regular curves, without gaps. If you open the Serial Monitor, the message "ready" appears (the board has just restarted — that's the DTR!). Test with a raw terminal: the first 2–3 characters emitted just after opening may be lost, and the first bytes YOU send may be swallowed by the bootloader.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials