Wifi LoRa 32 (V2) + MPU6050

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() {

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

Two suggestions:

  1. Run the I2C port scanner and check that you can see the MPU6050 board (I believe that it should show as port 0x68). It shouldn’t matter that the OLED display is also on the same I2C bus.

  2. Try using a different pair of pins for the I2C bus. Note that, on the V2 boards, GPIO21 is also used to control the voltage on the Vext pin. If you’re not using Vext, this shouldn’t make any difference, but you never know. I do use Vext and I use GPIO4 (SDA) and GPIO15 (SCL) for my I2C bus. If you use something other than the defaults, the Wire initialisation must then identify the pins that you use:

Wire.begin(SDA,SCL); // e.g. SDA = 4, SCL = 15