Arduino Matrix Orbital LCD Library

I’ve had an old USB LCD sitting in my htpc for the past few years.  I no longer used it for display purposes; it wasn’t even plugged into a USB port.  I knew there had to be a way for me to re purpose it for an arduino.

Luckily for me I was not the first one to attempt something like this, and there were several other sources of information on how to do it.  The best site I found was from Roo Reynolds, who did this exact thing with a slightly different lcd model.

Using his description as a guide I proceeded to connect up my LCD display, a LK202-24-USB version 1.4 display.  One thing of note that is the manual for this version does not have the correct picture of the serial interface header.  The printing of the rx/tx pin labels are incorrect, but I discovered that they should be connected just as Roo did on his sight.  Below I have connected the arduino to the LCD using an old internal pc cdrom cable.  I have only connected the Arduino Tx to the LCD Rx (green wire to cdrom cable black  wire), since for my purposes I do not need to receive information from the LCD.

lcdback

Arduino to LCD

I now had an LCD that can display information from any arduino.  Rather than connecting the arduino IDE’s serial monitor interface to read debug information, I can just connect this display.  With the use of the Software Serial library I am also able to free up the serial interface for other uses (such as XBee).

Since I wanted this code to be reusable it seemed like a good opportunity to create my first arduino library.  I wrote two classes that implement the standard commands for Matrix Orbital LCDs (LCDSerial and LCDSwSerial).  As their name implies the first class uses the serial port and the second uses a configurable new software serial port (this library is required).  Both classes implement the standard Print.h, so the print and println commands can be used.

Here is an example sketch showing the library in use, and as you can see it is easy to switch between using the serial port and the software serial port classes.

// Example sketch for Matrix Orbital LK202-24 Display.
// This should work with other MO displays, but not verified.
// You must install the NewSoftSerial library for this to compile.
// http://arduiniana.org/libraries/NewSoftSerial/
#include <NewSoftSerial.h>

// Use below include for serial lcd
#include <LCDSerial.h>

// Use below include for software serial lcd
#include <LCDSwSerial.h>

// Uncomment the below line to use the serial pins
// rxpin is 0, txpin is 1
//LCDSerial lcd;

// Uncomment the below line to use software serial
// it is set to use rxpin as 12, txpin as 13
LCDSwSerial lcd(12,13);

int x = 0;

void setup()
{
// Initialize serial port to 19200, the default for this LCD
lcd.begin(19200);

// Clear the LCD Screen
lcd.clear();
}

void loop()
{
// set cursor position
lcd.cursorSet(5,2);
lcd.print(”S “);
delay(5000);

// move cursor left
lcd.cursorLeft();
lcd.print(”L”);
delay(5000);

// move cursor right
lcd.cursorRight();
lcd.print(”R”);
delay(5000);

// return cursor home and down
lcd.cursorHome();
lcd.println(”H”);
delay(5000);

// print character after new line
lcd.print(x);
delay(5000);

// move cursor back one space
lcd.backspace();
lcd.print(”B”);

x++;
}

Now in future arduino sketches I can just create an instance of one of these classes and have access to all of the lcd commands.  If you are concerned about the class size you can comment out the commands that you do not intend to use from the .h and .cpp files in the library.

lcdfront

Laserpup LCD Library in Use

Download the LCDSerial Library!

May 29, 2009 • Tags:  • Posted in: Projects

2 Responses to “Arduino Matrix Orbital LCD Library”

Leave a Reply