bonjour tout le monde,
d'abord merci pour la mine d'info dispo ici, qui m'a valu de rester longtemps 'guest' tellement quasi toute l'info possible est dispo
je me suis donc inscrit car là je cale dur sur le démarrage d'un LCD en I2C et je tourne sans trouver
comme j'ai déjà une horloge I2C, ça permet de n'utiliser aucune pin de plus, sacré avantage !
le LCD en cause est un Batron BT21605 de 2x16 caractères, sa doc est ici, il est basé sur un PCF2119
le câblage est 'classique' I2C avec les ports analog 4 et 5 de la Duemilanove, montés sans pull-up (j'ai vérifié que la librairie Wire enclenchait bien les pull-up internes). longueur des fils 20cm
son adresse I2C est 0x76 (write) pour le LCD, il peut être affublé d'un mini-clavier accessible par l'adresse 0x77 (read)
j'ai peu à peu viré le code qui n'était pas indispensable pour ne garder que l'essentiel...
voici donc le prog principal :
#include <Wire.h>
#include "LCDI2C.h"
#define LCDI2C_WRITEADDRESS 0x76 // found on www.datasheetarchive.com/datasheet-pdf/09/DSA00151661.html
LCDI2C lcd = LCDI2C(2,16,LCDI2C_WRITEADDRESS); // Number of lines, cols and i2c address of the display
void setup() {
Serial.begin(9600);
// start I2C master
Wire.begin();
lcd.init(); // Init the display
lcd.write(0x30); // 0
lcd.write(0x31); // 1
lcd.write(0x32); // 2
lcd.write(0x33); // 3
lcd.write(0x34); // 4
lcd.write(0x35); // 5
lcd.write(0x36); // 6
lcd.write(0x37); // 7
lcd.write(0x38); // 8
lcd.write(0x39); // 9
lcd.write(0x41); // A
lcd.write(0x42); // B
lcd.write(0x43); // C
lcd.write(0x44); // D
lcd.write(0x45); // E
lcd.write(0x46); // F
}
void loop()
{
}
la 'librairie' LCDI2C :
#include <Wire.h>
#include "LCDI2C.h"
#include <WConstants.h> //all things wiring / arduino
byte g_num_lines = 2;
byte g_num_col = 16;
byte g_i2caddress;
// constructor
LCDI2C::LCDI2C (int num_lines, int num_col, int i2c_address){
g_num_lines = num_lines;
g_num_col = num_col;
g_i2caddress = i2c_address;
if (g_num_lines < 1 || g_num_lines > 4){
g_num_lines = 2;
}
if (g_num_col < 1 || g_num_col > 40){
g_num_col = 16;
}
}
// init the LCD
void LCDI2C::init () {
on();
clear();
home();
}
//Turn the LCD ON
void LCDI2C::on(){
Wire.beginTransmission(g_i2caddress | false);
Wire.send(0x00); // control byte
Wire.send(0x34); // command: functions (2x16, basic set)
Wire.send(0x00); // control byte
Wire.send(0x0C); // command: display control (display on, cursor off, blink off)
Wire.send(0x00); // control byte
Wire.send(0x06); // command: entry mode (increment, no shift)
Wire.send(0x00); // control byte
Wire.send(0x35); // command: functions (2x16, extended instruction set)
Wire.send(0x00); // control byte
Wire.send(0x04); // command: left-to-right, top-to-bottom
Wire.send(0x00); // control byte
Wire.send(0x10); // command: TC1=0, TC2=0
Wire.send(0x00); // control byte
Wire.send(0x42); // command: HV stage 3
Wire.send(0x00); // control byte
Wire.send(0x9F); // command: set VLCD, store VA
Wire.send(0x00); // control byte
Wire.send(0x34); // command: functions (2x16, basic set)
Wire.send(0x00); // control byte
Wire.send(0x80); // command: DDRAM address = 0x00
Wire.send(0x00); // control byte
Wire.send(0x02); // command: return home
Wire.endTransmission();
}
//send the clear screen command to the LCD
void LCDI2C::clear(){
Wire.beginTransmission(g_i2caddress | false);
Wire.send(0x00); // control byte
Wire.send(0x01); // command : clear display
Wire.endTransmission();
delay(CLRDELAY);
}
//send the Home Cursor command to the LCD
void LCDI2C::home(){
setCursor(0,0);// The command to home the cursor
}
void LCDI2C::setCursor(int line_num, int col_num){
Wire.beginTransmission(g_i2caddress | false);
Wire.send(0x00);
if (line_num==0)
Wire.send(0x80+col_num);
else
Wire.send(0xC0+col_num);
Wire.endTransmission();
delay(STDDELAY);
}
//get information to the display
void LCDI2C::write(unsigned char value) {
Wire.beginTransmission(g_i2caddress | false);
Wire.send(0x40); // control byte for data
Wire.send(ASCIItoLCD(value));
Wire.endTransmission();
delay(5);
}
unsigned char LCDI2C::ASCIItoLCD(unsigned char ch){
unsigned char c;
if ( ((ch >= 0x20) && (ch <= 0x3F)) || ((ch >= 0x41) && (ch <= 0x5A)) || ((ch >= 0x61) && (ch <= 0x7A)) )
c = 0x80 + ch;
else
c = 0x40;
return c;
}
le .h contient en plus ces 2 définitions :
#define CLRDELAY 165 // Delay to wait after sending clear command
#define STDDELAY 3 // normal delay
voilà...
je dois faire une erreur basique, car je semble être dans la logique de tous les autres exemples que j'ai épluché, à commencer par celui-ci
si l'un de vous maîtrise l'I2C ou utilise cet écran, je serais bien heureux d'un conseil pour décoincer
donc merci d'avance