被TI坑的最惨的一次
他喵的给的管脚图跟代码居然对不上
图片上的IIc(0)对应代码的IIc(1)
图片上的IIc(1)对应代码的IIc(0)
直接上代码,大家可以烧录测试一下
这里使用的是IIc(0),所以要插板子上的IIC(1)
#include "Wire.h"
// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050.h"
// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
#define LED_PIN 13
bool blinkState = false;
void setup() {
// join I2C bus (I2Cdev library doesn't do this automatically)
Wire.begin();
// initialize serial communication
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
// it's really up to you depending on your project)
Serial.begin(38400);
// initialize device
Serial.println("Initializing I2C devices...");
accelgyro.initialize();
// verify connection
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
// configure Arduino LED for
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// read raw accel/gyro measurements from device
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
// these methods (and a few others) are also available
//accelgyro.getAcceleration(&ax, &ay, &az);
//accelgyro.getRotation(&gx, &gy, &gz);
// display tab-separated accel/gyro x/y/z values
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);
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
}
效果图
上一篇:基于msp430f2491的proteus仿真(实现流水灯)
下一篇:MSP432驱动st7920
推荐阅读最新更新时间:2024-11-10 10:28
设计资源 培训 开发板 精华推荐
- OP262GSZ单电源直接接入调制解调器的典型应用电路
- 用于计算机/外围设备的 12V DC 至 DC 单路输出电源
- 使用 Analog Devices 的 LTM4636-1EY 的参考设计
- 使用 ON Semiconductor 的 CAT3647HV3 的参考设计
- MAP9001NLG120V12W,MAP9001 高压交流 LED 驱动器演示板
- 具有电源良好状态的 LT3976IUDD 5V、2MHz 降压转换器的典型应用电路
- 具有基本抑制功能的 LF50ABDT-TR 5V 低压降稳压器的典型应用
- LT8330IDDB 4V 至 16V 输入、5V SEPIC 转换器的典型应用电路
- AM1/4S-4815SZ 15V 0.25 瓦 DC/DC 转换器的典型应用
- LTM4600 的典型应用 - 10A 高效 DC/DC 模块