Help with not detecting GPS and time

Hello everyone, need some help trying to detect my gps and time on my satellite, is a school project.

Here is the code, any help is much appreciated.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

#define BMP_SDA 21
#define BMP_SCL 22
#define GPS_TX 10
#define GPS_RX 11
#define RADIO_TX 8
#define RADIO_RX 9

Adafruit_BMP280 bmp;
TinyGPSPlus gps;
SoftwareSerial radio(RADIO_TX, RADIO_RX);

void setup() {
  Serial.begin(9600);
  Wire.begin(BMP_SDA, BMP_SCL);
  if (!bmp.begin()) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);
  }
  radio.begin(9600);
}

void loop() {
  static unsigned int counter = 0;
  if (gps.location.isValid() && gps.speed.isValid()) {
    counter++;
    float altitude = bmp.readAltitude();
    float pressure = bmp.readPressure();
    float temperature = bmp.readTemperature();
    unsigned long unixTime = gps.time.value();
    int hour = (unixTime / 3600) % 24;
    int minute = (unixTime / 60) % 60;
    int second = unixTime % 60;
    float speed_kph = gps.speed.kmph();
    float fall_speed = calculateFallSpeed(altitude);
    
    // Construye el paquete de datos
    String packet = String(counter) + ";" +
                    String(altitude, 2) + ";" +
                    String(temperature, 2) + ";" +
                    String(hour) + ":" + String(minute) + ":" + String(second) + ";" +
                    String(pressure, 2) + ";" +
                    String(gps.location.lat(), 6) + "," + String(gps.location.lng(), 6) + ";" +
                    String(speed_kph, 2) + ";" +
                    String(calculateFallSpeed, 2) + ";" +
                    "CERVANTESSAT";
    
    // Send packet via radio
    radio.println(packet);
    
    Serial.println(packet);
  }
  delay(1000);
}

float calculateFallSpeed(float altitude) {
  // calculates the speed
  float delta_altitude = altitude - last_altitude; // Calculate the altitude
  float delta_time = 1; // time between measurements (1 second)
  
  // calculates fall speed (metres per second)
  float fall_speed = delta_altitude / delta_time;
  
  last_altitude = altitude; // Update the next altitude for next cycle
  
  return fall_speed;
  
}

Thank you again!

And what problem do you have ?

Welcome to the forum

Whereabouts in your code do you read data from the GPS ?

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.