Let's Make Robots!

Serial LCD text display - hook 'em up from any platform

Gives text output from your project

** walk through in progress **

Introduction

These monochrome serial LCD text displays are apparently very popular and easy to use. But the official manual (pdf) deserves no credit for that. And that's quite uncharacteristic (...), given the usual high quality prose delivered by the Sparkfun documentation department.

Choices

There are many different text displays on the market. This walk through only discusses the kind with an HD44780 controller and a "serial backpack" based on a PIC 16F688 with open sourced firmware. These displays are produced by Sparkfun, but resellers, like Solarbotics, also have them in their shops. They come in quite a few varieties.
- five different colour combinations
- 16x2 or 20x4 characters
- 5.0 V or 3.3 V supply/data voltages
- "basic" or "serial enabled"

This walk through only discusses the "serial enabled" kind. I bought a 16x2 red on black with a 5 V supply, but my instructions should apply to any serial enabled display.

Electrical connections

Connecting to my backpack was not very straight forward. The slotted casing around the jumper header did not fit any connector I had in store. So I soldered three more pins to the empty pads on the lower right. I used a second hand jumper cable with three wires to connect to my project. I fiddled the order of the pins in the jacket to match the pinouts on either end of the cable.

The three relevant pins to recognise are:
- RX (receive data)
- GND (ground, common)
- VDD (V+, positive supply voltage, 5.0 V or 3.3 V)

Warning: there is a funny warning on the Sparkfun pages for 3.3 V displays you should probably read:
"Note: Though the silkscreen may say '5V', this is a 3.3v Serial LCD. Connect to a 3.3v power source."

Power supply

Make sure to connect the display's Ground (GND) to that of your project. Even if you supply it power from a separate source, like batteries.

Micro controllers like Picaxe or Arduino

The supply voltage should be chosen or regulated carefully. Most microcontrollers use 5.0 V, but the trend is to use lower voltages for different reasons. The next option is 3.3 V. If you still have a choice while shopping, buy a display with a supply voltage that matches your project, 5.0 V or 3.3 V. Unhappy gift recipients had better study voltage regulators.

Computer users (Mac, PC, PDP11, whatever)

Your computer will most likely not have a serial port available. You need to create a "virtual" serial port (com-port) through USB. Some of those also offer a supply voltage pin. This FTDI adapter even offers a choice of different voltages (by means of trace cutting and SMD jumper soldering, but still). This solution requires a driver for your operating system. [untested]

If you do own a stone age machine (like I do), you will find a proper serial comport (RS232 with DE9 or even DB25 female connector) on your machine. Be careful with those. The dinosaurs designed them to use voltages ranging from -12 V to +12V. If you find a pin in your comport that carries a permanent voltage, you will need to regulate it down to a safe voltage, or borrow a supply from a different source, like batteries or a nearby USB port (5.0 V). [untested]

Data connections

The display will only receive (RX) data from your project. It will not transmit (TX) any. This is relevant when trying to match different "logic levels" between project and display. Here are a few scenarios. The following tips are true for most any serial connection between incompatible devices.

Make sure to connect the display's Ground (GND) to that of your project. Even if you supply power from a separate source, like batteries. Your data connection needs a closed circuit as well.

If your project uses higher voltages then the display, you might fry the display. So, again: choose your display to match your project. Use voltage level converters if you must connect incompatible devices. [untested] Some even convert from low to high voltages. [untested]

Picaxe

Picaxe talks serial out of the box. You have two options:
- connect your display to any binary output pin (and use the command serout) [tested]
- connect your display to the serial programming connector (and use the command sertxd) [untested]

Picaxe uses "Transistor-Transistor Logic" or TTL voltages for serial communication. Those levels switch from GND to V+ (supply voltage). Your display expects the same levels. A low voltage means "idle" or "1", a high voltage means "active" or "0". Picaxe calls this convention "true signals".

A 5.0 V Picaxe should be able to talk to a 3.3 V display, provided you introduce a voltage divider, bringing down the high voltage to a low voltage. Note that the standard Picaxe "download circuit" is not such a divider. [untested]

Arduino

[untested]

Computer with USB

[untested]

Computer with proper RS232 comport

[untested]

 

Programming

to be continued...

Picaxe

The Picaxe Basic manual (pdf) mentions two commands to speak serial to any receiver: sertxd (through the programing pins) and serout (through any binary output in).

serout

