Pour 1€, l’adaptateur I2C IIC Serial Interface Board permet de contrôler l’écran LCD 1602 à l’aide de deux fils via l’interface SDA / SCL I2C. Pour désactiver la LED qui éclaire l’écran, retirer le « cavalier » plastique noir.
La tige proche de la broche GND doit être soudée sur le trou n°1 de l’écran LCD cf. photos ci dessous
Pour utiliser cet adaptateur, téléchargez la librairie LiquidCrystal pour I2C ici puis l’importer dans l’IDE Arduino.
Les broches sont :
ECRAN->ARDUINO
GND -> GND
VCC->+5v
SDA->A4 (UNO & NANO) 20(MEGA)
SCL->A5 (UNO & NANO) 21 (MEGA)
ATTENTION, déplacez ou renommer la librairie LiquidCrystal ou tout autre librairie LCD du dossier « Librairie ». Pour ce faire, aller dans le dossier Arduino du répertoire documents. A l’intérieur, il y a un dossier « Libraries ». Juste supprimer les librairies et redémarrer l’application Arduino.
#include <Wire.h> //-- Proviens de Arduino IDE
#include <LiquidCrystal_I2C.h> //-- A importer !
// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup()
{
Serial.begin(9600); //--Used to type in characters
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight
lcd.backlight(); // backlight on
//-------- Write characters on the display ------------------
// NOTE: Cursor Position: (CHAR, LINE) start at 0
lcd.setCursor(0,0); //Start at character 4 on line 0
lcd.print("*** LCD I2C ****");
lcd.setCursor(0,1);
lcd.print("-Andrologiciels-");
delay(5000);
// Wait and then tell user they can start the Serial Monitor and type in characters to
// Display. (Set Serial Monitor option to "No Line Ending")
lcd.clear();
lcd.setCursor(0,0); //Start at character 0 on line 0
lcd.print("Utilisez monit..");
lcd.setCursor(0,1);
lcd.print("pour saisir !");
}
int dp=1; //-- Pour afficher sur les 2 lignes
void loop()
{
{
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
if (dp==0)
{dp=1;
lcd.setCursor(0,1);
}
else
{lcd.clear();
dp=0;
lcd.setCursor(0,0);}
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
int c=Serial.read();
if (c>31)
lcd.write(c);
}
}
}
}
Détail d’utilisation : http://arduino-info.wikispaces.com/LCD-Blue-I2C
Votre commentaire