0
votes

I have 2 Serials in Arduino

Serial = To print data string in serial (dataRaspi)

Serial1 = To read the datas from "Serial1" and print this out on LCD Screen.

Here is my Code

#include <LiquidCrystal.h>

LiquidCrystal lcd(52, 50, 48, 46, 44, 42);

int byteRead;

void setup() 
{  
  Serial.begin(9600);
  Serial1.begin(9600); //INTIALISING THE SERIAL PORT
  lcd.begin(16, 2);
}

void loop()
{
**this is listing to print data string to Serial** 
dataRaspi = "$" + data_yaw + "|" + data_pitch + "|" + data_roll + "|" + data_lat + "|" + data_lon + "|" + data_airSpd + "|" + data_alt_qnh + "#";

Serial.println(dataRaspi);
delay(1);

**this is listing to read data from Serial1**
if(Serial1.available())
{
   while(Serial1.available < 0)
   byteRead = Serial1.read;
   lcd.print(byteRead);
}

The Question is...

my lcd got blank if i give a series of string input to serial1 like "qwerty". How to display the result from serial1 to my lcd display?

2

2 Answers

2
votes

Your code has : "while(Serial1.available < 0)", ie while available bytes less than 0... , also, the while statement will only control the single following statement... you need:

while (Serial1.available()) {
    lcd.print(Serial1.read());
}
0
votes

First you need to make sure the display initialisation is Ok. So, comment out the serial read block and try printing a hardcoded string on the display.

Here is an examle on how to use 16x2 lcd.

If you find out there is no initialisation problem you can continue with improving your serial read code. In the arduino forum there is a very good topic on serial communication basics by Robin2.

When you need to constantly update printed data on any display you need a string which is almost similar to the currently printed one or else it will flicker all the time and you won't see anything.

example (pseudocode):
print "clock: 10:31"
print "clock: 10:32"
print "clock: 10:33" etc.

This way only the time would change without the "clock" string. If you need to print strings that have nothing in common just add delay(ms) between the lcd.print() lines in order the change of the strings to be visible.

I hope that was useful in some way. Keep learning.