我的项目使用的是 mpu 6050 芯片,到目前为止效果良好。我读取四元数并通过蓝牙将其数据发送到我的电脑。 我现在需要的是震动检测。在 mpu 6050 的数据表中,它说这是支持的,但我在文档的其余部分找不到有关抖动检测的任何进一步信息。
我使用 Jeff Rowbergs arduino 库作为带有小型 3.0 板的芯片。 https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050
由于某种原因,尽管我尝试使用它,但我的芯片中断引脚从未被触发。这就是为什么我不断轮询来读取数据,因为它有效,所以没问题。
这是到目前为止我的 MPU 初始化和更新函数。如果有人知道一种检测抖动的好方法,请帮忙解决这个问题。我找不到办法。 (也许不使用芯片内置功能,而是根据可用数据计算)
void mpuInit()
{
Wire.begin();
TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
mpu.initialize();
boolean testConnection = mpu.testConnection();
#ifdef DEBUG
if(testConnection) Serial.println("MPU6050 connection successful");
else Serial.println("MPU6050 connection failed");
#endif
devStatus = mpu.dmpInitialize();
mpu.setXGyroOffset(220);
mpu.setYGyroOffset(76);
mpu.setZGyroOffset(-85);
mpu.setZAccelOffset(1788);
// make sure it worked (returns 0 if so)
if (devStatus == 0) {
mpu.setDMPEnabled(true);
mpuIntStatus = mpu.getIntStatus();
// set our DMP Ready flag so the main loop() function knows it's okay to use it
dmpReady = true;
// get expected DMP packet size for later comparison
packetSize = mpu.dmpGetFIFOPacketSize();
} else {
// ERROR!
// 1 = initial memory load failed
// 2 = DMP configuration updates failed
// (if it's going to break, usually the code will be 1)
#ifdef DEBUG
Serial.print("DMP Initialization failed (code ");
Serial.print(devStatus);
Serial.println(")");
#endif
}
}
void mpuUpdate()
{
// if programming failed, don't try to do anything
if (!dmpReady) return;
//get INT_STATUS byte
mpuIntStatus = mpu.getIntStatus();
// get current FIFO count
fifoCount = mpu.getFIFOCount();
// wait for MPU interrupt or extra packet(s) available
if ((fifoCount < packetSize)) return;
if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
// reset so we can continue cleanly
mpu.resetFIFO();
#ifdef DEBUG
Serial.println("Reset FIFO.");
#endif
// otherwise, check for DMP data ready interrupt (this should happen frequently)
} else if (mpuIntStatus & 0x02) {
// wait for correct available data length, should be a VERY short wait
while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
// read a packet from FIFO
mpu.getFIFOBytes(fifoBuffer, packetSize);
// track FIFO count here in case there is > 1 packet available
// (this lets us immediately read more without waiting for an interrupt)
fifoCount -= packetSize;
#ifdef OUTPUT_READABLE_QUATERNION
// display quaternion values in easy matrix form: w x y z
mpu.dmpGetQuaternion(&q, fifoBuffer);
#ifdef DEBUG
Serial.print("quat\t");
Serial.print(q.w);
Serial.print("\t");
Serial.print(q.x);
Serial.print("\t");
Serial.print(q.y);
Serial.print("\t");
Serial.println(q.z);
#endif
uint8_t *w = (uint8_t *) &q.w;
state[0] = w[0];
state[1] = w[1];
state[2] = w[2];
state[3] = w[3];
uint8_t *x = (uint8_t *) &q.x;
state[4] = x[0];
state[5] = x[1];
state[6] = x[2];
state[7] = x[3];
uint8_t *y = (uint8_t *) &q.y;
state[8] = y[0];
state[9] = y[1];
state[10] = y[2];
state[11] = y[3];
uint8_t *z = (uint8_t *) &q.z;
state[12] = z[0];
state[13] = z[1];
state[14] = z[2];
state[15] = z[3];
#endif
}
您的问题是MPU6050代码声明了UNO的中断引脚。 UNO 有几个中断引脚,第一个称为“0”。然而,这与引脚 2 相对应。
与 teensy 3.x 中断引脚声明类似,只是您将任何特定引脚声明为中断(其中大多数(如果不是全部)都具有中断能力。)
这是与 SteveH 类似的答案,我相信我刚刚说得更明确了。
我相信 Teensy 的创建者 Paul 存在一个 MPU6050 DMP 代码分支。我假设这部分代码是固定的。
同样的问题..
我有一个在 arduino uno 上工作的 mpu6050 使用杰夫的代码。
我把它移植到 Teensy 3.1.. 没用
我必须输入一行代码 使引脚用作中断 和输入引脚。我用的是15号针。
pinMode(15, INPUT);
attachInterrupt(15, dmpDataReady, RISING);
然后一切都成功了。
查看此链接: 晃动是否意味着检测加速度的变化?
http://www.raspberrypi.org/forums/viewtopic.php?t=66402&p=489229