SlashDevin / NeoGPS

NMEA and ublox GPS parser for Arduino, configurable to use as few as 10 bytes of RAM
GNU General Public License v3.0
708 stars 195 forks source link

I2C Input stream #33

Closed bluespider42 closed 7 years ago

bluespider42 commented 7 years ago

I can't find any reference to using an i2c in the documentation or code. Is the feature implemented? if so how should I start?

jamesmayes commented 7 years ago

You should be able to use the Arduino Wire library since it derives from Stream. That's really what the NeoGPS library cares about.

SlashDevin commented 7 years ago

Yes, use the I2C Wire library to obtain bytes from the device. Then pass those bytes to NeoGPS, through the Character-Oriented methods. NMEAblink shows how to pass one byte from the serial port (here).

You have to be careful about reading from I2C: it will return 0xFF bytes when no data is available. There is a TXDATA_READY pin you could use. The PPS pin could also be used as a start flag (read until 0xFF appears again). Or just read constantly and skip 0xFF bytes... or just pass everything to gps.decode and let NeoGPS ignore the 0xFF bytes.

bluespider42 commented 7 years ago

SHould I just Wire.requestFrom(0x42, 1) followed by a Wire.read() in a loop or is it better to request more bytes and then continue to read untill 0xFF is returned?

bluespider42 commented 7 years ago

I've found my problem from an earler version of my code (where I was using the UART port) I had a if (fix.valid.location) {..} (after assigning fix = gps.fix() safely) which was never returning true for some reason.

jamesmayes commented 7 years ago

Did you confirm the proper last sentence for your device?

SlashDevin commented 7 years ago

SHould I just Wire.requestFrom(0x42, 1) followed by a Wire.read() in a loop or is it better to request more bytes and then continue to read untill 0xFF is returned?

It depends on your device. Which one are you using? I have never used the DDC (aka I2C) interface of a ublox GPS device, but according to the NEO-6M spec (section 4.3), I would think that reading more than one byte at a time is much more efficient. You can read the registers at 0xFD and 0xFE to get the number of available bytes, if you want.

So many choices! :)

I've found my problem from an earlier version of my code (where I was using the UART port) I had a

fix = gps.fix();
if (fix.valid.location) {..}

which was never returning true for some reason.

Like @jamesmayes said, use NMEAorder.ino to confirm you have chosen the correct LAST_SENTENCE. This is almost always the problem. (0x42 internet points to james!)

bluespider42 commented 7 years ago

Thanks for the help - I making progress now. I hadn't realised that Wire was derived from Stream and using it as such seemed a little counter intuitive to me.