🛠 Console série et piège DTR du FTDI
Objectives
Master the serial console on the classic Nano: the single hardware UART (pins 0/1) goes through the FTDI FT232RL USB-to-serial bridge on official boards — the ATmega328P chip itself has no native USB. We build a mini command console and understand the DTR pitfall: opening the port resets the board via a 100 nF capacitor, and the bootloader swallows the first bytes sent just after connection.
Hardware
- 1 × Classic Arduino Nano (original FTDI FT232RL, or CH340 clone with WCH driver)
- 1 × USB Mini-B cable
- PC with serial monitor (Arduino IDE, PuTTY, or screen)
Complete code
// Mini-console serie : commande 'l' = LED, 'v' = valeur analogique
const uint8_t LED = LED_BUILTIN;
void setup {
Serial.begin(9600);
pinMode(LED, OUTPUT);
// Patiente ~2 s : laisse passer le reset DTR + bootloader
uint32_t t0 = millis;
while (millis - t0 < 2000) { while (Serial.available) Serial.read; }
Serial.println(F("Nano pret. Tapez l ou v."));
}
void loop {
if (Serial.available) {
char c = Serial.read;
if (c == 'l') { digitalWrite(LED, !digitalRead(LED)); Serial.println(F("LED toggle")); }
else if (c == 'v') { Serial.println(analogRead(A0)); }
while (Serial.available) Serial.read; // vide le reste de la ligne
}
}
Expected verification
After opening the serial monitor at 9600 baud, the message "Nano ready" appears about 2 seconds later: this is the trace of the automatic reset. The 'l' and 'v' commands respond immediately. By sending text BEFORE the bootloader finishes, you can observe that the bytes disappear — the pitfall is observable and documented.
Common errors
- Sending a configuration string as soon as the port opens: the bootloader intercepts the first bytes after the DTR reset; always wait for the ready message on the board side.
- Connecting an ESP8266 to the Nano's 3.3 V pin: this pin provides only 50 mA and the connection drops during transmission; power the module separately.
- CH340 clone without driver: no COM port appears; install the WCH driver (official boards use the FTDI VCP driver).
- Wrong baud rate on the PC side: unreadable characters scroll by; 9600 must match on both sides.
Other tutorials for this board
Code examples for this board
buzzer-melodie.inoArduinoservo-sweep.inoArduinoultrason-hcsr04.inoArduinolcd-i2c.inoArduinoeeprom-contre.inoArduinosommeil-watchdog.inoArduino