ESP8266使用记录(二)

ESP8266使用记录(二)_第1张图片
前文选择开发板类型错误,这里更正如上图

I2C方式获取mpu6050数据

#include 
const int MPU6050_addr = 0x68;
int16_t AccX, AccY, AccZ, Temp, GyroX, GyroY, GyroZ;
void setup() {
  Wire.begin();
  Wire.beginTransmission(MPU6050_addr);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);
  Serial.begin(9600);
}

void loop() {
  Wire.beginTransmission(MPU6050_addr);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU6050_addr, 14, true);
  AccX = Wire.read() << 8 | Wire.read();
  AccY = Wire.read() << 8 | Wire.read();
  AccZ = Wire.read() << 8 | Wire.read();
  Temp = Wire.read() << 8 | Wire.read();
  GyroX = Wire.read() << 8 | Wire.read();
  GyroY = Wire.read() << 8 | Wire.read();
  GyroZ = Wire.read() << 8 | Wire.read();
  Serial.print("AccX = ");
  Serial.print(AccX);
  Serial.print(" || AccY = ");
  Serial.print(AccY);
  Serial.print(" || AccZ = ");
  Serial.print(AccZ);
  Serial.print(" || Temp = ");
  Serial.print(Temp / 340.00 + 36.53);
  Serial.print(" || GyroX = ");
  Serial.print(GyroX);
  Serial.print(" || GyroY = ");
  Serial.print(GyroY);
  Serial.print(" || GyroZ = ");
  Serial.println(GyroZ);
  delay(100);
}

ESP8266使用记录(二)_第2张图片
mpu6050 esp8266
VCC 3V3
GND GND
SCL D1
SDA D2

相关链接地址
https://www.bilibili.com/read/cv4403414/
https://github.com/maksii/Accelerometer_MPU6050/blob/master/MPU6050/MPU6050.cs
http://eeskill.com/group/topic/id/1375

你可能感兴趣的:(esp8266,mpu6050)