-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjust sensitivity for startWakeOnMotion and startTiltDetection #15
Comments
Thank you for opening this issue! We will look into it shortly. |
Thanks for the prompt reply, I'll take a look. My use case is inside a beehive, I wish to determine if the beehive has fallen over, startWakeOnMotion seems to be the best for this. #include "ICM42670P.h"
ICM42670 IMU(Wire, 0);
volatile bool wake_up = false;
void irq_handler(void) {
wake_up = true;
}
void setup() {
int ret;
Serial.begin(115200);
while (!Serial) {}
pinMode(14, INPUT_PULLUP);
// Initializing the ICM42670
ret = IMU.begin();
if (ret != 0) {
Serial.print("ICM42670 initialization failed: ");
Serial.println(ret);
while (1)
;
}
IMU.startWakeOnMotion(14, irq_handler);
Serial.println("Going to sleep");
}
void loop() {
if (wake_up) {
Serial.println("Wake-up");
IMU.startAccel(100, 16); // 100 Hz, ±16g
IMU.startGyro(100, 2000); // 100 Hz, ±2000 dps
delay(100);
inv_imu_sensor_event_t imu_event;
int ret = IMU.getDataFromRegisters(imu_event);
if (ret == 0) {
// Convert acceleration to g
float accelX = imu_event.accel[0] / 2048.0;
float accelY = imu_event.accel[1] / 2048.0;
float accelZ = imu_event.accel[2] / 2048.0;
// Convert gyroscope to dps
float gyroX = imu_event.gyro[0] / 16.4;
float gyroY = imu_event.gyro[1] / 16.4;
float gyroZ = imu_event.gyro[2] / 16.4;
// Determine beehive position based on Z-axis acceleration
String position;
if (accelZ < -0.8) {
position = "Upright";
} else if (accelZ > 0.8) {
position = "Upside down";
} else {
position = "On its side";
}
// Report position if not upright
if (position != "Upright") {
Serial.println("Beehive is NOT upright.");
Serial.print("Position: ");
Serial.println(position);
Serial.print("Acceleration: ");
Serial.print("X: ");
Serial.print(accelX);
Serial.print(", Y: ");
Serial.print(accelY);
Serial.print(", Z: ");
Serial.println(accelZ);
} else {
Serial.println("Beehive is upright.");
}
}
delay(2000);
wake_up = false;
Serial.println("Going to sleep");
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it possible to adjust the sensitivity of startWakeOnMotion and startTiltDetection functions?
I see the attached in the datasheet, are you able to add this to the library?
The text was updated successfully, but these errors were encountered: