Hi ,
I have a esp32 as well as imu mpu6050 sensor .
I want to plot the value of &gx,& gy , &gz on a the plotter from mpu6050.
I will attach my code below and could you help me to add the line that is required so that when the mpu6050 moves , it will show the curve along x,y and z value ?
I am using this function : "mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); "
Below is the entire code :
#include <Wire.h>
#include <MPU6050.h>
#include <BleMouse.h>
#define MPU_ADDR 0x68
BleMouse bleMouse;
MPU6050 mpu;
int16_t ax, ay, az, gx, gy, gz;
int vx, vy;
int SDA_pin= 6;
int Scl_pin= 7;
int responseDelay = 10;
void setup() {
Serial.begin(115200);
Wire.setPins(SDA_pin ,Scl_pin);
pinMode(SDA_pin,INPUT_PULLUP);
pinMode(Scl_pin,INPUT_PULLUP);
Wire.begin();
Serial.println("I2C begin");
bleMouse.begin();
pinMode(0,INPUT);
pinMode(3,INPUT);
pinMode(1,INPUT);
pinMode(10,INPUT);
mpu.initialize();
if (!mpu.testConnection()) {
while (1);}
Serial.print("Sensor Initialized");
bleMouse.begin();
}
void loop() {
if(bleMouse.isConnected()) {
Serial.print("hi");
Wire.write(0x3B);
Wire.write(0x43);
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
{
Serial.print(gx);
Serial.print(gz);
}
vx = -(gx + 260) / 150; // "-400" because the x axis of gyroscope give values about -350 while it's not moving. Change this value if you get something different using the TEST code, chacking if there are values far from zero.
vy = (gz + 100) / 150; // same here about "-200"
bleMouse.move(vx, vy);
int a=digitalRead(0);
int b=digitalRead(1);
int c=digitalRead(10);
int d=digitalRead(3);
if(a==1)
{
bleMouse.click(MOUSE_LEFT);//10
Serial.print("Clicked");
}
if(b==1)
{
bleMouse.click(MOUSE_RIGHT);//1
Serial.print("Clicked");
}
if(c==1)
{
bleMouse.click(MOUSE_RIGHT);//1
Serial.print("Clicked");
Serial.print("Clicked");
}
delay(20);
}}