After trying in vain to get the software serial driver to work with my LCD kit http://www.sparkfun.com/products/10097(maybe a topic for another time), I discovered the SparkSoftLCD driver which does work for me, is smaller, and only uses one pin.
However, I have run into an issue with the “cursorTo()” command not working. I’m wondering if it’s something I’m doing wrong, or some incompatibility with my LCD kit (arduino based) compared to other Serial LCD’s (PIC based).
#include “SparkSoftLCD.h”
// LCD constants
#define LCD_TX 2
#define LCD_WIDTH 16
SparkSoftLCD lcd = SparkSoftLCD(LCD_TX, LCD_WIDTH);
int TempPin = 0;
void setup()
{
// setup lcd
pinMode(LCD_TX, OUTPUT);
lcd.begin(9600);
lcd.clear();
lcd.cursor(0); //Turn the cursor off
}
void loop()
{
int temp = analogRead(TempPin);
lcd.clear();
int tempC = 25 + (((temp * 4.88) - 750) / 10); //Adjust the reading to celcius; 10 mV per degree, 4.88mV per count (5V / 1024), 750mv = 25C
lcd.print("Temp: ");
lcd.print(tempC);
lcd.print((char)223); //send degrees symbol
lcd.print(“C”);
lcd.print((char)10); //send a carriage return
// lcd.cursorTo(2,1); //Set the cursor to the bottom row first position
int tempF = ((tempC * 1.8 ) + 32); //Convert to degrees fahrenheit
lcd.print("Temp: ");
lcd.print(tempF);
lcd.print((char)223);
lcd.print(“F”);
delay(1000);
}
Currently I’m sending a carriage return (as shown) which works but it would be nice to use the position command as my project gets more advanced. Any ideas?
I figured it out. The other (PIC based) serial LCD’s as well as the parallel LCD library use the command 0x80 with the lower nibble specifying the position (using offsets for the different lines). All the Serial LCD libraries I looked at used this structure as well.
However, the Arduino based Serial LCD uses the same command (0x80) but then it decodes a whole extra byte of data to determine the desired cursor position. This is a little easier to follow in the program, but it means that the available Serial LCD libraries will not work (at least the “cursorTo” command). Everything else in the other serial libraries that I’ve tried does seem to work.
I see 3 options for fixing this:
-
The best solution would be to rewrite the Arduino code in the LCD to accept the commands for the other serial LCD’s which are more common and share the same command structure as the “LiquidCrystal” library. This would allow the use of any Serial LCD library but means others would have to change the code on their Arduino kits as well. Maybe Sparkfun would update it?
-
The next best solution would be to rewrite the SparkSoftLCD library to send the command properly to the Arduino based board (which would be pretty easy). This means that you would have to use this library to interface the Arduino based serial LCD which may be the better option for ease of use for other people.
-
The easiest fix would be to just write my own function in the program to get the command sent properly. This would work fine, but it doesn’t help others very much and I would like to give back a little.
I will try to post my updated library or code depending on what I decide. Any votes for the desired solution?