esp32 C3 Mini with mpu6050

AlenHazard
Posts: 1
Joined: Wed Apr 17, 2024 8:54 am

esp32 C3 Mini with mpu6050

Postby AlenHazard » Wed Apr 17, 2024 11:06 am

Hi , My name is Alen .
I want to know how i could connect mpu6050 to esp32 C3 mini dev kit . I will put the code too. It runs on arduino ide .
Below i am attaching the esp32c3 mini Dev Kit and mpu6050 links.
I want to connect sda , scl , AD0, and Int to esp32c3 Mini . Please help me by sharing a figure or mapping the mpu 6050 pins to esp32C3 Mini dev kit pins

esp32 C3 mini dev kit : https://docs.espressif.com/projects/esp ... itm-1.html
Mpu6050 : https://circuitsgeek.com/getting-starte ... d-mpu6050/

Code :
#include <MPU6050_light.h>
MPU6050 mpu(Wire);
unsigned long timer = 0;
#include <BleMouse.h>

BleMouse bleMouse;

#define btnL 2
#define btnR 1
#define btnM 3


#include <Wire.h>
#define SDA 7
#define SCL 8

#define AD0 11
#define INT 12
void setup() {

pinMode(btnR,INPUT);
pinMode(btnL,INPUT);
pinMode(btnM,INPUT);

pinMode(INT, INPUT); //int goes high when activity is detected(wakeup?)
pinMode(AD0, OUTPUT);
digitalWrite(AD0, LOW);//sets I2C adress
delay(50);
Serial.begin(115200);
Wire.begin(SDA,SCL);

Serial.println("Starting BLE work!");
bleMouse.begin();
byte status = mpu.begin();
Serial.print(F("MPU6050 status: "));
Serial.println(status);
while(status!=0){ } // stop everything if could not connect to MPU6050

Serial.println(F("Calculating offsets, do not move MPU6050"));
delay(2000);
// mpu.upsideDownMounting = true; // uncomment this line if the MPU6050 is mounted upside-down
mpu.calcOffsets(); // gyro and accelero
Serial.println("Done!\n");
}


void loop() {
if(bleMouse.isConnected()) {
clicking();
mpu.update();
int x = map(mpu.getAngleX(),-90,90,10,-10);
int y = map(mpu.getAngleY(),-90,90,-10,10);
int z = map(mpu.getAngleZ(),-90,90,-10,10);

bleMouse.move(x,y);


if((millis()-timer)>10){ // print data every 10ms
Serial.print("X : ");
Serial.print(mpu.getAngleX());
Serial.print(x);
Serial.print("\tY : ");
Serial.print(mpu.getAngleY());
Serial.print(y);
Serial.print("\tZ : ");
Serial.println(mpu.getAngleZ());
Serial.print(z);

timer = millis();
}
}


}
void clicking(){

bool Lclick = digitalRead(btnL);
bool Mclick = digitalRead(btnM);
bool Rclick = digitalRead(btnR);
if (Lclick == 0){
bleMouse.click(MOUSE_LEFT);
}

if (Rclick == 0){
bleMouse.click(MOUSE_RIGHT);
}


if (Mclick == 0){
bleMouse.click(MOUSE_MIDDLE);
}

}

Who is online

Users browsing this forum: Baidu [Spider], ivanvasilenok and 81 guests