Hello, I'm trying to create an abort system using LoRa for a model rocket by having a flight computer send data to a receiver, which will sort of be a ground station, where flight data will be sent to. However, in the case of an emergency or for what ever reason I would like to be able to abort the flight and fire off parachutes and save all the inflight data.
I currently have my (rocket) sender sending bmp280 data as a test to the receiver which works fine, however not very consistently.
I don't have a button to act as the abort trigger so i'm using an mpu-6050 imu which will abort the flight if the receiver is tilted too much (Bit over complicated but it works).
I have the sender (rocket) sending data then listening straight away to see if the message 'ABORT' is received in which it will turn an LED red.
it doesn't seem to be able to listen for the abort message properly.
here is my sender (Rocket) code -
#include <SPI.h>
#include <LoRa.h>
#include <Adafruit_BMP280.h>
#include <Wire.h>
Adafruit_BMP280 bmp;
const int blue = 3;//set blue to pin 3
const int red = 1;//set red to pin 5
const int green = 2;//set green to pin 6
void setup() {
Serial.begin(9600);
delay(2000);
LoRa.setPins(22, 8, 9);
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.setTxPower(50);
bmp.begin(0x76);
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500);
pinMode(red, OUTPUT);//set red as an output
pinMode(green, OUTPUT);//set green as an output
pinMode(blue, OUTPUT);//set blue as an output
digitalWrite(red,LOW);
digitalWrite(green,LOW);
digitalWrite(blue,LOW);
}
void loop() {
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print(bmp.readPressure());
Serial.println(" Pa");
LoRa.beginPacket();
LoRa.print(bmp.readTemperature());
LoRa.print(" *C");
LoRa.print(" ");
LoRa.print(bmp.readPressure());
LoRa.print(" Pa");
LoRa.endPacket();
int packetSize = LoRa.parsePacket();
delay(100);
if (packetSize) {
// received a packet
Serial.print("Received packet '");
// read packet
while (LoRa.available()) {
//Serial.print((char)LoRa.read());
Serial.print((char)LoRa.read());
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
delay(100);
}
and here is my receiver code -
#include <SPI.h>
#include <LoRa.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
double acc ;
bool Abort = false;
void setup() {
Serial.begin(9600);
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
Serial.print("Accelerometer range set to: ");
switch (mpu.getAccelerometerRange()) {
case MPU6050_RANGE_2_G:
Serial.println("+-2G");
break;
case MPU6050_RANGE_4_G:
Serial.println("+-4G");
break;
case MPU6050_RANGE_8_G:
Serial.println("+-8G");
break;
case MPU6050_RANGE_16_G:
Serial.println("+-16G");
break;
}
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
Serial.print("Gyro range set to: ");
switch (mpu.getGyroRange()) {
case MPU6050_RANGE_250_DEG:
Serial.println("+- 250 deg/s");
break;
case MPU6050_RANGE_500_DEG:
Serial.println("+- 500 deg/s");
break;
case MPU6050_RANGE_1000_DEG:
Serial.println("+- 1000 deg/s");
break;
case MPU6050_RANGE_2000_DEG:
Serial.println("+- 2000 deg/s");
break;
}
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.print("Filter bandwidth set to: ");
switch (mpu.getFilterBandwidth()) {
case MPU6050_BAND_260_HZ:
Serial.println("260 Hz");
break;
case MPU6050_BAND_184_HZ:
Serial.println("184 Hz");
break;
case MPU6050_BAND_94_HZ:
Serial.println("94 Hz");
break;
case MPU6050_BAND_44_HZ:
Serial.println("44 Hz");
break;
case MPU6050_BAND_21_HZ:
Serial.println("21 Hz");
break;
case MPU6050_BAND_10_HZ:
Serial.println("10 Hz");
break;
case MPU6050_BAND_5_HZ:
Serial.println("5 Hz");
break;
}
//(CS, RST, IOD)
//LoRa.setPins(22, 8, 9);
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
Serial.println("Start")
}
void loop() {
//Listening loop
//Sending loop
if (Abort == true ){
//Print "ABORT" by going to a new void which turns the lora module into a sender
sending();
}
if (Abort == false){
listening();
}
}
void listening(){
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
acc = a.acceleration.x;
Serial.println(acc);
if (acc < 3){
Abort = true;
}
Serial.println("Searching");
int packetSize = LoRa.parsePacket();
delay(500);
if (packetSize) {
// received a packet
Serial.print("Received packet '");
// read packet
while (LoRa.available()) {
//Serial.print((char)LoRa.read());
Serial.print((char)LoRa.read());
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
delay(100);
}
void sending() {
//Dont know if this can be done in setup if it will effect the listening
LoRa.setTxPower(50);
Serial.println("ABORT");
LoRa.beginPacket();
LoRa.print("ABORT");
LoRa.endPacket();
delay(500);
}
My sender microprocessor is the teensy 4.0 and the receiver is an Arduino nano which work fine talking to each other. I'm hoping to turn the station into a raspberry pi later in the future.
any help is appreciated
-Harvey