There are currently a number of libraries and tutorials available for interfacing the Arduino with a standard HD44780 based LCD module, but they aren’t complete and you have to edit the source code to change pin numbers and use a different library for 4bit and 8bit mode.
So I decided to write another. This one lets you set the pin mapping (without modifying the source) and supports both 4bit and 8bit mode. It also supports all documented features of the HD44780 controller including defining custom characters.
The library is licensed under the GNU GPL.
You can always find the latest source code in here.
Latest snapshot can be downloaded here.
The first release 0.1 does not require the RW pin to be connected to the arduino since it does not check the busy flag of the LCD. This is likely less reliable but if you have problems with the latest version you might try this one instead.
Installing
You can find a simple schematic in the download package, or here.
Download the source and extract it to the Arduino libraries directory.
tar -xzf lcdlib-0.X.tar.gz
cp -r lcdlib-0.X /path/to/arduino/hardware/libraries
Getting Started
The best way to get to know the library is to read the header file Lcd.h. I have documented all of the functions and the LCD class rather thoroughly in there. Included with the package is also a README file and a few samples.
Here is a Hello, World! program to get you started with the basics. This sample uses 4pin mode.
/*
* Simple hello world program in 4 pin mode.
*/
#include <Lcd.h>
// LCD module is 16 columns wide, use 4 pin mode
Lcd lcd = Lcd(16, FUNCTION_4BIT);
char msg[] = "Hello, World!";
void setup()
{
// for the sake of demonstration change pin assignment
lcd.set_ctrl_pins(CTRLPINS(1,2,3)); // RS->1, RW->2, E->3
lcd.set_data_pins(_4PINS(4,5,6,7)); // D4->4, D5->5, D6->6, D7->7
lcd.setup(); // setup arduino and initialize LCD
}
void loop()
{
lcd.home(); // return cursor to home possition
lcd.print(msg); // print the ever so familiar message
}
Getting Help
Please use the forum to ask questions or get help using the library.
Comments 25
Hi,
I´m trying to get my LCD display running. For this I want to use your library. I did put your LCD-lib files in the Arduinio-libraries.
I did connect:
RS->1, RW->2, E->3
D4->4, D5->5, D6->6, D7->7
When I want to try your “hello world” example the chraracters are always flickering (changing very fast).
Posted 12 Jun 2008 at 12:57 am ¶Only taking all the commands from the loop – I get the thing running.-
Could you give me a tip.
thanks!
frank
Frank,
Does the LCD display the correct message despite the fact that it is flickering? If so, you might try putting a short delay in the loop (100 milliseconds or so).
Also, can you tell me the exact model of LCD you have? Maybe there is a clue in the spec sheet somewhere.
Posted 12 Jun 2008 at 8:32 am ¶I am using your LCD library for arduino, and it works wonderuflly, however i am new to the world of programming, i have a HD 44780 16×2 LCD screen, i was wondering if you could help me get text onto both lines of my LCD.
James
Posted 17 Oct 2009 at 3:55 pm ¶James,
Initialize the Lcd object like so:
Then use the move_to() function to print text on the second line:
okay, thanks! i tired what you suggested, however try as i might, i cant get it to print on the second lind and my first line of text goes all wierd and freaky here is the code i am using…
Good evening,
Posted 26 Oct 2009 at 2:20 pm ¶I tried to installed your Lcd Lib as you propose, but it’s not working, the include statement does not find the Lcd lib, also the import library function in the scetch menu does’nt show the Lcd Lib.
I am using Mac OS 10.6. Every other libraries has not only a .h and .cpp file but also a .o file.
Can you help me ?
Thanks
Ted hatt
Ted,
Are you sure you extracted the library correctly? I am using OS X 10.5.8 with arduino IDE v0016.
My Lcd library is extracted to /Applications/Arduino/hardware/libraries/Lcd so that the final directory structure looks like:
The .o file you see in other libraries is created the first time you compile a sketch that includes the library.
Posted 26 Oct 2009 at 2:26 pm ¶As i Use the cursor and blink, please examples
Posted 27 Oct 2009 at 9:48 am ¶thank you Juan,
Posted 27 Oct 2009 at 3:37 pm ¶there is a definite problem with IDE v0017, I think there must be a copy of the library anywhere, if I follow the path in the Finder, every thing looks ok, but in -> sketch -> Import Library I do not see any Lcd library.
So I went back to IDE v0016, OS X 10.3.9 (G3 Lombard PB ): At a first glance it looks fine – unless in the #include statement the string “Lcd” is not red like in other includs and the compilation of “hello_4pin” leads to multiple error lines, all the same:
“hardware/tools/avr/bin/avr-gcc: line 2: readlink: command not found” .
May be it sounds stupid to you: IDE 17 has also a bug in the official LED support, it’s ok for 2*16 displays but not for 1*16 (it only writes to first 8 positions!), that tis he reason I looked further an found your code. I think I’m not a beginner, on my Arduino Mega runs an applications which drives an IGBT-bridge for a 2 KVA 50Hz-to-60Hz Inverter…
Can you help me further?
Thanks
Ted
Ted,
I just installed Arduino IDE 17 on OSX 10.5.8.
It appear that in this version of the IDE libraries are installed under a sub-directory of your sketchbook.
~/Documents/Arduino/libraries(see this link)
Just tried compiling a sample from the LCD library and it seems to compile fine.
Posted 27 Oct 2009 at 10:12 pm ¶Dear jiGGaK,
Posted 28 Oct 2009 at 1:13 am ¶thank you, I will try it –
but in the mean time I found out that the actual
library of IDE 16 ist in the applicaton package (-> open package -> ..), I moved your library at this place and it compiles perfect – but another miss: I use a mega board and the control pins are 48,49,44 the data pins 50,51,52,53 should work??
Thanks
The pin mapping shouldn’t have any effect.
However, on the Arduino Diecimila you need to avoid using pin 0 and 1 for the LCD if you plan to also use the Arduino’s serial port.
Posted 28 Oct 2009 at 9:35 am ¶After getting fixed all staff with the libraries there remains a major problem: On my display (1*16) I only can write to the first 8 positions. Either with your library or the “official” lib in Arduino IDE 17. What I found out: There are 2 types of 1*16 display:
Posted 03 Nov 2009 at 2:51 pm ¶a) addresses of the displayram are 0 to 15
b) first 8 positions: 0 to 7
next 8 positions: 64 to 70 (hex 40 to 47)
The type I have is b)
I think I have to buy a 2*16 instead of loosing further time with the 1*16, I will have to generate some usefull information on the second line (wich is completely unnessary in my application …)
Thank you for your patience with the old Swiss guy
Ted
Hi,
I am trying to get my LCD to display what I am writing to a serial. I have the LCD hooked up and working for 4 Bit and can easily have it say “hello world”. Here is the part of my code that I am having trouble with:
Any suggestions?
Posted 01 Dec 2009 at 4:02 pm ¶THanks
Maxine,
What exactly is the problem?
I see one problem so far. When you print to the lcd from the serial port, be sure to cast the incoming byte to a char, eg:
Otherwise, the lcd will just contain a series of numbers instead of characters.
Also, be sure that you are not using pin 0 or pin 1 on the arduino for the LCD since these pins are reserved for serial communication.
Posted 01 Dec 2009 at 4:11 pm ¶Ok I added in the char but the LCD will still not display anything. The code seems to run fine, but the LCD remains completely blank.
Posted 03 Dec 2009 at 10:18 am ¶Thanks
Maxine,
I just added a new forum! I want to start moving support discussions out of the comments (really hard to provide support this way).
http://forum.slashdev.ca/forum/1
My first thought on your problem would be to just do some basic level debugging to see if the LCD is still working while you are using the serial connection.
For example:
If you see the message, then you can start movind the lcd.print() around to verify the code is being reached.
Posted 03 Dec 2009 at 2:35 pm ¶Hello jiGGaK !
I just have a problem to write on the second line of my 2×16 display
I tried what you said “lcd.move_to(1,2);” but it doesn’t work…
The word is still on the same line, but not at the same place.
Thanks in advance
Posted 06 Jan 2010 at 7:23 am ¶Hi Arthur,
The comments have become extremely cumbersome as a means to provide support.
Therefore I’ve decided to setup a dedicated support forum! Could you please create a topic there?
support forum
Please include all relevant snippets of code in your post (ie: lcd initialization).
Posted 06 Jan 2010 at 1:52 pm ¶Is it possible to use other LCDs? I have 8 lcd ranging from 16×2 to 30×8 that I toke out of machines. Can these be used or does it have to be a specific LCD brand? If they can, how do i go about getting the pin lay out for them?
Posted 16 Sep 2010 at 1:56 am ¶devinmccloud,
Many character based LCD’s are based on the same controller: the HD44780.
If you can find some markings that indicate that your LCD’s use this controller than they will work with this library.
With respect to pinout you really need some sort of datasheet. Try and google the model numbers (if any) on the LCD’s to see if you can find some reference online.
However, typically if it is in fact based on the HD44780 it will have 14-16 pins so that would be the first indicator that your are in luck.
Posted 16 Sep 2010 at 6:02 am ¶I have a LMB162AFC LCD, but I don’t see “Hello World” on it!! How can I fix this problem??
Posted 10 Feb 2012 at 2:01 pm ¶Double then tripple check your wiring. Remember, all three control pins (RS,RW,E) need to be connected using the latest version of the library. If all else fails, try the old version that doesn’t require the E pin to be connected and instead uses constant delays to wait for commands to finish.
Posted 10 Feb 2012 at 3:07 pm ¶I have a 16*2 LCD, which I am using through I2C.
Posted 09 Aug 2012 at 12:33 pm ¶I used the basic “Hello World” Program. The connections are perfect. Only the LCD backlight is glowing but it’s not printing anything.
I’ve tried running other programmes as well but the same thing is happening.
What do you think the problem could be?
This library does not support I2C. It’s designed to use the HD44780 bus and protocol. I suspect your I2C backpack has it’s own simplified protocol.
Posted 09 Aug 2012 at 12:56 pm ¶Trackbacks & Pingbacks 1
[...] and not the one that came with Arduino because it’s an initialisation bug.It’s based on http://www.slashdev.ca/arduino-lcd-library/ and has the necessary changes to integrate the ShiftOut Library that [...]
Post a Comment