Serial LCD quickstart


Welcome!

Thank you for purchasing our serial-enabled LCD! This LCD will allow your project to display all kinds of text and numbers. LCDs can be difficult to use, so we've added an embedded processor to this LCD that does the hard work for you. This LCD is easy to connect to any 5V microprocessor that has a serial port, such as an Arduino, AVR, PIC, etc.

Connecting the hardware

There are only three connections you need to make to the LCD:

signal name signal spec wire color (JST cable)
RX (receive) Serial receive (input to the display). 5V TTL level, 9600 baud (default rate, can be changed), 8 bits, 1 stop, no parity. Yellow
GND (ground) Ground for the power supply. Black
VDD (power) Power supply, this should be +5V at up to 60mA if the backlight is fully on. Red

The board has two headers with the above three signals. They are electrically identical, so you can use either one. One header is bare, the other has a 3-pin JST connector preattached to it that matches a JST cable. The cable only connects one way; press it in until it clicks. JST connectors are designed to be very snug; don't pull on the wires to disconnect it, see our tutorial on the proper way to disconnect JST cables.

(Tip: if you want to connect the display to a breadboard, tin the ends of the wires to make them easier to insert into the breadboard holes. To tin wire, strip about 1/4", and put some solder on the bare wire to make it stiffer).

Note that the RX input should be a 5V TTL-level signal directly from a 5V microcontroller or other 5V system. You should NOT connect the board to RS232-level voltages, which are +/-10V and will damage the board (see our explanation here). If you do wish to connect this display to RS232 signals, you can use a level-shifting board such as our PRT-00449 to translate the RS232 signals to TTL-level signals.

Using the display

When you power up the board, you'll briefly see a SparkFun splash screen, and then the display will go blank. To send text to the board, wait 1/2 second (500ms) after powerup for the splash screen to clear, then send text to the display through your serial port. The display understands all of the standard ASCII characters (upper and lowercase text, numbers, and punctuation), plus a number of graphic symbols and Japanese characters. See the HD44780 datasheet for the full list of supported characters.

If you send data that goes past the end of the first line, it will skip to the start of the second line. If you go past the end of the second line, the display will jump back up to the beginning of the first line. (Tip: you can simulate a scrolling window in software by copying the second line to the first line, and clearing the second line.)

Note that the Arduino and other systems with bootloaders may send "garbage" characters to the display while the system is starting up or being reprogrammed. To avoid this, you can use a software serial library to create a separate serial port from the USB port, as in the following examples.

NOTE that these examples were written for Arduino 1.0 and later. If you are using an older version of Arduino, you can download the older examples here: serial_lcd_quickstart_Arduino02.zip.

You can copy and paste these sketches into your Arduino 1.0 (or later) editing window, or download them here: serial_lcd_quickstart_Arduino10.zip.

// SparkFun Serial LCD example 1
// Clear the display and say "Hello World!"

// This sketch is for Arduino versions 1.0 and later
// If you're using an Arduino version older than 1.0, use
// the other example code available on the tutorial page.

// Use the softwareserial library to create a new "soft" serial port
// for the display. This prevents display corruption when uploading code.
#include <SoftwareSerial.h>

// Attach the serial display's RX line to digital pin 2
SoftwareSerial mySerial(3,2); // pin 2 = TX, pin 3 = RX (unused)

void setup()
{
  mySerial.begin(9600); // set up serial port for 9600 baud
  delay(500); // wait for display to boot up
}

void loop()
{
  mySerial.write(254); // move cursor to beginning of first line
  mySerial.write(128);

  mySerial.write("                "); // clear display
  mySerial.write("                ");

  mySerial.write(254); // move cursor to beginning of first line
  mySerial.write(128);
 
  mySerial.write("Hello, world!");

  while(1); // wait forever
}

Moving the cursor

A common LCD technique is to repeatedly display changing numbers such as RPM or temperature in the same place on the display. You can easily do this by moving the cursor before sending your data.

To move the cursor, send the special character 254 decimal (0xFE hex), followed by the cursor position you'd like to set. Each cursor position is represented by a number, see the table below to determine the number to send:
 

position 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
line 1 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
line 2 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207


For example, if you want to move to the beginning of the second line, send the bytes 254 192 (decimal).

Here's a slightly more complex example showing how to display data at fixed points on the display, plus the use of sprintf to convert numbers to strings (this right-justifies the numbers with leading spaces, which keeps them from "jumping around" if the number of digits changes):

// SparkFun Serial LCD example 2
// Format and display fake RPM and temperature data

// This sketch is for Arduino versions 1.0 and later
// If you're using an Arduino version older than 1.0, use
// the other example code available on the tutorial page.

// Use the softwareserial library to create a new "soft" serial port
// for the display. This prevents display corruption when uploading code.
#include <SoftwareSerial.h>

// Attach the serial display's RX line to digital pin 2
SoftwareSerial mySerial(3,2); // pin 2 = TX, pin 3 = RX (unused)

void setup()
{ 
  mySerial.begin(9600); // set up serial port for 9600 baud
  delay(500); // wait for display to boot up

  mySerial.write(254); // cursor to beginning of first line
  mySerial.write(128);

  mySerial.write("RPM:            "); // clear display + legends
  mySerial.write("TEMP:           ");
} 

int temp, rpm;
char tempstring[10], rpmstring[10]; // create string arrays

void loop() 
{ 
  temp = random(1000); // make some fake data
  rpm = random(10000);

  sprintf(tempstring,"%4d",rpm); // create strings from the numbers
  sprintf(rpmstring,"%4d",temp); // right-justify to 4 spaces

  mySerial.write(254); // cursor to 7th position on first line
  mySerial.write(134);
 
  mySerial.write(rpmstring); // write out the RPM value

  mySerial.write(254); // cursor to 7th position on second line
  mySerial.write(198);

  mySerial.write(tempstring); // write out the TEMP value
  
  delay(1000); // short delay
}

More information

Other commands are available to change the backlight level, turn the splash screen on and off (and customize it to your own text), change the baud rate, etc. See the LCD datasheet for information on all the available commands.

For a more extensive example sketch that shows oyu how to create a scrolling marquee, create a timer, display sensor data and control the backlight, downlaod the following examples:

Alternatively, you can use the SerLCD libary found on the Arduino website. If you are using Linux, you may want to try this library instead.

Tips and troubleshooting

If the display is powered up without the RX line connected to anything, the display may fill with strange characters. This is because the display is receiving random noise on the disconnected line. If you connect the RX line to a true TX port, this will not happen.

If the display is unreadable or washed out, the contrast may need to be adjusted. Send some text to the display (see the first example sketch above), then use a miniature Phillips screwdriver to gently turn the contrast trimpot labeled VR1 on the back of the display until the text is as clear as possible (please be gentle with the trimpot). This display also has a backlight that can be adjusted for best readability, see the LCD datasheet for information.

This display has a feature where if the display receives a CTRL-R character during its half-second splash screen display, it will temporarily revert to 9600 baud until power is cycled. This is to allow you to regain control of the display if you set it to an unknown baud rate. Some systems like Arduino send bootloader information out the serial port when the system starts up, which can fool the LCD into this recovery mode. If this is a problem, there are a few solutions: you can use a different pin and the NewSoftSerial library to create a TX port that doesn't get used during startup (as shown in the example sketches above), or leave the display at the default 9600 baud rate, and clear the display when your program starts.

Questions?

Enjoy your new display! If you have any problems, feel free to contact SparkFun Technical Support at techsupport@sparkfun.com.

Comments 9 comments

  • Hi, have this 16x2 LCD. Works fine once I have disconnected and reconnected ground. pressing reset button on arduino or unpowering arduino freezes the lcd on the next run….. only re-work once i have disconnected and reconnected lcd ground (thus each time I m loosing the first commands of my program, until i have done this ground unplug/plug) . FYI, I m waiting half a second after my setup and any special command sent to the lcd… anyone knows what is going wrong tks for help

  • This may be a stupid question, probably is. I just got an Mp3- Player shield, which I’m using with an Arduino Uno R3. Where exactly do I connect the LCD’s RX pin to?

    Any help would be very appreciated!

  • After sending the special command 124 and then 128-157 to adjust the brightness, you ’ll have to wait half a second to let the display settle. It isn’t mentioned in the LCD datasheet. Maybe other special commands 124 need this pause too.

  • Is there a command to make the text displayed scroll or must it be done manually?

  • I have ported LiquidCrystal library for use with the serial LCD you can look at my code here. Still working on finishing all the documentation. But putting up for now hopefully someone will find it usefull.
    http://arduino.cc/playground/Code/SerLCD
    -Thanks

  • You use the newsoftserial library, but you don’t elaborate. For those that want the library to make the examples work it is at:
    http://arduiniana.org/libraries/newsoftserial/
    You have to download and extract it to your arduino/libraries directory.
    I was able to get it working relatively easily after soldering 22 wire to the RX,GND, and VDD. You include a cable but that was not very good as it had to be tined so not good with a breadboard. If you are going to include a cable make it one that works with a breadboard then the experts can just cut it but the newbs can still play.
    I had to figure out the pin setup by looking at the sketches though.
    I think you should mention the lib you are using, how to download and install it, where to find it, etc if you plan on using non-standard install libs.
    Otherwise great product! It works fabulously.

    • as of 1.0 this is a part of the core, no need to download a library so long as you are using 1.0 or above.

    • Thanks for the comments! We’ve updated the example sketches with more information about retrieving the required library (sorry about that, we use it so often we forgot that not everyone does), and created new examples for Arduino 1.0 (which has adopted NewSoftSerial as the default SoftwareSerial library).