Arduino + HD44780 LCD Module

Posted by jiGGaK on January 13th, 2008

I’ve written a library for interfacing the Arduino with HD44780 based LCD modules. For now it lives here on my site, but if it’s popular enough it might need to move somewhere like the Arduino Playground.

Check out the Arduino LCD Library page for more details.

Sample animation demo


Josh July 8th, 2014

Hi Steve,

I haven’t been doing much arduino development lately so I’m not sure if the libraries directory has changed. Check out this page:

http://arduino.cc/en/Guide/Libraries

Looks like it describes how to manually install libraries.

Steve July 7th, 2014

Hey, thanks for the library. I haven’t gotten it working yet, but the readme file askes me to place files in locations that no longer exist given that the arduino software has been updated since your last release. If you have any info on that, I’d be grateful.

Nathan June 12th, 2009

Adjusting the contrast did work. I hate how often electronics can make you feel stupid :)

Thanks for your help. Awesome library. Out of the 5 I tried, it has been the only one that has worked.

jiGGaK June 12th, 2009

Nathan,

I just tested my 16x2 display in two line mode and it works fine. For example to print hello world on two lines:

lcd.print(hello);
lcd.move_to(1, 2);
lcd.print(hello);

If you don’t see anything at all in 2line mode, you might try adjusting contrast. Sometimes I find it needs to be tweaked when switching modes.

If this doesn’t help I’m afraid I’m out of ideas. Each LCD can sometimes have it’s own quirks I’m afraid.

Nathan June 12th, 2009

I’m having problems writing to the second line of my 16x2 LCD. It works great when only using the first line. When I OR the parameter FUNCTION_2LINE, nothing at all is displayed on the LCD, it doesn’t print on the first line either.

Even when in 1LINE mode, using the move_to(17,1), only messages on the first line are printed.

I am attempting to do this within the Hello_4pin example included with your code.

Any help or suggestions will be greatly appreciated. Thanks for writing this library, it has been a great help!

Erik January 8th, 2009

Hey, I just wanted to say thanks for the library! I spent some time trying to use the ones listed on Arduino Playground, and I was getting periodic non-sense characters (katakana, question marks, etc.)…using your library, everything fired right up!

If you’re interested, I’m using a Seiko SII L1682 display that I got from a Surplus store and it seems to be fully compatible.

jiGGaK October 23rd, 2008

Matt,

The only thing I can think to suggest is just double check that the pins are all connected correctly and that your code reflects that.

I’ve used this library with pin assignment different than the defaults before without a problem.

matt aspen October 22nd, 2008

Ok, but in you README (and examples) you say: RS -> 1 RW -> 2 E -> 3 D0 -> 4 … D7 -> 11

So, I tried the 4 pin ‘hello world’ with this mapping:

lcd.set_ctrl_pins(CTRLPINS(10,9,8)); // RS->10, RW->9, E->8
lcd.set_data_pins(_4PINS(4,5,6,7)); // D4->4, D5->5, D6->6, D7->7

and don’t see anything

Before, when I used

lcd.set_ctrl_pins(CTRLPINS(1,2,3)); // RS->1, RW->2, E->3

It worked.

What I am missing here?

Thanks, –MA

jiGGaK October 20th, 2008

Matt,

What does get displayed? I would have expected your use of itoa function to work as expected.

Also, since you are using the Serial library, be sure you are NOT using pins 0 and 1 for your LCD. These pins are used by the Serial library.

matt aspen October 20th, 2008

Hi,

Thank you for writing this library.

I have a question.

I was successfully able to set up and execute the “Hello World” example from the bottom of page: http://www.slashdev.ca/arduino-lcd-library/

I then modified it using Arduino’s Serial library: I sent a message and want the controller to print my text to the lcd.

The issue I’m having is that the Serial.read() returns an ‘int’ but the print for the LCD takes in a ‘char’ or ‘char*’.

I tried several things:

  1. integerRead = Serial.read();
  2. Serial.println( integerRead, BYTE );
  3. lcd.print(itoa(integerRead, charBufferArray, 10));
  4. lcd.print(Serial.read());
  5. itoa(integerRead, charArray, 10)

but none of these display what I want; the text that I’m sending.

Basically, what I want to do, again, is to read the characters that I’m sending via Serial (int) and print the ascii characters on the lcd.

Thanks, –MA

arkadian August 15th, 2008

Great library! I’m an arduino newbie and today I wasted a day trying to get a 16x2 lcd to work in a 4-pin mode. Your library saved me! The only thing I found strange was that (to get my lcd to work) I had to insert a small delay between two consecutive lcd commands i.e.

lcd.clear();delay(3);
lcd.move_to(1,1);delay(3);
lcd.print("Value: ");delay(3);

Thanks for sharing this library mate!

jiGGaK July 10th, 2008

Allan,

Well the sample seems to work on my LCD which is also a 20x2 but from a different manufacturer. A couple of things you could check:

  • you have the latest version (0.2, see ChangeLog and Lcd.h)
  • all control pins are connected correctly (RS,RW,E)

Apart from that I’m afraid me trying to debug this would be impossible without your model of LCD on hand. If you are feeling courageous, I’d love to get a patch from you if you figure out the problem. I suspect the check_bf function in LCD.cpp is not working correctly.

