New LiquidCrystal library - LCD library

@MikeOTool, simply copy the contents of the zip file into the LiquidCrystal library folder of the Arduino IDE. It would be good to copy the LiquidCrystal original files somewhere else for safe keeping and fallback if you need it.

Cheers and enjoy it.

Thanks, taught as much so that's what I did...

Running the test code resulted in two errors ('class LiquidCrystal' has no member named 'setBacklightPin' and 'class LiquidCrystal' has no member named 'setBacklight') so I posted the above...

To continue testing, I commented these out and everything worked fine... now I juts need to fix these...
Mike

Ummm, I'll review the code, but I am fairly sure that the librarwy does support it.

There is one thing that comes to mind, have you removed the old LiquidCrystal library?

I've been looking at the source under rel 1.2.1 and those methods are there, both in the header file and in the c file. So, there are two options, the old LiquidCrystal header file is still there or the zip file of version 1.2.0 in the download section is not correct.

Do let me know to see if I have to fix it, but no one else has raise the problem.

Thanks for that... no problem it should be a breeze to fix... (seems I said that a little quickly ;))

Update...
Assuming it was still loading the old header files (even though I had renamed the folder), I decided to remove it completely and of course it was...
When I tried to compile it reported it could not find the header file... I closed the Arduino console and restarted it... loaded the test code and it compiled perfectly....

The example files work now but the code I was working on (MyHelloWorld_4bit.ino) appears to have been turned into a binary file...
Is it possible the Arduino console compiled MyHelloWorld_4bit.ino and saved it overwriting my file?
Mike

Thanks fm, bperrybap and others for developing this library.

I've installed it and in preparation to begin working my way through its capabilities I tested my IDE 1.0 installation of the new Library with a number of the original LiquidCrystal examples. All worked fine until I struck an odd overload compile error with the Custom Characters sketch.

