Program to read data from sensors, write them to a file which can then be interpreted by software to help show the path of a bicycle as it travels around a field

Dependencies:   C12832_lcd FatFileSystemCpp MMA7660 CMPS03 GPS

Fork of MSCUsbHost by Igor Skochinsky

Issue: Read GPS time (Closed: Fixed)

Next we would like to get the GPS module to output time in order to make it easier to work out when our results were recorded. Of course a GPS uses the discrete change in time between the satellites it is locked onto in order to work out position, somehow we could use this to give us a time output.

Currently we are using:

Import libraryGPS

Library for the EM-406 GPS module

to get position. I have found another library for another GPS module:

Import libraryMBed_Adafruit-GPS-Library

Adafruit Ultimate GPS Arduino library adapted for mBed use. Original found at https://github.com/adafruit/Adafruit-GPS-Library.

which has support for finding time. Now despite it being designed for another module I was hoping to rejig the code around to be suitable for our EM406A

This is code based on the reference code for the other GPS module:

gps.cpp

//gps.cpp
//for use with Adafruit Ultimate GPS
//Reads in and parses GPS data
 
#include "mbed.h"
#include "MBed_Adafruit_GPS.h"
 
Serial * gps_Serial;
Serial pc (USBTX, USBRX);
 
int main() {
    
    pc.baud(115200); //sets virtual COM serial communication to high rate; this is to allow more time to be spent on GPS retrieval
    
    gps_Serial = new Serial(p28,p27); //serial object for use w/ GPS
    Adafruit_GPS myGPS(gps_Serial); //object of Adafruit's GPS class
    char c; //when read via Adafruit_GPS::read(), the class returns single character stored here
    Timer refresh_Timer; //sets up a timer for use in loop; how often do we print GPS info?
    const int refresh_Time = 2000; //refresh time in ms
    
    myGPS.begin(9600);  //sets baud rate for GPS communication; note this may be changed via Adafruit_GPS::sendCommand(char *)
                        //a list of GPS commands is available at http://www.adafruit.com/datasheets/PMTK_A08.pdf
    
    myGPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //these commands are defined in MBed_Adafruit_GPS.h; a link is provided there for command creation
    myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
    myGPS.sendCommand(PGCMD_ANTENNA);
    
    pc.printf("Connection established at 115200 baud...\n");
    
    wait(1);
    
    refresh_Timer.start();  //starts the clock on the timer
    
    while(true){
        c = myGPS.read();   //queries the GPS
        
        if (c) { pc.printf("%c", c); } //this line will echo the GPS data if not paused
        
        //check if we recieved a new message from GPS, if so, attempt to parse it,
        if ( myGPS.newNMEAreceived() ) {
            if ( !myGPS.parse(myGPS.lastNMEA()) ) {
                continue;   
            }    
        }
        
        //check if enough time has passed to warrant printing GPS info to screen
        //note if refresh_Time is too low or pc.baud is too low, GPS data may be lost during printing
        if (refresh_Timer.read_ms() >= refresh_Time) {
            refresh_Timer.reset();
            pc.printf("Time: %d:%d:%d.%u\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds);   
            pc.printf("Date: %d/%d/20%d\n", myGPS.day, myGPS.month, myGPS.year);
            pc.printf("Fix: %d\n", (int) myGPS.fix);
            pc.printf("Quality: %d\n", (int) myGPS.fixquality);
            if (myGPS.fix) {
                pc.printf("Location: %5.2f%c, %5.2f%c\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
                pc.printf("Speed: %5.2f knots\n", myGPS.speed);
                pc.printf("Angle: %5.2f\n", myGPS.angle);
                pc.printf("Altitude: %5.2f\n", myGPS.altitude);
                pc.printf("Satellites: %d\n", myGPS.satellites);
            }
        }
    }
}

I'll experiment over the next few days however initial testing seemed to work without problem, although the GPS module hadn't actually locked onto a satellite yet

Example program

2 comments:

16 Mar 2017

Might be able to use code from this .h file, which comes inbuilt with the main mbed.h file. https://developer.mbed.org/users/hlipka/code/TimeZone/docs/0c7207d674d3/Time_8h_source.html

Could set it to print the time every 0.5 seconds until data collection stops, not sure how you'd write it to the gps.txt file though.

Not sure if the Adafruit GPS code will work with our GPS, if it does then we'd have to download the library for that GPS and half-inch the timer code from it in hopes it would work.

Also I changed the issue to a feature request and set it as major, we can change it back to a bug when it inevitably doesn't work.

17 Mar 2017

I looked at that but it appears to just be a conversion between unix time and real time, not entirely sure where its getting its time from though, neither file in that program specifies where it's from.

Ryan Irving wrote:

Not sure if the Adafruit GPS code will work with our GPS, if it does then we'd have to download the library for that GPS and half-inch the timer code from it in hopes it would work.

I don't think it'll work as is either, however there are things in there which might be applied to our EM406A

Ryan Irving wrote:

We can change it back to a bug when it inevitably doesn't work

Bro, I feel you