This could eventually get you into all kinds of trouble. Depending on the available RAM on your processor, that could happen very soon, or later. But given the right circumstances (a transmitter constantly sending), eventually it will.
/*
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 <Wire.h>
#include <LiquidCrystal_I2C.h>
// 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
// Create LCD-object (adress 0x27 or 0x3F, depending on module)
LiquidCrystal_I2C lcd(0x27, 16, 2);
String received_text = "";
void setup() {
Serial.begin(9600);
while (!Serial)
;
// Initiera LCD
Wire.begin();
Wire.setClock(100000); // Run in 100 kHz for stability
lcd.init(); // Initiate LCD display
lcd.backlight(); // Turn on backlight
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("LoRa receiver");
// Setup LoRa module
LoRa.setPins(csPin, resetPin, irqPin);
Serial.println("LoRa Receiver Test");
// Serial.println("Setup");
// 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)
;
lcd.setCursor(0, 1);
lcd.print("LoRa error!");
}
}
void loop() {
received_text = "";
// 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());
// }
while (LoRa.available()) {
received_text += (char)LoRa.read();
}
// Print RSSI of packet
Serial.println(received_text);
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
int rssi = LoRa.packetRssi();
float snr = LoRa.packetSnr();
// Write to LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(received_text.substring(0, 16));
// lcd.setCursor(0, 1);
//lcd.print("R:");
//lcd.print(rssi);
//lcd.print(" S:");
//lcd.print(snr, 1);
}
}
Serial:
LoRa Receiver Test
Received 'Temperatur: 21.00
' with RSSI -28
Received 'Temperatur: 21.00
' with RSSI -29
Received 'Temperatur: 21.00
' with RSSI -28
And this doesnt, the only diffs are at the end.
With this, the serial output is unpredictable and the unit seems to restart.
/*
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 <Wire.h>
#include <LiquidCrystal_I2C.h>
// 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
// Create LCD-object (adress 0x27 or 0x3F, depending on module)
LiquidCrystal_I2C lcd(0x27, 16, 2);
String received_text = "";
void setup() {
Serial.begin(9600);
while (!Serial)
;
// Initiera LCD
Wire.begin();
Wire.setClock(100000); // Run in 100 kHz for stability
lcd.init(); // Initiate LCD display
lcd.backlight(); // Turn on backlight
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("LoRa receiver");
// Setup LoRa module
LoRa.setPins(csPin, resetPin, irqPin);
Serial.println("LoRa Receiver Test");
// Serial.println("Setup");
// 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)
;
lcd.setCursor(0, 1);
lcd.print("LoRa error!");
}
}
void loop() {
received_text = "";
// 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());
// }
while (LoRa.available()) {
received_text += (char)LoRa.read();
}
// Print RSSI of packet
Serial.println(received_text);
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
int rssi = LoRa.packetRssi();
float snr = LoRa.packetSnr();
// Write to LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(received_text.substring(0, 16));
lcd.setCursor(0, 1);
lcd.print("R:");
lcd.print(rssi);
lcd.print(" S:");
lcd.print(snr, 1);
}
}
Serial:
ReLoRa Receiver Test
Received 'Temperatur: 21.00
' with RSSI -31
R�LoRa Receiver Test
Received 'Temperatur: 21.00
' with RSSI -28
ReLoRa Receiver Test
Received 'Temperatur: 21.00
Sketch uses 7724 bytes (23%) of program storage space. Maximum is 32256 bytes.
Global variables use 580 bytes (28%) of dynamic memory, leaving 1468 bytes for local variables. Maximum is 2048 bytes.
Flashing with command:C:/Users/rekla/.arduino-create/arduino/avrdude/6.3.0-arduino17/bin/avrdude.exe -CC:/Users/rekla/.arduino-create/arduino/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -carduino -PCOM3 -b115200 -D -Uflash:w:C:/Users/rekla/AppData/Local/Temp/arduino-create-agent2187807675/Temp_LCD_LoRa_Receiver.hex:i
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:/Users/rekla/.arduino-create/arduino/avrdude/6.3.0-arduino17/etc/avrdude.conf"
Using Port : COM3
Using Programmer : arduino
Overriding Baud Rate : 115200
AVR Part : ATmega328P
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
eeprom 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff
flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff
lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
Programmer Type : Arduino
Description : Arduino
Hardware Version: 3
Firmware Version: 4.4
Vtarget : 0.3 V
Varef : 0.3 V
Oscillator : 28.800 kHz
SCK period : 3.3 us
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: reading input file "C:/Users/rekla/AppData/Local/Temp/arduino-create-agent2187807675/Temp_LCD_LoRa_Receiver.hex"
avrdude: writing flash (7724 bytes):
Writing | ################################################## | 100% 1.25s
avrdude: 7724 bytes of flash written
avrdude: verifying flash memory against C:/Users/rekla/AppData/Local/Temp/arduino-create-agent2187807675/Temp_LCD_LoRa_Receiver.hex:
avrdude: load data flash data from input file C:/Users/rekla/AppData/Local/Temp/arduino-create-agent2187807675/Temp_LCD_LoRa_Receiver.hex:
avrdude: input file C:/Users/rekla/AppData/Local/Temp/arduino-create-agent2187807675/Temp_LCD_LoRa_Receiver.hex contains 7724 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 1.00s
avrdude: verifying ...
avrdude: 7724 bytes of flash verified
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK (E:00, H:00, L:00)
avrdude done. Thank you.
Ok
————————————————
To me there seems to be enough RAM, right?
Unexpected Arduino resets are often power supply problems: a sudden demand for a large current causing a voltage drop which triggers the Arduino's brown-out detector.