LoRa Packet Timing

Greetings, I'm attempting to receive a packet using LoRa, before displaying it on my LCD screen followed by another screen showing some dummy values.

I'm using a Dragino LoRa Shield to send and transmit, an ST7920 LCD to display and an ESP32 Devkitc V4 and a microcontroller.

The basic receiving code works alone, (based on this tutorial from Random Nerd Tutorials), but as soon as I include the code to display some dummy temperature values on my LCD, I never receive any packets consistently, the intervals seem random.

Is this something to do with the delay included in the code? I use this as a timer for each LCD 'slide'. My transmitter code sends a packet every 10 seconds.


  String LoRaData;
  // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");

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

  // If a message is intercepted, write the LCD screen to high and write out what it says
  digitalWrite(hspi->pinSS(), LOW); //enable CS on LCD to write to via HSPI pins

  u8g2.setFont(u8g2_font_unifont_t_chinese2);  // use chinese2 for all the glyphs of "你好世界"
  u8g2.setFontDirection(0);
  u8g2.clearBuffer();
  u8g2.setCursor(25, 15);
  u8g2.print("Receiving:");
  u8g2.drawUTF8(0, 50, LoRaData.c_str()); //write String 
  u8g2.sendBuffer();

    digitalWrite(hspi->pinSS(), HIGH); //disable 
  delay(7500);

  }

  //delay(3000); 

// DISPLAY TEMPERATURE AND HUMIDITY
  digitalWrite(hspi->pinSS(), LOW); //enable CS on LCD to write to via HSPI pins

  int temperature = 15;
  int relative_humidity = 20;
  
  // Display Data recieved via temperature and humidty sensor
  u8g2.setFont(u8g2_font_unifont_t_chinese2);  // use chinese2 for all the glyphs of "你好世界"
  u8g2.setFontDirection(0);                    // set font to be written along x plane
  u8g2.clearBuffer();                          // clear memory so that LCD can be written to

  u8g2.setCursor(1, 15);                       // set cursor at desired location  x = 15, y = 15
  u8g2.print("Temperature");                   // Print 'Temperature'
  u8g2.setCursor(15, 30);                      // Set starting point on x = 15 and y = 30 BEGINS TOP LEFT
  u8g2.setFont(u8g2_font_sonicmania_tr);       // Set font
  u8g2.print(temperature);                     // Print temperature value
  u8g2.setCursor(52,23);                       // Print the celsius unit
  u8g2.print(".");
  u8g2.setCursor(55,30);
  u8g2.print("C");

  u8g2.setFont(u8g2_font_lubBI10_tf);          // set font
  u8g2.setCursor(1, 45);                       // set font to be written at x = 1, y = 45
  u8g2.print("Relative Humidity");
  u8g2.setCursor(15, 60);
  u8g2.setFont(u8g2_font_sonicmania_tr);
  u8g2.print(relative_humidity);
  u8g2.setCursor(45, 60);  
  u8g2.print("%");
  u8g2.sendBuffer();

  delay(5000);

  digitalWrite(hspi->pinSS(), HIGH); //disable 
}

if you only display on the LCD when a packet arrives every 10seconds you should not require the delay(7500); - try deleting it

I display on the LCD always, since the temp and humidity data is displayed afterwards. The LoRa LCD print occurs after a packet is detected and the delay is there to keep it on screen for 7.5 seconds when displayed

delay() blocks execution of code
have a look at millis() which can be none-blocking