Redefine "on fly" custom CGRAM characters problem

Hi all -.^

[With Arduino2009 + SparkFun SerLCD 16x2]

Since I'm trying to define more than 8 CGRAM characters without success (HD44780 speak about more ?) I saw what is possible to redefine "on fly" custom characters because CGRAM is refresh continuously.
It could be another way to make small animate icons etc. ^.^

But I get something unexpected: When I try to write after half the bottom line of the LCD it compromises other parts of the screen O.o
(start blinking, etc.)

I'm a bit noob with those gears, so here is a simple code:

#include <SoftwareSerial.h>

#define txPin 2
SoftwareSerial LCD = SoftwareSerial(0, txPin);

void setup()
{
  pinMode(txPin, OUTPUT);
  LCD.begin(9600);
  // définition des graphiques par défaut
  setGFX(0,152,152,128,131,132,132,131,128); // °C
  setGFX(1,128,128,130,135,130,128,128,128); // +
  setGFX(2,128,128,128,135,128,128,128,128); // -
  setGFX(3,138,159,145,142,132,132,152,128); // prise
  setGFX(4,142,145,145,145,145,145,159,128); // batterie (vide à l'origine)
  setGFX(5,128,128,128,128,128,128,128,128); //
  setGFX(6,128,128,128,128,128,128,128,128); //
  setGFX(7,128,128,128,128,128,128,128,128); //
  // initilisation de l'affichage
  setBackLight();
  clearLCD();
}

void loop()
{
  selectLineOne();
  LCD.print(3, BYTE);
  LCD.print(" 14.21V");
  LCD.print(" ");
  LCD.print(1, BYTE);
  LCD.print("19.4");
  LCD.print(0, BYTE);
  selectLineTwo();
  LCD.print(4, BYTE);
  LCD.print("  3.12A");
  //LCD.print("  ");
  //LCD.print("test");
  setGFX(4,142,145,145,145,145,145,159,128); // batterie vide
  delay(500);
  setGFX(4,142,145,145,145,145,159,159,128); // batterie 1/5
  delay(500);
  setGFX(4,142,145,145,145,159,159,159,128); // batterie 2/5
  delay(500);
  setGFX(4,142,145,145,159,159,159,159,128); // batterie 3/5
  delay(500);
  setGFX(4,142,145,159,159,159,159,159,128); // batterie 4/5
  delay(500);
  setGFX(4,142,159,159,159,159,159,159,128); // batterie pleine
  delay(750);
}

void setGFX(byte pos, byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8){
  LCD.print(0xFE, BYTE); // appel de fonction sur le HD44780
  LCD.print(64 + pos * 8, BYTE); // accès à la CGRAM
  LCD.print(b1, BYTE);
  LCD.print(b2, BYTE);
  LCD.print(b3, BYTE);
  LCD.print(b4, BYTE);
  LCD.print(b5, BYTE);
  LCD.print(b6, BYTE);
  LCD.print(b7, BYTE);
  LCD.print(b8, BYTE);
}
void selectLineOne(){ // place le curseur au début de la ligne 1
  LCD.print(0xFE, BYTE);
  LCD.print(128, BYTE);
  delay(2);
}
void selectLineTwo(){ // place le curseur au début de la ligne 2
  LCD.print(0xFE, BYTE);
  LCD.print(192, BYTE);
  delay(2);
}
void setBackLight(){
  LCD.print(0x7C, BYTE);
  LCD.print(130, BYTE);
  delay(100);
}
void clearLCD(){
  LCD.print(0xFE, BYTE);
  LCD.print(0x01, BYTE);
  delay(10);
}
void resetLCD(){
  LCD.print(0xFE, BYTE);
  LCD.print(0x72, BYTE);
}

If you uncomment lines 36 & 37 you can see what's append.

I hope my code and my English is not too bad,
thanks for any help .

