Hi! I have 2 LoRa Sx1278 Ra-02 modules, alongside with 2 Arduino Pro Mini boards, one is working as a Receiver and one as a Transmitter. The problem is that if I try to change the default Spreading Factor and/or Signal Bandwidth settings, the Receiver doesn't receive anything, or maybe the transmitter is not sending anything...
TX code:
#include <SPI.h>
#include <LoRa.h>
#include <EasyButton.h>
EasyButton Button(3);
long code = 1469543;
void setup() {
pinMode(13, OUTPUT);
pinMode(3, INPUT_PULLUP);
Button.begin();
Button.onPressed(Radio);
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Sender");
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
digitalWrite(13, HIGH);
while (1);}
LoRa.setTxPower(10);
LoRa.setSpreadingFactor(12);
LoRa.setSignalBandwidth(31.25E3);
}
void Radio() {
LoRa.beginPacket();
LoRa.print(code);
LoRa.endPacket();
delay(1000);
}
void loop() {
Button.read();
}
RX code:
#include <SPI.h>
#include <LoRa.h>
long code = 1469543;
void setup() {
pinMode(9, OUTPUT);
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Receiver");
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
digitalWrite(9, HIGH);
while (1);}
digitalWrite(9, LOW);
}
void loop() {
digitalWrite(9, LOW);
int packetSize = LoRa.parsePacket();
if (packetSize) {
char buffer[packetSize + 1]; // +1 for the trailing null char
for (int i = 0; i < packetSize; i++) buffer[i] = (char)LoRa.read();
buffer[packetSize] = '\0';
long value = strtol(buffer, nullptr, 10);
if(code == value) {
digitalWrite(9, HIGH);
delay(1000);}
}
}