Ameba Mini keeps crashing/resetting every 3-5 minutes

Hello all, I am using a AMB82 Mini, and using the ObjectDetectionLoop example from the Arduino list.

I also use MQTT to send data to the cloud every 20 seconds.

However, what happens is every 3-5 minutes the board resets/or hangs for 1-2 minutes, and the only thing in the logs is coming as :

20:33:16.254 → YOLOv7t tick[78]

20:33:16.484 → YOLOv7t tick[76]

20:33:16.715 → YOLOv7t tick[77]

20:33:16.944 → YOLOv7t tick[77]

20:33:17.175 → YOLOv7t tick[77]

20:33:17.371 → YOLOv7t tick[77]

20:33:17.569 → YOLOv7t tick[77]

20:33:17.767 → >>> YOLOv7t FPS = 4.76

20:33:17.767 → YOLOv7t tick[77]

For 1-2 minutes this is the only logs seen, then the device comes back on and starts detecting and sending data to MQTT again. I am unable to deploy my device because it is going blank every 3-5 minutes, then coming back automatically. Here is my source code:

#include “WiFi.h”
#include “StreamIO.h”
#include “VideoStream.h”
#include “RTSP.h”
#include “NNObjectDetection.h”
#include “VideoStreamOverlay.h”
#include “ObjectClassList.h”
#include <PubSubClient.h>
#include <NTPClient.h>

#define CHANNEL 0
#define CHANNELNN 3

// Lower resolution for NN processing
#define NNWIDTH 576
#define NNHEIGHT 320

VideoSetting config(VIDEO_FHD, 30, VIDEO_H264, 0);
VideoSetting configNN(NNWIDTH, NNHEIGHT, 10, VIDEO_RGB, 0);
NNObjectDetection ObjDet;
RTSP rtsp;
StreamIO videoStreamer(1, 1);
StreamIO videoStreamerNN(1, 1);
String strt;

char ssid = “my-ssid”; // your network SSID (name)
char pass = “my-pass”; // your network password
int status = WL_IDLE_STATUS;

IPAddress ip;
int rtsp_portnum;
int counter = 0;

WiFiUDP ntpUDP;

// You can specify the time server pool and the offset (in seconds, can be
// changed later with setTimeOffset() ). Additionally you can specify the
// update interval (in milliseconds, can be changed using setUpdateInterval() ).
NTPClient timeClient(ntpUDP, “0.pool.ntp.org”, 3600, 60000); // Indicator of Wifi status

char mqttServer = “mqtt-dashboard.com”;
char clientId = “clientId-ZY9NGa8GU2”;
char publishTopic = “outTopicX2”;
char publishPayload = “hello from edge”;
char subscribeTopic = “inTopic”;

void reset() {
NVIC_SystemReset();
}

void callback(char* topic, byte* payload, unsigned int length)
{
Serial.print(“Message arrived [”);
Serial.print(topic);
Serial.print("] ");
for (unsigned int i = 0; i < length; i++) {
Serial.print((char)(payload[i]));
}
Serial.println();
}

WiFiClient wifiClient;
PubSubClient client(wifiClient);

void reconnect()
{
// Loop until we’re reconnected
if (!(client.connected())) {
Serial.print(“\r\nAttempting MQTT connection…”);
// Attempt to connect
if (client.connect(clientId)) {
Serial.println(“connected”);
// Once connected, publish an announcement and resubscribe
client.publish(publishTopic, publishPayload);
client.subscribe(subscribeTopic);
} else {
Serial.println(“failed, rc=”);
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
// delay(5000);
}
}
}

void setup()
{
Serial.begin(115200);

// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);

    // wait 5 seconds for connection:
    delay(5000);
    timeClient.begin();

}


client.setServer(mqttServer, 1883);
client.setCallback(callback);

// Allow Hardware to sort itself out
delay(1500);

ip = WiFi.localIP();

// Configure camera video channels with video format information
// Adjust the bitrate based on your WiFi network quality
config.setBitrate(2 * 1024 * 1024);    // Recommend to use 2Mbps for RTSP streaming to prevent network congestion
Camera.configVideoChannel(CHANNEL, config);
Camera.configVideoChannel(CHANNELNN, configNN);
Camera.videoInit();

// Configure RTSP with corresponding video format information
rtsp.configVideo(config);
rtsp.begin();
rtsp_portnum = rtsp.getPort();

// Configure object detection with corresponding video format information
// Select Neural Network(NN) task and models
ObjDet.configVideo(configNN);
ObjDet.modelSelect(OBJECT_DETECTION, DEFAULT_YOLOV7TINY, NA_MODEL, NA_MODEL);
ObjDet.begin();

// Configure StreamIO object to stream data from video channel to RTSP
videoStreamer.registerInput(Camera.getStream(CHANNEL));
videoStreamer.registerOutput(rtsp);
if (videoStreamer.begin() != 0) {
    Serial.println("StreamIO link start failed");
}

// Start data stream from video channel
Camera.channelBegin(CHANNEL);

// Configure StreamIO object to stream data from RGB video channel to object detection
videoStreamerNN.registerInput(Camera.getStream(CHANNELNN));
videoStreamerNN.setStackSize();
videoStreamerNN.setTaskPriority();
videoStreamerNN.registerOutput(ObjDet);
if (videoStreamerNN.begin() != 0) {
    Serial.println("StreamIO link start failed");
}

// Start video channel for NN
Camera.channelBegin(CHANNELNN);

// Start OSD drawing on RTSP video channel
OSD.configVideo(CHANNEL, config);
OSD.begin();

}

