首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >与esp8266 esp-01模块和mpu6050的接口问题

与esp8266 esp-01模块和mpu6050的接口问题
EN

Stack Overflow用户
提问于 2018-10-23 04:40:47
回答 2查看 1.8K关注 0票数 1

我使用Arduino uno将草图上传到esp 01模块。我附上了连接esp-01mpu6050的图像,浏览器连续打印陀螺仪值,但是增加到0.0 1,我需要实际的陀螺仪值。

代码语言:javascript
复制
[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

当客户端实际连接并在浏览器中输入ip地址时,在浏览器中打印的值为0.69,0.69,0.60,0.70, 0.70 ,0.60,0.70,继续递增0.01,但我需要实际的陀螺仪读取。请帮帮我

我将esp 01和mpu6050连接在此图像列表项中。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-10-23 10:33:23

与使用MPU 6050库不同,只需使用Wire获取值,参考MPU6050的数据表,使用地址0x68开始转移。

代码语言:javascript
复制
 Wire.beginTransmission(0x68);

您可以参考下面的数据表。为了获得陀螺值,我们将写入0x1B(MSB)和0x18(LSB)。我们将得到6个字节的数据

代码语言:javascript
复制
 // Select gyroscope configuration register
 Wire.write(0x1B);
 Wire.write(0x18);

现在写入数据寄存器0x43以接收陀螺仪值。我们将从传感器接收6字节的值,其中x、y和z轴的16位(1字节)分别是Wire.requestFrom(Addr,6);

代码语言:javascript
复制
// 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];

在获得加速度计值时,我们写入0x1C(MSB)和0x18(LSB)。您可以在这个github链接中找到完整的代码。这里我们从传感器得到陀螺仪和加速度计的值。

也要像这个Wire.begin(SDA,SCL)一样,在您的情况下是Wire.begin(0,2);*注意到MPU6000和MPU6050有相同的规范和地址,所以不要担心。

票数 0
EN

Stack Overflow用户

发布于 2018-11-10 06:48:12

陀螺仪的全量程范围可以从寄存器地址0x1B检测到,有不同的分辨率在250到2000度/秒之间,以得到你需要的旋转轴的确切值,你需要用陀螺仪规格列中定义的比例因子来除以你的原始值。这是灵敏度/比例系数。您要获得的原始值是十进制值,此缩放因子以LSB(度数/秒)表示。例如,如果选择了500德克/秒,则需要将其偏离65.5才能得到值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52941292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档