I’m, like, totally serial!

I hooked up an old Matrix Orbital LK205-24-USB LCD display with my Arduino today. This 80-character backlit display can be plugged into a computer using the handy dandy USB cable (hence the -USB part of the name) but it turns out it has a 5V TTL serial jumper on the back which can provide power the display, as well as an alternative means to control it.

Arduino + Matrix Orbital LCD display

It was incredibly quick and easy to get it connected up to my new favourite toy, the Arduino. The one thing that took me a few moments to realise (as in, “why isn’t this working? Oh…”) is that the Receive and Transmit pins are relative rather than absolute. It sounds stupid to say it now, but the Rx pin on the Arduino has to be connected to the Tx pin on the LCD display, and vice versa.

Arduino + Matrix Orbital LCD display

It was also a chance to learn how to use the excellent Arduino SoftwareSerial library, which lets you use digital pins as virtual serial connections. Especially handy if you want to have multiple serial connections at one (for example, if you want to continue to use the built in serial port for sending and receiving data from the computer). It even seems to work at 19200 baud required for this display, which I wasn’t expecting. The same thing will work nicely for the Current Cost device (which spits out 3.3V TTL serial at 2400 or 9600 baud depending on the model) too.

Here’s a little Arduino sketch I cobbled together, based on the Software Serial example and this Serial LCD tutorial.

#include <SoftwareSerial.h>
#define rxPin 6 // software Rx pin (connect to Tx on LCD)
#define txPin 7 // software Tx pin (connect to Rx on LCD)

// set up a new serial port
SoftwareSerial swSerial =  SoftwareSerial(rxPin, txPin);

void setup()  {
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  // set the data rate for the SoftwareSerial port
  swSerial.begin(19200);
  // and set the date rate for the real serial port
  Serial.begin(9600);
  delay(100); // (can't use port immediately?)
  clearLCD();
  swSerial.print("Hello, world!");
}

void loop() {
   // retransmit bytes read from the computer to LCD
   if (Serial.available() > 0) {
      byte inchar = Serial.read();
      swSerial.print(inchar);
   }
}

// Clear the LCD (works with my Matrix Orbital LK204-24-USB)
// See http://www.arduino.cc/playground/Learning/SerialLCD
// (and compare with your LCD display docs)
// for many more LCD display helper functions.
void clearLCD(){
  swSerial.print(254, BYTE);
  swSerial.print(88, BYTE);
}

I’m thinking about turning it into an in-house Twitter display, or possibly something which lets me check the artist and title of the current iTunes track being played on our Mac-Mini-acting-as-a-living-room-media-center without having to turn on the television. That’s something I find myself doing at least, ooh, a couple of times per month, so of course a massively overengineered solution technical would be perfect. I have a feeling that as soon as I start using it, I’ll want to use it for more things.

3 Comments »

RSS feed for comments on this post.

  1. When I first saw this I thought it looked like one of those really unrealistic bombs they always have in films.

    Could you not connect it to your current cost thing to give helpful environmentally friendly pointers, “the dolphins, the dolphins! Turn that washing machine off!” and such and such. :-)

    Comment by Darren — May 21, 2008 #

  2. Whilst playing catch-up and getting my Matrix Orbital hooked up, I have found some interesting things about the digital pins on the arduino.

    I have found the screen only works off pins 6/7 or pins 12/13 using SoftwareSerial. For the other pin pairs, the output is garbled; almost as if the connection is not running at the right speed.

    This is probably a consequence of trying to drive it at 19200.

    Comment by Nick — May 21, 2008 #

  3. Very interesting that pins 6+7 and 12+13 work with the SoftwareSerial library at 19200 baud but the others don’t.

    Comment by Roo — May 21, 2008 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
The postings on this site are my own and don't necessarily represent my employer's positions, strategies or opinions.