void loop()
{
Serial.print("Running… ");
counter += 1;
Serial.println(counter);

if (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
    timeClient.begin();

}



std::vector<ObjectDetectionResult> results = ObjDet.getResult();

uint16_t im_h = config.height();
uint16_t im_w = config.width();

Serial.print("Network URL for RTSP Streaming: ");
Serial.print("rtsp://");
Serial.print(ip);
Serial.print(":");
Serial.println(rtsp_portnum);
Serial.println(" ");

printf("Total number of objects detected = %d\r\n", ObjDet.getResultCount());
OSD.createBitmap(CHANNEL);

if (ObjDet.getResultCount() > 0) {
    for (int i = 0; i < ObjDet.getResultCount(); i++) {
        int obj_type = results[i].type();
        if (itemList[obj_type].filter) {    // check if item should be ignored

            ObjectDetectionResult item = results[i];
            // Result coordinates are floats ranging from 0.00 to 1.00
            // Multiply with RTSP resolution to get coordinates in pixels
            int xmin = (int)(item.xMin() * im_w);
            int xmax = (int)(item.xMax() * im_w);
            int ymin = (int)(item.yMin() * im_h);
            int ymax = (int)(item.yMax() * im_h);

            // Draw boundary box
            printf("Item %d %s:\t%d %d %d %d\n\r", i, itemList[obj_type].objectName, xmin, xmax, ymin, ymax);
            OSD.drawRect(CHANNEL, xmin, ymin, xmax, ymax, 3, OSD_COLOR_WHITE);

            // Print identification text
            char text_str[20];
            snprintf(text_str, sizeof(text_str), "%s %d", itemList[obj_type].objectName, item.score());
            OSD.drawText(CHANNEL, xmin, ymin - OSD.getTextHeight(CHANNEL), text_str, OSD_COLOR_CYAN);
        }
    }
}
OSD.update(CHANNEL);

Serial.println("Completed streaming job.");

timeClient.update();
if (!(client.connected())) {
    Serial.println("MQTT Not connected.");
    reconnect();
}
else{
  Serial.println("MQTT is connected.");

  String strt = timeClient.getFormattedTime();
  sendMqtt(strt);
}
Serial.println("Completed one loop.");

// delay to wait for new results
delay(100);

}

void sendMqtt(String time){
Serial.println(“Sending mqtt message.”);
if(counter > 100){
client.publish(publishTopic,time.c_str());
counter = 0;

}

}

What can be the reason ? Please help.

Hi @roq ,

May I know can ObjectDetectionLoop the default example alone run successfully?

Hi @pammyleong - I figured out the issue.

while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);

// wait 5 seconds for connection:
delay(5000);
timeClient.begin();

}

In the above function I am not updating “status”, so even if the Wifi is down it doesn’t attempt to reconnect. Its fixed now !