I am working on a project where I am sending information over to another Arduino device using 2 Lora radios. One is the transmitter, and the other is a receiver. They each run on 915 MHz, and they work alright. I have an antenna attached to both as well to boost communications between them. However, when I attempt to send information over, it only does so once, despite being inside a loop function for both the transmitter code, and the receiver code. I want it to loop multiple times, but I don't exactly know what is stopping me, Can someone please help? The code is posted below here for you to take a look at.
Transmitter Code:
#include <SPI.h>
#include <LoRa.h>
int LED = 4;
int GND = A0;
int counter = 10;
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(GND, OUTPUT);
digitalWrite(GND, HIGH);
while (!Serial);
Serial.println("LoRa Sender");
if (!LoRa.begin(915E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop() {
if (counter > 0) {
Serial.print("Sending packet: ");
Serial.println(counter);
// send packet
digitalWrite(LED, HIGH);
delay(100);
digitalWrite(LED, LOW);
LoRa.beginPacket();
LoRa.print("We have some kind of signal on bus line 1 ");
LoRa.print(counter);
LoRa.endPacket();
counter++;
delay(3000);
}
}
Receiver code:
#include <SPI.h>
#include <LoRa.h>
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Receiver");
if (!LoRa.begin(915E6)) {
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());
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
}