I used the Arduino
uno to upload the sketch to the esp 01 module. I attached the image how I connected the esp-01
and mpu6050
, browser continuously prints the gyro values but incrementing by 0.01 I need actual gyro values
[1]
#include <ESP8266WiFi.h>
#include <MPU6050_tockn.h>
#include <Wire.h>
MPU6050 mpu6050(Wire);
const char* ssid = "TP-LINK";
const char* password = "1913131";
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(1000);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
delay(5000);
//Serial.begin(9600);
Wire.begin(0,2);
delay(1000);
mpu6050.begin();
delay(1000);
mpu6050.calcGyroOffsets(true);
delay(1000);
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
Serial.print("Client did not connect");
delay(1000);
return;
}
// Wait until the client sends some data
Serial.println("new client");
while (!client.available()) {
delay(1);
}
while(client.available()){
mpu6050.update();
client.print(mpu6050.getGyroAngleX());
client.print(",");
client.print(mpu6050.getGyroAngleY());
client.print(",");
client.println(mpu6050.getGyroAngleZ());
delay(10);
}
delay(1);
Serial.println("Client disonnected");
// The client will actually be disconnected
// when the function returns and 'client' object is detroyed
}
> Blockquote
when client actually connects and when I enter the ip address in the browser values printed in the browser are 0.69,0.69,0.60 0.70,0.70,0.60 0.70 and goes on incrementing the values by 0.01 but I need actual gyroscope reading. help me please
I connected the esp 01 and mpu6050 like in this image List item
instead of using MPU 6050 library just use Wire Library to get the values refer to the data sheet of MPU6050 uses address 0x68 to start trnsmission.
Wire.beginTransmission(0x68);
you can refer to following datasheet. To get the Gyro values we write to 0x1B(MSB) and 0x18(LSB). We will get the 6 bytes of data
// Select gyroscope configuration register
Wire.write(0x1B);
Wire.write(0x18);
now write to data register 0x43 to recieve the gyro values. We will receive 6 bytes of values from the sensor where the 16 bits(1byte) for x, y and z axis respectively 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];
where as To get accelerometer values we write to 0x1C(MSB) and 0x18(LSB). you can find the full code in this github link. Here we have got the gyro and accelerometer values from the sensor
also Do it like this Wire.begin(SDA,SCL) in your case it would be Wire.begin(0,2); *Note MPU6000 and MPU6050 have the same specification and address so don't worry about that.