The LCD backpack (aka. K107) board interfaces any HD44780-based LCD (this is the vast majority of LCD’s you will encounter) with a three-wire serial interface, consisting of +5volts, ground and serial data. The board uses a programmed PIC chip, created by Maryland EE professor Peter Anderson, to convert serial commands (e.g. Serial.print(“Freeduino”) ) into LCD text.

This boards turns any inexpensive (HD44780-compatible) LCD into a serial LCD.

Hook up power, ground and data and you’re good to go. No fussy libraries or handfuls of wires. Peter Anderson’s feaure set is really robust. You can check the command summary and sample code below.

This board is engineered for microcontrollers. Brian Riley of wulfden.org has a similar board but his includes an inverter option. If you need to hook up an LCD directly to a computer RS232 serial port get his board.

LCD Serial Backpack by ModernDevice

Board is currently available through Modern Device.

Custom Character Definitions
The character strings found below can be used to define custom characters when using the K107 backpack.

  1. 040E0E0E0E1F0004 => BELL
  2. 00000103161C0800 => CHECKMARK

Command Summary

Reference adopted from http://phanderson.com/lcd106/lcd107.html

Some commands require a delay to ensure proper transmission.

Command / Comments

Suggested Pause

Example

Send Text

Serial.print(“Hello World!”);

?a

Home Cursor

Serial.print(“?a”);

?b

Destructive Backspace

Serial.print(“?b”); // backspace

?c#

Set Cursor Style:  0= none 2= blinking 3=underline

(“?c0”); // turn cursor off

?f

Clear Screen

Serial.print(“?f”);

?g

Beep (requires speaker on pin 6)

Serial.print(“?g”);

?h

Backup Cursor (Non-destructive backspace)

Serial.print(“?h”);

?i

Forward cursor

Serial.print(“?i”);

?j

Up cursor

Serial.print(“?j”);

?k

Down cursor

Serial.print(“?k”);

?l

Clear cursor line

Serial.print(“?k”);

?m

Carriage Return

Serial.print(“?m”);

?n

CRLF, carriage return & line feed,
cursor at start of next line, line cleared

Serial.print(“?n”);

?s#

Set tabs at # spaces

100 ms

Serial.print(“?s7”);
// set tab to 7 spaces

?t

Tab, advance one tab position

Serial.print(“?t”);

?x##

Position cursor on x column, (two characters are required), first column is column 0

Serial.print(“?x09”);
// cursor to column 10

?y#

Position cursor at y row, first row is row 0,
one digit only (no leading zero)

Serial.print(“?y3”);
// cursor to row 4

??

Display a “?”

Serial.print(“??”);

?!

Send direct command to LCD

Serial.print(“?!01”);

?B

Backlight Intensity – sets PWM value, two hex digits req. (00 to FF)

100 ms

Serial.print(“?BFF”);
// backlight on full brightness

?D#

Define Character “?D#1A001A001A001A00” D# = character
# 0-7 then 8 two character hex digits representing
(5 bit values top to bottom)

100 ms

Serial.print(“?D31F001F001F001F00”);
// custom character 3
// every other line black

?#

Print a custom character
numerals 0-7 are valid

5 ms

Serial.print(“?3);
// print custom character 3

?H

High output on auxiliary digital pins: valid numbers are 4,5,6

Serial.print(“?H4”);
// aux pin 4 HIGH

?L

Low output on auxiliary digital pins: valid numbers are 4,5,6

Serial.print(“?L4”);

// aux pin 4 LOW

?G

Configure for LCD geometry. Supported formats:
2X16, 2X20, 2X24, 2X40, 4X16 and 4X20.

Serial.print(“?G216”);
// configure driver for 2 x 16 LCD

Ganging up commands is OK, except for commands requiring a following  pause

Serial.print(“?x01?y1?fHello World”);
// cursor to beginning of line 1
// clear screen, print “Hello World”

Enhanced Commands

?>#

Enter BIG Number Mode (numbers only!) “?>3” X # = 3 or 4 ,

# represents number of characters displayed. (20×4 LCD’s only)

100 ms

Serial.print(“?>4”);
// enter big number mode, 4 character option.

?<

Exit BIG number mode “?<“

Serial.print(“?<“);

?C#

Define custom boot screen line # = 0 – 3

100 ms

Serial.print(“?C0abcdefghijklmnopqrst”)

?S#

“?S0” – display no screen on boot.
“?S1”  – display the configuration setting on boot
“?S2” – display the user custom text screen on boot.

