1. Francisco Malpartida
  2. New LiquidCrystal
  3. Issues

Issues

Issue #8 resolved

Bug with createChar

Anonymous created an issue

There is a bug in the createChar() function. It actualy writes something to the CGRAM, but it's garbish. I'm using a LCD in 4bit mode, tested with Aruino 0022 and v1.0. If I change back to original LiquidCrystal library, the custom characters are OK. To reproduce this bug, simply define 8 characters and print them on LCD and compare.. I tried to have a look at the library code on my own, but it is too complicated for myselfe. I hope you can fix this, I would like to stay with your version because of the speed. Everything else works quite nice.

Comments (11)

  1. Anonymous

    This should do the trick. The custom chars are from the big font threads from the arduino forum. But you can also create smilies, that doesn't changes anything.

    #include <LiquidCrystal.h>
    
    
    LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
    #define   CONTRAST_PIN   9
    #define   CONTRAST       95 //highest OK at roomtemp
    
    byte LT[8] =
    {
      B00111,
      B01111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111
    };
    byte UB[8] =
    {
      B11111,
      B11111,
      B11111,
      B00000,
      B00000,
      B00000,
      B00000,
      B00000
    };
    byte RT[8] =
    {
      B11100,
      B11110,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111
    };
    byte LL[8] =
    {
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B01111,
      B00111
    };
    byte LB[8] =
    {
      B00000,
      B00000,
      B00000,
      B00000,
      B00000,
      B11111,
      B11111,
      B11111
    };
    byte LR[8] =
    {
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11110,
      B11100
    };
    byte UMB[8] =
    {
      B11111,
      B11111,
      B11111,
      B00000,
      B00000,
      B00000,
      B11111,
      B11111
    };
    byte LMB[8] =
    {
      B11111,
      B00000,
      B00000,
      B00000,
      B00000,
      B11111,
      B11111,
      B11111
    };
    
    void setup()
    {
      TCCR1B = TCCR1B & 0b11111000 | 0x02; //min 3900Hz for flicker free LCD
      // Switch on the backlight and LCD contrast levels
      pinMode(CONTRAST_PIN, OUTPUT);
      analogWrite(CONTRAST_PIN, CONTRAST);
      
      lcd.createChar(0, LT);
      lcd.createChar(1, UB);
      lcd.createChar(2, RT);
      lcd.createChar(3, LL);
      lcd.createChar(4, LB);
      lcd.createChar(5, LR);
      lcd.createChar(6, UMB);
      lcd.createChar(7, LMB);  
      lcd.begin(8, 2);               // initialize the lcd  
    }
    
    void loop()
    {
      lcd.setCursor(0, 0);
      for (byte i= 0; i < 8; i++){
        lcd.write(i);
      }
    
      delay(5000);
    }
    
  2. Anonymous

    Belive me, I tried every possible combination for .begin and .createChar. I also added some delays, hoping that the display only needs little more time between the calls. But without success.

  3. Anonymous

    Found it: It's a timing issue. In LiquidCrystal.cpp, there should be a 40µs delay.

    void LiquidCrystal::pulseEnable(void) 
    {
       // There is no need for the delays, since the digitalWrite operation
       // takes longer.
       digitalWrite(_enable_pin, HIGH);   
       waitUsec(1);          // enable pulse must be > 450ns   
       digitalWrite(_enable_pin, LOW);
       delayMicroseconds(40);   // commands need > 37us to settle
    }
    

    For some reason, every other command seems to work without this delay, but createChar needs it. At last on my 3 LCDs.

  4. Francisco Malpartida repo owner

    Ummm! I will give it a shot, it seams that not all the LCDs behave the same way, with the ones I use (must have a faster controller) it works fine. In any case, you should comment the FAST_MODE definition in LCD.h, the purpose of that was to cater for slower LCDs.

    This makes me wander if this definition should be commented out by default.

  5. Anonymous

    It's me again. Just want to let you know there seems to be a slightly bigger problem then only fastmode on or off. Custom chars worked for me with FAST_MODE off, but yesterday I moved the code from my test arrangement (Arduino Duemilanove, programed by USB connection) to the real hardware (Arduino Pro Mini, programed by AVR ISP MKII) => the LCD shows garbage characters again. Switched back to original LiquidCrystal and it now works fine..

    I'm sorry, but I would say you should at a note to you library entry at http://arduino.cc/playground/Code/LCD that the timings are reduced to the limits even without fastmode (or what else is the reason for the errors) and it may not work with every LCD with all functions like customchars. And yes I think FAST_MODE should be off by default. Arduino is a board for µC beginners, most of them will not even know where they could find the fastmode "switch".

    For my purpose, I will do some minor rework the original library and stay with it.

  6. Log in to comment