Hi,
So I'm building a weather balloon payload and am currently working on transmitting GPS and atmospheric data over LoRa to a ground station.
My setup is Sparkfun/Arduino Pro-micro 3.3v 8MHz, RFM9x LoRa 433MHz and a UBLOX M8N GPS.
The radio is transmitting fine to my receiver and sending a structure over no problem. The GPS on its own works great, but I'm having an issue adding it all together.
Take the code below;
#include <SPI.h>
#include <RH_RF95.h>
#include <NMEAGPS.h>
#define RFM95_CS 10
#define RFM95_RST 6
#define RFM95_INT 3
#define gpsPort Serial1
#define RF95_FREQ 433.0
RH_RF95 rf95(RFM95_CS, RFM95_INT); // Singleton instance of the radio driver
static NMEAGPS gps;
struct payload{
uint16_t Secs_since_launch;
float Lat;
float Long;
float GPS_Alt;
float GPS_Speed;
float VS;
float Temp_in;
float Temp_out;
float V_batt;
};
payload test = {0, 53.42652, -2.24709, 9.99, 4.65, 5.5, -20.4, -56.34, 3.3};
void setup()
{
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
Serial.begin(9600);
while (!Serial);
Serial.println("Arduino LoRa TX Test!");
digitalWrite(RFM95_RST, LOW);
delay(10);
digitalWrite(RFM95_RST, HIGH);
delay(10);
while (!rf95.init()) {
Serial.println("LoRa radio init failed");
Serial.println(" ");
while (1);
}
Serial.println("LoRa radio init OK!");
if (!rf95.setFrequency(RF95_FREQ)) {
Serial.println("setFrequency failed");
while (1);
}
rf95.setTxPower(10, false);
rf95.setSpreadingFactor(12);
rf95.setSignalBandwidth(62500);
gpsPort.begin(38400);
Serial.println("Setup Complete");
}
void loop()
{
GPS();
test.Secs_since_launch = millis() / 1000;
rf95.send((uint8_t *)&test, sizeof(test));
rf95.waitPacketSent();
//while (gpsPort.available()) {. //Testing code for GPS, works fine.
// char data = Serial1.read();
//Serial.print(data);
}
}
void GPS(){
while (gps.available(gpsPort)) {
gps_fix fix = gps.read();
if (fix.valid.location) {
int32_t Lat_GPS_raw = fix.latitudeL();
int32_t Long_GPS_raw = fix.longitudeL();
test.Lat = Lat_GPS_raw / 10000000.0;
Serial.println(test.Lat, 5);
test.Long = Long_GPS_raw / 10000000.0;
test.GPS_Alt = fix.altitude(); //meters MSL
float speed_mph = fix.speed_metersph();
test.GPS_Speed = speed_mph / 3600.0;
}
}
}
I tested the LoRa code on its own, no issues. I tested the GPS code on its own, and it parses the data with no issues, but when I uncomment both the GPS code and LoRa code in the main loop, the LoRa is still sending data but it's not being updated with the GPS values nor is the Serial.print line in the GPS code printing.
I have a theory as to why this isn't working but my knowledge isn't good enough to work out how to fix it. I was struggling earlier today with just getting the GPS to run alone, I had a 'delay(500);' statement after 'GPS();' and that was enough to stop it working. So I think this is a similar issue something to do with the processor is running the delay() code while it should be doing things in the GPS.
I've tried a few things but nothing has worked, any ideas how do I best go about fixing it?
Many thanks.