Allan July 9th, 2008

Josh, First, thanks for the work on the library. It looks really clean and I’ve found it much easier to follow than the other’s out there.

I’ve been trying to use your library with an Hitachi lm032L 20x2 lcd in four bit mode and I’ve run into a problem. When I try your hello_4pin example the text scrolls across the screen. It starts out Hello World! and then ello World!! and so on. It seems that there is some sort of buffer corruption or that something is off by a bit somewhere. –Thanks.

Ben June 26th, 2008

Thank you! That’s all I needed! Great library!

jiGGaK June 26th, 2008

If you want to use the send() function, just move it’s declaration in Lcd.h to the public section.

Ben June 25th, 2008

Is there just a generic function to send a command? Like the other one (that I’m sure you’ve seen, you referenced other, sloppy ones) had a commandWrite where I could send little things. If I wanted something like that, what could I do? I saw there was a send, but it’s apparently ‘protected’ (private?). Thanks! Glad I got this working, but the newer one not working still puzzles me. (I got a similar effect to what I was getting on the new version when RW was left floating with the 0.1 code, expect this was scrolling, I assume shift is initialized when the Lcd object is created? That may mean something, or maybe not :D)

Ben June 25th, 2008

Heh. Version 0.1 works Sorry about that

jiGGaK June 25th, 2008

Ben,

Forgive me for asking, but when you went back to the old version did you connect the RW pin to ground?

Ben June 25th, 2008

I did have the RW attached on the the newer version, when I tried the old version, I got nothing. I redefined the pins, compiled both the cpp file and the Arduino sketch and uploaded, but nothing happened on the LCD, not even a cursor

jiGGaK June 25th, 2008

Ben,

I did update the library in March. In version 0.1 (first release) all commands sent to the LCD where followed by a fixed sleep interval. This is technically not the way these LCD’s should function, so I modified the library to poll the busy flag (basically indicates the LCD is in the middle of an operation) and released a second version, 0.2.

As a result of this change, the wiring of the LCD changed and it now requires that all three of the control pins be connected (RW,RS,E). In version 0.1 only RS, E where required. There is a blurb in the README file that describes the wiring requirements.

Today, I modified the arduino lcd library page to provide a download link to version 0.1. You might try this old version to see if it fixes the problem.

Ben June 25th, 2008

Hi, thanks for the response. I”m using 8-pin mode, print works, but something like lcd.print(‘a’); prints ‘a ‘. The LiquidCrystal library on the Arduino playground works just as it should with this LCD, but lacks features like moving the cursor directly, so I wanted to use yours. I notice someone else had this problem too, here: http://www.slashdev.ca/arduino-lcd-library/ That’s what I was getting, the reason it’s flickering is because the home command was sending the cursor to a random spot, usually (always?) less than 0, so you may get “llo, world” covering up “hello, wo” to give you “llor, worldrld”, but it would do that all at a very rapid pace giving it the illusion of random letters flickering. Hope that helps. I’ll try a few debugging tricks on my end here, but I wonder if there may be a problem in the version of the code you uploaded? It seemed to work in February, did you upload a newer version between then and June? If not, then it’s something else, but I’m not sure what….

jiGGaK June 25th, 2008

Hi Ben,

Sadly it seems that even though most LCD’s use the HD44780 IC, each one seems to behave slightly differently. The two modules I have seem to work great.

Are you using your LCD in 4 pin or 8 pin mode? Do any of the functions work, such as print()?

If you want to debug this problem, you might try modifying the microsecond delays in either the enable function or the check_bf function in Lcd.cpp.

Ben June 24th, 2008

Hi, I’d really like to use this since it has multi-line LCD support, but I’m having a few issues. The lcd.home() and lcd.clear() functions seem to just put the cursor at some random spot and when I try to output data, I get a space after each character… Any ideas what’s wrong? The LCD’s hooked up right and contrast is fine… No clue what’s wrong

jiGGaK February 8th, 2008

Thanks Mike. I’m glad you like it.

To print to the second line, use the move_to() method to ‘move’ to the a given location.

You can enable 2LINE mode by OR’ing the function parameters:

Lcd lcd = Lcd(20, FUNCTION_4BIT | FUNCTION_2LINE);
lcd.move_to(1,2); // move to col 1, row 2
...
lcd.move_to(1,3); // move to col 1, row 3

It’s worth mentioning that even in 1LINE mode, the lcd acts as one long line of characters. So to move to column one of the second line you would move_to(21,1).

Having said that I haven’t tested all of this much so you might need to play with it a bit. Feel free to post some sample code if you find it doesn’t work right for you and I’ll give it a try here. I have a 20x4 display here somewhere I can test with.

Happy Arduino’ing!

Bellyacres February 7th, 2008

This has to be the best LCD effort for Arduino I’ve come across. My dumb non programmer, newbie question is how do I call or setup the constructor for a 2 line display? I can get the library working and get things to the display. Only one line though…

Also looking through the code (not that I grok it) I don’t see any indication of > 2 line support. I have a 4 x 20 around here also. What would it take to add support for that?

Thanks for the great work on this library and any help that you may offer.

Mike