Hi,
I want to transfer data between an Arduino UNO (transmitter) and a Wemos D1 mini pro (transceiver) using two LoRa modules (SX1278 Ra-02 LoRa Module 433Mhz (OT3206)), both equipped with an external antenna.
One LoRa modules is connected to the Arduino UNO as follows:
- RA-02 VCC to Arduino Uno 3.3V
- RA-02 GND to Arduino Uno GND
- RA-02 MISO to Arduino Uno pin 12
- RA-02 MOSI to Arduino Uno pin 11
- RA-02 SCK to Arduino Uno pin 13
- RA-02 NSS to Arduino Uno pin 10
The other LoRa module is connected to the Wemos D1 mini pro as follows:
- RA-02 VCC to ESP8266 3.3V
- RA-02 GND to ESP8266 GND
- RA-02 MISO to ESP8266 GPIO
- RA-02 MOSI to ESP8266 GPIO
- RA-02 SCK to ESP8266 GPIO
- RA-02 NSS to ESP8266 GPIO )
The following code is used at the transmitter side to send a simple message:
#include <SPI.h>
#include <LoRa.h>
#define LORA_SDA 11
#define LORA_SCL 13
#define LORA_SS 10
#define LORA_RST 9
#define LORA_FREQUENCY 433E6
void setup() {
Serial.begin(19200);
while (!Serial);
if (!LoRa.begin(LORA_SS)) {
Serial.println("LoRa init failed. Check your connections.");
while (true);
}
LoRa.setFrequency(LORA_FREQUENCY); // Set the frequency
Serial.println("LoRa init succeeded. Frequency set to 433MHz.");
}
void loop() {
String message = "Hello, ESP8266!";
LoRa.beginPacket();
LoRa.print(message);
LoRa.endPacket();
Serial.println("Message sent: " + message);
delay(2000);
}
The following code is used at the transceiver side to receive the message:
#include <SPI.h>
#include <LoRa.h>
#define LORA_SDA 7
#define LORA_SCL 5
#define LORA_SS 8
#define LORA_RST 4
#define LORA_FREQUENCY 433E6
void setup() {
Serial.begin(19200);
while (!Serial);
if (!LoRa.begin(LORA_SS)) {
Serial.println("LoRa init failed. Check your connections.");
while (true);
}
LoRa.setFrequency(LORA_FREQUENCY); // Set the frequency
Serial.println("LoRa init succeeded. Frequency set to 433MHz.");
LoRa.receive();
}
void loop() {
int packetSize = LoRa.parsePacket();
if (packetSize) {
String received = "";
while (LoRa.available()) {
received += (char)LoRa.read();
}
Serial.print("Received packet with size: ");
Serial.println(packetSize);
Serial.print("Received message: ");
Serial.println(received);
}
else {
Serial.println("No packet received");
}
delay(1000);
}
Looking at the serial monitor of the transmitter side it appears that the message is being sent every 2s such as desired. However, at the receiver side i am getting gibberish text. I have checked for the correct COM port and baud rate of the serial monitor. I have tried another Ra-02 module at the transceiver side as well.
Any help or suggestions are greatly appreciated!
Kind Regards,
Emilebe