Hi guys, I have the LCD code that I need help with.
Can you guys please help me out.
I want to write to a 2X16 LCD.
The first Line is
"Barcode Scanned"
the second line will be the BARCODE number from the serial port.
I tried the code I have right now..
all data from the serial port goes to the first line index out of 16 LCD slots?
for instant 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 box on the 2x16 lcd.
all information goes to box 1.
#include <LiquidCrystal.h>
// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4, d5, d6, d7 on pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backLight = 13; // pin 13 will control the backlight
void setup()
{
Serial.begin(9600);
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.clear(); // start with a blank screen
lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row)
lcd.print("Barcode Scanned"); // change this text to whatever you like. keep it clean.
lcd.setCursor(0,1); // set cursor to column 0, row 1
}
void loop()
{
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
lcd.write(Serial.read());
}
}
When you clear the LCD, it will clear the screen and then reposition the cursor at 0,0. This clears your message, "Barcode Scanned". I have not done serial communication, but it appears from the serial reference pages that you need to assign the information being received by the arduino to a variable. When you print, you print the variable. In your loop, I believe it basically goes: Print "Barcode Scanned" -> Serial Available -> Yes -> Print the digit -> Serial Available -> Print the next digit...and so on. From the reference page, if you use this, I believe you'll get the desired result:
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
lcd.setCursor(0,1);
lcd.print(incomingByte, DEC);
}
}
yes!!!
that works...it was giving me hard time..
can you help me with one more thing.
when i take out the clear lcd function.
everytime i add new data, its wouldn't clear the row 0 and just add to it...
how would i control the LCD to add clear
Row 1 and place the new data in row 1? only in row 1 hopefully
In my experience so far, I have noticed that if you don't clear before writing new information, it will leave the old characters in the blocks that are not written to. For example, if one time you send "Hello World" to the LCD and the next time you send "Howdy", it does not delete " World" and would say "Howdy World" as hello and howdy have the same number of characters. You could force it to write a space over the previously written characters, so that you would have a known character in each of the 16 spaces. This is a bit cumbersome, but it works. You may want to tell it to lcd.setCursor(col, row), just to make sure you know where it is going to write.