🛠 Afficher sur un LCD 16×2 en bus parallèle 8 bits
Objectives
Take advantage of the 54 I/O pins on the Mega 2560 to wire up a 16×2 HD44780 character display in full 8-bit mode (eight data lines D0–D7 plus RS, E, and RW, totaling eleven pins) — a luxury that is impossible on an Uno without sacrificing half of its pins. The 8-bit bus doubles the write speed compared to the classic 4-bit mode.
Hardware
- 1 × Arduino Mega 2560 + USB cable
- 1 × 16×2 LCD display based on HD44780 (16-pin connector)
- 1 × 10 kΩ potentiometer (contrast control on V0)
- 1 × 220 Ω resistor (backlight, pin A/K)
- Breadboard and numerous ribbon cables/wires
Wiring used (free pins on the Mega): RS=22, RW=23 (tied to GND for write-only operation), E=24, D0–D7 = 25 to 32. LCD: VSS→GND, VDD→5 V, V0→potentiometer wiper (the other two legs: 5 V and GND). The display is designed for 5 V logic, the nominal voltage of the Mega's pins.
Complete Code
// LCD 16x2 en bus 8 bits — bibliothèque LiquidCrystal
#include <LiquidCrystal.h>
// (RS, RW, E, D0, D1, D2, D3, D4, D5, D6, D7) : mode 8 bits
LiquidCrystal lcd(22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32);
void setup {
lcd.begin(16, 2);
lcd.print(F("Mega 2560"));
lcd.setCursor(0, 1);
lcd.print(F("Bus 8 bits"));
}
void loop {
lcd.setCursor(11, 0);
lcd.print(millis / 1000); // chrono sur la 1re ligne
}
Expected Verification
"Mega 2560" and "8-bit Bus" are displayed on the two lines, with a seconds counter updating at the end of the first line. By adjusting the potentiometer, the contrast varies from completely off to completely black.
Common Errors
- Poorly adjusted contrast: the screen appears dead even though the code is running — adjust V0 before looking for a bug.
- Confusion with LiquidCrystal constructors: 10 arguments = 8-bit mode, 6 arguments = 4-bit mode; mixing the two results in random characters.
- RW left floating: tie it to GND if you never read the busy flag.
- Backlight without a resistor on A/K: it works, but in the short term the internal LED will degrade; a pin must never approach 40 mA.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinodouble-servo.inoArduinopont-uart.inoArduinopwm-respiration.inoArduinopotentiometre-plotter.inoArduino