Sketch resets periodically after adding IMU read

I'm using a Nano RP2040 Connect and a very simple script that keeps track of the run time in minutes. This simple sketch (phase1) was created after having difficulties with a full featured script in an attempt to troubleshoot the problem.

If I run the script as defined above, it runs trouble free for hours. I ran it overnight and had no problems for over 6 hours. I then added support for the 2040 IMU (phase2), and only added reading the X, Y and Z accelerometer values. After a few minutes, the sketch reset, and again 40 minutes later.

Not sure how to proceed from here without adding additional debug statements in the libraries.

Here are my notes and serial port logs from the test...

phase 1 ran with no issues for over 400 minutes.
The test was run from a standalone USB power brick.

Moved the RP2040 back to my macbook, rebuilt with phase2

phase 2 reset within 1 minute, and again 40mins later, here's the log
06:18:29.536 -> 
06:18:30.398 -> ***** Arduino IoT Cloud - configuration info *****
06:18:30.398 -> Device ID: 06d05788-cb04-448c-9215-7de51f35aadc
06:18:30.398 -> MQTT Broker: mqtts-sa.iot.arduino.cc:8883
06:18:31.185 -> WiFi.status(): 0
06:18:31.185 -> Current WiFi Firmware: 1.4.8
06:18:32.343 -> Connection to "weecabin" failed
06:18:32.343 -> Retrying in  "500" milliseconds
06:18:32.878 -> Connected to "weecabin"
06:18:37.425 -> Connected to Arduino IoT Cloud
06:18:37.425 -> Thing ID: 1c5a84a3-062b-47df-9d12-d01b35291de4
06:19:16.400 -> 
06:19:17.282 -> ***** Arduino IoT Cloud - configuration info *****
06:19:17.282 -> Device ID: 06d05788-cb04-448c-9215-7de51f35aadc
06:19:17.282 -> MQTT Broker: mqtts-sa.iot.arduino.cc:8883
06:19:18.060 -> WiFi.status(): 0
06:19:18.060 -> Current WiFi Firmware: 1.4.8
06:19:19.227 -> Connection to "weecabin" failed
06:19:19.227 -> Retrying in  "500" milliseconds
06:19:19.661 -> Connected to "weecabin"
06:19:24.320 -> Connected to Arduino IoT Cloud
06:19:24.320 -> Thing ID: 1c5a84a3-062b-47df-9d12-d01b35291de4
07:00:04.266 -> 
07:00:05.167 -> ***** Arduino IoT Cloud - configuration info *****
07:00:05.167 -> Device ID: 06d05788-cb04-448c-9215-7de51f35aadc
07:00:05.167 -> MQTT Broker: mqtts-sa.iot.arduino.cc:8883
07:00:05.931 -> WiFi.status(): 0
07:00:05.931 -> Current WiFi Firmware: 1.4.8
07:00:07.059 -> Connection to "weecabin" failed
07:00:07.059 -> Retrying in  "500" milliseconds
07:00:07.807 -> Connected to "weecabin"
07:00:10.737 -> Connected to Arduino IoT Cloud
07:00:10.737 -> Thing ID: 1c5a84a3-062b-47df-9d12-d01b35291de4

Running phase2 from the standalone USB power brick, to rule out any influence from the macbook
This test reset after 4 minutes.

Here's the sketch... The sketch includes a "#define phase2" that brings in the IMU. Without phase2, the sketch runs without issues. With phase 2, it resets at random intervals.

#include "arduino_secrets.h"
/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/1c5a84a3-062b-47df-9d12-d01b35291de4 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  float counter;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

/*
 * Troubleshooting phases
 * 1) Build a simple thing that tracks the number of minutes running
 * result: ran over 400 minutes without issue
 * 
 * 2) Add the IMU and only read X,Y and Z
 * result: restarted within one minute, but has been running 10mins now
 * will let it continue the rest of the day, or until the next reset.
 */

// Troubleshooting phases
// phase 1 ran fine
// the defines below will be used to bring in additional code
#define phase2

#include "thingProperties.h"
#ifdef phase2
#include <Arduino_LSM6DSOX.h>
#endif

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(2000); 
  Serial.println();

  #ifdef phase2
  if (!IMU.begin()) 
  {
    Serial.println("Failed to initialize IMU!");
    while (1);
  }
  #endif
  
  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();

  // Added these printouts after my initial testing that was documented in Notes.
  // The Notes logs don't include these printouts.
  Serial.print("phase1");
  #ifdef phase2
  Serial.print(" + phase2");
  #endif
  Serial.println();
}

unsigned long startTime;
bool firstPass = true;
void loop() {
  if (firstPass)
  {
    startTime = millis();
    firstPass=false;
  }
  ArduinoCloud.update();
  // Your code here 

  #ifdef phase2 
  float Ax,Ay,Az;
  if (IMU.accelerationAvailable()) 
  {
    IMU.readAcceleration(Ax, Ay, Az);
  }
  #endif
  
  counter = float(millis()-startTime)/6e4; // tracks the number of minutes the running. resets to zero on a restart.
  WaitMs(20);
}

void WaitMs(int ms)
{
  unsigned long exitTime = millis() + ms;
  while(millis()<exitTime);
}

In order to verify that it's not a board related issue, I ordered another RP2040 connect, and will run this test again with that new board.

Second Nano rp2040 connect has the same problem. My very simple sketch reset in 19 minutes.

I'm relatively new here, what's the best way to raise this as an issue that needs attention?

Silence was the sweet reply!

1 Like

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