sparkfun / SparkFun_u-blox_GNSS_Arduino_Library

An Arduino library which allows you to communicate seamlessly with the full range of u-blox GNSS modules
Other
227 stars 100 forks source link

Ublox Neo-M9N module with UART or I2C? #193

Closed RodEnry closed 1 year ago

RodEnry commented 1 year ago

Hello everyone, I'm developing a custom board that uses a Ublox Neo-M9N module. The main microcontroller is an ESP32-S3. I'm able to communicate with UART with no issues.

I'd like to ask, from you experience, which is the best way to get the max speed/performance out from the GPS device. I absolutely need to get the LAT, LON, ALT, SPEED, SATELLITES and isFix at the rate of 20/25Hz.

In fact, the UART is now working at 38400 baud. Do you think that connecting the GPS by I2C will be better than through UART?

Many thanks! RodEnry

PaulZC commented 1 year ago

Hi @RodEnry ,

For high-speed logging applications, I'd recommend SPI over both I2C and UART. This library supports all three.

But, here's a back-of-the-envelope calculation that may help:

LAT, LON, ALT, SPEED, SATELLITES and isFix are all contained in the UBX PVT (Position Velocity Time) message. The UBX PVT message is 100 bytes total, 800 bits. At 20Hz, the data rate is going to be about 16000 bits per second - excluding overheads. So, yes, even UART at 38400 should be fast enough. So would standard 100kHz I2C.

But that's only true if PVT is the only message being generated. If you don't disable the standard NMEA messages, the module will attempt to produce those at 20Hz too and exceed what I2C and UART can support. If you later decide you want to log NMEA or perhaps UBX RAWX and SFRBX too, then you're kind of stuck.

You're developing a custom board, so my advice would be to design in SPI now, rather than wish you'd done it later... Prototype it first with one of our NEO-M9N breakouts and then make up your mind.

Best wishes, Paul

RodEnry commented 1 year ago

Hello Paul, many thanks for your prompt reply!

Yes, I already have the Sparkfun boards. They works great and they're extremely valuable for testing.

That's my code snipped about the initialization of the GPS module:

GPS_Serial.begin(38400,SERIAL_8N1, RXD2, TXD2); myGNSS.setUART1Output(COM_TYPE_UBX); //Set the UART port to output UBX only myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise) myGNSS.setMeasurementRate(50); //Set rate at 20Hz - one every 50 millis //Now change the baudrate to max myGNSS.setSerialRate(230400); //Set baudrate to 230400 GPS_Serial.updateBaudRate(230400); //Update baud rate of the serial port

I'm now trying to disable all the sentences except the UBX PVT you proposed. How I can do that? Do you have any code snippet? I'm asking because there are a ton of parameters and I don't want to make wrong things...

And why I should turn off NMEA noise on I2C port? (I saw an example about this)

Many thanks Enry

PaulZC commented 1 year ago

Hi Enry,

myGNSS.setUART1Output(COM_TYPE_UBX); disables the NMEA protocol on UART1. That will automatically disable all NMEA messages.

If you are not using the I2C port, you can disable it completely by sending myGNSS.setI2COutput(0); . It lightens the load on the module processor so it is better able to run at 20Hz.

You code is missing myGNSS.begin(GPS_Serial); - but I guess you knew that?

This example will help you configure the PVT message.

If you mess up, don't worry. You can always reset the module via the USB port. Please see: https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library/issues/191#issuecomment-1515038572

Best wishes, Paul