龙空技术网

MPU-6050模块三轴加速度+三轴陀螺仪

优信电子企业店 242

前言:

目前姐妹们对“6050陀螺仪驱动算法”可能比较关注,小伙伴们都需要学习一些“6050陀螺仪驱动算法”的相关资讯。那么小编也在网摘上汇集了一些有关“6050陀螺仪驱动算法””的相关资讯,希望各位老铁们能喜欢,大家一起来学习一下吧!

简介模块引脚说明名称接线Arduino例程代码总结简介

MPU-6050集成了3轴MEMS陀螺仪,3轴MEMS加速度计,以及一个可扩展的数字运动处理器DMP,可用IIC接口连接一个第三方的数字传感器。

模块引脚说明名称

接线

5v——VCC

GND——GND

SCL——SCL

SDA——SDA

Arduino例程代码

include "I2Cdev.h"include "MPU6050.h"if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIREinclude "Wire.h"endifMPU6050 accelgyro;int16_t ax, ay, az;int16_t gx, gy, gz;define OUTPUT_READABLE_ACCELGYROdefine LED_PIN 13bool blinkState = false;void setup() {if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE        Wire.begin();elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE        Fastwire::setup(400, true);endif      Serial.begin(38400);       Serial.println("Initializing I2C devices...");    accelgyro.initialize();      Serial.println("Testing device connections...");    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");       pinMode(LED_PIN, OUTPUT);}void loop() {        accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);ifdef OUTPUT_READABLE_ACCELGYRO               Serial.print("a/g:\t");        Serial.print(ax); Serial.print("\t");        Serial.print(ay); Serial.print("\t");        Serial.print(az); Serial.print("\t");        Serial.print(gx); Serial.print("\t");        Serial.print(gy); Serial.print("\t");        Serial.println(gz);    #endif    #ifdef OUTPUT_BINARY_ACCELGYRO        Serial.write((uint8_t)(ax >> 8)); Serial.write((uint8_t)(ax & 0xFF));        Serial.write((uint8_t)(ay >> 8)); Serial.write((uint8_t)(ay & 0xFF));        Serial.write((uint8_t)(az >> 8)); Serial.write((uint8_t)(az & 0xFF));        Serial.write((uint8_t)(gx >> 8)); Serial.write((uint8_t)(gx & 0xFF));        Serial.write((uint8_t)(gy >> 8)); Serial.write((uint8_t)(gy & 0xFF));        Serial.write((uint8_t)(gz >> 8)); Serial.write((uint8_t)(gz & 0xFF));    #endif    blinkState = !blinkState;    digitalWrite(LED_PIN, blinkState);

打开串口检测器,把波特率设置为38400

总结

像MPU-6050这种带有SCL,SDA串行IIC接口的模块,可以连接Arduino的IIC接口通过例程进行简单使用,也方便对模块进行测试。

标签: #6050陀螺仪驱动算法