7 years, 8 months ago.

GPS With Nucleo F401RE

I have been having a horrible time trying to get GPS working.

#include "mbed.h"
#include "GPS.h"
#include "main.h"

#include <iostream>
#include <sstream>
#include <bitset>
 
Serial pc(USBTX, USBRX);
GPS gps(D8, D2);
 
DigitalOut myled(LED1);

int main() {
    pc.printf("Searching...");
    while (1) {  //run in this loop forever
        if (gps.sample()) {  //if gps.sample returns 1 do this code
            //myled = myled=0;
            myled=0;
            pc.printf("long %f, lat %f\n\r", gps.longitude, gps.latitude);
            wait(1);
        }
        else{
            //myled = myled=1;
            myled=1;
            pc.printf("No Lock Found!!!!");  // Lock must equal a GPS signal
            wait(1);
            }
    }
}

When I run the program, I see "Searching..." and then nothing happens. I can tell it goes into the while loop, but it doesn't seem to do either section of the if statement. If a lock isn't found, "No Lock Found" should get printed. Instead, nothing happens at all. Any ideas?

Hi there,

Which GPS module are you using?

- Jenny, team Mbed

posted by Jenny Plunkett 22 Mar 2018
Be the first to answer this question.