Reputation: 1
I have a problem making LoRa connection between MKR WAN 1300 and WEMOS D1 mini EDP32 boards.
I've connected the WEMOS D1 mini ESP32 to LoRa Grove module (868 MHz). 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 made sure to connect the right pins on ESP32 to the 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
Upvotes: 0
Views: 318
Reputation: 6213
There are a couple of issues. This is how you define the rf95 object.
RH_RF95<Uart> rf95(Serial2);
And you should NOT set the baud speed (it's done internally), and especially not to the wrong baud speed.
Upvotes: 0