Hi, I am sure I am being dumb but I got a Lora transmitter and receiver working. When I receive data it is displayed on my LCD. The issue is that every time a new message is received it continues on the LCD screen. I tried resetting the cursor but it does not seem to work. Below is the code that is working but the LCD gets the information displayed inside of the while loop. Any guidance is appreciated.
#include <SPI.h> #include <LoRa.h> #include <LiquidCrystal_I2C.h> // Library for LCD
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Receiver");
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop()
{
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize)
{
// received a paket
Serial.print("Received packet '");
// read packet
while (LoRa.available())
{
char incoming = (char)LoRa.read();
if (incoming == 'c')
{
}
else
{
lcd.print(incoming);
}
}
Sure my lcd display is getting the message "Temp 95 F" but when it get the next message it displays like this Temp 95FTemp96FTemp96FTemp96FTemp96FTemp96F and starts wrapping to the next line. I want to clear the LCD display so that it only displays Temp95F and not a long run on message. Hope that clarifies and thank you for any help.
Thanks! That made it clear. You could use an lcd.clear() when a new message is detected.
Scroll is not usually supported as far as I know.
Using the code tags, </>, symbol my suggestion looks like:
#include <SPI.h>
#include <LoRa.h>
#include <LiquidCrystal_I2C.h> // Library for LCD
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x26, 20, 4);
void setup()
{
lcd.init();
lcd.backlight();
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Receiver");
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop()
{
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize)
{
// received a paket
Serial.print("Received packet '");
lcd.clear();//Added by Railroader
// read packet
while (LoRa.available())
{
char incoming = (char)LoRa.read();
if (incoming == 'c')
{
}
else
{
lcd.print(incoming);
}
}
}
}
Next you will complain that the LCD is flickering. The proper design will display the fixed text one time only. Then using cursor control, print blanks where the new value will be displayed, then print the new value. No flicker and no running off the line of the LCD.
Paul
No I not complain about the flickering. I am just trying to get a POC. I am going to use the set cursor and blank out the data when I switch off of the LCD and over to a TFT. Thanks !