Arduino Tutorial "Arduino Nicla Sense ME as a MKR Shield" NOT Working

I am trying to get this basic tutorial working for the Nicla and Portenta H7 connected over ESLOV. The bug in the example is that it only works for a little over half an hour before crashing.

I modified their code for debugging purposes:
nicla-sense-me-fw/Arduino_BHY2Host/examples/Accelerometer/Accelerometer_copy.ino:

#include "Arduino.h"
#include "Arduino_BHY2Host.h"
#include <LandoRGBLedPortenta.h>

SensorXYZ accel(SENSOR_ID_ACC);
LandoRGBLedPortenta portentaLeds;

const int MAX_DUPLICATE_READINGS = 10;
String colorToToggle = "white";
int duplicateReadings = 0;

static unsigned long printTime = 0;
static unsigned long startTime = 0;
static String timeToCrash = "";
static String lastAccelReading = "";

void setup()
{
  Serial.begin(115200);
  while(!Serial);
  Serial.println("Serial started!");
  portentaLeds.setColor("red");
  BHY2Host.begin(false, NICLA_VIA_ESLOV);
  Serial.println("BHY2HostSuccess!");
  portentaLeds.setColor("green");
  accel.begin();
  Serial.println("Leaving setup!");
  portentaLeds.setColor("blue");
  
  printTime = millis();
  startTime = printTime;
}

void loop()
{
  BHY2Host.update();

  if (millis() - printTime >= 1000) {
    printTime = millis();
    String accelReading = accel.toString();
    if(accelReading == lastAccelReading) {
      duplicateReadings++;
      if(duplicateReadings == MAX_DUPLICATE_READINGS) {
        timeToCrash = " " + String(printTime - startTime) + " ms";
        colorToToggle = "red";
      }
    }
    else {
      duplicateReadings = 0;
    }
    Serial.println(String("Acceleration values: ") + String(accelReading) + String(timeToCrash));
    portentaLeds.toggleColor(colorToToggle);
    lastAccelReading = accelReading;
  }
}

nicla-sense-me-fw/Arduino_BHY2/examples/App/App_copy.ino:

#include "Nicla_System.h"
#include "Arduino.h"
#include "Arduino_BHY2.h"

void colorCycle(int loops) {
  for(int i = 0; i < loops; i++) {
    nicla::leds.setColor(red);
    delay(1000);
    nicla::leds.setColor(green);
    delay(1000);
    nicla::leds.setColor(blue);
    delay(1000);
  }
  nicla::leds.setColor(off);
}

void setup(){
  BHY2.begin(NICLA_I2C, NICLA_VIA_ESLOV);
  nicla::leds.begin();
  colorCycle(5);
}

void loop(){
  // Update and then sleep
  nicla::leds.setColor(blue);
  BHY2.update(500);
  nicla::leds.setColor(off);
}

After 1,741,691–2,398,485 ms, the Nicla stops updating…

  • The blue led on Nicla stops flashing indicating that the BHY2.update(500); line in the loop probably caused an exception.

If I reset just the Portenta and relaunch the serial printer, the Portenta halts at the accel.begin(); line in the setup...

Anyone know how I can resolve this?

In order to make all relevant information available to all who are interested in this subject, I'll share a link to the related report here:

Thank you @lsi8

1 Like

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