ecran-i2c-lcd.ino
A 16x2 LCD fitted with a PCF8574 I2C backpack uses only two pins (SDA/SCL). The sketch shows the voltage measured on A0 and the uptime, refreshed twice per second.
Hardware
An Arduino Pro Mini (ATmega328P, 5 V/16 MHz or 3.3 V/8 MHz variants) wired to a USB-serial adapter (FTDI) or an ICSP programmer. 1 16x2 LCD with PCF8574 I2C backpack (address 0x27 or 0x3F).
Wiring
SDA to A4, SCL to A5 (I2C pins of AVR boards), VCC 5V, GND. Verify the I2C address with a scanner (e.g. i2c_scanner).
How it works
Wire drives the I2C bus; LiquidCrystal_I2C translates print() into LCD commands. setCursor moves the cursor, trailing spaces erase leftovers.
Running it
Select « Arduino Pro Mini » in the IDE (5 V/16 MHz or 3.3 V/8 MHz per your model), ATmega328P processor, the right port, then Upload. The adapter must be wired DTR-DTR, RX-TX, TX-RX, VCC-VCC, GND-GND.
Variants
Change the address (0x3F) if nothing shows, or stack several sensors with automatic page scrolling every 5 s.
ecran-i2c-lcd.ino
// LCD 16x2 + convertisseur I2C PCF8574 : affichage de mesures.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // adresse usuelle 0x27 (0x3F sur certains)
void setup() {
Serial.begin(9600);
Wire.begin();
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Hello, monde !");
delay(1500);
lcd.clear();
}
void loop() {
// Exemple : tension d'alimentation mesuree sur la reference interne.
analogRead(A0); // rechauffe de l'ADC
long brut = analogRead(A0);
float tension = brut * 5.0 / 1023.0;
lcd.setCursor(0, 0);
lcd.print("A0:");
lcd.print(tension, 2);
lcd.print("V "); // efface les chiffres residuels
lcd.setCursor(0, 1);
lcd.print("Uptime:");
lcd.print(millis() / 1000);
lcd.print("s ");
delay(500);
}