For the following code I am implementing a light sensor and a gps. The light sensor works fine, but I’m having trouble with the gps. It can’t seem to get the long and lat values for some reason…? (It just returns invalid) When I use the example code from the tinygps library though, the correct data is sent via serial to putty. Any ideas? Thank you so much in advance!
The GPS device continously sends data via the serial connection to the microcontroller but your code needs to read that data and feed it into the library via gps.encode() for the library to parse it. I can’t see your code doing any of that.
Yes, the common way to wrap multiple variables into one string goes via snprintf()
This is the gps code I have that works for when my electron is connected to my computer via USB. I’d like for my gps to work solely via battery (no USB connection) though, so I thought I would need to get rid of the serial prints/reads. If that is the case, how would I get the gps data (from gps.encode()) without having a usb connection?
Serial1 has nothing to do with USB but is the way the controller and the GPS module communicate - you need to keep that.
And even if there is no connection to your computer, the Serial.xxx() functions won’t interfere - so just leave them there.
Don’t confuse/conflate Serial and Serial1 - they are two different interfaces.
But to get the data off of your device into the world, then you may want to look into the docs regarding Particle.publish()