Skip to content

Arduino 1.0 and Sparkfun Serial LCD

As I was interested in getting data out of my Arduino UNO to a LCD, I just bought a Sparkfun Serial LCD (V2.5) for fun.

The display is almost plug-and-play. As it uses its own PIC 16F88 controller it accepts serial ASCII characters input and some special commands for controlling the display. In a few minutes you are ready with your setup, you just need to wire one digital line from the Arduino board to the display RX pin. You can provide GND and PWR externally or also from your Arduino board (+5V).

The Sparkfun serial library, provided by the manufacturer for interfacing the lCD, is using the external “NewSoftwareSerial”-library, which is now included in the official Arduino 1.0 build, known as “SoftwareSerial” library. In fact I did not modify the Sparkfun Library (it does not work with Arduino 1.0), instead just used the new SoftwareSerial library directly. That worked pretty good for me.

Here is my sketch for a very basic COM-port repeater (I call it repeater because just does that: it sends the data it gets on the serialport to the LC-display).

 

#include <SoftwareSerial.h>

#define txPin 3
#define rxPin -1

#define CLEAR 0x01
#define CURSOR_MOVE_RIGHT 0x14
#define CURSOR_MOVE_LEFT 0x10
#define CURSOR_BOX_BLINK_ON 0x0D
#define CURSOR_BOX_BLINK_OFF 0x0C
#define CURSOR_POS_LINE1 128
#define CURSOR_POS_LINE2 192

SoftwareSerial lcd = SoftwareSerial(rxPin, txPin);

void setup()
{
// set controller pins
pinMode(txPin, OUTPUT);
// set serial mode
Serial.begin(9600);
// sparkfun default port speed
lcd.begin(9600);
// clear the display first
sendCmd(CLEAR);
// set position to first character
sendCmd(CURSOR_POS_LINE1);
}

void loop()
{
// read data if incoming...
if (Serial.available() > 0) {
lcd.write(Serial.read());
}
}

void sendCmd(byte cmd) {
lcd.write(0xFE);
lcd.write(cmd);
}

You can use your command-line to send text to the display:
echo "Hello my friend." > com3:
will output the text on your LCD (if you are using com3 for your arduino).

you can also send the content of a file
type test.txt > com3:
So you can do pretty funny things with your display :)

I just experimented with some scripts which displayed some MUD-Parameters of my character (like skills etc.), the computers IP-Address, current directory of the shell etc…really funny :)

Here is a example PowerShell-Script which reads a file and filters out lines containing a search-pattern.
In fact I’m using this for outputting my MUD AP/PE health information, so I don’t have to switch tasks… :)

function getZeile(){
return (Get-content "C:\temp\mudlog.txt").count-1
}

$port= new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one
$port.Open()

$myvar = (Get-content "C:\temp\mudlog.txt" |find "AP und")[-1]

$myvar = $myvar.replace("und","")

$port.Write([byte]0xFE,0,1)
$port.Write([byte]0x01,0,1)
$port.Write($myvar)

$port.Close()

That only took some minutes from the start. Arduino is great for beginners…

Post a Comment

You must be logged in to post a comment.