Batron LCD sur I2C

bon, j'ai réduit la librairie pour limiter la place (je veux que le projet tienne sur une Duemilanove), et je n'ai pas gardé les finesses graphiques...

voilà ce que donne LCDI2C.h :

// library for Batron BTHQ21605 LCD display on I2C bus
// from Digid at https://public.me.com/digid/fr/

#ifndef LCDI2C_h
#define LCDI2C_h

#define CMDDELAY   165        // Delay to wait after sending commands;
#define POSDELAY   10         // Long delay required by Position command
#define CHARDELAY  0

#include <inttypes.h>
#include "Print.h"

class LCDI2C : public Print {

public: 
   LCDI2C(int,int,int);
   void init();
   virtual void write(unsigned char ch);
   void clear();
   void home();
   void on();
   void left();
   void right();
   void printstr(const char[]);
   void setCursor(int line_num, int x);
  
private:
   unsigned char ASCIItoLCD(unsigned char ch);

};

#endif

LCDI2C.cpp :

// library for Batron BTHQ21605 LCD display on I2C bus
// from Digid at https://public.me.com/digid/fr/

#include <Wire.h>
#include <string.h> //needed for strlen()
#include <inttypes.h>
#include "WConstants.h"  //all things wiring / arduino

#include "LCDI2C.h"
  
#define LCDI2C_MAX_STRLEN      40
#define LCDI2C_PRINT_STR_DELAY 20

int g_num_lines;
int g_num_col;
int 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;
   }
}

// initialisation of LCD
void LCDI2C::init () {
   on();
   clear();
}

// Turn the LCD ON
void LCDI2C::on(){
   Wire.beginTransmission(g_i2caddress | false<<0);
   Wire.send(0x00); // control byte
   Wire.send(0x34); // command: functions (2x16, basic set)
   Wire.send(0x0C); // command: display control (display on, cursor off, blink off)
   Wire.send(0x06); // command: entry mode (increment, no shift)
   Wire.send(0x35); // command: functions (2x16, extended instruction set)
   Wire.send(0x04); // command: left-to-right, top-to-bottom
   Wire.send(0x10); // command: TC1=0, TC2=0
   Wire.send(0x42); // command: HV stage 3
   Wire.send(0x9F); // command: set VLCD, store VA
   Wire.send(0x34); // command: normal instruction set
   Wire.send(0x80); // command: DDRAM address = 0x00
   Wire.send(0x02); // command: return home
   Wire.endTransmission();
   delay(CMDDELAY);  
}

//send the clear screen command to the LCD
void LCDI2C::clear(){
   setCursor(0,0);
   printstr("                ");
   setCursor(1,0);
   printstr("                ");
   setCursor(0,0);
}

//Used by the print library to get information to the display
void LCDI2C::write(unsigned char value) {
   Wire.beginTransmission(g_i2caddress | false);
   Wire.send(0x40);
   Wire.send(ASCIItoLCD(value));
   Wire.endTransmission();
   delay(CHARDELAY);
}

//send the Home Cursor command to the LCD      ********** Not Working ***************
void LCDI2C::home(){
   setCursor(0,0);
}

//Move the cursor left 1 space
void LCDI2C::left(){
   Wire.beginTransmission(g_i2caddress | false);
   Wire.send(0x00);
   Wire.send(0x10);
   Wire.endTransmission();
   delay(CMDDELAY);
}

//Move the cursor right 1 space
void LCDI2C::right(){
   Wire.beginTransmission(g_i2caddress | false);
   Wire.send(0x00);
   Wire.send(0x11);
   Wire.endTransmission();
   delay(CMDDELAY);
}

void LCDI2C::setCursor(int line_num, int x){
   Wire.beginTransmission(g_i2caddress | false);
   Wire.send(0x00);
   if (line_num==0)
      Wire.send(0x80+x);
   else
      Wire.send(0xC0+x);
   Wire.endTransmission();
   delay(POSDELAY);
}

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;
}

// print a string 
void  LCDI2C::printstr(const char c[])
{
   byte len;
   while (*c)
   {
      len = min(strlen(c), LCDI2C_MAX_STRLEN);
      Wire.beginTransmission(g_i2caddress | false<<0);
      Wire.send(0x40);
      while (len--)
         Wire.send(ASCIItoLCD(*c++));
      Wire.endTransmission();
      if (*c)
         delay(LCDI2C_PRINT_STR_DELAY);      // More to send.  Wait a bit
   }
}

et le prog principal de test :

#include <Wire.h>
#include "LCDI2C.h"

#define LCDI2C_ADDRESS 0x3B // found by I2C bus scanner

LCDI2C lcd = LCDI2C(2,16,LCDI2C_ADDRESS);             // Number of lines and i2c address of the display

void setup() {
  Serial.begin(9600);
  Wire.begin();
  lcd.init();                          // Init the display, clears the display
  lcd.printstr("Hello");
  lcd.setCursor(1,0);
  lcd.printstr("world");
}

void loop()
{
}