/*
  LiquidCrystal Library - Custom Characters
 
 Demonstrates how to add custom characters on an LCD  display.  
 The LiquidCrystal library works with all LCD displays that are 
 compatible with the  Hitachi HD44780 driver. There are many of 
 them out there, and you can usually tell them by the 16-pin interface.
 
 This sketch prints "I <heart> Arduino!" and a little dancing man
 to the LCD.
 
  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K potentiometer:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 * 10K poterntiometer on pin A0
 
 created21 Mar 2011
 by Tom Igoe
 Based on Adafruit's example at
 https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde
 
 This example code is in the public domain.
 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 
 Also useful:
 http://icontexto.com/charactercreator/
 
 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// make some custom characters:
byte heart[8] = {
  0b00000,
  0b01010,
  0b11111,
  0b11111,
  0b11111,
  0b01110,
  0b00100,
  0b00000
};

byte smiley[8] = {
  0b00000,
  0b00000,
  0b01010,
  0b00000,
  0b00000,
  0b10001,
  0b01110,
  0b00000
};

byte frownie[8] = {
  0b00000,
  0b00000,
  0b01010,
  0b00000,
  0b00000,
  0b00000,
  0b01110,
  0b10001
};

byte armsDown[8] = {
  0b00100,
  0b01010,
  0b00100,
  0b00100,
  0b01110,
  0b10101,
  0b00100,
  0b01010
};

byte armsUp[8] = {
  0b00100,
  0b01010,
  0b00100,
  0b10101,
  0b01110,
  0b00100,
  0b00100,
  0b01010
};
void setup() {
  // create a new character
  lcd.createChar(0, heart);
  // create a new character
  lcd.createChar(1, smiley);
  // create a new character
  lcd.createChar(2, frownie);
  // create a new character
  lcd.createChar(3, armsDown);  
  // create a new character
  lcd.createChar(4, armsUp);  

  // set up the lcd's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the lcd.
  lcd.print("I "); 
  lcd.write(0);
  lcd.print(" Arduino! ");
  lcd.write(1);

}

void loop() {
  // set the cursor to the bottom row, 5th position:
  lcd.setCursor(4, 1);
  // draw the little man, arms down:
  lcd.write(3);
  delay(500);
  lcd.setCursor(4, 1);
  // draw him arms up:
  lcd.write(4);
  delay(500);
}

I get the following compile error which I do not have the Arduino knowledge to resolve:

CustomCharacter.cpp: In function 'void setup()':
CustomCharacter:114: error: call of overloaded 'write(int)' is ambiguous
/Applications/Arduino.app/Contents/Resources/Java/libraries/LiquidCrystal/LCD.h:479: note: candidates are: virtual size_t LCD::write(uint8_t)
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Print.h:49: note: size_t Print::write(const char*)

Umm, everything is possible with SW, but that is a bit odd.

@dweston - did you remove the old library, not just moving it somewhere else. There is an example in the New LiquidCrystal library that uses the creation of custom characters, helloworld_4bit. Give that a shot.

@dweston - the other thing you can do is to change the byte declaration of the character creation variable by int8_t. This should fix it by not having ambiguities in the call.

@fm I followed your advice at Reply #80 "simply copy the contents of the zip file into the LiquidCrystal library folder of the Arduino IDE." The library folder I presumed you mean is the one within the Arduino.app contents package (I'm using MacOSX) i.e. [/Applications/Arduino.app/Contents/Resources/Java/libraries/LiquidCrystal/].

Pardon the embarrassment of my naivety but I don't know how to apply your suggested "change the byte declaration of the character creation variable by int8_t"?

The example "helloworld_4bit" works fine, although I noted a spelling error in line 8:

LiquidCrystal lcd(8, 9, 4, 5, 6, 7, BACKLIGH_PIN, POSITIVE );

should read:

LiquidCrystal lcd(8, 9, 4, 5, 6, 7, BACKLIGHT_PIN, POSITIVE );

The pin number changes reflect the DFRobot-007 LCD Keypad shield I'm using.

dweston,
I want to stress DO NOT use the backlight control on the DFRrobot-007 LCD keypad shield.
That board as a hardware design issue and if you set D10 to high,
it creates a short from D10 to ground.
See this thread for details:
http://arduino.cc/forum/index.php/topic,96747.0.html

In the mean time I'll go off and test the latest zip file ( LiquidCrystal_v1.2.0.zip) with Arduino 1.0.
I've not seen the issue you are seeing, but lately I've only been running
the pre-release version of the library. I'll go try a bone stock Arduino 1.0
with the library from the latest zip and see if there is an issue.

--- bill

Update:
I have downloaded LiquidCrystal_v1.2.0.zip ( https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/LiquidCrystal_v1.2.0.zip )
and used it to replace the LiquidCrystal library in bone stock download of the Arduino 1.0 IDE.
All the included example sketches compile without issue.

In looking closer at the example sketch that got the errors, (should have seen this earlier),
that sketch will not compile with the standard Arduino 1.0
It is a pre 1.0 sketch.
0 (zero) is an ambiguous type in C.
The Arduino Print class use C++ overloading and the Arduino team did not include enough functions
in Arduino 1.0 to catch zero. This is an Arduino library issue. It is easily fixed by either modifying the print class
(which is what Teensyduino has done for the teensy boards) or you can modify your sketch.

To modify your sketch you must type case zero.
So things like:

  lcd.write(0);

need to be:

  lcd.write((char)0);

or

  lcd.print((char)0);

All the examples that come with the new library like Hello_World_4bit.ino have this modification
already in them.

--- bill

@bperrybap - thank you for your timely warning in thread:
http://arduino.cc/forum/index.php/topic,96747.0.html

However please note at Reply #10 to that thread, that I posted a simple fix to the cct error you point to inherent in the DFRrobot-007 LCD keypad shield.

Hopefully DFRobot themselves will point to this fix themselves from within their support documentation.

And with regard to the "Custom Characters" sketch compile error, I much appreciate your effort in explaining that - the 0 (zero) as an ambiguous type in C not being caught in the Arduino Print class - is an inherent error of the IDE, and not the New LiquidCrystal library.

However as a learning exercise I continued to try and see whether you advice could 'fix' the original error through replacing the offending line of code with your example:

lcd.write((char)0);

but am still encountering a compilation error as follows:

CustomCharacter.cpp: In function 'void setup()':
CustomCharacter:114: error: call of overloaded 'write(char)' is ambiguous
/Applications/Arduino.app/Contents/Resources/Java/libraries/LiquidCrystal/LCD.h:479: note: candidates are: virtual size_t LCD::write(uint8_t)
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Print.h:49: note: size_t Print::write(const char*)

If I alter the offending code to:

  lcd.print((char)0);

the compile is successful but the sketch does not run when uploaded.

dweston,
I'm so sorry on both counts.

write() wants an unsigned char. Shame on me. I should have looked to make sure and then tested it.

The proper code would be:

xxx.write((uint8_t) 0);

or
xxx.print((char) 0);

moral of the story: print "char"s and write "bytes".

I tested your exact example sketch after changing the
lcd.write(0); to lcd.write((uint8_t) 0);

It worked on my lcd shield. (mine is same pinout as the DFR)

I'm not sure what the issue is about not running.
Which version of the library are you using? The tip of the tree?
with backlight control?
Are you using the backlight control?
(in RC5 library will use it during begin() if it is in the constructor)
Was the shield working ok with backlight control after the mod?

--- bill

Bill

  lcd.write((uint8_t) 0);

works perfectly on my DFRrobot-007 LCD keypad shield. Thank you.

I am indeed using back light control now that the cct. error has been corrected. A working code example involving back light control is:

//Sample using LiquidCrystal library
#include <LiquidCrystal.h>

/*******************************************************

This program will test the LCD panel and the buttons of
the DFRobot LCD Keypad Shield for Arduino
Product code : RB-Dfr-07
http://www.robotshop.com/dfrobot-lcd-keypad-shield-arduino-1.html

Note cct error identified by Arduino forum discussion at:
http://arduino.cc/forum/index.php/topic,96747.0.html
which advises insertion of a Germanium 1n34a or a Schotky 1N5819
diode between pin 10 and the base of Q1 (K to pin 10).

sample code originally by Mark Bramwell, July 2010
modifications by Dion Weston, March 2012



********************************************************/

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// define some values used by the panel and buttons
int backLight   = 10;    // LCD Panel Backlight LED connected to digital pin 10
int lightLevel  = 255;   // Initialise light full on
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

