Hi , i am using a code that combines adafruit library as well as mpu6050. Mpu6050 helps me to get data to be used as ble mouse .
I am using adafruit library to get gyro x, y and z to plot as a curve on a graph .
So my experiemnet is to see my ble mouse as a graph(gyro X, gyro y and gyro Z) .
Unfortunately , i am not getting this curve although the adafruit library code would help me to get a graph independently when not use with mpu6050 ble code . Can you tell me the mistake ? I will attach my code and do let me know the line in the code which is wrong . I will screenshot of the curve too.
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu1;
#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);
pinMode(0,INPUT);
pinMode(3,INPUT);
pinMode(1,INPUT);
pinMode(10,INPUT);
Wire.setPins(SDA_pin ,Scl_pin);
pinMode(SDA_pin,INPUT_PULLUP );
pinMode(Scl_pin,INPUT_PULLUP );
Wire.begin();
bleMouse.begin();
mpu.initialize();
if (!mpu.testConnection()) {
while (1);
}
mpu1.setAccelerometerRange(MPU6050_RANGE_16_G);
mpu1.setGyroRange(MPU6050_RANGE_250_DEG);
mpu1.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.println("");
delay(100);
}
void loop() {
if(bleMouse.isConnected()) {
Wire.write(0x3B);
Wire.write(0x43);
sensors_event_t a, g, temp;
mpu1.getEvent(&a, &g, &temp);
/* Print out the values */
Serial.print(g.gyro.x);
Serial.print(",");
Serial.print(g.gyro.y);
Serial.print(",");
Serial.print(g.gyro.z);
Serial.println("");
delay(10);
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &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 a4=digitalRead(0);
int b=digitalRead(3);
int c=digitalRead(5);
if(a4==1)
{
bleMouse.click(MOUSE_LEFT);//10
Serial.print("Clicked");
}
if(b==1)
{
bleMouse.click(MOUSE_RIGHT);//1
Serial.print("Clicked");
}
if(c==1)
{
Serial.print("Clicked");
}
delay(20);
}}
