Raspberry Pi with Hitachi HD44780

- tags: cpp, hardware, programming, raspberry pi, rpi-hw - 8 comments

I just released version 0.2.2 of Rpi-hw library and, as you can see below, this version finally supports LCDs compatible with the Hitachi HD44780 controller.

Hitachi HD44780 interfacing - Video

You can manage an HD44780-based LCD instantiating the class display::hd44780, defined in the header file “rpi-hw/display/hd44780.hpp”.

Its constructor method takes the list of GPIO pins used by the device (either in 8-bit or 4-bit mode) as in following example:

display::hd44780( RS, E, D0, D1, D2, D3, D4, D5, D6, D7 );
display::hd44780( RS, E, D4, D5, D6, D7 );

The class has an internal data buffer, therefore you no need to read the data from the display controller. Remember, however, that you must connect the RW pin to GND.

Hitachi HD44780 interfacing (8-bit mode) - Circuit

Hitachi HD44780 interfacing (8-bit mode) - Circuit

The following example show how to print “Hello world!” on your display:

// Include Rpi-hw headers
#include <rpi-hw.hpp>
#include <rpi-hw/display/hd44780.hpp>

// Use Rpi-hw namespace
using namespace rpihw;

int
main( int argc, char *args[] ) {

    // Create the display controller
    display::hd44780 dev( 14, 18, 4, 17, 21, 22 );

    // Initialize the 20x2 display
    dev.init( 20, 2 );

    // Move the cursor position
    dev.move( 2, 0 );

    // Write a string at cursor position
    dev.write( "Hello World!" );

    return 0;
}

This uses the following GPIOs: 14 (RS), 18 (E), 4 (D4), 17 (D5), 21 (D6), and 22 (D7). To compile it (or any other programs using the library) use the command:

g++ `pkg-config --libs --cflags rpi-hw` <SOURCE> -o <TARGET>

You can find more information on the reference manual and on the wiki.

Did you find this article helpful?

8 comments

  1. Thanks a lot for your great work !
    It works fine with my MDLS 20265K LCD display =)

    Hanzohatoryv on Sun, 7 Apr 2013 @ 12:34 pm user image
  2. Thank you, Hanzohatoryv..
    If you are interested, the next version of the library will include the Philips PCD8544 (Nokia 3310) driver and much more.. ;)

    admin on Sun, 7 Apr 2013 @ 2:00 pm user image
  3. Can I join pins 3 and 15 directly to GND on Pi?

    Bartek on Tue, 10 Sep 2013 @ 11:36 am user image
  4. Hi Bartek,

    Are you referring to the pin VO (contrast adjustment) and the backlight cathode? Usually you can connect them directly to GND, but to be sure consult the datasheet of your display.

    admin on Tue, 10 Sep 2013 @ 7:58 pm user image
  5. I would like to use it with my Hitachi HD44780 and I2C. Is possible ?

    Pedro Rodrigues on Wed, 20 Aug 2014 @ 4:40 pm user image
  6. Hi Pedro,

    HD44780 doesn’t support I2C, but you can use an I/O expander like MCP23008 or MCP23S08 to connect it to the I2C bus.

    Regards,
    Giacomo

    admin on Sat, 23 Aug 2014 @ 11:48 am user image
  7. I have HD44780 with LCM1602.

    I’m have simple python code working with some text and info like CPU, TEMP, DATE/TIME. However i would like to others things like scroll and show big characters and custom characters. Image Show Time Clock in full LCD that use all 4 lines.

    Thanks

    Pedro Rodrigues on Fri, 5 Sep 2014 @ 5:10 pm user image
  8. Hey,

    Did you use Fritzing to draw the schematics?

    Can you please share the 20x4 LCD part file?

    Thanks

    Vasco on Tue, 7 Oct 2014 @ 3:29 pm user image