I am working with two Lora ra-02 sx1278 modules and two Arduino Uno. Programming on Arduino IDE 2.1.1
sender
receiver
The problem is the receiver receives a few packets successfully, but then the board no longer receives the signal. I know the sender is sending data constantly because the RX LED on Arduino blinks. Every time I reset the receiver board, it starts receiving again and then stops after a few packets.
I have this problem when running the basic send and receive example of the Lora library itself. Here's the library I'm using from Arduino IDE libraries: link of the Lora library (I just changed the frequency to 433 for my area, and reduced the delay of sending packets from 5 seconds to 1 second)
I couldn't find anything helpful on the internet. Any suggestions?
Update: My project is a hand-gesture-controlled car. I uploaded the project's program on boards. With this code, if the command to the robot car is "stop", it receives some packets every 1 second and then after an acceptable time, doesn't receive anymore. But if I move my hand so it sends move commands to the car, it receives the move command and motors work but it doesn't receive the next packet. When I detached the motor drivers from Arduino, it received at least 15-20 packets. Apparently, it receives packets but after motor drivers and motors work, it suddenly doesn't receive anything. I'm confused.
Sender:
#include <SPI.h>
#include <LoRa.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
int counter = 0;
String msg = "";
int xdata = 0;
int ydata = 0;
int flag=0;
Adafruit_MPU6050 mpu;
void setup() {
Serial.begin(9600);
while (!Serial)
Serial.println("LoRa Sender");
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 Found!");
LoRa.setTxPower(10);
}
void loop() {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
xdata = a.acceleration.x;
ydata = a.acceleration.y;
Serial.println(counter);
if((xdata>2)&&(flag==0))
{
flag=1;
msg = "l";
Serial.println("l");
}
if(xdata<-2 && flag==0)
{
flag=1;
msg = "r";
Serial.println("r");
}
if(ydata>2 && flag==0)
{
flag=1;
msg = "b";
Serial.println("b");
}
if(ydata<-2 && flag==0)
{
flag=1;
msg = "f";
Serial.println("f");
}
if((xdata<2)&&(xdata>-2)&&(ydata<2)&&(ydata>-2)&&(flag==1))
{
flag=0;
msg = "s";
Serial.println("s");
}
LoRa.beginPacket();
LoRa.print(counter);
LoRa.print(msg);
LoRa.endPacket();
counter++;
delay(1000);
}
Receiver:
#include <SPI.h>
#include <LoRa.h>
int motor1pin1 = 3; //front left
int motor1pin2 = 4;
int motor2pin1 = 5; //front right
int motor2pin2 = 6;
int motor3pin1 = A0; //back right
int motor3pin2 = A1;
int motor4pin1 = A2; //back left
int motor4pin2 = A3;
String msg="";
void setup() {
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(motor2pin1, OUTPUT);
pinMode(motor2pin2, OUTPUT);
pinMode(motor3pin1, OUTPUT);
pinMode(motor3pin2, OUTPUT);
pinMode(motor4pin1, OUTPUT);
pinMode(motor4pin2, OUTPUT);
Serial.begin(9600);
while (!Serial);
Serial.println("LoRa Receiver");
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop() {
// try to parse packet
int packetSize = LoRa.parsePacket();
yield();
if (packetSize) {
// received a packet
Serial.print("Received packet '");
// read packet
while (LoRa.available()) {
msg=(char)LoRa.read();
Serial.print(msg);
}
//Serial.println(msg);
if(msg=="f")
{
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
digitalWrite(motor3pin1, HIGH);
digitalWrite(motor3pin2, LOW);
digitalWrite(motor4pin1, HIGH);
digitalWrite(motor4pin2, LOW);
Serial.println(" : Forward");
}
else if(msg=="b")
{
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, HIGH);
digitalWrite(motor3pin1, LOW);
digitalWrite(motor3pin2, HIGH);
digitalWrite(motor4pin1, LOW);
digitalWrite(motor4pin2, HIGH);
Serial.println(" : Back");
}
else if(msg=="l")
{
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);
digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);
digitalWrite(motor3pin1, HIGH);
digitalWrite(motor3pin2, LOW);
digitalWrite(motor4pin1, LOW);
digitalWrite(motor4pin2, HIGH);
Serial.println(" : Left");
}
else if(msg=="r")
{
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, HIGH);
digitalWrite(motor3pin1, LOW);
digitalWrite(motor3pin2, HIGH);
digitalWrite(motor4pin1, HIGH);
digitalWrite(motor4pin2, LOW);
Serial.println(" : Right");
}
else if(msg=="s")
{
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, LOW);
digitalWrite(motor3pin1, LOW);
digitalWrite(motor3pin2, LOW);
digitalWrite(motor4pin1, LOW);
digitalWrite(motor4pin2, LOW);
Serial.println(" : Stop");
}
LoRa.receive();
}
}