I have a strange problem. When I upload this sketch to Arduino, everything works and I am getting satellites number:
#include <TinyGPSPlus.h>
TinyGPSPlus gps;
boolean validGPS = false;
void setup()
{
Serial1.begin(9600); // or what ever the GPS's baudrate is
Serial.begin(9600);
}
void loop()
{
if (Serial1.available())
{
validGPS = gps.encode(Serial1.read());
}
if (validGPS)
{
// TinyGPS has told us we have received a valid GPS fix. We can now query it for position/course/time/etc. information.
Serial.println(gps.satellites.value());
}
}
Then I copy exactly the same code into my more complex sketch with other functionality and validGPS is always false. Why so?
Here is where things get broken:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <TinyGPSPlus.h>
// Define pin for temperature sensor
OneWire oneWire(12);
DallasTemperature sensors(&oneWire);
TinyGPSPlus gps;
boolean validGPS = false;
void setup()
{
Serial1.begin(9600); // or what ever the GPS's baudrate is
Serial.begin(9600);
sensors.begin();
}
void loop()
{
if (Serial1.available())
{
validGPS = gps.encode(Serial1.read());
}
if (validGPS)
{
Serial.println(gps.satellites.value());
}
sensors.requestTemperatures();
int airTemperatureValue = sensors.getTempCByIndex(0);
}
The way you're using the Dallas library is blocking. This is probably causing you to miss data on Serial1. Look at the library's 'WaitForConversion' and 'WaitForConversion2' examples to learn how to use it in a non-blocking manner.
Also, you're attempting to get a temperature reading every time the loop() function is called. Why? Do you really think the temperature will be changing so rapidly that you need to do that? If so, you're using the wrong sensor.
Finally, instead of using sensors.getTempCByIndex() every time, get the device's address once and then use getTempC() passing in the address. That way the library code doesn't have to do a bus scan every time you want the temperature.
at 9600 bauds you get roughly 960 characters per second so up to 720 characters during your 750ms
The Serial buffer can only hold the last 64 characters so the next time you go to gps.encode(Serial1.read()) you might have missed many characters (and you only submit 1 character before blocking again for 750ms) and the sentence does not make sense anymore and thus the library ignores it.
@mrwd, you've marked this thread as "SOLVED", yet you keep deleting your posts and code. Just as well, I guess, because what I saw before you deleted them was wrong. I'm curious what is the code that you finally think "SOLVED" it?