Serial.print(“?S2); // custom boot screen

?* display boot screen at any time Serial.print(“?*); // show boot screen
Share

6 Comments

Chris · 02/03/2012 at 04:23

Hey, got it working (almost) baud rate was spot on, and I inverted (through jumper on k107) for rs 232 (duh) however, not sure how the code sends commands the the LCD. I am used to sending the commands as strings (ie ?A) as a newbie to C#, obviously the commands are sent as bytes, am I not getting something here. The LCD (4×20) is writing the first line “FEZ is great” on the first line , but the H in “Hello” is also on the first line with “ello” on line 3. I get that the code is set up for a 2X16 LCD but how????? thanks so much for the guidance so far 🙂

pixel · 02/02/2012 at 17:50

I don’t see anything particularly wrong in the code snippet. But there are 2 things I noticed that might be causing the problem.

1) Make sure your K107 is actually set to work at 9600 baud. I think the newer versions ship with a higher default baud rate (You can check by just using your PICAXE setup to test the LCD).

2) I am no expert at C# but I think you need to use a different function in place of Encoding.UTF8.GetBytes(s). The UTF-8 translation is probably messing up the actual bytes being sent across the serial line.

Hope that helps with your problem.
Pixel

Chris · 02/02/2012 at 04:48

Hi Pixel

I will cut and paste the code in here. I have couple of questions… Why can I only find code that sends byte data to the serial port (I am used to SEROUT on a picaxe, so easy) and I would imagine that the commands for the LCD in this code are all byte data, but they should be string data with the K107 commands starting with “?”. So frustrating to not know enough about it. I hope you can help, and I’m up for “stating the obvious”

Cheers

Here is the code that I like the most. (there are heaps of examples but this is pretty tight)
(source code or class)
using System;
using System.IO.Ports;
using System.Text;
using System.Threading;
using GHIElectronics.NETMF.FEZ;

namespace LCD
{
public class SerialLCD
{
const byte DISP_ON = 0xC; //Turn visible LCD on
const byte CLR_DISP = 0x01; //Clear display
const byte CUR_HOME = 5; //Move cursor home and clear screen memory
const byte SET_CURSOR = 0x80; //SET_CURSOR + X : Sets cursor position to X
const byte Move_CURSOR_LEFT = 0x10;

private SerialPort UART = new SerialPort(“COM1”, 9600);

public SerialLCD()
{
UART.Open();

}

public void Print(string s)
{
byte[] buffer = Encoding.UTF8.GetBytes(s);
UART.Write(buffer, 0, buffer.Length);
}

public void ClearScreen()
{
SendCommand(CLR_DISP);
}

public void CursorHome()
{
SendCommand(CUR_HOME);
}

public void SetCursor(byte row, byte col)
{
SendCommand((byte)(SET_CURSOR | row << 6 | col));
}

public void MoveLeft()
{
SendCommand(Move_CURSOR_LEFT);
}

private void SendCommand(byte cmd)
{
SendByte(0xFE);
SendByte(cmd);
}

private void SendByte(byte cmd)
{
byte[] buffer = new byte[1] { cmd };
UART.Write(buffer, 0, buffer.Length);
}
}
}

——————————–
execution code

using System;
using System.IO.Ports;
using System.Text;
using System.Threading;
using GHIElectronics.NETMF.FEZ;
using LCD;

namespace FEZ_Domino_Application1
{
public class Program
{
public static void Main()
{
SerialLCD lcd = new SerialLCD();

lcd.ClearScreen();
lcd.Print("FEZ is great");
lcd.SetCursor(1, 0);
lcd.Print("Hello"); // prints on the second row
}

}
}

———————————————————–

pixel · 01/31/2012 at 15:30

I can take a look for you. I started out with the PICAXE and have used a combination of PICAXE and LCD in several projects. Send me a copy or post it as a comment and I will take a look.

Chris · 01/30/2012 at 04:36

Hi there
I have been using the K107 in my Picaxe projects and I think they are great. I have been dabbling using a Fez Domino, and trying to send a string to the K107 LCD (whcih worked ok with the picaxe. I can get some characters, but I think the code I am using sends Bytes to the K107 (not sure how top send anything else in C#). I am trying to use the commands (K107 eg ?a) but i cannot convert these to bytes (not sure, a byte should be a int value???). I’ll send code that I have hacked (using UART in C#), can you help?

Leave a Reply