Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions senseBox-bike-atrai-v2/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ lib_deps =
sensebox/SenseBoxBLE@^1.1.0
adafruit/Adafruit NeoPixel@^1.12.2
invensenseinc/ICM42670P@^1.0.7
adafruit/Adafruit ICM20X@^2.0.7
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ void AccelerationSensor::initSensor()
icm.startGyro(21, 500); // Gyro ODR = 100 Hz, Full Scale Range = 2000 dps
activeSensor = ICM42670X;
}
else if (icm2.begin_I2C(0x68, &Wire1))
{
icm2.setAccelRange(ICM20948_ACCEL_RANGE_8_G);
icm2.setAccelRateDivisor(10.25); // 100 Hz sample rate
activeSensor = ICM20948;
}
else
{
Serial.println("No compatible acceleration sensor found");
Expand All @@ -46,7 +52,7 @@ float probSett = 0.0;
float probStanding = 0.0;
float anomaly = 0.0;

float prevAccTime = millis();
// float prevAccTime = millis();

bool AccelerationSensor::readSensorData()
{
Expand Down Expand Up @@ -75,13 +81,25 @@ bool AccelerationSensor::readSensorData()
buffer[ix++] = (imu_event.gyro[1]*2.0)/6550.0;
buffer[ix++] = (imu_event.gyro[2]*2.0)/6550.0;
}
else if (activeSensor == ICM20948)
{
sensors_event_t a, g, m, temp;
icm2.getEvent(&a, &g, &m, &temp);
buffer[ix++] = a.acceleration.x;
buffer[ix++] = a.acceleration.y;
buffer[ix++] = a.acceleration.z;
buffer[ix++] = g.gyro.x;
buffer[ix++] = g.gyro.y;
buffer[ix++] = g.gyro.z;
}
else
{
return false; // No sensor active
}

Serial.println(millis() - prevAccTime);
prevAccTime = millis();
// Serial.print("acc: ");
// Serial.println(millis() - prevAccTime);
// prevAccTime = millis();

// one second interval
if (EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE <= ix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "../BaseSensor.h"
#include <Adafruit_MPU6050.h>
#include "ICM42670P.h" // Include for ICM42670P
#include <Adafruit_ICM20948.h> // Include for ICM20948
#include <Adafruit_Sensor.h> // Include for ICM20948

class AccelerationSensor : public BaseSensor
{
Expand All @@ -20,12 +22,14 @@ class AccelerationSensor : public BaseSensor
{
NONE,
MPU6050,
ICM42670X // ICM42670X is a placeholder for the ICM42670P
ICM42670X, // ICM42670X is a placeholder for the ICM42670P
ICM20948
};

SensorType activeSensor = NONE; // Track which sensor is active
Adafruit_MPU6050 mpu;
ICM42670 icm = ICM42670(Wire1, 0); // Instantiate an ICM42670 with LSB address set to 0
Adafruit_ICM20948 icm2;
};

#endif // ACCELERATION_SENSOR_H
1 change: 1 addition & 0 deletions senseBox-bike-nancy/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ lib_deps =
sensebox/SenseBoxBLE@^1.1.0
adafruit/Adafruit NeoPixel@^1.12.2
invensenseinc/ICM42670P@^1.0.7
adafruit/Adafruit ICM20X@^2.0.7
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ void AccelerationSensor::initSensor()
icm.startGyro(21, 500); // Gyro ODR = 100 Hz, Full Scale Range = 2000 dps
activeSensor = ICM42670X;
}
else if (icm2.begin_I2C(0x68, &Wire1))
{
icm2.setAccelRange(ICM20948_ACCEL_RANGE_8_G);
icm2.setAccelRateDivisor(10.25); // 100 Hz sample rate
activeSensor = ICM20948;
}
else
{
Serial.println("No compatible acceleration sensor found");
Expand Down Expand Up @@ -75,6 +81,17 @@ bool AccelerationSensor::readSensorData()
buffer[ix++] = (imu_event.gyro[1]*2.0)/6550.0;
buffer[ix++] = (imu_event.gyro[2]*2.0)/6550.0;
}
else if (activeSensor == ICM20948)
{
sensors_event_t a, g, m, temp;
icm2.getEvent(&a, &g, &m, &temp);
buffer[ix++] = a.acceleration.x;
buffer[ix++] = a.acceleration.y;
buffer[ix++] = a.acceleration.z;
buffer[ix++] = g.gyro.x;
buffer[ix++] = g.gyro.y;
buffer[ix++] = g.gyro.z;
}
else
{
return false; // No sensor active
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "../BaseSensor.h"
#include <Adafruit_MPU6050.h>
#include "ICM42670P.h" // Include for ICM42670P
#include <Adafruit_ICM20948.h> // Include for ICM20948
#include <Adafruit_Sensor.h> // Include for ICM20948

class AccelerationSensor : public BaseSensor
{
Expand All @@ -20,12 +22,14 @@ class AccelerationSensor : public BaseSensor
{
NONE,
MPU6050,
ICM42670X // ICM42670X is a placeholder for the ICM42670P
ICM42670X, // ICM42670X is a placeholder for the ICM42670P
ICM20948
};

SensorType activeSensor = NONE; // Track which sensor is active
Adafruit_MPU6050 mpu;
ICM42670 icm = ICM42670(Wire1, 0); // Instantiate an ICM42670 with LSB address set to 0
Adafruit_ICM20948 icm2;
};

#endif // ACCELERATION_SENSOR_H