Hello everyone, I'm pretty new to all of this, so any help would be appreciated.
I am using a 20x4 serial LCD that was given to me and I am having trouble setting the cursor where I want it. I have a more involved code, but I simplified it down to try and get to the root of my problem. Here is the code:
#include <SoftwareSerial.h>
SoftwareSerial lcd(2, 3);
void setup()
{
Serial.begin(9600); // start serial monitor serial
lcd.begin(9600); // start lcd serial
setLCDCursor(66);
lcd.print(" Please Help! ");
delay(1500);
clearDisplay();
}
void loop()
{
while(Serial.available()) // If serial data is available do this
lcd.print((char) Serial.read());
}
void clearDisplay()
{
lcd.write(0xFE); // send the special command
lcd.write(0x01); // send the clear screen command
}
void setLCDCursor(byte cursor_position)
{
lcd.write(0xFE); // send the special command
lcd.write(0x80); // send the set cursor command
lcd.write(cursor_position); // send the cursor position
}
Many of you will probably recognize that the clearDisplay and setLCDCursor was taken directly from the Sparkfun getting started page example code. Anyway, everything is working great except the setLCDCursor command. If I understand this correctly, when I type "setLCDCursor(_);", the _ should be a number from 0-79 which corresponds to all 80 lines on the 20x4 serial LCD, so if I type in 0 it should go to the first line, first column location, or if I type, say, 25 it should go to the 2nd line, 6th column location, etc. It simply does not do this. Trying all sorts of numbers I did find something out, and it has something to do with ASCII. For example, if I put in 66 for the _ then it types "B" in the first line, first column location but doesn't move the cursor to where 66 should be (it immediately follows the "T" in the first line, 2nd column location). So it follows the table near the bottom of ASCII - Wikipedia for Dec.
I've been looking for other ways to move the cursor on a serial lcd as well, but I'm not really sure what I'm doing. Possibly use a different driver/library like SparkSoftLCD? Or looking at the github (Serial Enabled LCD Kit Datasheet · jimblom/Serial-LCD-Kit Wiki · GitHub) it says, "A line feed (CTRL+ENTER), ASCII 0×0A, will move the cursor to the beginning of the following row. If it’s on the bottom row, it’ll move to the beginning of the top." which would also work for what I need, but am not sure how to use. I know that is for a 16x2 serial LCD so Idk if that's the problem or what.
Sorry this is getting wordy but I'm just trying to give the details of what I need and what I've tried. Again any help I can get on this would be amazing, and the sooner the better (I'm running out of time!). Thanks guys
*Note: with this code, when I open the serial port and type something it does start at the 1,1 location where I'd like it, but on my more involved code with multiple inputs (3 load cells) it starts in various places in the middle of the LCD for some reason and again using setLCDCursor doesn't move it as I think it should.