// read the buttons
int read_LCD_buttons()
{
 adc_key_in = analogRead(0);      // read the value from the sensor 
 // my [Mark Bramwell's] buttons when read are centered at these values: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 if (adc_key_in < 50)   return btnRIGHT;  
 if (adc_key_in < 195)  return btnUP; 
 if (adc_key_in < 380)  return btnDOWN; 
 if (adc_key_in < 555)  return btnLEFT; 
 if (adc_key_in < 790)  return btnSELECT;   
 return btnNONE;  // when all others fail, return this...
}

void setup()
{
 lcd.begin(16, 2);              // start the LCD library
 lcd.setCursor(0,0);            // move cursor to beginning of line "0"
 lcd.print("Backlight adjust"); // print a simple message
// Serial.begin(9600);            // initialise serial communications:

}
 
void loop()
{
 analogWrite(backLight, lightLevel);
 lcd.setCursor(13,1);            // move to position 13 on the second line
 lcd.print(lightLevel);

 lcd.setCursor(0,1);            // move to the beginning of the second line
 lcd_key = read_LCD_buttons();  // read the buttons

 switch (lcd_key)               // depending on which button was pushed, we perform an action
 {
   case btnRIGHT:
     {
     lcd.print("LED On          ");
     lightLevel = 255;
     break;
     }
   case btnLEFT:
     {
     lcd.print("LED Off         ");
     lightLevel = 1;
     break;
     }
   case btnUP:
     {
     lcd.print("LED Fade Up     ");
     if (lightLevel < 255) lightLevel += 1;
     break;
     }
   case btnDOWN:
     {
     lcd.print("LED Fade Down   ");
     if (lightLevel > 1) lightLevel -= 1;
     break;
     }
   case btnSELECT:
     {
     lcd.print("Select          ");
     break;
     }
     case btnNONE:
     {
     lcd.print("                ");
     break;
     }
 }
 
}

Hi folks,

I have just published release 1.2.1 of the New LiquidCrystal library. So what do we have on this release:

  • improved backlight control
  • enhanced support for shift register control: 2 wire, 3 wire and 1 wire (preview)
  • if it was fast, now is even faster: for the shift register configurations, in some cases 5.55 times faster than the standard (courtesy of bperrybap)
  • reorganized and cleaned up a bit
  • gone through intensive testing

Check it out @ https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
Download it @ https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads

Within the coming days I will be updating the wiki to improve the schematic section, it will also have for each library a description as to how to configure it.

All this with the contribution of:

  • bperrybap
  • piccaso

The latest library also works on Chipkit.
(Has been tested on the Uno32)
So you can use the same LCD interfaces and backlight control on the pic32 based
Arduino boards using mpide.

There are also some new examples.
LCDiSpeed can be used to show the speed of the LCD interface.
It will tell you how fast a single character and how fast the full
display can be updated.
(See the sketch for details)

--- bill

Thanks again fm, bperrybap and piccaso

@bperryap

For what it may be worth I obtained the following speeds using a DFRrobot-007 LCD keypad shield coupled to an Arduino Duemilanove using the LCDiSpeed sketch:

(ByteXfer) 85uS
Frame/Sec (FPS) 345.78
Frame Time (Ftime) 2.89mS

Am I right in assuming the new Liquidcrystal library doesn't support event handling as in: addEventListener in the old version?
Also, prior to writing to LCD (write/print), port pins are not set/reset so as to allow usage of pins by other device (multiplexing)?

All these features would have to be built around it. See the library as a generic LCD driver, adding a listener in the application and callbacks is a trivial task. Arbitrating pin usage is also trivial and the library doesn't constrain you, further more this is application dependent, not the responsibility of the driver. Why do you want to penalise users if they don't use muxing, for example?

My apologies, I posted out of context...

In agreement in relation to the first point, it doesn't need it, as to multiplexing, the driver already ensures the pins are set prior to writing therefore it already supports multiplexing...

I incorrectly assumed the new driver did do pin assignment before writing as a sketch (using shared/mulitplexed pins), that worked with the old library did not work on the new... I now need to determine the real problem...
Mike