0

I am working with two Lora ra-02 sx1278 modules and two Arduino Uno. Programming on Arduino IDE 2.1.1

sender Schematic of the sender

receiver Schematic of the 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();
  }
}
2
  • 2
    1) There are 10 sketches in the library, you need to be more specific which is/are the one you are using. We don't want to guess which one. 2) Does it crash/stop working if you change the interval to 5s instead of 1s? 3) BTW, Lora is designed for Long range communication(as compare to WiFi) for a limited shared frequency resource, before you decide to blasting the airwave every second (even you are using it as peer-to-peer), please be away of duty cycle requirement.
    – hcheung
    Sep 18 at 0:50
  • @hcheung thanks for your reply. 1)I'm testing LoRaSender and LoRaReceiver. 2) Yes. With more delay, it receives more packets but it stops again. 3)I don't have much information about it. Can you tell me the limitations? I'm using 433 MHz. I read the link you provided but don't know what the duty cycle is in my case.
    – Rouhi
    Sep 18 at 8:19

1 Answer 1

0

The first thing that comes to mind is that the delay between sends is too short. Not only are you flooding the airwaves with your packets (fair use, 1% airtime and all that), but after a few packets your receiver might not be able to keep up and start missing packets.

Also, there's the definite possibility that another device in the neighourhood is sending packets too, and interferes with your transmission. You are after all on the standard 433 MHz frequency, with default settings.

Try:

  • Change frequency to something less crowded.
  • Change SF / BW to something less standard.
  • Set delay between pings to around 30 seconds.
  • Depending on the LoRa library you are using, consider using CAD, Channel Activity Detection.

I just saw you are using the arduino-LoRa library. It has CAD, not in the master branch, but in a separate branch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.