Hi guys,
I have a problem making LoRa connection between MKR WAN 1300 and WEMOS d1 mini esp32 boards.
I've connected WEMOS d1 mini esp32 to LoRa grove module (868mhz). The sender code is working .fine but the receiver code is not giving me the output I'm looking for
i changed the code multiple times. i tried different serial ports on esp32 (UART0, URT1, UART2) and also changed the baud rates on both codes but still the output I'm getting is either "Recv failed" or some weird characters on my serial monitor.
What could possibly be wrong with this code?
I also make sure to connect the right pins on esp32 to LoRa module each time that I change the serial port.
Receiver code
#include <Arduino.h>
#include <RH_RF95.h>
RH_RF95 rf95(Serial2);
#define RXD2 16
#define TXD2 17
void setup() {
// Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
Serial.begin(115200);
// Serial.println("test");
//Serial1.begin(9600, SERIAL_8N1, RXD2, TXD2);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
Serial.println("Serial Txd is on pin: "+String(TX));
Serial.println("Serial Rxd is on pin: "+String(RX));
}
void loop() { //Choose Serial1 or Serial2 as required
if (rf95.available()) {
Serial.println("Receiving message...");
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if(rf95.recv(buf, &len)){
Serial.print("got request: ");
Serial.println((char*)buf);
}
}
else{
Serial.println("Recv failed");
}
delay(5000);
}
Sender code
#include <SPI.h>
#include <LoRa.h>
int counter = 0;
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Sender");
if (!LoRa.begin(868E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.setTxPower(20); // Set transmit power to 20 dBm (maximum)
}
void loop() {
Serial.print("Sending packet: ");
Serial.println(counter);
// send packet
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
counter++;
delay(5000);
}
Many things, including incorrect default settings of the radio, incorrect Serial baud rate settings, incorrect interpretation of the message data type, etc.
Check all those carefully against the transmitter code, which you forgot to post.
In the receiver code, where is .begin() or .init() for the radio, and how do all the other radio settings compare between TX and RX?
Bandwidth, spreading factor, frequency, etc. must all be chosen identically for TX and RX.
It is probably a mistake to start out with two different devices from different manufacturers, because any or all of the default settings could be different.
Unless you know the exact LoRa setiing of the two entirely different LoRa devices, one UART front ended and the other SPI based and you match them your not going to get any communications.
And whilst you might think the 'sender code is working correctly' how can you know your actually sending stuff with LoRa settings that the receiver can work with ?
That's actually a good point. We're not sure if the sender code is actually sending packets, but I still believe that the receiver code is the main problem here.
All of the radio settings (except for transmit power) must be identical for transmitter and receiver. If you don't know what those are, you have some reading to do. There are plenty of introductory tutorials for LoRa radios.
Before I try to make LoRa connection between these two boards, I was using MKR VIDOR 4000
instead of WEMOS mini esp32 and I experienced the same problem,