// MAIN BALLOON TESTING CODE - By Vivek Samani
// Send b or B to trigger the burn wire from GS
// Serial transmit string format: Read_Count, gps_Altd, Lat, Lng, Sats, Hf, T, Po
/* ************ PROJECT DESCRIPTION ************
HOT AIR BALLOON - MODEL SATELLITE DROP TEST
Hardware description:
MCU : Rpi Pico
Burn wire triggering: MOSFET Module
LOCATION: L89 GPS module
Temp / Absolute Altitude / Pressure: BMP 280
For Burnner valve control: Servo SG90
Radio Module: LORA EBYTE E22 400T30D
GS : Ground station occupied with LORA With (viaz TTL to USB) laptop and monitoring data on CUTECOM Software)
*/
// Including necessary libraries
#include <Wire.h>
#include <Servo.h>
#include <TinyGPS++.h>
#include <hardware/uart.h>
#include <Adafruit_BMP280.h>
#include <SimpleKalmanFilter.h>
// LORA Rx & Tx pins declaration
#define LORA_Tx 16
#define LORA_Rx 17
// GPS @ Rx & Tx pins declaration
#define Tx_UART1 8
#define Rx_UART1 9
#define burn_pin 15
// Servo pin
#define svr_pin 22
bool newData;
float incoming_serial_pressure, Po, Pf;
SimpleKalmanFilter pressureKalmanFilter(1, 1, 1);
// Instance and object declaration6h
Servo svr;
TinyGPSPlus gps;
Adafruit_BMP280 bmp;
// Serial output refresh time
unsigned long refresh_time;
const long SERIAL_REFRESH_TIME = 100;
volatile float gps_Altd, Lat, Long, Hf, T, P, H;
volatile signed int Sats, svr_pos = 0, Read_Count = 1;
void setup() {
// GPS Baud Rates and UART declaration
Serial2.setTX(Tx_UART1);
Serial2.setRX(Rx_UART1);
Serial2.begin(9600);
// LORA Baud Rates and UART declaration
Serial1.setTX(LORA_Tx);
Serial1.setRX(LORA_Rx);
Serial1.begin(9600);
// Serial monitor baud rate
Serial.begin(9600);
// Attach & Set servo to initial position
svr.attach(svr_pin);
svr.write(svr_pos);
// Check the status of sensor
unsigned status;
status = bmp.begin(0x76);
if (!status)
{
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
"try a different address!"));
}
// Defining sampling rates for BMP280
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_1); /* Standby time. */
// Set reference pressure
for (int i = 0; i < 10; i++) {
incoming_serial_pressure += bmp.readPressure();
// wait for next reading
delay(200);
}
// Reference pressure
Po = incoming_serial_pressure / 10; P = Po;
}
void loop()
{
// send to Serial output every 100ms
if (millis() > refresh_time)
{
/* Activate burn wire or Rotate servo as per command */
if (Serial1.available() > 0)
{
char receivedChar = Serial1.read();
if (receivedChar == 'B' || receivedChar == 'b')
{
BurnWire();
}
svr_pos = Serial1.read();
if (svr_pos >= 0 || svr_pos <= 180)
{
svr.write(svr_pos);
}
}
// Collect data from L89 GPS Module
if (Serial2.available() > 0)
{
if (gps.encode(Serial2.read()))
{
SATS = gps.satellites.value();
LAT = gps.location.lat();
LAT = gps.location.lng();
gps_Altd = gps.altitude.meters();
}
}
// filtered_pressure_value
Pf = pressureKalmanFilter.updateEstimate(bmp.readPressure());
// measured altitude
H = bmp.readAltitude(Po * 0.01);
// measured temperature
T = bmp.readTemperature();
// filtered altitude
Hf = 44330 * (1 - pow((Pf / Po), (0.1903)));
// Read_Count, gps_Altd, Lat, Lng, Sats, Hf, T, Po
String csvData = String(Read_Count) + "," + String(gps_Altd) + "," + String(Lat) + "," +
String(Long) + "," + String(Sats) + "," + String(Hf) + "," + String(T) + "," + String(Po);
Serial1.println(csvData); // Send this data to UART pins of LORA Tx
Serial.println(csvData); // Print it to current serial monitor
Read_Count+=1;
refresh_time = millis() + SERIAL_REFRESH_TIME;
}
}
void BurnWire()
{
static bool executed = false;
if (!executed) {
Serial.println(" BURN WIRE TRIGGERED SUCCESSFULLY !! ");
digitalWrite(burn_pin, HIGH);
delay(1000);
digitalWrite(burn_pin, LOW);
}
executed = true;
}
Problems and errors :
1). I'm not getting GPS data, I tried debugging the block of GPS separately without modifying it and it worked. but with the integrated code it didn't worked!
2). I tried testing the burn wire triggering but as soon as I transmitted b or B the main system of MCU didn't received it.
3). Same as 2nd it is with the servo angle transmitting.
4). The communication is only happening one way: MCU to GS and not GS to MCU (Viaz Radio) ....already I have set the radio to Normal mode (2 WAY UART = > M0 = M1 = GND! ) but still it didn't worked!.... I'm only getting string to GS but not getting triggering logic for burn wire and servo.
My references:
-
Arduino Pico : Rpi Pico With Arduino IDE - Documentation
-
Lora Ebyte E22: Lora E22 - User manual
Please help me out with the way to get the solutions with the above problems and errors.
Thank you for investing your time and effort in reading!
