Since the M8P is in SMD technology, I can't test it with an Arduino board and I can only test it with a standalone arduino.
I'm not sure what you mean... You can test the I2C interface by connecting the M8P evaluation board to "an Arduino". Aren't you going to prototype something?
I would like to be sure if I can successfully use the I2C protocol in order to connect the SDA and SCL pins or if it is better to use the RX and TX pins.
The M8P can only act as an I2C slave. This means the master must constantly check for available bytes at address 0xFF (device address defaults to 0x42).
Alternatively, you could configure the TXD pin (normally the UART TX pin) to signal that bytes are available (TX READY). You would watch for that signal and then start reading bytes.
I can't find a way on how to use the Ublox Arduino NeoGPS Library to read the module by using the I2C protocol.
Because Wire
is derived from Stream
, you can use it in with NeoGPS:
#include <NMEAGPS.h>
#include <Wire.h>
#define gpsPort Wire
const uint8_t NEO_M8P_ADDR = 0x42;
const uint8_t NEO_M8P_DATA = 0xFF;
NMEAGPS gps;
//--------------------------
void setup()
{
Serial.begin(9600);
Serial.print( F("NEO-M8P test started\n") );
Serial.flush();
gpsPort.begin( NEO_M8P_ADDR );
// Configure TXREADY pin and threshold...
}
//--------------------------
void loop()
{
if (digitalRead( TXREADY )) {
// "Some" data bytes are ready
gpsPort.requestFrom( NEO_M8P_DATA, TXTHRESHOLD );
}
while (gps.available( gpsPort )) {
gps_fix fix = gps.read();
if (fix.valid.location)
Serial.print( fix.latitude(), 6 ); // floating-point display
Serial.print( ',' );
if (fix.valid.location)
Serial.print( fix.longitude(), 6 ); // floating-point display
Serial.println();
}
}
You just need to "request" the data so it becomes "available" for reading.
You should be aware that requestFrom
is a blocking routine. Nothing else will happen until all 8 bytes have been received by the Arduino. At 400KHz, that's only 250us, but that's a lot longer than reading a byte from the HardwareSerial input buffer.
It seems kind of silly to check the pin and request the bytes, but that's how master/slave works. You could skip using the TXREADY pin and just keep asking for bytes. When no bytes are ready, the M8P returns 0xFF bytes, which are ignored by the NeoGPS parser.
Using AltSoftSerial on pins 8 & 9 is more CPU intensive than I2C, so the I2C is probably faster in the long run. My NeoSWSerial is almost is good. Don't even think about using SoftwareSerial. Could you use Serial
for the M8P?
Cheers,
/dev,
author of NeoGPS