Hello I need some help! I’m doing a project where I’m trying to use a Lora 32 Wifi Ble V2 card to detect movement in an MPU6050, but I’m not succeeding. Note: When I use the same code with an Arduino Uno it works perfectly. I saw that the board’s OLED also uses SDA and SLC pins, would I have to change something in my code to ignore the OLED or specify the MPU pins?Thanks! Here is the pinout I am using and the code:
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
const int16_t thresholdAccel = 500; // Threshold of acceleration (the higher the value, the more intense movement is needed for it to be considered as movement)
const int16_t thresholdGyro = 500; // Rotation threshold to detect motion (same thing)
void setup() {
Serial.begin(9600);
Wire.begin();
mpu.initialize();
}
void loop() {
// Reads acceleration and gyro data from the MPU6050
int16_t accelX, accelY, accelZ;
int16_t gyroX, gyroY, gyroZ;
mpu.getMotion6(&accelX, &accelY, &accelZ, &gyroX, &gyroY, &gyroZ);
// Calculates the resulting acceleration
float acceleration = sqrt(accelX * accelX + accelY * accelY + accelZ * accelZ);
// Checks if the badge is moving based on acceleration and rotation
bool isMoving = (acceleration > thresholdAccel) || (abs(gyroX) > thresholdGyro) || (abs(gyroY) > thresholdGyro) || (abs(gyroZ) > thresholdGyro);
// Displays badge status in Serial Monitor
if (isMoving) {
Serial.println("MPU moving");
} else {
Serial.println("MPU stop");
}
delay(1000); // Wait 1 second before taking the next reading
}