M9N Sparkfun i2c - freezes after random time

Hello support community,

I would appreciate your support in the following situation:

I have a M9N Sparkfun i2c, an Arduino MEGA and the Sparkfun UBLOX GNSS Library.

In the code’s loop (see below), I am constantly asking for the coordinates ant other data (with approx 2 seconds between each set of interrogations); The device works well for a random time (5 minites to 4 hours), and then freezes. Using my noob investigation methods (serial println’s everywhere in the code), i noticed it freezes right when calling the myGNSS.getLatitude(); I also printed the library’s debug, using: myGNSS.enableDebugging(Serial, false);

The debug freezes here:

    ...Test 1
    ...Sending: CLS:NAV ID:PVT Len: 0x0 Payload:
    ...sendCommand: Waiting for No ACK response
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: Reading 100 bytes
    ...

Whyle it normally prints the whole thing as so:

    ...Test 1
    ...Sending: CLS:NAV ID:PVT Len: 0x0 Payload:
    ...sendCommand: Waiting for No ACK response
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: OK, zero bytes available
    ...checkUbloxI2C: Reading 100 bytes
    ...Incoming: Size: 92 Received: CLS:NAV ID:PVT Len: 0x5C Payload: 58 16 62 16 E7 7 2 2 8 12 1D 37 1E 0 0 0 86 AD FB FF 3 3 FA 18 F9 E3 8B F 84 8E 80 1A D3 14 2 0 C2 8C 1 0 36 8 0 0 BE A 0 0 1 0 0 0 F9 FF FF FF FA FF FF FF 7 0 0 0 7A 87 F3 0 DF 0 0 0 DD 4D 5C 0 5F 0 0 0 EE 13 4F 2F 0 0 0 0 0 0 0 0
    ...packetCfg now valid
    ...packetCfg classAndIDmatch
    ...waitForNoACKResponse: valid data with CLS/ID match after 852 msec

My loop code is:

    void loop() {
      bool dateTimeCheck = false;
      int del = 250;  //printing delay times
      printingActive = false;
     
      twist.setColor(100, 100, 100);
     
      delay(1000);
     
      if (millis() - lastTime > 1200000) {
        printingActive = true;
        lastTime = millis();
      }
     
      if (twist.isPressed()) {
        twist.setColor(0, 255, 0);  //Set the Red, Green, and Blue LED brightnesses
        printingActive = true;
        printer.wake();
        delay(1000);
        //printData("", 200);
        //printer.flush();
      }
     
      pressure = sezorBME.readFloatPressure() * 0.00750062;
      temperature = sezorBME.readTempC();
     
      delay(500);
     
      twist.setColor(0, 0, 100);  //Set the Red, Green, and Blue LED brightnesses
     
      delay(500);
     
      Serial.println("Test 1");
     
      latitude = myGNSS.getLatitude(1500) / 10000000.000000;
      delay(100);
      longitude = myGNSS.getLongitude(1500) / 10000000.000000;
      delay(100);
      heading = myGNSS.getHeading(1500) / 100000.0000;  //degrees
      delay(100);
      speed = myGNSS.getGroundSpeed(1500) * 0.00194384;  //mm/s to knots
      delay(100);
      SIV = myGNSS.getSIV(1500);
      delay(100);
      Serial.println("Test 2");
     
      if (SIV > 7 && speed > 0.8 && myGNSS.getGnssFixOk()) {
        //getGnssFixOk
        distanceLog += distanceInKmBetweenEarthCoordinates(ilatitude, ilongitude, latitude, longitude);
        ilatitude = latitude;
        ilongitude = longitude;
        //distanceLog2 = myGNSS.assumeAutoNAVODO(bool enabled)
      }
     
      delay(100);
      year = myGNSS.getYear(1500);
      delay(100);
      month = myGNSS.getMonth(1500);
      delay(100);
      day = myGNSS.getDay(1500);
      delay(100);
      hour = myGNSS.getHour(1500);
      delay(100);
      minute = myGNSS.getMinute(1500);
      delay(100);
      second = myGNSS.getSecond(1500);
      delay(100);
      Serial.println("07 - read date");
      //myGNSS.setDGNSSConfiguration()
     
      String datecheck = String("");
      if (myGNSS.getTimeValid(1500) && myGNSS.getDateValid(1500)) {
        datecheck = datecheck + "DT: OK";
      } else {
        datecheck = datecheck + "DT: NOT OK";
      }
     
      String title = "\n** BOOK ENTRY nr." + String(logbookEntry) + " **\n";
      String dateTime = String(year) + "/" + String(month) + "/" + String(day) + ", " + String(hour) + ":" + String(minute) + ":" + String(second) + "; ";
      //String coords1 = "LAT: " + String(latitude, 6) + ";";
      //String coords2 = "LONG: " + String(longitude, 6) + ";";
      String coords = "LAT: " + String(latitude, 6) + "; LONG: " + String(longitude, 6) + ";";
      String navi = "HEADING: " + String(heading, 3) + "; ";
      String navi2 = "SPD: " + String(speed, 2) + "; ";
      String logprint = "Dist. log: " + String(distanceLog, 2);
      String logprint2 = "Dist. log2: " + String(distanceLog2, 2);
      String weather = "T: " + String(temperature, 2) + ", P: " + String(pressure, 3);
      String other = "SIV: " + String(SIV) + "; Sail[ ]/Engine[ ]\nWIND Spd:______WIND Dir:______";
     
     
      Serial.println("\nDATA Pack:\n");
      Serial.println(dateTime);
      Serial.println(datecheck);
      Serial.println(coords);
      Serial.println(navi);
      Serial.println(navi2);
      Serial.println(logprint);
      Serial.println(logprint2);
      Serial.println(weather);
      Serial.println(other);
      Serial.println();
     
      if (printingActive == true) {
        //printer.justify('C');
        //printer.printBitmap(traversLogo_width, traversLogo_height, traversLogo_data);
        //printer.feed(1);
        //--------------------------------
        printEntry(title, del);
        //--------------------------------
        printTitle("DATE/TIME:", del);
        printDataL(dateTime, del);
        printData(datecheck, del);
        //--------------------------------
        printTitle("COORDS:", del);
        printData(coords, del);
        //printData(coords2, del);
        //--------------------------------
        printTitle("NAVI:", del);
        printData(navi + navi2, del);
        //printDataL(navi2, del);
        printData(logprint, del);
        printData(logprint2, del);
        //--------------------------------
        printTitle("WEATHER:", del);
        printData(weather, del);
        printData("Prs. diff: " + String(pressure - lastPressure, 3), del);
        //--------------------------------
        printTitle("OTHER:", del);
        printData(other, del);
      } 
      twist.setColor(100, 100, 100);
     
      delay(1000);
      if (printingActive == true) {
        printer.feed(2);
        printingActive = false;
        printer.sleep();
        logbookEntry++;
        lastPressure = pressure;
      }
    }

