diff --git a/LightAPRS-pico-balloon/LightAPRS-pico-balloon.ino b/LightAPRS-pico-balloon/LightAPRS-pico-balloon.ino index bd783f5..0b59032 100644 --- a/LightAPRS-pico-balloon/LightAPRS-pico-balloon.ino +++ b/LightAPRS-pico-balloon/LightAPRS-pico-balloon.ino @@ -75,6 +75,7 @@ uint32_t GEOFENCE_no_tx = 0; boolean radioSetup = false; boolean GpsFirstFix=false; +boolean ublox_high_alt_mode_enabled = false; //do not change this. static char telemetry_buff[100];// telemetry buffer uint16_t TxCount = 1; @@ -161,6 +162,7 @@ void loop() { updateTelemetry(); GpsOFF; + ublox_high_alt_mode_enabled = false; //gps sleep mode resets high altitude mode. GpsFirstFix=true; //APRS frequency isn't the same for the whole world. (for pico balloon only) if (!radioSetup) { @@ -209,13 +211,19 @@ void aprs_msg_callback(struct AX25Msg *msg) { } void sleepSeconds(int sec) { - if(GpsFirstFix)GpsOFF;//sleep gps after first fix + if (GpsFirstFix){//sleep gps after first fix + GpsOFF; + ublox_high_alt_mode_enabled = false;//gps sleep mode resets high altitude mode. + } RfOFF; RfPttOFF; Serial.flush(); wdt_disable(); for (int i = 0; i < sec; i++) { - if(readBatt() < GpsMinVolt) GpsOFF; //(for pico balloon only) + if (readBatt() < GpsMinVolt){ + GpsOFF; + ublox_high_alt_mode_enabled = false;//gps sleep mode resets high altitude mode. + } LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_ON); } wdt_enable(WDTO_8S); @@ -561,6 +569,18 @@ int getDifference(Date dt1, Date dt2) static void updateGpsData(int ms) { GpsON; + + if(!ublox_high_alt_mode_enabled){ + //enable ublox high altitude mode. increase ublox max. altitude limit from 12.000 meters to 50.000 meters. + delay(100); + setGPS_DynamicModel6(); + #if defined(DEVMODE) + Serial.println(F("ublox DynamicModel6 enabled...")); + #endif + ublox_high_alt_mode_enabled = true; + + } + while (!Serial1) { delayMicroseconds(1); // wait for serial port to connect. } @@ -701,4 +721,80 @@ static void printStr(const char *str, int len) #endif } +//following GPS code from : https://github.com/HABduino/HABduino/blob/master/Software/habduino_v4/habduino_v4.ino +void setGPS_DynamicModel6() +{ + int gps_set_sucess=0; + uint8_t setdm6[] = { + 0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x06, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, + 0x05, 0x00, 0xFA, 0x00, 0xFA, 0x00, 0x64, 0x00, 0x2C, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xDC }; + + while(!gps_set_sucess) + { + sendUBX(setdm6, sizeof(setdm6)/sizeof(uint8_t)); + gps_set_sucess=getUBX_ACK(setdm6); + } +} +void sendUBX(uint8_t *MSG, uint8_t len) { + Serial1.flush(); + Serial1.write(0xFF); + delay(500); + for(int i=0; i 9) { + // All packets in order! + return true; + } + +// Timeout if no valid response in 3 seconds + if (millis() - startTime > 3000) { + return false; + } + +// Make sure data is available to read + if (Serial1.available()) { + b = Serial1.read(); + +// Check that bytes arrive in sequence as per expected ACK packet + if (b == ackPacket[ackByteID]) { + ackByteID++; + } + else { + ackByteID = 0; // Reset and look again, invalid order + } + } + } +}