0

I have been actively trying to connect the 'Ultimate Breakout GPS v3' with an Ardunio UNO & have the BLYNK application running at the same time. I have a fully functional GPS module working in its own sketch and I also have a fully functional BLYNK app working in its own sketch. However, when I try to combine the code to have the GPS and BLYNK app working together, my GPS code gets stuck in a while loop. I think that it may have something to do with the Software Serial communication I am using for both the app and GPS module, but I am in college right now still new to learning these concepts. I can only think to attach the whole code so that you can see what is going on.

//Bluetooth/Blynk Definitions

#define BLYNK_USE_DIRECT_CONNECT
#define BLUETOOTH_TX_PIN 10
#define BLUETOOTH_RX_PIN 11

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
//#include <BlynkSimpleStream.h>
#include <BlynkSimpleSerialBLE.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>

//Cart GPS Definitions
#define GPS_TX_PIN 4
#define GPS_RX_PIN 5



char auth[] = "ruf1xsvCA3b-YPsR8CTGT2CgYwEYj78t";


//Serial Setups

SoftwareSerial bluetoothSerial(BLUETOOTH_TX_PIN, BLUETOOTH_RX_PIN); //(10,11)
SoftwareSerial cartSerial(GPS_TX_PIN, GPS_RX_PIN); //(4,5)


//Global Varibles

int x, y; //X,Y for Joystick Data
String NMEA1; //variable for first NMEA sentence
String NMEA2; //variable for second NMEA sentence
double cartLat, cartLon; 
char c; //to read characters coming from GPS

struct GeoLoc {
  float lat;
  float lon;
};

GeoLoc cartLoc;




//Joystick
BLYNK_WRITE(V10) {
  x = param[0].asInt(); // It extracts the x value of the Joystick inlcuded in the Mobile APP Blynk
  y = param[1].asInt(); // It extracts the y value of the Joystick inlcuded in the Mobile APP Blynk

  Serial.print("JoyX:"); Serial.println(x);
  Serial.print("JoyY:"); Serial.println(y);
}

//User GPS
double userLon, userLat, userAlt, userSpeed;
BLYNK_WRITE(V11) {
  GpsParam gps(param);
  userLon = gps.getLon();
  userLat = gps.getLat();
  userAlt = gps.getAltitude();
  userSpeed = gps.getSpeed();

  Serial.print("userLat: "); Serial.println(userLat, 7);
  Serial.print("userLon: "); Serial.println(userLon, 7);

  cartLoc = getLocation();

  Serial.print("cartLat: "); Serial.println(cartLoc.lat, 7);
  Serial.print("cartLon: "); Serial.println(cartLoc.lon, 7);

}

//cartGPS

Adafruit_GPS cartGPS(&cartSerial);


void readCartGPS(){

  Serial.print("Start of readCartGPS");
  clearCartGPS();
  Serial.print("Start of Whileloop");
  while(!cartGPS.newNMEAreceived()){ //loop until we have a good NMEA sentence
    c = cartGPS.read();
    Serial.print("Inside");
  }

  cartGPS.parse(cartGPS.lastNMEA()); //parse last good NMEA sentence
  NMEA1 = cartGPS.lastNMEA();

  while(!cartGPS.newNMEAreceived()){ //loop until we have a good NMEA sentence
    c = cartGPS.read();
  }
  cartGPS.parse(cartGPS.lastNMEA()); //parse last good NMEA sentence
  NMEA2 = cartGPS.lastNMEA();


  Serial.print("NMEA1:"); Serial.print(NMEA1);
  Serial.print("NMEA2:"); Serial.println(NMEA2);
}

