//APRS_neo_gps_V1.1 #include #include //------------------------------------------------------------------------- // The GPSport.h include file tries to choose a default serial port // for the GPS device. If you know which serial port you want to use, // edit the GPSport.h file. // #include // Simply removed that for APRS Controller board and added the following: #define gpsPort Serial #define GPS_PORT_NAME "Serial" #warning Using Serial for GPS connection. //------------------------------------------------------------ // This object parses received characters // into the gps.fix() data structure static NMEAGPS gps; //------------------------------------------------------------ // Define a set of GPS fix information. It will // hold on to the various pieces as they are received from // an RMC sentence. It can be used anywhere in your sketch. static gps_fix fix; // the OLED used U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); uint32_t timer; bool screencleared = false; void setup() { gpsPort.begin( 9600 ); u8x8.begin(); u8x8.setFont(u8x8_font_chroma48medium8_r); /* // Start up screen on OLED u8x8.fillDisplay(); delay(1000); for (uint8_t r = 0; r < u8x8.getRows(); r++ ) { u8x8.clearLine(r); delay(100); } */ delay(100); u8x8.println("Waiting for"); delay(100); u8x8.println("SATs Fix!"); delay(500); u8x8.print("**"); timer = millis(); } //---------------------------------------------------------------- // This function gets called about once per second, during the GPS // quiet time. static void doSomeWork() { // timer = millis(); // reset the timer //---------------------------------------------------------------- // This section is run before a fix is made to show sat info (Available, Tracked, Time) // Count how satellites are being received for each GNSS int totalSatellites, trackedSatellites; totalSatellites = gps.sat_count; for (uint8_t i = 0; i < totalSatellites; i++) { if (gps.satellites[i].tracked) { trackedSatellites++; } } u8x8.inverse(); u8x8.drawString(0, 6, "TKD"); u8x8.drawString(5, 6, "AVL"); u8x8.drawString(10, 6, "UTC"); u8x8.noInverse(); enum {BufSizeTracked = 3}; //Space for 2 characters + NULL char trackedchar[BufSizeTracked]; snprintf (trackedchar, BufSizeTracked, "%d", trackedSatellites); u8x8.drawString(0, 7, " "); u8x8.drawString(0, 7, trackedchar); enum {BufSizeTotal = 3}; char availchar[BufSizeTotal]; snprintf (availchar, BufSizeTotal, "%d", totalSatellites); u8x8.drawString(5, 7, " "); u8x8.drawString(5, 7, availchar); if (fix.valid.time) { enum {BufSizeTime = 3}; int hour = fix.dateTime.hours;// + 2; KEEP UTC TIME int minute = fix.dateTime.minutes; char hourchar[BufSizeTime]; char minutechar[BufSizeTime]; snprintf (hourchar, BufSizeTime, "%d", hour); snprintf (minutechar, BufSizeTime, "%d", minute); if ( hour < 10 ) { snprintf (hourchar, BufSizeTime, "%02d", hour); } if ( minute < 10 ) { snprintf (minutechar, BufSizeTime, "%02d", minute); } u8x8.drawString(10, 7, hourchar); u8x8.drawString(12, 7, ":"); u8x8.drawString(13, 7, minutechar); } //---------------------------------------------------------------- // Once the location is found the top part of the screen is cleared and the fix data is shown if (fix.valid.location) { if (!screencleared) // do once { int r; for ( int r = 0; r < 5; r++ ) { u8x8.clearLine(r); } screencleared = true; } u8x8.inverse(); u8x8.drawString(0, 0, "FIX"); u8x8.drawString(0, 2, "LAT"); u8x8.drawString(0, 4, "LNG"); u8x8.noInverse(); enum {BufSize = 3}; // Space for 2 digits char satchar2[BufSize]; snprintf (satchar2, BufSize, "%d", fix.satellites); u8x8.drawString(4, 0, " "); u8x8.drawString(4, 0, satchar2); char latchar[10]; // Buffer big enough for 9-character float dtostrf(fix.latitude(), 3, 7, latchar); // Leave room for large numbers u8x8.drawString(4, 2, latchar); char longchar[10]; dtostrf(fix.longitude(), 3, 7, longchar); u8x8.drawString(4, 4, longchar); } } // This is the main GPS parsing loop. static void GPSloop() { while (gps.available( gpsPort )) { fix = gps.read(); doSomeWork(); } } void loop() { GPSloop(); // until we get a fix, print a dot every 5 seconds if (millis() - timer > 5000 && !screencleared) { timer = millis(); // reset the timer u8x8.print("."); } }