Sunday, July 10, 2011

Dual HD 44780 Controller Liquid Crystal Library for Arduino

I came across a four row LCD panel while browsing at an electronics store: the model name was WM-C4004A. I wasn't sure if I could drive it through an Arduino but decided to try. It was easy to drive once I hunted down the datasheet for the WM C4004A, a dual HD44780 controller, and understood the controller.

There is a good Arduino library for driving HD 44780 compatible controllers and I modified the LiquidCrystal library to drive two separate controllers. The usage is identical to the LiquidCrystal library. You specify the Register Select (RS) and enable bits for both controllers, the data pins, and the rows and column per controller. Then you can seek() and write() through Arduino.

My modifications are available as the  LiquidCrystalDual library. Download the library: LiquidCrystalDual.tar.gz or Unzip and place the contents in the libraries/ directory in the arduino installation.

Here is a small example program (there is a detailed program in the examples/ menu in the Arduino IDE).

#include <LiquidCrystalDual.h>

// 2 controllers: RS, RW, EN1, EN2, D4, D5, D6, D7
// We have the RS (RS=12) line, *no* RW line (RW=-1),
// two enable lines (EN1=6, EN2=7),
// four data lines (D4=11, D5=10, D6=9, D7=8)
LiquidCrystalDual lcd(12, -1, 6, 7, 11, 10, 9, 8);

void setup()
  // I have 40 characters and two lines per controller.

  // Move to the first column of second row.
  lcd.print("Line 1: Hello");
  lcd.setCursor(0, 1);
  lcd.print("Line 2: World");
  // Move to the second controller
  lcd.setCursor(0, 2);
  lcd.print("Line 3: Four...");
  lcd.setCursor(0, 3);
  lcd.print("Line 4! Lines!");

void loop()
  // Do nothing.