Hi, I am coding a project for NASA Student Launch. A ground station will send an arming command for an autonomous drone deployment at 400 ft (triggered with an altimeter). I programmed a GPS transmitter and rocket using the LoRa E5s and got telemetry from apogee with it. However, using the LoRas for the drone deployment sequence has been very flaky for me. Sometimes, the Loras can send their command, but more often than not, they don’t.
To make matters worse, the LoRa that listens for the arming command sometimes gets interference from the onboard GPS transmitter, and the arming command cannot be received. The wiring is not the issue here; I feel as if I’m not programming the Loras correctly. Can anyone please suggest improvements on the code? I use the test mode for everything, and I feel that might be a contributing factor.
Please let me know if I left anything out that can be helpful for you in giving advice.
Groundstation Armer
#include <SoftwareSerial.h>
const byte Rx = 3;
const byte Tx = 2;
SoftwareSerial Serial1(Rx,Tx);
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
// Serial1.write(“AT+ MODE= RESET\r\n”);
delay(1000);
Serial1.write(“AT+TEST=RFCFG,868,SF7,125,8,8,14,ON,OFF,OFF”);
delay(1000);
Serial1.write(“AT+ MODE= TEST\r\n”);
}
void loop() {
Listen();
}
void TX() {
Serial1.write(“AT+TEST=TXLRSTR, “ARM”\r\n”);
//Serial1.write(“AT+MSG=“ARM”\r\n”);
}
void Listen(){
if(char(Serial.read()) == ‘1’){
TX();
}
}
Onboard Deployment System
#include <SoftwareSerial.h>
//int enA = 4;
int in1 = 3;
int in2 = 5;
bool RSO_Permission = false;
bool configured = false;
bool configured_1 = false;
bool configured_2 = false;
bool deployed = false;
bool Open_2 = false;
const byte rxPin = A1; //Yellow on LoRa!
const byte txPin = A2; //White on LoRa!
int firingPin = 7;
int LED = 4;
SoftwareSerial mySerial(rxPin, txPin);
void setup() {
pinMode(firingPin, INPUT_PULLUP);
//pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(LED, INPUT);
Serial.begin(9600);
mySerial.begin(9600);
Configure_Receiver();
while (configured == false) {
configured = Configure_Barrel_Break(configured);
Close(5);
digitalWrite(LED, HIGH);
delay(10);
digitalWrite(LED, LOW);
delay(10);
}
while (configured_1 == false) {
configured_1 = Configure_Barrel_Break_1(configured_1);
Open(5);
digitalWrite(LED, HIGH);
delay(10);
digitalWrite(LED, LOW);
delay(10);
}
}
void loop() {
Close(5);
while (RSO_Permission == false) {
RSO_Permission = Listen(RSO_Permission);
}
// Serial.println(“STANDBY FOR SAIL DEPLOY”);
if (digitalRead(firingPin) == LOW) { // Corrected the condition here
Butter_Dawg();
deployed = true;
}
while (deployed == true){
while (Open_2 == false) {
Open_2 = Listen(Open_2);
}
Open(5);
}
}
bool Listen(bool RSO_Permission) {
if (mySerial.find("+TEST: RX “”)) {
String receivedString = mySerial.readStringUntil(’"’);
Serial.println(“Received: " + receivedString);
// Find the position of the first double quote after “+TEST: RX "
int startPos = receivedString.indexOf(””", 11);
// Extract the substring starting from startPos + 1 and with a length of 8
String parsedString = receivedString.substring(startPos + 1, startPos + 1 + 15);
Serial.println("Parsed: " + parsedString);
if (parsedString == “41524D”) {
RSO_Permission = true;
digitalWrite(LED, HIGH);
} else {
RSO_Permission = false;
}
}
return RSO_Permission; // Return RSO_Permission outside the if block
}
void Close_Flight() {
//digitalWrite(enA,HIGH);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
delay(5);
}
void Close(int Time) {
//digitalWrite(enA,HIGH);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
delay(Time);
}
void Open(int Time) {
//digitalWrite(enA, HIGH);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
delay(Time);
}
void Butter_Dawg() {
Open(11000);
Close(5000);
}
void Scan() {
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
//This checks for data from whatever is connected to Serial1 (i.e. the lora)
//if (Serial1.available())
//{
// Serial.write(Serial1.read());
//}
//if (Serial.available())
//{
// Serial1.write(Serial.read());
//}
}
void Configure_Receiver() {
// mySerial.write(“AT+ MODE= RESET\r\n”);
delay(1000);
mySerial.write(“AT+ MODE= TEST\r\n”);
delay(1000);
mySerial.write(“AT+TEST=RFCFG,868,SF7,125,8,8,14,ON,OFF,OFF”);
delay(1000);
mySerial.write(“AT+ TEST= RXLRPKT\r\n”);
delay(1000);
void Parse() {
if (mySerial.find("+TEST: RX “”)) {
String receivedString = mySerial.readStringUntil(’"’);
// Find the position of the first double quote after “+TEST: RX "
int startPos = receivedString.indexOf(”"", 11);
// Extract the substring starting from startPos + 1 and with a length of 8
String parsedString = receivedString.substring(startPos + 1, startPos + 1 + 8);
Serial.println(parsedString);
}
}
bool Configure_Barrel_Break(bool configured) {
if (mySerial.find("+TEST: RX “”)) {
String receivedString = mySerial.readStringUntil(’"’);
Serial.println(“Received: " + receivedString)
// Find the position of the first double quote after “+TEST: RX "
int startPos = receivedString.indexOf(””", 11);
// Extract the substring starting from startPos + 1 and with a length of 8
String parsedString = receivedString.substring(startPos + 1, startPos + 1 + 15);
Serial.println(“Parsed: " + parsedString);
if (parsedString == “41524D”) {
configured = true;
return configured;
} else {
configured = false;
}
}
return configured; // Return RSO_Permission outside the if block
}
bool Configure_Barrel_Break_1(bool configured) {
if (mySerial.find(”+TEST: RX “”)) {
String receivedString = mySerial.readStringUntil(’"’);
Serial.println(“Received: " + receivedString);
// Find the position of the first double quote after “+TEST: RX "
int startPos = receivedString.indexOf(””", 11);
// Extract the substring starting from startPos + 1 and with a length of 8
String parsedString = receivedString.substring(startPos + 1, startPos + 1 + 15);
Serial.println("Parsed: " + parsedString);
if (parsedString == “41524D”) {
configured = true;
return configured;
} else {
configured = false;
}
}
return configured; // Return RSO_Permission outside the if block
}