I had this program working at one point but now Iβm not getting any data displaying on the blynk app. If somebody has a suggestion that would be great. Thanks.
// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// MPU-6000
// This code is designed to work with the MPU-6000_I2CS I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/content/Accelorometer?sku=MPU-6000_I2CS#tabs-0-product_tabset-2
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <SimpleTimer.h> // here is the SimpleTimer library
// MPU-6000 I2C address is 0x68(104)
#define Addr 0x68
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxx";
char pass[] = "xxxx";
SimpleTimer timer; // Create a Timer object called "timer"!
void myTimerEvent()
{
unsigned int data[6];
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x3B);
// Stop I2C transmission
Wire.endTransmission();
// Request 6 bytes of data
Wire.requestFrom(Addr, 6);
// Read 6 byte of data
if(Wire.available() == 6)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
data[4] = Wire.read();
data[5] = Wire.read();
}
// Convert the data
int xAccl = data[0] * .256 + data[1];
int yAccl = data[2] * .256 + data[3];
int zAccl = data[4] * .256 + data[5];
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write(0x43);
// Stop I2C transmission
Wire.endTransmission();
// Request 6 bytes of data
Wire.requestFrom(Addr, 6);
// Read 6 byte of data
if(Wire.available() == 6)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
data[4] = Wire.read();
data[5] = Wire.read();
}
// Convert the data
int xGyro = data[0] * .256 + data[1];
int yGyro = data[2] * .256 + data[3];
int zGyro = data[4] * .256 + data[5];
// Output to blynk
// Output data to serial monitor
Serial.print("Acceleration in X-Axis : ");
Serial.println(xAccl);
Blynk.virtualWrite(V1, xAccl);
Serial.print("Acceleration in Y-Axis : ");
Serial.println(yAccl);
Blynk.virtualWrite(V2, yAccl);
Serial.print("Acceleration in Z-Axis : ");
Serial.println(zAccl);
Blynk.virtualWrite(V3, zAccl);
Serial.print("X-Axis of Rotation : ");
Serial.println(xGyro);
Blynk.virtualWrite(V4, xGyro);
Serial.print("Y-Axis of Rotation : ");
Serial.println(yGyro);
Blynk.virtualWrite(V5, yGyro);
Serial.print("Z-Axis of Rotation : ");
Serial.println(zGyro);
Blynk.virtualWrite(V6, zGyro);
}
void setup()
{
// Initialise I2C communication as Master
Wire.begin();
// Initialise serial communication, set baud rate = 9600
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select gyroscope configuration register
Wire.write(0x1B);
// Full scale range = 2000 dps
Wire.write(0x18);
// Stop I2C transmission
Wire.endTransmission();
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select accelerometer configuration register
Wire.write(0x1C);
// Full scale range = +/-16g
Wire.write(0x18);
// Stop I2C transmission
Wire.endTransmission();
// Start I2C transmission
Wire.beginTransmission(Addr);
// Select power management register
Wire.write(0x6B);
// PLL with xGyro reference
Wire.write(0x01);
// Stop I2C transmission
Wire.endTransmission();
timer.setInterval(1000L, myTimerEvent); // Here you set interval (1sec) and which function to call
}
void loop()
{
Blynk.run();
timer.run(); // SimpleTimer is working
}