[partly tested] Remember, your display expects signals that Picaxe calls "true signals". The syntax according to the manual:
SEROUT pin,baudmode,({#}data,{#}data...)

Here, "pin" is a number or name for your output pin. I am using pin 3 in my examples. The "baudmode" is a magic word that instructs Picaxe (the pre-compiler actually) to use the right signals and speed. The display, by default, expects 9600 bits per second. Also, it expects things like a start bit, a stop bit, not a parity bit and it expects bytes to have a modern 8 bits in them. This is often summarized as "9600-8N1".

Picaxes should be fine with all that, except that for the 9600 bits per second the processor's clock should run at 8 MHz, sometimes even 16 MHz. And your's might be running at a different default speed, say 4 MHz. Make up your mind: speed up your Picaxe or slow down the display. This example speeds up the Picaxe28x1 and then uses baudmode "T9600_8" aka "True signals at 9600 bps on a 8 MHz processor".

setfreq m8   ; change the frequency to 8 MHz
high 3       ; make the output pin high because high mean "idle"
serout 3, T9600_8, ("alabtu")  ;
(literal text output between quotes)

We often need no literal text, but raw bytes to be sent out - ascii code that can look like gibberish to us meat bags. Compare the following ways of sending numbers out.
serout 3, T9600_8, (13)        ; decimal thirteen aka "carriage return"
                               ;  (ask any dinosaur what that is)
serout 3, T9600_8, ($0D)       ; hexadecimal thirteen
serout 3, T9600_8, (%00001101) ; binary thirteen
serout 3, T9600_8, (b4)        ; whatever number sits in variable b4
serout 3, T9600_8, (#b5)       ; translate the number in b5 to text before sending:
                               ;  (13) comes out as ("1", "3") -
one value becomes two letters
serout 3, T9600_8, (mynumber)  ; whatever number sits in symbol-variable mynumber
serout 3, T9600_8, (#value)    ; translated value

BTW, a carriage return on itself is pretty meaningless to the display. Read on...

Multiple bytes can be sent out by stringing them together using commas.
serout 3, T9600_8, (97, 108, 97, 98, 116, 117) ; I guess most ascii is human-readable after all...

2bc.....

Arduino

[untested]

Computer with USB

[untested]

Computer with proper RS232 comport

[untested]

Magic

Your display, in default mode, will write everything and anything it receives to the first line, starting at the first column (0, 0). Then it overflows to the next line and the next. After so many lines it will return to "home" (0, 0) and start over. But sometimes you want to whisper something in its ear. Something that is not for all to read. You sometimes need to send it a command that is just for the brain inside the display. You need to speak one of the two magic words first: please or prettyplease. These magic words are merely single byte codes. In decimal, they are 124 and 254.

To understand the magic, you need to understand who you are talking to. The display comes with two chips: a PIC16F688 (pd) micro controller that runs the serial protocol and some additional tasks (like PWM'ing the back light) plus a specialized LCD driver chip called HD44780 (pdf).

 

magic word

please

prettyplease

you are talking to

PIC16F688 serial controller

HD44780 LCD driver

about

communication settings,

backlight,

LCD type,

splash screen,

reset factory settings

cursor position

clear screen

cursor type

writing direction

custom characters

decimal magic word

124

254

hexadecimal magic word

0x7C

$7C (in picaxe basic)

0xFE

$FE (in picaxe basic)

binary magic word

0111 1100

%0111100 (in picaxe basic)

1111 1110

%11111110 (in picaxe basic)

human readable character

| (vertical bar)

(black square, only in extended ascii table)

So every command byte you want to send must be preceded by the corresponding magic word. You choose how to send it - decimal, literal text, binary, hex. Make sure to directly follow the magic word with your command.

Commands for Sparkfun's serial controller

[mostly tested]

Always preceed these commands with please. See table above.

LCD type

(only use these commands if you bought the serial backpack separately)

decimal command

readable command”

20 characters wide

3

CTRL-C

16 characters wide

4

CTRL-D

4 lines

5

CTRL-E

2 lines

6

CTRL-F

baud speed

decimal command

readable command”

2400

11

CTRL-K

4800

12

CTRL-L

9600

13

CTRL-M

14400

14

CTRL-N

19200

15

CTRL-O

38400

16

CTRL-P

factory reset to 9600

(during boot up

splash screen)

17

CTRL-R

customizing

decimal command

readable command”

change splash screen to whatever is on the top 2 lines now

10

CTRL-J

backlight brightness

decimal command

hexadecimal command

0%

128

0x80

40%

140

0x8C

73%

150

0x96

100%

157

0x9D

(not valid)

158

0x9E

Commands for HD44780 LCD driver

[mostly untested]

Always preceed these commands with prettyplease. See table above.

extended commands
(according to concise reference)

decimal command

hexadecimal command

clear display

1

0X01

home cursor

2

0X02

cursor move direction "decrement" without auto shift

4

0X04

cursor move direction "decrement" with auto shift

5

0X05

cursor move direction "increment" without auto shift

6

0X06

cursor move direction "increment" with auto shift

7

0X07

 

 

 

cursor move options

add up decimal values:

add up hex values:

  no automatic shift

0

0X00

  automatic shift

1

0X01

  "decrement"

0

0X00

  "increment"

2

0X02

combined

0 - 2

0X00 - 0X02

2bc...

 


 

Claimer: if any of the artwork smells stolen, it probably is. Click them for reference. Thanks to the creators, especially the ones who won't complain about the theft.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

 

 

You are indeed the LCD walkthrough mastah!

I bow to you.

I am going center more of my comments in the furure.

The one I got has 16 pins in a row. They are labeled as follows:

GND VDD V0 RS RW E DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7 LED-(K) LED+(A)

However, when I connect it to picaxe ( GND to ground, VDD to V+ and RS (tried to connect RW as well) to the output pin) no symbols are shown. What may cause this?

 

thanks

You must own a "basic" version without serial interface. Sorry, I don't speak parallel, yet. Does this datasheet help?

Yeah, atleast now I know what each pin actually is.

 

What do you think? Any possibilities to connect "basic" version of the LCD to picaxe?

That's exactly (well almost) what Sparkfun did: by adding a PIC micro controller (programmed in a different language) they created the serial backpack. The schematics and sourcecode are all on their website.

That only proves it can be done. I chose to pay them money and receive the finished product.