Any opinions and recommendations? Thank you very much!

George

Try re-ordering the the calls…(move latitude down, longitude up, and see if it stops @ same spot). You also might want to make them into ‘long’, like this https://github.com/sparkfun/SparkFun_u- … sition.ino

Finally, I’m not sure what the math suffix on those functions are, but you may want to perform them separately, instead of in the same line as the myGNSS.getXXXXX (do calculations on a new line after calling them)

Hello George,

Please be careful. Your Arduino MEGA board is probably using 5V I/O signals for I2C. All of our u-blox boards are 3.3V. You will need to use a level-shifter to connect the two.

I hope this helps,

Paul

Thank you for your replies. I used the qwiic connectors accordingly on the mega board and it workes fine (without the rare random freezes). Is this not enough?

TS-Russell:
Try re-ordering the the calls…(move latitude down, longitude up, and see if it stops @ same spot). You also might want to make them into ‘long’, like this https://github.com/sparkfun/SparkFun_u- … sition.ino

Finally, I’m not sure what the math suffix on those functions are, but you may want to perform them separately, instead of in the same line as the myGNSS.getXXXXX (do calculations on a new line after calling them)

Thank you, will try so and let you know!

Hello George,

Please tell us which Arduino board you are using. If it has a Qwiic connector then the voltage will be OK. But I wonder if it is running out of RAM? The GNSS library, Qwiic Twist and BME sensor together could be using a lot of its RAM.

Best wishes,

Paul

PaulZC:
Hello George,

Please tell us which Arduino board you are using. If it has a Qwiic connector then the voltage will be OK. But I wonder if it is running out of RAM? The GNSS library, Qwiic Twist and BME sensor together could be using a lot of its RAM.

Best wishes,

Paul

I am running on an Arduino Mega. Indeed, i first tried it with the Sparkfun red board with the qwiik connector, but it had memory issues. I then naturally tried it on Arduino Mega, with the qwiik to individual pin connectors (there are also other qwiic device connected together - bme, twist button and openlog). And it works smooth, sometimes for 1 hour, sometimes for 12 hours doing GPS work every couple of seconds. But it will eventually freeze in the ublox library (?). On my limited knowledge it does not seem to be a logic level problem only once in a while. Or can it be?

Thank you,

George

Hello George,

Please post a link to your Arduino MEGA board.

Is it this one? Arduino MEGA 2560?

https://store.arduino.cc/products/ardui … -2560-rev3

If it is, then it is a 5V (Five Volt) board. The Input-Output pins are all 5V. You must use a level shifter when connecting to Qwiic boards.

https://www.sparkfun.com/products/15439

Best wishes,

Paul

I used the logic converter and seems to work better now! thank you! still testing