欢迎大家来到IT世界,在知识的湖畔探索吧!
- 简介
- 模块引脚说明名称
- 接线
- 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);
欢迎大家来到IT世界,在知识的湖畔探索吧!
打开串口检测器,把波特率设置为38400
总结
像MPU-6050这种带有SCL,SDA串行IIC接口的模块,可以连接Arduino的IIC接口通过例程进行简单使用,也方便对模块进行测试。
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://itzsg.com/30232.html