ZED F9P communication issues with Arduino Mega using UART 1

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();
  }
}

Pins 0 and 1 are a hardware UART. No need to use SoftwareSerial on hardware pins. Also, your code this is not working is opening up Serial (which is pins 0 and 1) and then opening up Software serial which also uses pin 0 and 1. You can't do that.

Since you are using a Mega, you have multiple hardware serial ports. Leave pins 0 and 1 free so you can Serial.print() debug messages to the Serial Monitor. Connect your device to Serial1 (pins 18 & 19).

BUT, before you do that, You can not power your device at 3.3V and then communicate with +5V on RX/TX. You need level shifters, at least on the TX line from the Mega to your device.

The code in your link is not using pins0 and 1.
Is there some special reason, you need to use the same serial that is connected to your usb??

EDIT: @blh64 already answered you while I was writing...

1 Like

Thanks for the information about the Serial, I was not aware of this before and made the change :slight_smile:

And also you're right on the 5V, it is how I wired it at first but I changed it (for a reason I don't remember). I am back to 5V.
But with this change, from my knowledge I don't need level shifters since the IOREF pin is doing this work, so the pins of my gnss board are working in 5V.

I tried the code again with all the changes but I still can't get this connection to the gnss module :confused:
(Also, I did not mentionned it before but, I had to configure the gnss module. So, gnss has UBX+NMEA messages as output and UBX messages as input)

For the one who might have this issue too:

I was doing everything correctly but it was because of the ArduSimple configuration which has conflicting with the code.

On u-center, go to UBX-CFG-CFG to restore the default u-blox configuration. Select "Revert to default configuration" and click "Send".

Then "Save current configuration" and "Send" again.

Also just in case, make sure you have the good firmware in using UBX-MON-VER. It should be 1.32 for best results.

Last thing, after having restored the f9p default configuration, do not touch at all to UBX-CFG-PRT. For the protocol in, do not put anything or it will not work, even "none".

Capture

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.