Hello everyone, I'm currently working on a project where I have to use the MPU6050 and what I tried to do was use the I2Cdevlib code to allow my MPU6050 to give stable enough values. Now I'm trying to create parameters to it, so I can write what I want in an LCD according to the position of the gyroscope but for some reason, it does not recognize the statement and does not write anything at all. This is the code I'm trying to use:
#include "MPU6050_6Axis_MotionApps20.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(3,2,11,9,7,5);
MPU6050 mpu;
uint8_t mpuIntStatus;
uint16_t packetSize;
uint16_t fifoCount;
uint8_t fifoBuffer[64];
Quaternion q;
VectorFloat gravity;
float ypr[3];
#define contra 9
#define bri 10
void setup() {
//Código do MPU6050.
Wire.begin();
lcd.begin(16, 2);
pinMode(contra, OUTPUT);
pinMode(bri, OUTPUT);
digitalWrite(contra, LOW);
analogWrite(bri, 255);
lcd.print("Inete TEAC16");
lcd.setCursor(0, 1);
TWBR = 24;
mpu.initialize();
mpu.dmpInitialize();
mpu.setXAccelOffset(-1343);
mpu.setYAccelOffset(-1155);
mpu.setZAccelOffset(1033);
mpu.setXGyroOffset(19);
mpu.setYGyroOffset(-27);
mpu.setZGyroOffset(16);
mpu.setDMPEnabled(true);
packetSize = mpu.dmpGetFIFOPacketSize();
//Por algum motivo se utilizar "9600" aparece erro "FIFO overflow!".
//COMENTAR_OFICIAL
Serial.begin(115200);
}
void gyro()
{
while (fifoCount < packetSize) {
//do stuff
fifoCount = mpu.getFIFOCount();
}
if (fifoCount == 1024) mpu.resetFIFO();
else {
fifoCount = mpu.getFIFOCount();
mpu.getFIFOBytes(fifoBuffer, packetSize);
mpu.resetFIFO();
fifoCount -= packetSize;
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
}
}
void screen()
{
Serial.print(" ||p = "); Serial.print(ypr[1]*180/PI);
Serial.print(" r = "); Serial.print(ypr[2]*180/PI);
Serial.println();
delay(200);
}
void loop() {
gyro();
screen();
if(ypr[1]>=40) //Tried this basic task, reading if the value was above 40 and eventhough it was it did not // write anything at all
{
lcd.setCursor(0,2);
lcd.print("Letter: A");
Serial.println("Letter A");
}
}