void clearCartGPS(){  //Clear old and corrupt data from Serial Port

  Serial.print("Start of clearCartGPS");
  while(!cartGPS.newNMEAreceived()){ //loop until we have a good NMEA sentence
    c = cartGPS.read();
    Serial.println("DEBUG: INSIDE WHILE");
  }

  cartGPS.parse(cartGPS.lastNMEA()); //parse last good NMEA sentence

  while(!cartGPS.newNMEAreceived()){ //loop until we have a good NMEA sentence
    c = cartGPS.read();
  }

  cartGPS.parse(cartGPS.lastNMEA()); //parse last good NMEA sentence

  while(!cartGPS.newNMEAreceived()){ //loop until we have a good NMEA sentence
    c = cartGPS.read();
  }

  cartGPS.parse(cartGPS.lastNMEA()); //parse last good NMEA sentence

}

GeoLoc getLocation(){

    Serial.print("Start of GetLocation");
    readCartGPS();
    Serial.print("After readCartGPS is run");
    delay(300);

    cartLat = cartGPS.latitude;
    char latDirection = cartGPS.lat;
    if(latDirection == 'S'){
      cartLat = -1 * cartLat;
    }

    cartLon = cartGPS.longitude;
    char lonDirection = cartGPS.lon;
    if(lonDirection == 'W'){
      cartLon = -1 * cartLon;
    }



    cartLoc.lat = cartLat;
    cartLoc.lon = cartLon; 

//    Serial.print("Cart Latitude: "); Serial.println(cartLat, 7);
//    Serial.print("");
//    
//    Serial.print("Cart Longitude: "); Serial.println(cartLon, 7);
//    Serial.print("");

    return(cartLoc);

}


void setup() {

  Serial.begin(4800);

  cartGPS.begin(9600);
  cartGPS.sendCommand("$PGCMD,33,0*6D"); //Turn off antenna update message
  cartGPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ); //Set update rate to 10Hz
  cartGPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //Request RMC and GGA sentences only

  bluetoothSerial.begin(9600);
  Blynk.begin(bluetoothSerial, auth);
  Serial.println("Test_Setup");

}

void loop() {

  Blynk.run();

  delay(100);

}

If I run this code on the Arduino, then my serial monitor will read the following: (Note that the BLYNK_WRITE(V11) is an interupt triggered when the GPS 'widget' in the BLYNK app updates)

Test_Setup
userLat: 42.1978645
userLon: -83.1744308
Start of GetLocation
Start of readCartGPS
Start of clearCartGPS
DEBUG: INSIDE WHILE
DEBUG: INSIDE WHILE
DEBUG: INSIDE WHILE
DEBUG: INSIDE WHILE
DEBUG: INSIDE WHILE
DEBUG: INSIDE WHILE
DEBUG: INSIDE WHILE
DEBUG: INSIDE WHILE
DEBUG: INSIDE WHILE
DEBUG: INSIDE WHILE
DEBUG: INSIDE WHILE
DEBUG: INSIDE WHILE

However, if I isolate only the code relating to the cartGPS, then the Serial Monitor will read:

NMEA1:$GPRMC,232347.000,A,4211.8708,N,08310.4676,W,0.08,78.84,091119,,,A*4D
NMEA2:$GPGGA,232348.000,4211.8708,N,08310.4675,W,1,08,1.06,171.9,M,-33.9,M,,*5C

Cart Latitude: 4211.8706054
Cart Longitude: -8310.4677734
NMEA1:$GPRMC,232350.000,A,4211.8707,N,08310.4676,W,0.06,164.81,091119,,,A*73
NMEA2:$GPGGA,232351.000,4211.8707,N,08310.4675,W,1,08,1.06,171.9,M,-33.9,M,,*5B

Cart Latitude: 4211.8706054
Cart Longitude: -8310.4677734

Which is expected.

EBELL
  • 1

1 Answers1

0

Just a quick comment - you may want to take the delay command out of your void loop. You can create a timer event for it and put the timer.run in the void loop

  • Hi Robin, I took delay out, and it doesn't seem to have any affect on the program. Thanks for the comment though. Do you have any other thoughts on the program issue mentioned above? – EBELL Nov 12 '19 at 22:46