Lora received packet print in serial monitor but not on Lcd

Hi Everyone.

I use the standard example LoRaSender and LoRaReceiver in the Lora Library.

Only changed the 433e6 Freq.

With the Standard example the receiver prints the received message and the counter and the RSSI in the serial monitor.

I then added a LCD to the receiver and the ''Hello'' and counter value(only a single digit is displayed) does not display in the LCD only the RSSI value is displayed.

The counter value will show 1 and then override with a 2 and then 3 up to 9 and then start at 0 again but never shows double digits.

This is the Receiver code with the LCD .

#include <SPI.h>
#include <LoRa.h>
#include <LiquidCrystal.h> //Arduino standard LCD Library

//
//                            RS   E  D4  D5  D6  D7
LiquidCrystal lcd(14, 15, 16, 17, 18, 19);

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);

  lcd.setCursor(0, 0);
  lcd.print("Lora Receiver");//This works
  delay(500);
  lcd.clear();
  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 packet
    Serial.print("Received packet '");

    // read packet
    while (LoRa.available()) {
      Serial.print((char)LoRa.read());//This works

      lcd.setCursor(0, 0);
      lcd.print((char)LoRa.read());//This does not work

    }

    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());

    lcd.setCursor(0, 1);
    lcd.print("     ");//Clear previous digits

    lcd.setCursor(0, 1);
    lcd.print(LoRa.packetRssi());//This works on LCD

  }
}

Thanks in advance.

lcd.print((char)LoRa.read());//This does not work

LoRa.read() presumably removes the incoming data so it is not there the second time you read it

Read the data into a variable and print that to Serial and the LCD

If you change the program to the above does the same message get pronted twice ?

Thanks.

I tried this.

 incoming = ((char)LoRa.read());
      //Serial.print((char) LoRa.read());
      Serial.print(incoming);
      lcd.setCursor(0, 0);
      lcd.print(incoming);

This is the Serial monitor.But on the LCD I only get 1,2,3,4,......9 and then 1,2,3....9 keeps on repeating but no "Hello"

Received packet 'hello 224' with RSSI -62
Received packet 'hello 225' with RSSI -61
Received packet 'hello 226' with RSSI -61
Received packet 'hello 227' with RSSI -61
Received packet 'hello 228' with RSSI -60
Received packet 'hello 229' with RSSI -63
Received packet 'hello 230' with RSSI -61
Received packet 'hello 231' with RSSI -62
Received packet 'hello 232' with RSSI -61
Received packet 'hello 233' with RSSI -60
Received packet 'hello 234' with RSSI -61
Received packet 'hello 235' with RSSI -61
Received packet 'hello 236' with RSSI -60
Received packet 'hello 237' with RSSI -61
Received packet 'hello 238' with RSSI -61
Received packet 'hello 239' with RSSI -59

As you set the cursor position before printing each letter, you'll only see the last one in the time elapsed between packets. Everything else flashes past too fast to see.

Thanks wildbill just solved my problem.

I moved the setCursor to void setup and also to the bottom of the void loop for the next print loop.

![20211121_152011|375x500](upload://p6M2HYSmJkLystz3mb6hu34ezf9.jpeg)

Getting a picture on this site is way beyond my skill level!

Just start a new reply then select and drag the picture from your PC into it

Somehow missed this.

No it does not print twice actually messing the monitor and the LCD up also the RSSI value change while the units is on exactly the same spot.

I get one reading every 5 seconds.

LoRa Receiver
Received packet '1010001⸮' with RSSI -28
Received packet '1010001⸮' with RSSI -55
Received packet '1010001⸮' with RSSI -51
Received packet '1010001⸮' with RSSI -50
Received packet '1010001⸮' with RSSI -57
Received packet '1010001⸮' with RSSI -53
Received packet '1010001⸮' with RSSI -52
Received packet '1010001⸮' with RSSI -53
Received packet '1010001⸮' with RSSI -30
Received packet '1010001⸮' with RSSI -53
Received packet '1010001⸮' with RSSI -51
Received packet '1010001⸮' with RSSI -50
Received packet '1010001⸮' with RSSI -57

The last digit is a zero not a upside down question mark.

No surprise there

EDIT : corrected English

What is the whole story going on in the while loop?
In this while loop the data packet prints on the Lcd .

while (LoRa.available())
    {
      incoming = ((char)LoRa.read());
      //Serial.print((char) LoRa.read());
      Serial.print(incoming);
      lcd.print(incoming);
    }
    
    Serial.print("' with RSSI ");// print RSSI of packet
    Serial.println(LoRa.packetRssi());

    lcd.setCursor(0, 1);
    lcd.print("     ");//Clear previous digits

    lcd.setCursor(0, 1);
    lcd.print(LoRa.packetRssi());//This works on LCD outside the while loop.
    lcd.setCursor(0, 0);//Set Cursor for next print loop
  }
}

But when I move the lcd.print out of the while loop I only get 1 digit again!

 while (LoRa.available())
    {
      incoming = ((char)LoRa.read());
      //Serial.print((char) LoRa.read());
      Serial.print(incoming);
     
    }
     lcd.print(incoming);//Move lcd.print here!!

    Serial.print("' with RSSI ");// print RSSI of packet
    Serial.println(LoRa.packetRssi());

    lcd.setCursor(0, 1);
    lcd.print("     ");//Clear previous digits

    lcd.setCursor(0, 1);
    lcd.print(LoRa.packetRssi());//This works on LCD
    lcd.setCursor(0, 0);//Set Cursor for next print loop
  }
}

My understanding is that when the LoRa packet is received the while loop is entered then the packet is read and type cast to char and then stored in variable incoming.

Done finish exit while loop.

Next line is lcd.print(incoming) .. only 1 digit is displayed.

But when I remove incoming and change the line to:

lcd.print("abcdefg");

The abcdefg is printed on the lcd?

Something else is going on here that I cannot see .. Please explain.

lora.read returns a single character from the received packet. I assume that incoming is a char (best to post all your code), so the while loop reads the entire packet character by character and on each iteration, overwrites incoming with the last character read.

It's not accumulating the data, so if you want to see it on the LCD, you must print it before overwriting it with the next one.

Here is my code , only the while part is changed.

If I understand correct then one character will be printed in the serial monitor and then on the LCD then the next char goes toe the serial mon and also to the LCD .. repeat until the packetSize is reached.

#include <SPI.h>
#include <LoRa.h>
#include <LiquidCrystal.h> //Arduino standard LCD Library

//
//                RS   E  D4  D5  D6  D7
LiquidCrystal lcd(14, 15, 16, 17, 18, 19);

char incoming ;

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);

  lcd.setCursor(0, 0);
  lcd.print("Lora Receiver");//This works
  delay(500);
  lcd.clear();

  lcd.setCursor(0, 0);
  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 packet
    Serial.print("Received packet '");

    // read packet
    while (LoRa.available())

    {
      incoming = ((char)LoRa.read());
      //Serial.print((char) LoRa.read());


      Serial.print(incoming);
      
      lcd.print(incoming);


    }


    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());

    lcd.setCursor(0, 1);
    lcd.print("     ");//Clear previous digits

    lcd.setCursor(0, 1);
    lcd.print(LoRa.packetRssi());//This works on LCD
    lcd.setCursor(0, 0);
  }
}

That's it.

Thanks.

So a delay after serial.print and after lcd.print will prove that the chars is printed one at a time and toggle between serial mon and lcd.

Will try that tonight.

It doesn't need "proving". That's the way it is. Don't add needless delays to your code.