ProgrammingTeensy
Member
Hi,
I am trying to make this code to work and all other sensors work fine, but the GPS module shows:
and after a while it shows like this:
but it doesn't update - time stays the same (I've changed location, but it shows the right one). I have the GPS module connected via I2C (the schematic is also included).
Here is the code I am using (all sensors combined):
The GPS sensor works with the following sensor perfectly:
So I want the GPS to output correct data, but I don't have ideas on what to do.
Here is the schematic:
Thanks in advance for all help.
I am trying to make this code to work and all other sensors work fine, but the GPS module shows:
Code:
Time: 00:00:00.000
Date: 0/0/200
Fix: 0 quality: 0
Code:
Time: 16:08:14.000
Date: 19/2/2023
Fix: 1 quality: 1
Location: xxxx.xxxxN, yyyy.yyyyE
Speed (knots): 0.68
Angle: 15.35
Altitude: 280.10
Satellites: 4
Here is the code I am using (all sensors combined):
Code:
#include <Wire.h>
#include <WireIMXRT.h>
#include <WireKinetis.h>
#include <Adafruit_GPS.h>
#include <Adafruit_BMP085.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
Adafruit_GPS GPS(&Wire);
#define GPSECHO false
uint32_t cas;
uint32_t pre_cas = 0;
uint32_t pre_cas1 = 0;
uint32_t pre_cas2 = 0;
int hitr_vetra_10m[6], hitr_vetra_120m[6], hitr_vetra_80m[6], hitr_vetra_180m[6], full_array[48];
int smer_vetra_10m[6], smer_vetra_80m[6], smer_vetra_120m[6], smer_vetra_180m[6];
float hitr_vetra_10m_ko[6], hitr_vetra_120m_ko[6], hitr_vetra_80m_ko[6], hitr_vetra_180m_ko[6];
float tempL, tempD, pritL, pritD, visL, visD, vis_let, yaw, pitch, roll, vis_let_prava, vis_tla1, vis_tla, vis_od_tal, longitude, latitude, kompas;
long int prit_morje; //zračni pritisk v Kopru - podatki https://meteo.arso.gov.si/uploads/probase/www/observ/surface/text/sl/observationAms_KOPER_KAPET-IJA_history.html, python script - ker se zracni tlak ob morju spreminja visina nenatancna po dolocenem casu
int i, j ,m, n, k, r, t, d, s;
String pritisk_vnesen;
String ser_string;
Adafruit_BMP085 bmp;
Adafruit_BMP085 bmp1;
Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28, &Wire);
void setup() {
while (!Serial);
Serial.begin();
Wire.begin();
Wire1.begin();
bmp.begin();
bmp1.begin();
bno.begin();
if(!GPS.begin(0x10)){
for(s = 0; s >=10; s++) delay(100);
if(s >= 10) Serial.println("!!!!!!!!!!!!!!!!!GPS senzor se ni zagnal!!!!!!!!!!!!!!!!!!!!");
s = 0;
while (1);
}
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
//GPS.sendCommand(PGCMD_ANTENNA);
delay(5000);
Serial.println("Pritisk v koprski kapitaniji: ");
delay(10000);
if(Serial.available()>=5 && Serial.available()<20){
pritisk_vnesen = Serial.readStringUntil('\n');
prit_morje = pritisk_vnesen.toFloat();
Serial.println(prit_morje);
Serial.flush();
}
vis_tla1 = 0.0;
for(j=0; j<200; j++){ //naredi povprečje levega in desnega krila, da ugotovi višino letala
vis_tla1 = ((bmp.readAltitude(prit_morje) + bmp1.readAltitude(prit_morje))/2.0) + vis_tla1;
delay(10);
}
j = 0;
vis_tla = vis_tla1/200.0;
bno.setExtCrystalUse(true);
Serial.println("Zacetna nadmorska visina: ");
Serial.println(vis_tla, 1);
Serial.println("Vetrne karakteristike");
delay(2000);
if (Serial.available() >= 30) {
ser_string = Serial.readStringUntil("\n");
delay(500);
Serial.flush();
}
for(int i=0;i<ser_string.length();i++){
if(ser_string.charAt(i) == ','){
full_array[t] = ser_string.substring(r,i).toInt();
r = (i+1);
t++;
}
}
for(k=0;k<=47;k++) {
if(k<6) {
hitr_vetra_10m[k] = full_array[k];
hitr_vetra_10m_ko[k] = hitr_vetra_10m[k]/10.0;
}
if(k<12 && k>5) {
hitr_vetra_80m[k-6] = full_array[k];
hitr_vetra_80m_ko[k-6] = hitr_vetra_80m[k-6]/10.0;
}
if(k<18 && k>11) {
hitr_vetra_120m[k-12] = full_array[k];
hitr_vetra_120m_ko[k-12] = hitr_vetra_120m[k-12]/10.0;
}
if(k<24 && k>17) {
hitr_vetra_180m[k-18] = full_array[k];
hitr_vetra_180m_ko[k-18] = hitr_vetra_180m[k-18]/10.0;
}
if(k<30 && k>23) {
smer_vetra_10m[k-24] = full_array[k];
}
if(k<36 && k>29) {
smer_vetra_80m[k-30] = full_array[k];
}
if(k<42 && k>35) {
smer_vetra_120m[k-36] = full_array[k];
}
if(k<48 && k>41) {
smer_vetra_180m[k-42] = full_array[k];
}
}
Serial.println("Let se lahko pricne");
}
void loop() {
cas = millis();
tempL = bmp.readTemperature();
//pritL = bmp.readPressure();
visL = bmp.readAltitude(prit_morje);
tempD = bmp1.readTemperature();
//pritD = bmp1.readPressure();
visD = bmp1.readAltitude(prit_morje);
if(cas-pre_cas2 >500){
pre_cas2=cas;
vis_let=0.0;
for(i=0; i<30; i++){ //naredi povprečje levega in desnega krila, da ugotovi višino letala
vis_let = ((bmp1.readAltitude(prit_morje) + bmp.readAltitude(prit_morje))/2.0) + vis_let;
}
}
if(abs(visD - visL) > 6.0){
Serial.println("Napaka zaradi prevelikega razpona senzorjev");
}
vis_let_prava = vis_let/30.0;
vis_od_tal = vis_let_prava - vis_tla;
sensors_event_t event;
bno.getEvent(&event);
yaw = event.orientation.x;
pitch = event.orientation.y;
roll = event.orientation.z;
char c = GPS.read();
if (GPSECHO)
if (c) Serial.print(c);
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
if(cas - pre_cas1 >= 5000){
pre_cas1 = cas;
tren_lokacija();
}
if (cas - pre_cas >= 2000){//zakasnitev za 2 sekundi
pre_cas = cas;
Serial.println(" ");
Serial.println("visina letala: ");
Serial.println(vis_let_prava, 1);
Serial.println(" ");
Serial.println("oddaljenost od tal: ");
Serial.println(vis_od_tal);
Serial.print("Yaw: ");
Serial.print(yaw);
Serial.print("\tPitch: ");
Serial.print(pitch);
Serial.print("\tRoll: ");
Serial.print(roll);
Serial.println("");
}
if(Serial.available()>=5){
pritisk_vnesen = Serial.readStringUntil('\n');
prit_morje = pritisk_vnesen.toInt();
Serial.println(prit_morje);
}
}
void tren_lokacija(){
Serial.print("\nTime: ");
if ((GPS.hour) < 10) { Serial.print('0'); }
Serial.print(GPS.hour, DEC); Serial.print(':');
if (GPS.minute < 10) { Serial.print('0'); }
Serial.print(GPS.minute, DEC); Serial.print(':');
if (GPS.seconds < 10) { Serial.print('0'); }
Serial.print(GPS.seconds, DEC); Serial.print('.');
if (GPS.milliseconds < 10) {
Serial.print("00");
} else if (GPS.milliseconds > 9 && GPS.milliseconds < 100) {
Serial.print("0");
}
Serial.println(GPS.milliseconds);
Serial.print("Date: ");
Serial.print(GPS.day, DEC); Serial.print('/');
Serial.print(GPS.month, DEC); Serial.print("/20");
Serial.println(GPS.year, DEC);
Serial.print("Fix: "); Serial.print((int)GPS.fix);
Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
if (GPS.fix) {
Serial.print("Location: ");
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
Serial.print(", ");
Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
Serial.print("Speed (knots): "); Serial.println(GPS.speed);
Serial.print("Angle: "); Serial.println(GPS.angle);
Serial.print("Altitude: "); Serial.println(GPS.altitude);
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
}
}
The GPS sensor works with the following sensor perfectly:
Code:
#include <Adafruit_GPS.h>
#include <Wire.h>
Adafruit_GPS GPS(&Wire);
#define GPSECHO false
uint32_t timer = millis();
int i;
void setup() {
while (!Serial);
Serial.begin(115200);
Wire.begin();
if(!GPS.begin(0x10)){
for(i = 0; i >=10; i++) delay(100);
if(i >= 10) Serial.println("!!!!!!!!!!!!!!!!!GPS senzor se ni zagnal!!!!!!!!!!!!!!!!!!!!");
i = 0;
while (1);
}
Serial.println("!!!!!!!!!!!!!!!!!!!!!!Zacetek GPS meritev!!!!!!!!!!!!!!!!!!!!");
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
//GPS.sendCommand(PGCMD_ANTENNA);
delay(1000);
}
void loop() {
// read data from the GPS in the 'main loop'
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if (GPSECHO)
if (c) Serial.print(c);
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
// a tricky thing here is if we print the NMEA sentence, or data
// we end up not listening and catching other sentences!
// so be very wary if using OUTPUT_ALLDATA and trying to print out data
//Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
// approximately every 2 seconds or so, print out the current stats
if (millis() - timer > 1000) {
timer = millis(); // reset the timer
Serial.print("\nTime: ");
if ((GPS.hour + 1) < 10) { Serial.print('0'); }
Serial.print(GPS.hour + 1, DEC); Serial.print(':');
if (GPS.minute < 10) { Serial.print('0'); }
Serial.print(GPS.minute, DEC); Serial.print(':');
if (GPS.seconds < 10) { Serial.print('0'); }
Serial.print(GPS.seconds, DEC); Serial.print('.');
if (GPS.milliseconds < 10) {
Serial.print("00");
} else if (GPS.milliseconds > 9 && GPS.milliseconds < 100) {
Serial.print("0");
}
Serial.println(GPS.milliseconds);
Serial.print("Date: ");
Serial.print(GPS.day, DEC); Serial.print('/');
Serial.print(GPS.month, DEC); Serial.print("/20");
Serial.println(GPS.year, DEC);
Serial.print("Fix: "); Serial.print((int)GPS.fix);
Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
if (GPS.fix) {
Serial.print("Location: ");
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
Serial.print(", ");
Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
Serial.print("Speed (knots): "); Serial.println(GPS.speed);
Serial.print("Angle: "); Serial.println(GPS.angle);
Serial.print("Altitude: "); Serial.println(GPS.altitude);
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
}
}
}
So I want the GPS to output correct data, but I don't have ideas on what to do.
Here is the schematic:
Thanks in advance for all help.