Hi, I would appreciate if someone can help me. It turns out that I connected the accelerometer with gyroscope GY-521 to the Arduino Leonardo. So I set out to upload the code and I had verified normal, but when I go to serial monitor I get nothing.
So I tried everything to find out where the problem was, and I saw that the code stayed on the line
if (!mpu.testConnection()) { while (1); }
I tried uninstalling and reinstalling the MPU6050 library from electronic cats, and it still doesn't give me an answer. The truth is that I don't understand what could be happening with the library, since there are a few times when it works but others when it does not.
Any suggestions as to what might be going on?
#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>
#include <Mouse.h>
MPU6050 mpu;
int16_t ax, ay, az, gx, gy, gz;
int vx, vy;
void setup() {
Serial.begin(9600);
Wire.begin();
mpu.initialize();
if (!mpu.testConnection()) { while (1); }
}
void loop() {
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
vx = (gx+300)/150; // change 300 from 0 to 355
vy = -(gz-100)/150; // same here about "-100" from -355 to 0
Serial.print("gx = ");
Serial.print(gx);
Serial.print(" | gz = ");
Serial.print(gz);
Serial.print(" | X = ");
Serial.print(vx);
Serial.print(" | Y = ");
Serial.println(vy);
Mouse.move(vx, vy);
delay(20);
}
Hi, I would appreciate if someone can help me. It turns out that I connected the accelerometer with gyroscope GY-521 to the Arduino Leonardo. So I set out to upload the code and I had verified normal, but when I go to serial monitor I get nothing.
So I tried everything to find out where the problem was, and I saw that the code stayed on the line
if (!mpu.testConnection()) { while (1); }
I tried uninstalling and reinstalling the MPU6050 library from electronic cats, and it still doesn't give me an answer. The truth is that I don't understand what could be happening with the library, since there are a few times when it works but others when it does not.
Any suggestions as to what might be going on?
#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>
#include <Mouse.h>
MPU6050 mpu;
int16_t ax, ay, az, gx, gy, gz;
int vx, vy;
void setup() {
Serial.begin(9600);
Wire.begin();
mpu.initialize();
if (!mpu.testConnection()) { while (1); }
}
void loop() {
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
vx = (gx+300)/150; // change 300 from 0 to 355
vy = -(gz-100)/150; // same here about "-100" from -355 to 0
Serial.print("gx = ");
Serial.print(gx);
Serial.print(" | gz = ");
Serial.print(gz);
Serial.print(" | X = ");
Serial.print(vx);
Serial.print(" | Y = ");
Serial.println(vy);
Mouse.move(vx, vy);
delay(20);
}
Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.
Repeated cross-posting can result in a suspension from the forum.
In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.
And I upload a video to YouTube with more or less the problem I have. After it works for a few seconds, it doesn't work again and I have to wait some time to reconnect it and it works again for a few seconds.