Serial Graphic LCD Hookup

Contributors: JoelEB

Pages

ASCII Commands

The Graphic Serial LCD Backpack is designed to be controlled by a variety of means. One of which is through a serial terminal. This can be useful if you want to use a personal computer as your control device. You can also send commands to the backpack in real time using the ASCII commands. This is useful for testing the LCD before embedding it into a project. Here is a full list of the ASCII commands.

Note: There are several instances where you will need to send ASCII values that require certain, unusual key presses. Anywhere you see /, this means that you have to press both the Control key and that character on your keyboard at the same time. If you are using a Mac, some of these commands need to be issued in a slightly different manner. For any command that doesn’t work using control, try using the unicode version of that character.

All commands are preceded with “|”, or ASCII decimal 124 (0x7C). This tells the display that a command sequence follows. Before any of the following commands are given, they must be preceded with “|”. The actual character “|” is not (and cannot) be printed to the screen.

Clear Screen

Sending “<control>@ (0x00)” clears the screen of all written pixels. If you’re operating in normal mode, all pixels are reset. If you’re operating in reverse mode, all pixels are set. An example of a “clear screen” command would be to send 0x7C 0x00, or from a keyboard send “|” and <control>@.

Demo Mode

Sending “<control>d (0x04)” runs demonstration code. This is in the firmware just as an example of what the display can do. To see the demonstration, send 0x7C 0x04, or from a keyboard send “|” and <control>d.

Reverse Mode

Sending “<control>r (0x12)” toggles between white on blue and blue on white on the 160x128 pixel display and black on green and green on black on the 128x64 pixel display. Setting the reverse mode causes the screen to immediately clear with the new background. To set the reverse mode, send 0x7C 0x12 , or from a keyboard send “|” and <control>r. This setting is saved between power cycles. If the display is turned off while in reverse mode, it will next power up in reverse mode.

Splash Screen

Sending “<control>s (0x13)” allows or disallows the SparkFun logo to be displayed at power up. The splash screen serves two purposes. One is to put our mark on the product, but the second is to allow a short time at power up where the display can be recovered from errant baud rate changes (see Baud Rate for more info). Disabling the splash screen suppresses the logo, but the delay remains active. To disable the splash screen, send 0x7C, 0x13, or from a keyboard send “|” and <control>s.

Set Backlight Duty Cycle

Sending “<control>b (0x02)” followed by a number from 0 to 100 will change the backlight intensity (and therefore current draw). Setting the value to zero turns the back light off, setting it at 100 or above turns it full on, and intermediate values set it somewhere in- between. The number setting in the command sequence is an 8-bit ASCII value. As an example, to set the backlight duty cycle to 50, send 0x7C 0x02 0x32, or from a keyboard send “|”, <control>b and “2”.

Change Baud Rate

Sending “<control>g (0x07)” followed by an ASCII character from “1” to “6” changes the baud rate. The default baud rate is 115,200bps, but the backpack can be set to a variety of communication speeds:

CharacterBaud Rate
"1"4800
"2"9600
"3"19200
"4"38400
"5"57600
"6"115200

As an example, to set the baud rate to 19,200bps, send 0x7C 0x07 0x33, or from a keyboard send “|”, <control>g and “3”. The baud rate setting is retained during power cycling, so if it powers down at 19,200bps, it will next power up with that setting.

In a pinch, the baud rate can be reset to 115,200. During the one second delay at power up, send the display any character at 115,200bps.

Set X or Y Coordinates

Sending “<control>x (0x18)” or “<control>y (0x19)” followed by a number representing a new reference coordinate changes the X or Y coordinates. The X and Y reference coordinates (x_offset and y_offset in the source code) are used by the text generator to place text at specific locations on the screen. As stated earlier, the coordinates refer to the upper left most pixel in the character space. If the offsets are within 6 pixels of the right edge of the screen or 8 pixels of the bottom, the text generator will revert to the next logical line for text so as to print a whole character and not parts. As an example, to set x_offset to 80 (the middle of the horizontal axis of the 160x128 pixel display) send 0x7C 0x18 0x50, or from a keyboard send “|”, <control>x and “P”. Attempting to set values greater than the length of each axis result in maximizing the respective offsets.

Set/Reset Pixel

Sending “<control>p (0x10)” followed by x and y coordinates and a 0 or 1 to determine setting or resetting of that pixel. Any pixel on the display can independently set or reset with this command. As an example, to set the pixel at (80, 64) send 0x7C 0x10 0x50 0x40 0x01, or from a keyboard send “|”, <control>p, “P”, “@” and <control>a. Remember that setting a pixel doesn’t necessarily mean writing a one to that location, it means to write the opposite of the background. So if you’re operating in reverse mode, setting a pixel actually clears the pixel and sets it apart from the white background. Resetting that pixel causes it to be white like the background.

Draw Line

Sending “<control>l (0x0C)” followed by two sets of (x, y) coordinates defining the line’s start and stop, followed by a 0 or 1 determines whether to draw or erase the line. As an example, to draw a line from (0,10) to (50,60) send 0x7C 0x0C 0x00 (x1) 0x0A (y1) 0x32 (x2) 0x3C (y2) 0x01, or from a keyboard send “|”, <control>l, <control>@, <control>j, “2”, “<” and <control>a. To erase the line (and leave surrounding text and graphics unchanged), submit the same command but changing the last <control>a to <control>@.

Draw Circle

Sending “<control>c (0x03)” followed by x and y coordinates defining the center of the circle, followed by a number representing the radius of the circle, followed by a 0 or 1 determines whether to draw or erase the circle. As an example, to draw a circle at center (80, 64) with radius 10 send 0x7C 0x03 0x50 0x40 0x0A 0x01, or from a keyboard send “|”, <control>c, “P”, “@”, <control>j and <control>a. To erase the circle (and leave surrounding text and graphics unchanged), submit the same command but changing the last <control>a to <control>@. Circles can be drawn off-grid, but only those pixels that fall within the display boundaries will be written.

Draw Box

Sending “<control>o (0x0F)” followed by two sets of (x, y) coordinates defining opposite corners of the box, followed by a 0 or 1 determines whether to draw or erase the box. This command is exactly like the draw line command, but instead of drawing a line you get a box that exactly contains the line between the given coordinates. As an example, to draw a rectangular box around the line from (0,10) to (50,60) send 0x7C 0x0F 0x00 (x1) 0x0A (y1) 0x32 (x2) 0x3C (y2) 0x01, or from a keyboard send “|”, <control>o, <control>@, <control>j, “2”, “<” and <control>a. To erase the box (and leave surrounding text and graphics unchanged), submit the same command but changing the last <control>a to <control>@.

Erase Block

Sending “<control>e (0x05)” followed by two sets of (x, y) coordinates defines opposite corners of the block to be erased. This is just like the draw box command, except the contents of the box are erased to the background color. As an example, to erase a rectangular block around the line from (0,10) to (50,60) send “0x7C 0x05 0x00 (x1) 0x0A (y1) 0x32 (x2) 0x3C (y2)”, or from a keyboard send “|”, <control>e, <control>@, <control>j, “2” and “<”.


Want more information about SparkFun's classes? Interested in getting involved with teaching electronics? Just want to talk? Sign up for our newsletter, or contact our education department.

SparkFun is a company built around one core idea – sharing ingenuity. We think everyone should have the hardware and resources to learn and play with cool electronic gadgetry.

Share, give, learn, SparkFun.

Do you regularly instruct classes and workshops in a formal or informal learning environment? SparkFun offers Educator Discounts to people teaching and sharing electronics.

Find out more.