mpu6050(MPU-6050模块三轴加速度 三轴陀螺仪)

MPU-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_WIRE include "Wire.h" endif MPU6050 accelgyro; int16_t ax, ay, az; int16_t gx, gy, gz; define OUTPUT_READABLE_ACCELGYRO define LED_PIN 13 bool 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接口经过例程举行简便使用,也便利对模块举行测试。

内容底部广告位(手机)
标签:

管理员
草根站长管理员

专注网站优化+网络营销,只做有思想的高价值网站,只提供有担当的营销服务!

上一篇:除湿机价格(米家智能变频除湿机30L发布;OPPO Reno13发布会四大新品价格汇总)
下一篇:返回列表

相关推荐