LoRa received packet print in serial monitor but not on LED Matrix

Hello,
With my project, I am receiving a packet from a transmitter using LoRa and trying to display it on my LED Matrix. The Serial monitor prints the packet perfectly fine, but when I try to print it on my LED Matrix, it doesn't work. My code is below.

/*
  LoRa Demo 1 Receiver
  lora-demo1-receive.ino
  Receives and displays contents of test packet
  Requires LoRa Library by Sandeep Mistry - https://github.com/sandeepmistry/arduino-LoRa
  
  DroneBot Workshop 2023
  https://dronebotworkshop.com
*/

// Include required libraries
#include <SPI.h>
#include <LoRa.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN   9
#define DATA_PIN  8
#define CS_PIN    10

MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);


// Define the pins used by the LoRa module 
const int csPin = 4;     // LoRa radio chip select 
const int resetPin = 2;  // LoRa radio reset 
const int irqPin = 3;    // Must be a hardware interrupt pin 
char incoming;


void setup() {
  Serial.begin(9600);
  while (!Serial);
  LoRa.setPins(csPin, resetPin, irqPin); // Setup LoRa module
  Serial.println("LoRa Receiver Test");

  // The display code starts here 
  myDisplay.begin();
  myDisplay.setIntensity(5);
  myDisplay.displayClear();
//  myDisplay.displayScroll("Farah Haddad", PA_CENTER, PA_SCROLL_LEFT, 200);

  
  // Start LoRa module at local frequency
  // 433E6 for Asia
  // 866E6 for Europe
  // 915E6 for North America
  if (!LoRa.begin(866E6)) {
    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 ");

    // Read packet
    while (LoRa.available()) {
      Serial.print((char)LoRa.read());
      myDisplay.print((char)LoRa.read());
      
    
    }

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

 

}

If you remove all the LoRa stuff from your code can you print what would be the received packet direct to the LED matrix ?

I am unsure what do you mean by "Remove all the LoRa Stuff" can you please clarify ?

Remove all the code for setting up, initialising and reading packets for the LoRa device and just have code that writes a message to the LED matrix.

Oh yeah, that works perfectly fine. Even when I add athe below code to my program it prints the RSSI perfectly fine"

    myDisplay.print(LoRa.packetRssi());

So of the LoRa message\packet received, the first character in the message gets printed to the Serial monitor and the second character in the message goes to the LED matrix, etc ?

To illustrate the issue I’m experiencing with the LED Matrix display, I created a slow-motion video, but I couldn’t upload it here. What happens is that a jumbled mix of characters quickly flashes on the display, and then only the last character (I am guessing) remains visible (as seen in the attached image). And the serial monitor shows weird characters with some numbers. And if I remove the myDisplay line completely the serial monitor shows the message perfectly fine as per the sender

Change the code that @srnet referenced in reply #6 to the following and you can at least see the correct message in the Serial monitor. As that reply points out, you are showing one character on Serial, the next character on the display, the character after that on Serial, etc. Every LoRa.read() removes a character from the buffer.

    // Read packet
    while (LoRa.available()) {
      char c = LoRa.read();
      Serial.print(c);
      myDisplay.print(c);
    }

For the display, you will need to save the entire message then display it all at once. As it is, you are displaying a single character at a time, and that apparently just overwrites the previous character.

As as it is the routine also potentially reads a character that is beyond the end of the packet and sends it to the LED matrix.

Thanks, David. I changed the part you told me about, and the Serial monitor is now showing the right message. Quite honestly, I don't know how to save the entire message and display it all simultaneously. I will have to figure it out; I am thinking of a loop to build the whole string from each character.

Or, study the Serial Input Basics tutorial.

1 Like

In your first post your comment about the (not correct?) code posted was;

"The Serial monitor prints the packet perfectly fine"

Hence my comment in post #6.

1 Like

Thank you all for the help, I think I need more study to find the right solution, its not working so far but I will have to study more and learn more thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.