🛠 Ajouter un deuxième port série avec SoftwareSerial (GPS sur broches 10/11)
Objectives
The Duemilanove has only one hardware UART (pins 0/1), and it is already occupied by the FTDI USB-to-serial bridge. The official page states this explicitly: "the SoftwareSerial library allows serial communication on any digital pin." You will connect a GPS to pins 10/11 and create a bidirectional serial bridge between the GPS and the USB monitor — the technique that has allowed generations of GPS/GSM/MP3 projects to live on AVR.
Hardware
- 1 Arduino Duemilanove (ATmega328 recommended: the 1 KB of SRAM on the 168 limits program size)
- 1 TTL GPS module (e.g., NEO-6M, 4800 or 9600 baud) — at 5 V it is compatible with the Duemilanove's 5 V logic, no level shifter needed
- 4 male-to-male wires, mini-USB cable
Complete code
// Pont moniteur USB <-> GPS sur SoftwareSerial (RX=10, TX=11)
#include <SoftwareSerial.h>
SoftwareSerial gps(10, 11); // RX, TX
void setup {
Serial.begin(9600); // USB (FTDI)
gps.begin(4800); // NEO-6M par defaut : 4800
Serial.println("Pont GPS actif — attendez le fix");
}
void loop {
if (gps.available) Serial.write(gps.read); // GPS -> moniteur
if (Serial.available) gps.write(Serial.read); // moniteur -> GPS
}
Expected verification
The serial monitor (9600) displays NMEA sentences $GPGGA, $GPRMC… as soon as the GPS acquires a signal (a few minutes for a cold start, near a window). Sending a UBX command or a valid sentence from the monitor forwards it to the GPS. The GPS status LED blinks every second.
Common errors
- Believing SoftwareSerial is full-duplex at 9600+ on AVR: it works at 4800; at 9600 and above, bytes are lost if
loopdoes anything else — this is the physical limit of software emulation on a 16 MHz AVR. - Reversing the crossover: GPS TX → pin 10 (software RX), GPS RX ← pin 11 (software TX); without crossover, there is total silence.
- Using pin 11 for PWM at the same time: SoftwareSerial on 10/11 monopolizes the timer used by PWM on pins 9/10/11 —
analogWritecalls on these pins degrade. - Connecting the GPS to pins 0/1: direct conflict with the FTDI, the monitor and the GPS talk over each other, and uploading becomes impossible.
- Choosing pins 2/3 for the GPS: possible, but they are often reserved for external interrupts; 10/11 is the classic choice.
- Expecting a fix indoors: without a view of the sky, sentences arrive empty — go outside to test.
- Forgetting the
delay(1000)after opening the port in a host script: the DTR auto-reset causes the loss of the first half-second (see the button tutorial).
Other tutorials for this board
- Faire clignoter la LED 13 d'une Duemilanove (et choisir le bon ATmega)
- Bouton poussoir et moniteur série sur la Duemilanove (avec ses 0,5 s de silence)
- Potentiomètre et variation LED : l'ADC 10 bits et le PWM 8 bits version AVR
- Régler la référence de mesure avec AREF et analogReference
- Persister une calibration dans l'EEPROM de l'ATmega (512 octets ou 1 Ko)
- Convertir la Duemilanove en programmateur AVR (ArduinoISP) pour graver des puces nues
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinopwm-respiration.inoArduinopotentiometre-plotter.inoArduinoservo-balayage.inoArduinobuzzer-melodie.inoArduino