Arduino serial pain

So I have been trying to make my newly acquired Arduino (mega) talk to this old 16×2 char, serial-interface LCD display I have.

This should have been fairly easy – you just feed the LCD ASCII over serial and it displays it. An Arduino can output ASCII over serial directly. Should be easy.

The short story is “its a bit messed up”. The slightly long story goes like this:

I started by trying to print the character ‘a’ to it. Logically I tried:
Serial1.print(‘a’);
The display showed “0”. I also tried:
Serial1.print(97, BYTE);
Serial1.write(97);
Same result.

After a lot of scrabbling in the dark, I finally tried:
Serial1.write(61);
And got an ‘a’ character to appear.

Seems something is getting confused between DEC and HEX. I tried driving the LCD from my PC’s serial port and it worked as expected. I tried reading the serial data from the Arduino back into a serial port on my PC and it looked ok. But for some reason when I send the display DEC from the Arduino it reads it as HEX. If I try using the hex literal in the Arduino code:
Serial1.write(0x61);
I get ‘0’ on the display again.

I have probably missed something obvious somewhere, but I have no idea what. I have a backup plan that involves using some form of nasty conversion, but I would prefer to avoid it.

Tags: , ,

Leave a Reply