#include<Wire.h>
#include <SPI.h>
#define BLYNK_PRINT Serial
#include <Blynk.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
char auth[] = "xxxxxx"; // You should get Auth Token in the Blynk App new project from NODEMCU
// WiFi network Credentials
const char* ssid = "xxxxx"; // your SSID
const char* password = "xxxx"; //your WIFI Password
const int MPU_addr=0x68;
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
int minVal=265;
int maxVal=402;
double x;
double y;
double z;
void setup(){
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(9600);
Blynk.begin(auth, ssid, password);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
}
void loop(){
Blynk.run();
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true);
AcX=Wire.read()<<8|Wire.read();
AcY=Wire.read()<<8|Wire.read();
AcZ=Wire.read()<<8|Wire.read();
int xAng = map(AcX,minVal,maxVal,-90,90);
int yAng = map(AcY,minVal,maxVal,-90,90);
int zAng = map(AcZ,minVal,maxVal,-90,90);
x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI);
y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI);
z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);
Serial.print("AngleX= ");
Serial.println(x);
Serial.print("AngleY= ");
Serial.println(y);
Serial.print("AngleZ= ");
Serial.println(z);
Serial.println(" ***************");
lcd.setCursor(0,0);
lcd.print("3 Axis Angle Monitor");
lcd.setCursor(0,1);
lcd.print("X");
lcd.print((char)223);
lcd.print(": ");
lcd.print(x);
lcd.setCursor(0,2);
lcd.print("Y");
lcd.print((char)223);
lcd.print(": ");
lcd.print(y);
lcd.setCursor(0,3);
lcd.print("Z");
lcd.print((char)223);
lcd.print(": ");
lcd.print(z);
Blynk.virtualWrite(V1, x);
Blynk.virtualWrite(V2, y);
Blynk.virtualWrite(V3, z);
delay(1000);
}