SparkFun Photon RedBoard + SparkFun Weather Shield + GP-735 + BLYNK ( Problem with ParticleSoftSerial library)

photon
Tags: #<Tag:0x00007fe21f72aca0>

#1

Hello everyone,
I’m new user of this forum and beginer in programming. Please be indulgence. I try to build home weather station project using SparkFun Photon RedBoard + SparkFun Weather Shield + GP-735 + BLYNK. I connected everything besides GP-735. I think I have problem to get data from this GPS module. I know that SerialSoftware.h from Arduino don’t work in this case. I tried to use ParticleSoftSerial library, but I have problem to implement this to my program. This is the piece of orginal code of GPS module.

#include <SoftwareSerial.h> //Needed for GPS

static const int RXPin = 5, TXPin = 4; //GPS is attached to pin 4(TX from GPS) and pin 5(RX into GPS)
SoftwareSerial ss(RXPin, TXPin); 

const byte GPS_PWRCTL = 6; //Pulling this pin low puts GPS to sleep but maintains RTC and RAM

void setup()
{
  ss.begin(9600); //Begin listening to GPS over software serial at 9600. This should be the default baud of the module.
  
  pinMode(GPS_PWRCTL, OUTPUT);
  digitalWrite(GPS_PWRCTL, HIGH); //Pulling this pin low puts GPS to sleep but maintains RTC and RAM
}

void loop()
{
  Serial.print(",lat=");
  Serial.print(gps.location.lat(), 6);
  Serial.print(",lng=");
  Serial.print(gps.location.lng(), 6);
  Serial.print(",altitude=");
  Serial.print(gps.altitude.meters());
  Serial.print(",sats=");
  Serial.print(gps.satellites.value());

  char sz[32];
  Serial.print(",date=");
  sprintf(sz, "%02d/%02d/%02d", gps.date.month(), gps.date.day(), gps.date.year());
  Serial.print(sz);

  Serial.print(",time=");
  sprintf(sz, "%02d:%02d:%02d", gps.time.hour(), gps.time.minute(), gps.time.second());
  Serial.print(sz);
  
  //smartdelay(800); //Wait 1 second, and gather GPS data
}

//While we delay for a given amount of time, gather GPS data
static void smartdelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

I tried to convert this code to be compatible with new library. I looked the example of ScruffR code and wrote something like this. Please tell me what to convert to get correct data from this GPS module.

#include <ParticleSoftSerial.h>

#define GPS data

// GPS is attached to pin 4(TX from GPS) and pin 5(RX into GPS)
static const int RXPin = 5, TXPin = 4; 
ParticleSoftSerial data(RXPin, TXPin); 

const byte GPS_PWRCTL = 6; //Pulling this pin low puts GPS to sleep but maintains RTC and RAM

void setup()
{
  GPS.begin(9600); //Begin listening to GPS over software serial at 9600. This should be the default baud of the module.
  
  pinMode(GPS_PWRCTL, OUTPUT);
  digitalWrite(GPS_PWRCTL, HIGH); //Pulling this pin low puts GPS to sleep but maintains RTC and RAM
}

void loop()
{
  Serial.print(",lat=");
  Serial.print(gps.location.lat(), 6);
  Serial.print(",lng=");
  Serial.print(gps.location.lng(), 6);
  Serial.print(",altitude=");
  Serial.print(gps.altitude.meters());
  Serial.print(",sats=");
  Serial.print(gps.satellites.value());

  char sz[32];
  Serial.print(",date=");
  sprintf(sz, "%02d/%02d/%02d", gps.date.month(), gps.date.day(), gps.date.year());
  Serial.print(sz);

  Serial.print(",time=");
  sprintf(sz, "%02d:%02d:%02d", gps.time.hour(), gps.time.minute(), gps.time.second());
  Serial.print(sz);
  
  //smartdelay(800); //Wait 1 second, and gather GPS data
}

//While we delay for a given amount of time, gather GPS data
static void smartdelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (GPS.available())
      gps.encode(GPS.read());
  } while (millis() - start < ms);
}

Thank you in advance for your help.


#2

Just out of interest, why are you not using hardware Serial1 (RX & TX pins)?

I’m also not sure about the reason for the double indirection to first #define GPS data and then use ParticleSoftSerial data(RXPin, TXPin) to then use GPS.begin(9600). Why not just directly use ParticleSoftSerial GPS(RXPin, TXPin)?
Next, you are using gps (lower case) but I can’t see where you have that declared.
Finally, you do mention something doesn’t work but you don’t really say what exactly is not working and in what way.

  • do you get build errors?
  • do you get no data?
  • do you get wrong data?

BTW, we recommend not to use anonymous pin numbers but be more explicit and use something like D4 and D5 as printed on the board.


#3

Thank you for your answer. I used code from the example. SparkFun used 4,5,6 pins, declared specially for the GPS in their Weather Shield. Ok I correct this, now is directly ParticleSoftSerial GPS(RXPin, TXPin) I added declaration of GPS module to this example code and also correct pins do D4,D5,D6. I don’t have build errors, I get no data - 0.00. I used TinyGPS++.h library from particle.io. Maybe this library is wrong or GPS module is broken ? Other data pressure, humidity, temperature, etc. are correct.

#include <TinyGPS++.h>
#include <ParticleSoftSerial.h>

// GPS is attached to pin 4(TX from GPS) and pin 5(RX into GPS)
static const int RXPin = D5, TXPin = D4; 
ParticleSoftSerial GPS(RXPin, TXPin); 

TinyGPSPlus gps;

const byte GPS_PWRCTL = D6; //Pulling this pin low puts GPS to sleep but maintains RTC and RAM

void setup()
{
  GPS.begin(9600); //Begin listening to GPS over software serial at 9600. This should be the default baud of the module.
  
  pinMode(GPS_PWRCTL, OUTPUT);
  digitalWrite(GPS_PWRCTL, HIGH); //Pulling this pin low puts GPS to sleep but maintains RTC and RAM
}

void loop()
{
  Serial.print(",lat=");
  Serial.print(gps.location.lat(), 6);
  Serial.print(",lng=");
  Serial.print(gps.location.lng(), 6);
  Serial.print(",altitude=");
  Serial.print(gps.altitude.meters());
  Serial.print(",sats=");
  Serial.print(gps.satellites.value());

  char sz[32];
  Serial.print(",date=");
  sprintf(sz, "%02d/%02d/%02d", gps.date.month(), gps.date.day(), gps.date.year());
  Serial.print(sz);

  Serial.print(",time=");
  sprintf(sz, "%02d:%02d:%02d", gps.time.hour(), gps.time.minute(), gps.time.second());
  Serial.print(sz);
  
  //smartdelay(800); //Wait 1 second, and gather GPS data
}

//While we delay for a given amount of time, gather GPS data
static void smartdelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (GPS.available())
      gps.encode(GPS.read());
  } while (millis() - start < ms);
}


#4

I’m still not sure why you use a software interface (ParticleSoftSerial) when you still have the hardware interface available.

Are you sure your GPS module does have a fix? When you are testing inside chances are quite high that you just don’t get a good enough signal.

You are also not calling smartdelay() which would be required to actually read the data from the module and without data there will be little to get any information off of :wink:


#5

In this shield I have deep switch to change HW or SW UART comunnication. Ok I called smartdelay() and no results. Maybe you have a good idea to test this gps module outside, away form high buildings