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);
}
Output