Nobody can help meh?.. :-[

I saw what is possible to redefine "on fly" custom characters because CGRAM is refresh continuously.

I am not sure where you read that. The problem is that the refresh rate of the LCD is not synchronized to the arduino so I doubt if you can do this at all.

I don't read it somewhere, in fact.
When I saw how CGRAM access works I just imagine it could be possible >.>

And for my previous code, there's something strange.. Maybe a timing RAM access problem.

But I rewrite some parts, and if the re-definition loop is not ending by a delay(), it's working ^.^

Here is a code where you can see it's working:

#include <SoftwareSerial.h>

#define txPin 2
SoftwareSerial LCD = SoftwareSerial(0, txPin);

void setup()
{
  pinMode(txPin, OUTPUT);
  LCD.begin(9600);
  // définition des graphiques par défaut
  setGFX(0,152,152,128,131,132,132,131,128); // °C
  setGFX(1,128,128,130,135,130,128,128,128); // +
  setGFX(2,128,128,128,135,128,128,128,128); // -
  setGFX(3,138,159,145,142,132,132,152,128); // prise 220V
  setGFX(4,142,145,145,145,145,145,159,128); // batterie (vide à l'origine)
  setGFX(5,128,128,128,159,128,128,159,128); // sortie 12V
  setGFX(6,128,128,136,149,130,128,159,128); // sortie 220V
  setGFX(7,128,128,135,133,135,130,129,128); // petite prise
  // initilisation de l'affichage
  setBackLight();
  clearLCD();
}

void loop()
{
  selectLineOne();
  LCD.print(3, BYTE);
  LCD.print(" 14.21V");
  LCD.print(" ");
  LCD.print(1, BYTE);
  LCD.print("19.4");
  LCD.print(0, BYTE);
  selectLineTwo();
  LCD.print(4, BYTE);
  LCD.print("  3.12A");
  LCD.print(" ");
  LCD.print(7, BYTE);
  LCD.print(6, BYTE);
  LCD.print(7, BYTE);
  LCD.print(5, BYTE);
  LCD.print(7, BYTE);
  LCD.print(5, BYTE);
  LCD.print(" ");
  animGFX();
}

void animGFX(){
  delay(500);
  setGFX(4,142,145,145,145,145,159,159,128); // batterie 1/5
  delay(500);
  setGFX(4,142,145,145,145,159,159,159,128); // batterie 2/5
  delay(500);
  setGFX(4,142,145,145,159,159,159,159,128); // batterie 3/5
  setGFX(6,128,128,130,149,136,128,159,128);
  delay(500);
  setGFX(4,142,145,159,159,159,159,159,128); // batterie 4/5
  delay(500);
  setGFX(4,142,159,159,159,159,159,159,128); // batterie pleine
  delay(750);
  setGFX(4,142,145,145,145,145,145,159,128); // batterie vide
  setGFX(6,128,128,136,149,130,128,159,128);
}

void setGFX(byte pos, byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8){
  LCD.print(0xFE, BYTE); // appel de fonction sur le HD44780
  LCD.print(64 + pos * 8, BYTE); // accès à la CGRAM
  LCD.print(b1, BYTE);
  LCD.print(b2, BYTE);
  LCD.print(b3, BYTE);
  LCD.print(b4, BYTE);
  LCD.print(b5, BYTE);
  LCD.print(b6, BYTE);
  LCD.print(b7, BYTE);
  LCD.print(b8, BYTE);
}
void selectLineOne(){ // place le curseur au début de la ligne 1
  LCD.print(0xFE, BYTE);
  LCD.print(128, BYTE);
  delay(2);
}
void selectLineTwo(){ // place le curseur au début de la ligne 2
  LCD.print(0xFE, BYTE);
  LCD.print(192, BYTE);
  delay(2);
}
void setBackLight(){
  LCD.print(0x7C, BYTE);
  LCD.print(130, BYTE);
  delay(100);
}
void clearLCD(){
  LCD.print(0xFE, BYTE);
  LCD.print(0x01, BYTE);
  delay(10);
}
void resetLCD(){
  LCD.print(0xFE, BYTE);
  LCD.print(0x72, BYTE);
}

I imagine it can help some people who's looking for a solution to use more than 8 customs chars -.^
Or who want to make animate icons, like you can see in the code just here ^.^

I think I misunderstood you problem. I thought you wanted to redefine them on the fly so that you had more than 8 custom characters being displayed at the same time, not having the custom characters being redefined once they were on the screen. That is an old trick we used to use in 8 bit desktop computers to get animation.

Harf... indeed, my English is "possibly" not very good ::slight_smile:
Of course, like I said, there's no easy way to have more than 8 customs chars.
I'll try to be more... Clear, next time -.^

This may help . . .
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1268281540

There's more if you type "custom characters lcd" in the search box.

(Your English is fine.)

Oops, I missed this post..
It's exactly the same thing I'm doing ^.^
I'll see to adapt it for serial use, thank you Sparks -.^