Hello Community
I've been dealing with Arduino for a few months. Right now, my problem is this.
Board Arduino nano ble sense 33
I wrote a small test program to read the values of the board's own sensors, acceleration sensor (Arduino_LSM9DS1), pressure sensor (Arduino_LPS22HB), and temperature/humidity sensor (Arduino_HTS221).
I use the Arduino libraries for this. I query the sensor values in a cycle of 250 ms.
Usually the individual functions need times to
IMU: 5 ms
BARO: 2 ms
Temp/humidity: 14 ms
to pick up the values
But after a while, the behavior changes completely, so that times change by
IMU: 44 ms
BARO: 99 ms
Temp/humidity: 267 ms
to pick up the readings.
Also the values e.g. from the accelerometer are totally wrong.
Has anyone here had similar experiences? Is the board possibly defective?
Can anyone tell me what I am doing wrong?
The whole thing can be readjusted super and also repeated. The time until the described behavior occurs is very different. Sometimes it takes only a few seconds or up to 10 minutes.
Could you please post your code? Use code tags and copy your code inside the post so people can read the code without downloading a file. It is easy to create a test sketch from that. e.g.
Your example code
If you use any non Arduino libraries please provide a link.
There is a "How to ..." at the beginning of each forum section.
Here the test program to adjust
#include <Arduino_HTS221.h>
#include <Arduino_LPS22HB.h>
#include <Arduino_LSM9DS1.h>
#include <Wire.h>
unsigned long currentMillis;
unsigned long previousMillis0 = 0;
unsigned long interval250ms = 250;
unsigned long startMillis;
unsigned long endMillis;
void setup() {
if (!IMU.begin()) {
Serial.println( "Failed to initialize IMU!");
while (1);
}
if (!BARO.begin()) {
Serial.println("Failed to initialize BARO!");
while (1);
}
if (!HTS.begin()) {
Serial.println("Failed to initialize HTS!");
while (1);
}
}
void loop() {
currentMillis = millis();
Serial.printf("----------------------------------- current millis: %ld -----------------------------------", currentMillis);
Serial.println();
if ((currentMillis - previousMillis0) >= interval250ms) {
Serial.printf("previousMillis interval: %d duration: %ld", interval250ms, currentMillis - previousMillis0);
Serial.println();
previousMillis0 = currentMillis;
startMillis = millis();
float ax, ay, az, acc;
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(ax, ay, az);
}
endMillis = millis();
Serial.printf("duration IMU: %ld", endMillis - startMillis);
Serial.println();
acc = sqrt(pow(ax, 2) + pow(ay, 2) + pow(az, 2));
Serial.printf("acceleration: %.2f", acc);
Serial.println();
startMillis = millis();
float pressure = BARO.readPressure(MILLIBAR);
endMillis = millis();
Serial.printf("duration BARO: %ld", endMillis - startMillis);
Serial.println();
Serial.printf("pressure: %.2f", pressure);
Serial.println();
startMillis = millis();
float temperature = HTS.readTemperature();
float humidity = HTS.readHumidity();
endMillis = millis();
Serial.printf("duration Temp/Humidity: %ld", endMillis - startMillis);
Serial.println();
Serial.printf("Temp: %.2f Humidity: %.2f", temperature, humidity);
Serial.println();
}
}
I have now had the test program running for about 25 minutes. After that the problem occurred.
The last valid data set was:
previousMillis interval: 250 duration: 262
duration IMU: 1
acceleration: 0.96
duration BARO: 3
pressure: 1005.40
duration Temp/Humidity: 41
Temp: 28.84 Humidity: 30.47
The first invalid record
previousMillis interval: 250 duration: 256
duration IMU: 41
acceleration: 3.90
duration BARO: 99
pressure: -0.00
duration Temp/Humidity: 156
Temp: 20.54 Humidity: 30.47
I would not trust the numbers with all the printing going on. The data is send by your controller using code that you do not see. The Arduino uses its own USB module and software to send the data. So, at some point you likely get interrupts inside your code.
To minimize the chance of this happening I would collect the data with a min and max value and only print these every now and then or even better when the value exceeds a certain maximum.
Another factor could be the SerialMonitor window. Do you use this to look at the data? Maybe when the window has a certain amount of characters received it slows down the virtual serial.
I only use the serial window for output to see when no more data is correct.
I have now adjusted the test program and only output the max and min values every 60 seconds.
The same behaviour.
Does anyone have any suggestions.
I use the following versions of the individual libraries
Arduino_HTS221 Version 1.0.0
Arduino_LPS22HB Version 1.0.0
Arduino_LSM9DS1 version 1.1.0
ArduinoBLE version 1.1.2
I have already tested with the older versions and the behaviour is always the same. After about 10-15 minutes the data is not updated anymore and it takes a long time to fetch the data.
Here the last version of the test code:
#include <Arduino_HTS221.h>
#include <Arduino_LPS22HB.h>
#include <Arduino_LSM9DS1.h>
#include <Wire.h>
unsigned long currentMillis;
unsigned long beginMillis;
unsigned long previousMillis0 = 0;
unsigned long previousMillis1 = 0;
unsigned long interval250ms = 250;
unsigned long interval = 60*1000;
unsigned long startMillis;
unsigned long endMillis;
unsigned long durationMillis = 0;
unsigned long durationMillisMin = 2500;
unsigned long durationMillisMax = 0;
void setup() {
if (!IMU.begin()) {
Serial.println( "Failed to initialize IMU!");
while (1);
}
if (!BARO.begin()) {
Serial.println("Failed to initialize BARO!");
while (1);
}
if (!HTS.begin()) {
Serial.println("Failed to initialize HTS!");
while (1);
}
beginMillis = millis();
}
float ax, ay, az, acc;
float accSum = 0;
float accMin = 10;
float accMax = 0;
uint16_t count = 0;
void loop() {
currentMillis = millis();
if ((currentMillis - previousMillis0) >= interval250ms) {
previousMillis0 = currentMillis;
startMillis = millis();
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(ax, ay, az);
}
float pressure = BARO.readPressure(MILLIBAR);
float temperature = HTS.readTemperature();
float humidity = HTS.readHumidity();
endMillis = millis();
acc = sqrt(pow(ax, 2) + pow(ay, 2) + pow(az, 2));
if (accMin > acc) {
accMin = acc;
}
if (accMax < acc) {
accMax = acc;
}
accSum += acc;
count++;
durationMillis = endMillis - startMillis;
if (durationMillisMin > durationMillis) {
durationMillisMin = durationMillis;
}
if (durationMillisMax < durationMillis) {
durationMillisMax = durationMillis;
}
}
if ((currentMillis - previousMillis1) >= interval) {
previousMillis1 = currentMillis;
Serial.printf("Duration: %ld, acceleration: %.2f, acc min %.2f, acc max %.2f, acc mean: %.2f", (currentMillis - beginMillis)/1000, acc, accMin, accMax, (accSum/count));
Serial.println();
Serial.printf("Duration: %ld, Duration max: %ld, Duration min: %ld", durationMillis, durationMillisMax, durationMillisMin);
Serial.println();
accSum = 0;
count = 0;
accMax = 0;
accMin = 10;
durationMillis = 0;
durationMillisMin = 2500;
durationMillisMax = 0;
}
}
Your test code runs on my Arduino Nano 33 BLE Sense without issues for a little over 2 hours now. I only added the serial initialization to make sure I catch all prints.
Serial.begin( 9600 );
while ( !Serial );
19:58:45.427 -> Duration: 42, acceleration: 0.99, acc min 0.90, acc max 1.00, acc mean: 0.99
19:58:45.427 -> Duration: 7, Duration max: 8, Duration min: 7
19:59:45.411 -> Duration: 102, acceleration: 0.99, acc min 0.98, acc max 1.01, acc mean: 0.99
19:59:45.411 -> Duration: 7, Duration max: 7, Duration min: 7
...
22:11:45.340 -> Duration: 8022, acceleration: 0.99, acc min 0.99, acc max 1.00, acc mean: 0.99
22:11:45.340 -> Duration: 7, Duration max: 8, Duration min: 7
22:12:45.327 -> Duration: 8082, acceleration: 0.99, acc min 0.27, acc max 5.55, acc mean: 1.15
22:12:45.327 -> Duration: 7, Duration max: 8, Duration min: 7
22:13:45.323 -> Duration: 8142, acceleration: 0.99, acc min 0.99, acc max 1.00, acc mean: 0.99
22:13:45.323 -> Duration: 7, Duration max: 8, Duration min: 7
After your examination and your post, I did more tests and came across the same problem over and over again. After 5-10 minutes the accelerometer stopped working.
I have now bought a new nano ble sense.
Here the test program runs since yesterday without problems. Also my original program runs with more sensors and display. No matter if many log outputs or not.
It seems that the quality of the boards can vary a lot. I have also considered to switch to other boards.
Thanks for your help and testing with your nano.