Transmitting 2 signal using LoRa Ra-02

Hello everyone!!!

I have 2 joysticks (joyL and joyR) to run 2 dc motors (motorL and motorR) individually. But only one dc motor are running (for joyL and motorL) and for the (joyR and motorR) produces this error in the Serial Monitor.

0@1@?I1@?R1@?[1@?d1@?m1@?v1@?1@?�1@?�1@?�1@?�1@?�1@?�1@?Exception was unhandled.

THIS IS MY CODE FOR THE TRANSMITTER

`//TRANSMITTER

#include <LoRa.h>
#include <SPI.h>
 
#define ss 5
#define rst 14
#define dio0 2
 

const int joyLpin = 34;     // left joystick
const int joyRpin = 33;     // right joystick
 
void setup() 
{
  Serial.begin(115200); 
  
  while (!Serial);
  Serial.println("LoRa Sender");
 
  LoRa.setPins(ss, rst, dio0);    //setup LoRa transceiver module
  
  while (!LoRa.begin(433E6))     //433E6 - Asia, 866E6 - Europe, 915E6 - North America
  {
    Serial.println(".");
    delay(500);
  }
  LoRa.setSyncWord(0xA5);
  Serial.println("LoRa Initializing OK!");
}
 
void loop() 
{
  int joyL = map(analogRead(joyLpin),0,1024,0,255);
  int joyR = map(analogRead(joyRpin),0,1024,0,255);


  Serial.println("Sending packet: ");
 
  LoRa.beginPacket();
  LoRa.print("<");
  LoRa.print(joyL);
  LoRa.print(",");
  LoRa.print(joyR);
  LoRa.print(">");
  LoRa.endPacket();

  delay(50);
}`

THIS IS THE CODE FOR THE RECEIVER

//RECEIVER

#include <LoRa.h>
#include <SPI.h>
 
#define ss 5
#define rst 14
#define dio0 2

const int motorLfwd = 32;   // left motor forward pin
const int motorLbck = 33;    // left motor backward pin
const int motorLen = 15;   // left motor enable pin
const int motorRfwd = 13;    // right motor fwd pin
const int motorRbck = 12;    // right motor backward pin
const int motorRen = 25;   // right motor enable pin

int deadzone = 20;
int motorLspeed;            // left motor speed (0-255 for PWM)
int motorRspeed;            // right motor speed (0-255 for PWM)

void setup() 
{
  Serial.begin(115200);
  
  pinMode(motorLfwd,OUTPUT);
  pinMode(motorRfwd,OUTPUT);
  pinMode(motorLbck,OUTPUT);
  pinMode(motorRbck,OUTPUT);
  pinMode(motorLen,OUTPUT);
  pinMode(motorRen,OUTPUT);

  while (!Serial);
  Serial.println("LoRa Receiver");
 
  LoRa.setPins(ss, rst, dio0);    //setup LoRa transceiver module
 
  while (!LoRa.begin(433E6))     //433E6 - Asia, 866E6 - Europe, 915E6 - North America
  {
    Serial.println(".");
    delay(500);
  }
  LoRa.setSyncWord(0xA5);
  Serial.println("LoRa Initializing OK!");
}
 
void loop() 
{
  int packetSize = LoRa.parsePacket();    // try to parse packet
  if (packetSize) 
  {
    
    Serial.println("Received packet '");
 
    while (LoRa.available()) {
      char receivedChar = LoRa.read(); // Read a character from LoRa
      if (receivedChar == '<') { // Check if it's the start marker
        String dataString = ""; // Create an empty string to store the received data
        while (LoRa.available()) {
          receivedChar = LoRa.read(); // Read the next character
          if (receivedChar == '>') { // Check if it's the end marker
            // Extract X and Y values from dataString
            int commaIndex = dataString.indexOf(',');
            if (commaIndex != -1) { // Check if comma exists in the string
              String joyLString = dataString.substring(0, commaIndex); // Extract joyL string
              String joyRString = dataString.substring(commaIndex + 1); // Extract joyR string
              int joyL = joyLString.toInt(); // Convert joyL string to integer
              int joyR = joyRString.toInt(); // Convert joyR string to integer
              // Now you have joyL and joyR values
              // You can use them for further processing
              Serial.print("Received joyL: ");
              Serial.print(joyL);

                int joyLneutral = 460;

                if((joyL-joyLneutral) < -deadzone){ // joystick pushed forward
                  digitalWrite(motorLfwd,HIGH);
                  digitalWrite(motorLbck,LOW);
                  motorLspeed = map(joyL,joyLneutral,0,0,255);
                  Serial.print(" fwd ");
                }
                else if((joyL-joyLneutral) > deadzone){
                  digitalWrite(motorLfwd,LOW);
                  digitalWrite(motorLbck,HIGH);
                  motorLspeed = map(joyL,joyLneutral,1023,0,255);
                  Serial.print(" back ");
                }
                else{
                  digitalWrite(motorLfwd,LOW);
                  digitalWrite(motorLbck,LOW);  
                  Serial.print(" stop ");    
                  motorLspeed = 0; 
                }
                Serial.print(motorLspeed);

                Serial.print(" Right: ");
                Serial.print(joyR);

                  int joyRneutral = 460;
                                  // set right motor direction and speed
                  if((joyR-joyRneutral) < -deadzone){ // joystick pushed forward
                    digitalWrite(motorRfwd,HIGH);
                    digitalWrite(motorRbck,LOW);
                    motorRspeed = map(joyR,joyRneutral,0,0,255);
                    Serial.print(" fwd ");
                  }
                  else if((joyR-joyRneutral) > deadzone){
                    digitalWrite(motorRfwd,LOW);
                    digitalWrite(motorRbck,HIGH);
                    motorRspeed = map(joyR,joyRneutral,1023,0,255);
                    Serial.print(" back ");
                  }
                  else{
                    digitalWrite(motorRfwd,LOW);
                    digitalWrite(motorRbck,LOW);  
                    Serial.print(" stop ");    
                    motorRspeed = 0; 
                  }
                  Serial.println(motorRspeed);
                  analogWrite(motorLen,motorLspeed);
                  analogWrite(motorRen,motorRspeed);

                  Serial.print(motorLspeed);
                  Serial.println("   " + motorRspeed);
                  

              Serial.print("Received joyR: ");
              Serial.println(joyR);

            }
            break; // Exit the inner loop
          } else {
            dataString += receivedChar; // Add the character to dataString
          }
        }
      }
    }
    // LoRa.packetRssi();


  }

}

what microcontroller are you using?
before attempting to parse the received packet check it is received OK

try transmitting a newline on the end of you text and increasing the delay, e.g.

  LoRa.println(">");
  LoRa.endPacket();

  delay(5000);

then in the receiver read a complete line and parse it, e.g.

void loop() {
  static int joyL = 1, joyR = 10;
  int packetSize = LoRa.parsePacket();  // try to parse packet
  if (packetSize) {
    Serial.println("Received packet '");
    char text[100] = { 0 };
    LoRa.readBytesUntil('\n', text, 100);
    Serial.println(text);
    if (sscanf(text, "<%d,%d>", &joyL, &joyR) == 2) {
      Serial.print("joyL = ");
      Serial.print(joyL);
      Serial.print(" joyR = ");
      Serial.println(joyR);
    }
  }
}

receiver serial monitor prints

Received packet '
<871,8710>
joyL = 871 joyR = 8710
Received packet '
<872,8720>
joyL = 872 joyR = 8720
Received packet '
<873,8730>
joyL = 873 joyR = 8730

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.