I have been working on a project that uses a Adafruit GPS chip, and for some reason it doesn't work with my custom code, only the examples work, i have tried removing parts of the code to see if it works but have had no luck, it only works with my code when i remove everything except the code talking to the GPS.
The code that doesn't work:
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#include "SdFat.h"
#include "sdios.h"
#include <Adafruit_GPS.h>
#include <Wire.h>
#include <Adafruit_MS8607.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h"
#include <Adafruit_INA260.h>
//setup SdFat not confusing at all
uint32_t timer = millis();
//const int8_t DISABLE_CS_PIN = -1;
#ifndef SDCARD_SS_PIN
const uint8_t SD_CS_PIN = BUILTIN_SDCARD;
#else // SDCARD_SS_PIN
const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
//#endif // SDCARD_SS_PIN
//#if HAS_SDIO_CLASS
//#define SD_CONFIG SdioConfig(FIFO_SDIO)
//#elif ENABLE_DEDICATED_SPI
//#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(16))
//#else // HAS_SDIO_CLASS
//#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(16))
#endif // HAS_SDIO_CLASS
SdFs sd;
FsFile file;
FsFile file1;
FsFile file2;
FsFile file3;
FsFile file4;
#define LOG_EVENTS "Events.csv"
#define LOG_ALTDAT "Altitude.csv"
#define LOG_GPS "GPS Log.csv"
#define LOG_EVERYTHING "Fused data.csv"
#define LOG_POWER "Power level.csv"
//set up everything else
const int buzzer = 8;
int alt = 0.00;
boolean ready = false;
boolean launch = false;
boolean Main_out = false;
boolean Sec_out = false;
boolean GPS_out = false;
boolean Chip_check = false;
boolean Powermes = true;
boolean onlybuzz1 = true;
boolean onlybuzz12 = true;
boolean onlyone = true;
boolean onlyone2 = true;
boolean onlyone3 = true;
boolean apogge = false;
unsigned long previousTime = 0;
unsigned long previousTime2 = 0;
int reading1 = 0.0;
int reading2 = 0.0;
#define LED_PIN 4
#define LED_COUNT 2
#define BRIGHTNESS 50
#define NUMPIXELS 2
Adafruit_NeoPixel pixels(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_MS8607 ms8607;
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BMP3XX bmp;
#define GPSSerial Serial6
Adafruit_GPS GPS(&GPSSerial);
#define GPSECHO false
Adafruit_INA260 ina260 = Adafruit_INA260();
void setup(){
pixels.begin();
Serial.begin(115200);
Serial.println("Starting up....");
//setup GPS
delay(1000);
//setup current sensor
if (!ina260.begin()) {
Serial.println("Couldn't find INA260 chip :(");
while (1);
}
Serial.println("Current monitor setup....");
delay(1000);
// setup main altimeter
if (!bmp.begin_I2C()) {
Serial.println("Could not find BMP390 :(");
while (1);
}
bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
bmp.setOutputDataRate(BMP3_ODR_50_HZ);
Serial.println("BMP390 setup....");
delay(1000);
//setup high altitude altimeter
if (!ms8607.begin()) {
Serial.println("Failed to find MS8607 chip :(");
while (1) { delay(10); }
}
ms8607.setHumidityResolution(MS8607_HUMIDITY_RESOLUTION_OSR_8b);
Serial.println("High altitude altimeter setup....");
delay(1000);
//setup sd card.... pray/send good vibes/plz work
if (!sd.begin(SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(50)))) {
Serial.println("SD card not found...bruh :(");
}
//now make the files
file = sd.open(LOG_EVENTS, FILE_WRITE);
file1 = sd.open(LOG_ALTDAT, FILE_WRITE);
file2 = sd.open(LOG_GPS, FILE_WRITE);
file3 = sd.open(LOG_EVERYTHING, FILE_WRITE);
file4 = sd.open(LOG_POWER, FILE_WRITE);
if (!file.open(LOG_EVENTS, FILE_WRITE)) {
Serial.println("open failed file 1 :(");
return;
}
if (!file1.open(LOG_ALTDAT, FILE_WRITE)) {
Serial.println("open failed file 2 :(");
return;
}
if (!file2.open(LOG_GPS, FILE_WRITE)) {
Serial.println("open failed file 3 :(");
return;
}
if (!file3.open(LOG_EVERYTHING, FILE_WRITE)) {
Serial.println("open failed file 4 :(");
return;
}
if (!file4.open(LOG_POWER, FILE_WRITE)) {
Serial.println("open failed file 4 :(");
return;
}
delay(1000);
Serial.println("GPS maybe up..idk.....");
delay(1000);
Serial.println("Aight we good");
pinMode(buzzer, OUTPUT);
GPS.begin(9600);
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// uncomment this line to turn on only the "minimum recommended" data
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
// For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
// the parser doesn't care about other sentences at this time
// Set the update rate
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
// For the parsing code to work nicely and have time to sort thru the data, and
// print it out we don't suggest using anything higher than 1 Hz
// Request updates on antenna status, comment out to keep quiet
GPS.sendCommand(PGCMD_ANTENNA);
delay(1000);
// Ask for firmware version
GPSSerial.println(PMTK_Q_RELEASE);
}
void 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.print(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 > 2000) {
timer = millis(); // reset the timer
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);
Serial.print("Antenna status: "); Serial.println((int)GPS.antenna);
}
}
sensors_event_t temp, pressure, humidity;
ms8607.getEvent(&pressure, &temp, &humidity);
if (!file.open(LOG_EVENTS, O_WRITE)) {
Serial.println("open failed file 1 :(");
return;
}
if (!file1.open(LOG_ALTDAT,O_WRITE)) {
Serial.println("open failed file 2 :(");
return;
}
if (!file2.open(LOG_GPS, O_WRITE)) {
Serial.println("open failed file 3 :(");
return;
}
if (!file3.open(LOG_EVERYTHING, O_WRITE)) {
Serial.println("open failed file 4 :(");
return;
}
file4.open(LOG_POWER, O_WRITE);
if(Powermes == true){
file4.print("Powered up at:");
file4.print(GPS.hour); file.print(":");
file4.print(GPS.minute);
file4.println("--------------------------");
file.print("Powered up at:");
file.print(GPS.hour); file.print(":");
file.print(GPS.minute);
file.println("--------------------------");
file1.print("Powered up at:");
file1.print(GPS.hour);
file1.print(":");
file1.print(GPS.minute);
file1.println("-------------------------");
file2.print("Powered up at:");
file2.print(GPS.hour);
file2.print(":");
file2.print(GPS.minute);
file2.println("-------------------------");
file3.print("Powered up at:");
file3.print(GPS.hour);
file3.print(":");
file3.print(GPS.minute);
file3.println("------------------------");
Powermes = false;
}
if(ready == true){
if(onlybuzz1 == true){
if((int)GPS.fix == 1){
file.print("Ready for launch at ");
file.print(GPS.hour);
file.print(":");
file.print(GPS.minute);
file.println(" UTC");
}else{
file.print("Ready for launch at ");
file.println(millis());
}
onlybuzz1 = false;
}
if(bmp.readAltitude(1013.25) >= 5.0){
if(onlyone == true){
if((int)GPS.fix == 1){
file.print("Launch! at ");
file.print(GPS.hour);
file.print(":");
file.print(GPS.minute);
file.println(" UTC");
}else{
file.print("Launch! at: ");
file.println(millis());
}
onlyone = false;
}
reading1 = bmp.readAltitude(1013.25) - alt;
unsigned long currentTime = millis(); // launch stuff done here
if(currentTime - previousTime >= 40){
reading2 = bmp.readAltitude(1013.25) - alt;
previousTime = currentTime;
}
if(reading2 - reading1 >= 3.0){
apogge = true;
}
if(apogge == true){
if(onlyone3 == true){
if((int)GPS.fix == 1){
file.print("Apogge at an altitude of: ");
file.print(bmp.readAltitude(1013.25) - alt);
file.print(" At ");
file.print(GPS.hour);
file.print(":");
file.print(GPS.minute);
file.println(" UTC");
}else{
file.println("Apogge at an altitude of: ");
file.print(bmp.readAltitude(1013.25) - alt);
file.print(" At ");
file.println(millis());
}
onlyone3 = false;
}
}
}
}else{
pixels.clear();
pixels.setPixelColor(1, pixels.Color(1, 120, 255)); // not ready yet,set MCO blue.
pixels.show();
if(bmp.readAltitude(1013.25) >= alt){
alt++;
}
if(bmp.readAltitude(1013.25) <= alt){
alt--;
}
if(bmp.readAltitude(1013.25) - alt <= 0.50){
ready = true;
pixels.clear();
pixels.setPixelColor(1, pixels.Color(12, 255, 1)); // ready for launch, set MCO green.
pixels.show();
}
}
if((int)GPS.fix == 1){
pixels.setPixelColor(0, pixels.Color(28, 255, 1)); // no gps fix, set PCI green
pixels.show();
if(onlybuzz12 == true){
file.print("Got a GPS fix at ");
file.print(GPS.hour);
file.print(":");
file.print(GPS.minute);
file.println(" UTC");
onlybuzz12 = false;
}
}else{
pixels.setPixelColor(0, pixels.Color(255, 8, 1)); // gps got a fix, set PCI red
pixels.show();
}
if(ina260.readBusVoltage() <= 5500){
unsigned long currentTime2 = millis();
if(currentTime2 - previousTime2 >= 4000){
file.print("LOW VOLTAGE! VOLTAGE AT: ");
file.print(ina260.readBusVoltage() / 1000);
file.println(" VOLTS!");
previousTime2 = currentTime2;
}
}
if((int)GPS.fix == 1){
file4.println(GPS.hour);
file4.print(":");
file4.print(GPS.minute);
file4.print(" UTC");
}else{
file4.print(millis());
file4.print(" | ");
}
file4.print(ina260.readBusVoltage() / 1000);
file4.print(" Volts");
file4.print(" | ");
file4.print(ina260.readCurrent());
file4.print(" mA");
file4.print(" | ");
file4.print(ina260.readPower());
file4.print(" mW");
file4.println(" | ");
file2.print(" Time: ");
file2.print(GPS.hour);
file2.print(":");
file2.print(GPS.minute);
file2.print(".");
file2.print(GPS.seconds);
file2.print(" | ");
file2.print(" Location: ");
file2.print(GPS.latitude, 4);
file2.print(GPS.lat);
file2.print(", ");
file2.print(GPS.longitude, 4);
file2.print(GPS.lat);
file2.print(" | ");
file2.print(" Speed (knots): ");
file2.print(GPS.speed);
file2.print(" | ");
file2.print(" Angle: ");
file2.print(GPS.angle);
file2.print(" | ");
file2.print(" Altitude(sea level): ");
file2.print(GPS.altitude);
file2.print(" | ");
file2.print(" Satellites: ");
file2.print(GPS.satellites);
file2.print(" | ");
file2.print(" Fix: ");
file2.print((int)GPS.fix);
file2.print(" | ");
file2.print(" Quality: ");
file2.print((int)GPS.fixquality);
file2.print(" | ");
file2.print(" Date: ");
file2.print(GPS.day, DEC);
file2.print('/');
file2.print(GPS.month, DEC);
file2.print("/20");
file2.print(GPS.year, DEC);
file2.print(" | ");
file2.print(" Antenna status: ");
file2.println((int)GPS.antenna);
if((int)GPS.fix == 1){
file1.print(GPS.hour);
file1.print(":");
file1.print(GPS.minute);
file1.print(" UTC");
}else{
file1.print(millis());
}
file1.print(" BMP390: ");
file1.print(" Altitude: ");
file1.print(bmp.readAltitude(1013.25) - alt);
file1.print(" hPa ");
file1.print(bmp.pressure / 100.0);
file1.print(" Temp(C) ");
file1.print(bmp.temperature);
file1.print(" | ");
file1.print("MS8607: ");
file1.print(" hPa: ");
file1.print(pressure.pressure);
file1.print(" Temp(C): ");
file1.print(temp.temperature);
file1.print(" Humidity: ");
file1.println(humidity.relative_humidity);
file.flush();
file1.flush();
file2.flush();
file3.flush();
file4.flush();
//Serial.println(bmp.readAltitude(1013.25) - alt);
}
The code that does work:
// Test code for Ultimate GPS Using Hardware Serial (e.g. GPS Flora or FeatherWing)
//
// This code shows how to listen to the GPS module via polling. Best used with
// Feathers or Flora where you have hardware Serial and no interrupt
//
// Tested and works great with the Adafruit GPS FeatherWing
// ------> Adafruit Ultimate GPS FeatherWing : ID 3133 : Adafruit Industries, Unique & fun DIY electronics and kits
// or Flora GPS
// ------> Flora Wearable Ultimate GPS Module : ID 1059 : Adafruit Industries, Unique & fun DIY electronics and kits
// but also works with the shield, breakout
// ------> Adafruit Ultimate GPS Logger Shield - Includes GPS Module : ID 1272 : Adafruit Industries, Unique & fun DIY electronics and kits
// ------> Adafruit Ultimate GPS Breakout - 66 channel w/10 Hz updates [PA1616S] : ID 746 : Adafruit Industries, Unique & fun DIY electronics and kits
//
// Pick one up today at the Adafruit electronics shop
// and help support open source hardware & software! -ada
#include <Adafruit_GPS.h>
// what's the name of the hardware serial port?
#define GPSSerial Serial6
// Connect to the GPS on the hardware port
Adafruit_GPS GPS(&GPSSerial);
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO false
uint32_t timer = millis();
void setup()
{
//while (!Serial); // uncomment to have the sketch wait until Serial is ready
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
// also spit it out
Serial.begin(115200);
Serial.println("Adafruit GPS library basic parsing test!");
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
GPS.begin(9600);
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// uncomment this line to turn on only the "minimum recommended" data
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
// For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
// the parser doesn't care about other sentences at this time
// Set the update rate
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
// For the parsing code to work nicely and have time to sort thru the data, and
// print it out we don't suggest using anything higher than 1 Hz
// Request updates on antenna status, comment out to keep quiet
GPS.sendCommand(PGCMD_ANTENNA);
delay(1000);
// Ask for firmware version
GPSSerial.println(PMTK_Q_RELEASE);
}
void loop() // run over and over again
{
// 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.print(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 > 2000) {
timer = millis(); // reset the timer
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);
Serial.print("Antenna status: "); Serial.println((int)GPS.antenna);
}
}
}
In my code it just outputs all the info as zero even when it has a fix, not sure what is going on. Im using a Teensy 3.6 built onto a custom pcb for my micro processor.
type or paste code here