I am reading accelerometer data from an Adafruit LSM6DS33 sensor. I am reading this data both with a Mega and with the Nano 33 IoT boards.
With the Mega the readings seem to be working well as follows:
7.19
8.43
7.96
7.91
9.07
10.66
10.11
9.18
8.02
8.91
10.08
9.34
8.75
8.96
9.55
9.63
10.07
9.73
9.37
9.79
9.94
9.52
10.04
While with the Nano 33 IoT I am getting these unwanted spikes (close to 0):
9.85
9.80
0.17
1.26
-0.15
0.61
0.85
-0.00
0.04
0.03
0.00
0.03
9.27
9.50
9.57
0.27
9.81
9.82
9.71
9.80
8.65
9.74
0.00
9.57
and when I turn the accelerometer over a certain angle the readings go berserk:
-0.57
-0.59
-0.38
-0.46
-0.46
-0.91
-19.56
-19.56
-19.56
0.33
-19.56
-19.56
37.03
-19.56
0.33
1.78
-19.56
2.38
-19.56
-19.56
1.97
2.35
2.02
-19.56
1.99
2.34
2.05
1.76
1.44
-19.56
-19.56
1.23
-19.56
The above readings are all from the Z-axis' accelerometer.
This is the code I am using:
#include <OSCMessage.h>
// accelerometer and gryroscope libraries
#include <Adafruit_LSM6DS33.h>
Adafruit_LSM6DS33 lsm6ds;
// magnetometer library
#include <Adafruit_LIS3MDL.h>
Adafruit_LIS3MDL lis3mdl;
float thetaX, thetaY, thetaZ;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
// ---- SENSORS -----
bool lsm6ds_success, lis3mdl_success;
// hardware I2C mode, can pass in address & alt Wire
lsm6ds_success = lsm6ds.begin_I2C();
lis3mdl_success = lis3mdl.begin_I2C();
if (!lsm6ds_success) {
Serial.println("Failed to find LSM6DS chip");
}
if (!lis3mdl_success) {
Serial.println("Failed to find LIS3MDL chip");
}
lsm6ds.setAccelRange(LSM6DS_ACCEL_RANGE_4_G);
lsm6ds.setAccelDataRate(LSM6DS_RATE_104_HZ);
lsm6ds.setGyroRange(LSM6DS_GYRO_RANGE_500_DPS );
lsm6ds.setGyroDataRate(LSM6DS_RATE_104_HZ);
lis3mdl.setDataRate(LIS3MDL_DATARATE_155_HZ);
// You can check the datarate by looking at the frequency of the DRDY pin
lis3mdl.setRange(LIS3MDL_RANGE_4_GAUSS);
lis3mdl.setOperationMode(LIS3MDL_CONTINUOUSMODE);
lis3mdl.setIntThreshold(500);
lis3mdl.configInterrupt(false, false, true, // enable z axis
true, // polarity
false, // don't latch
true); // enabled!
}
void loop() {
//delay(100);
//printCurrentNet();
// creating events for all sensors
sensors_event_t accel, gyro, mag, temp;
// /* Get new normalized sensor events */
lsm6ds.getEvent(&accel, &gyro, &temp);
lis3mdl.getEvent(&mag);
// calculation of 3D trigonometry (refer to notes)
thetaX = atan2(accel.acceleration.x / 9.8, accel.acceleration.z / 9.8) / 2 / PI * 360 ;
thetaZ = atan2(accel.acceleration.y / 9.8, accel.acceleration.z / 9.8) / 2 / PI * 360 ;
Serial.print("\t");
Serial.println(accel.acceleration.z);
delay(100);
}
Now one important thing is that I could not calibrate the the sensor. I was using an example code from Adafruit's Sensor Calibration Library (sensor_calibration_write) which accesses either EEPROM or Flash and saves the values on either one of the types of memories found. The Nano IoT should have 256KB of Flash memory, but still this is not working for me. I still think that the sensor data shown above wouldn't be that far off and creating such spikes because it is not calibrated, but I might be wrong.
Would the Arduino Nano 33 IoT and the Arduino Mega work so differently from each other because of the different chip? Or is it really because of the calibration settings? If so why is the sensor_calibration_write example not finding any memory to save data on?
Would really appreciate any directions from your parts. Thanks.