Arduino Nano RP2040 Connect reboot every ~30mins

I have a nano rp2040 hook up with dht11 & OLED (128x64), connected to arduino iot cloud. What it does is:

  • read temperature from DHT11 every 3sec
  • compare temperature if within hi or lo limit
  • send room state (as string) to arduino iot cloud dashboard
  • the thing is connected to IFTTT via webhook to send me email whenever room state change.

Managed get the board run without issue, but it will reboot every ~30mins. What I'd verified so far:

  • suspect network, but no wifi network drop out.
  • suspect power issue, had verified with different charger/cable, which supply 5v via USB port, issue persist.
  • suspect dht11 & oled drawn too much current from the 3v3 pin (of nano), but the datasheet says its max 800mA (counted for those IC on Nano as well), but I checked that the the oled max is 20mA, shouldn't be any issue.

Looking forward if any clue from internet but no clue. Appreciate if anyone can point where to look into.

Attached my code below.

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"

  Arduino IoT Cloud Variables description

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

  String roomState;
  int temp_hiLim;
  int temp_loLim;

  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.
*/

#include "arduino_secrets.h"
#include "thingProperties.h"

#include <Arduino_LSM6DSOX.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>

#define DHTPIN 4
#define DHTTYPE DHT11

#define SCREEN_WIDTH 128 
#define SCREEN_HEIGHT 64
#define SCREEN_ADDRESS 0x3C

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

unsigned long millis_curr = 0;
unsigned long millis_prev = 0;
unsigned long interval    = 2000;
float temp_deg	= 0.0;
float humi_RH 	= 0.0;

DHT dht(DHTPIN, DHTTYPE);

void setup() {

  Serial.begin(9600);
  delay(500); 
  IMU.begin();
  delay(500); 
  dht.begin();
  delay(500);
  display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
  delay(500);
  // 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();
  
  temp_hiLim = 30.0;
  temp_loLim = 25.0;

  pinMode(LEDR, OUTPUT);
  pinMode(LEDG, OUTPUT);
  pinMode(LEDB, OUTPUT);
  digitalWrite(LEDR, LOW);
  digitalWrite(LEDG, LOW);
  digitalWrite(LEDB, LOW);
  display.clearDisplay();
  display.setTextColor(WHITE);
}

void loop() {
  ArduinoCloud.update();
  millis_curr = millis();
  if(millis_curr - millis_prev >= interval){
    millis_prev = millis_curr;

    temp_deg = dht.readTemperature();
    humi_RH = dht.readHumidity();
    Serial.print(temp_hiLim);
    Serial.print("\t");
    Serial.print(temp_loLim);
    Serial.print("\t");
    Serial.print(temp_deg);
    Serial.print("\t");
    Serial.println(humi_RH);
    // clear display
    display.clearDisplay();
  
    // display temperature
    display.setTextSize(1);
    display.setCursor(0,0);
    display.print("Temperature: ");
    display.setTextSize(2);
    display.setCursor(0,10);
    display.print(temp_deg);
    display.print(" ");
    display.setTextSize(1);
    display.cp437(true);
    display.write(167);
    display.setTextSize(2);
    display.print("C");
  
    // display humidity
    display.setTextSize(1);
    display.setCursor(0, 35);
    display.print("Humidity: ");
    display.setTextSize(2);
    display.setCursor(0, 45);
    display.print(humi_RH);
    display.print(" %"); 
  
    display.display(); 
    logic(temp_deg);
  }
}

void logic(float temp_deg) {
  if (temp_deg > temp_loLim && temp_deg > temp_hiLim) {
    digitalWrite(LEDR, HIGH);
    digitalWrite(LEDG, LOW);
    digitalWrite(LEDB, LOW);
    roomState = "Too hot!";
  }
  else if (temp_deg > temp_loLim && temp_deg == temp_hiLim) {
    digitalWrite(LEDR, HIGH);
    digitalWrite(LEDG, HIGH);
    digitalWrite(LEDB, LOW);
  }
  else if (temp_deg < temp_loLim && temp_deg < temp_hiLim) {
    digitalWrite(LEDR, LOW);
    digitalWrite(LEDG, LOW);
    digitalWrite(LEDB, HIGH);
    roomState = "Too cold!";
  }
  else if (temp_deg == temp_loLim && temp_deg < temp_hiLim) {
    digitalWrite(LEDR, LOW);
    digitalWrite(LEDG, HIGH);
    digitalWrite(LEDB, HIGH);

  }
  else {
    digitalWrite(LEDR, LOW);
    digitalWrite(LEDG, HIGH);
    digitalWrite(LEDB, LOW);
    roomState = "Just nice.";
  }
}

/*
  Since TempHiLim is READ_WRITE variable, onTempHiLimChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onTempHiLimChange()  {
  // Add your code here to act upon TempHiLim change
}
/*
  Since TempLoLim is READ_WRITE variable, onTempLoLimChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onTempLoLimChange()  {
  // Add your code here to act upon TempLoLim change
}

Further investigate with the nano connected to my own phone hotspot, the board didn't reboot after 30mins so I suspect it could be the network that i was tested earlier. It was a guest network at apartment (sharing) so probably there is a 30mins restriction.
So I simulate it by turning off my phone hotspot and re-enable, the board lost connection then attempt to reconnect and it DID reboot then reconnect with success.
So I believe this line below will handle the reconnection, but something must be wrong that cause the board to reboot. Interesting point to investigate...

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

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