Hi everyone,
I'm using a SIMPLERTK2budget board from Ardusimple with the ZED-F9P and I'm having problems trying to receive data on my Arduino Mega, using UART 1 communication. (The ArduSimple board doesn't support I2C, so I have to use UART).
Wiring:
- Arduino 3.3V -> Vin F9P board
- Arduino GND -> GND F9P board
- Arduino IOREF -> IOREF F9P board
- Arduino RX (PIN 0) -> TX F9P board
- Arduino TX (PIN 1) -> RX F9P board
Arduino program 1: No issues
While using this basic program I do well received NMEA messages and can read them in the Arduino serial monitor so the communication is working.
void setup() {
Serial.begin(38400);
}
void loop() {
while ( Serial.available () )
{
Serial.write( Serial.read() );
}
Serial.println("");
delay(3000);
}
Arduino program 2: Issues
My goal is not only to read NMEA messages but to use all the advantages of the ZED-F9P and Arduino Library "SparkFun_u-blox_GNSS_Arduino_Library.h" to easily parse NMEA messages and get status like we can do it with I2C communication.
There is a code that has been developped which allows with an UART communication to get the same results as with I2C coomunication -> [code link here] for the original / at the end of this post, the code I use with RX pin = 0 and TX pin = 1 + comment where the code is stuck.
However, when I run it, the code gets stuck in the synchronization loop to check if it runs well at 38400 baud, so I'm not able to read anything -> so I think it means the Serial communication is not working and I don't understand why as it works with the program 1.
Would you know where this problem could comes from and how I can fix it?
Thanks a lot for your support!
Lucas
/*
Reading lat and long via UBX binary commands using UART @38400 baud - free from I2C
This example shows how to configure the library and U-Blox for serial port use as well as switching the module from the default 9600 baud to 38400.
Note: Long/lat are large numbers because they are * 10^7. To convert lat/long
to something google maps understands simply divide the numbers by 10,000,000. We do this so that we don't have to use floating point numbers.
Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!
Hardware Connections:
Connect the U-Blox serial TX pin to Uno pin 0
Connect the U-Blox serial RX pin to Uno pin 1
Open the serial monitor at 115200 baud to see the output
*/
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
SFE_UBLOX_GNSS myGNSS;
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX, TX. Pin 0 on Uno goes to TX pin on GNSS module.
long lastTime = 0; //Simple local timer. Limits amount of I2C traffic to u-blox module.
void setup()
{
Serial.begin(115200);
while (!Serial); //Wait for user to open terminal
Serial.println("SparkFun u-blox Example");
//Assume that the U-Blox GNSS is running at 9600 baud (the default) or at 38400 baud.
//Loop until we're in sync and then ensure it's at 38400 baud.
do {
//THIS IS WHERE THE PROGRAM IS STUCK AND STAY IN THE LOOP
Serial.println("GNSS: trying 38400 baud");
mySerial.begin(38400);
if (myGNSS.begin(mySerial) == true) break;
delay(100);
Serial.println("GNSS: trying 9600 baud");
mySerial.begin(9600);
if (myGNSS.begin(mySerial) == true) {
Serial.println("GNSS: connected at 9600 baud, switching to 38400");
myGNSS.setSerialRate(38400);
delay(100);
} else {
//myGNSS.factoryReset();
delay(2000); //Wait a bit before trying again to limit the Serial output
}
} while(1);
Serial.println("GNSS serial connected");
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.saveConfiguration(); //Save the current settings to flash and BBR
}
void loop()
{
//Query module only every second. Doing it more often will just cause I2C traffic.
//The module only responds when a new position is available
if (millis() - lastTime > 1000)
{
lastTime = millis(); //Update the timer
long latitude = myGNSS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(latitude);
long longitude = myGNSS.getLongitude();
Serial.print(F(" Long: "));
Serial.print(longitude);
Serial.print(F(" (degrees * 10^-7)"));
long altitude = myGNSS.getAltitude();
Serial.print(F(" Alt: "));
Serial.print(altitude);
Serial.print(F(" (mm)"));
byte SIV = myGNSS.getSIV();
Serial.print(F(" SIV: "));
Serial.print(SIV);
Serial.println();
}
}
