Hello,
I tried to show the angle given by my MPU6050 on a 3,5" TFT display. First, here's my code:
#include <MPU6050_tockn.h>
#include "Dash.h"
MPU6050 mpu6050(Wire);
Dash dash;
void setup() {
Serial.begin(9600);
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
dash.init();
}
void loop() {
mpu6050.update();
Serial.print("angleX : ");
Serial.print(mpu6050.getAngleX());
Serial.print("\tangleY : ");
Serial.print(mpu6050.getAngleY());
Serial.print("\tangleZ : ");
Serial.println(mpu6050.getAngleZ());
dash.printNr(0, 0, mpu6050.getAngleX());
delay(50);
}
In the loop() I first update the MPU and then print the value on my Display.
Here's the dash.cpp
#include "dash.h"
//define some colour values
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#include <LCDWIKI_GUI.h> //Core graphics library
#include <LCDWIKI_KBV.h> //Hardware-specific library
LCDWIKI_KBV lcd(320,480,A3,A2,A1,A0,A4);//width,height,cs,cd,wr,rd,reset
void Dash::init() {
lcd.Init_LCD();
lcd.Fill_Screen(BLACK);
}
void Dash::printNr(int h, int v, float nr) {
lcd.Set_Text_Mode(0);
//display 1 times string
lcd.Fill_Screen(0x0000);
lcd.Set_Text_colour(RED);
lcd.Set_Text_Back_colour(BLACK);
lcd.Set_Text_Size(5);
lcd.Print_Number_Float(nr, 2, 0, 8, '.', 0, ' ');
//lcd.Print_Number_Float(01234.56789, 2, 0, 8, '.', 0, ' ');
//lcd.Print_Number_Int(0xDEADBEF, 0, 16, 0, ' ',16);
}
Now the problem is, when I use the display, the value isn't correct, if I don't move the MPU, it slowly gets higher and higher, and if I move it, it completely gets crazy. The strange thing is, if I don't use the display (I only commented all code of the dash out), then it works fine. The display is on and shows only a white screen, but I don't use it.
So could it be, that maybe some magnetic field or anything of the display is distracting the MPU?
Or is it possible that it is because of the fact, that they use the same ground and 5V?
Some more information:
I use a Arduino Eleego Mega 2560, this tft display and this MPU6050. The display is directly plugged on the Arduino, the MPU 6050 is soldered between the display and the Arduino. Next to the MPU, there is also a bluetooth Modul, not in use, so I think it shouldn't cause the error.
I hope someone can help me, hopefully it's only a code problem.
Thanks
Sek