Buenas,
Estoy utilizando un MPU5060 para un drone. El sketch que estoy utilizando es el siguiente:
SETUP de MPU:
#include <Wire.h>
void setup() {
//Setup the MPU-6050
Wire.beginTransmission(gyro_address); //Start communication with the address found during search.
Wire.write(0x6B); //We want to write to the PWR_MGMT_1 register (6B hex)
Wire.write(0x00); //Set the register bits as 00000000 to activate the gyro
Wire.endTransmission(); //End the transmission with the gyro.
Wire.beginTransmission(gyro_address); //Start communication with the address found during search.
Wire.write(0x1B); //We want to write to the GYRO_CONFIG register (1B hex)
Wire.write(0x08); //Set the register bits as 00001000 (500dps full scale)
Wire.endTransmission(); //End the transmission with the gyro
Wire.beginTransmission(gyro_address); //Start communication with the address found during search.
Wire.write(0x1C); //We want to write to the ACCEL_CONFIG register (1A hex)
Wire.write(0x10); //Set the register bits as 00010000 (+/- 8g full scale range)
Wire.endTransmission(); //End the transmission with the gyro
//Let's perform a random register check to see if the values are written correct
Wire.beginTransmission(gyro_address); //Start communication with the address found during search
Wire.write(0x1B); //Start reading @ register 0x1B
Wire.endTransmission(); //End the transmission
Wire.requestFrom(gyro_address, 1); //Request 1 bytes from the gyro
while (Wire.available() < 1); //Wait until the 6 bytes are received
if (Wire.read() != 0x08) { //Check if the value is 0x08
// Error MPU LED??
while (1)delay(10); //Stay in this loop for ever
}
Wire.beginTransmission(gyro_address); //Start communication with the address found during search
Wire.write(0x1A); //We want to write to the CONFIG register (1A hex)
Wire.write(0x03); //Set the register bits as 00000011 (Set Digital Low Pass Filter to ~43Hz)
Wire.endTransmission(); //End the transmission with the gyro
}
LOOP:
void loop() {
///// resto del código
tiempo_1 = micros();
MPU_6050(); // Leer MPU
tiempo_2 = micros();
tiempo_MPU = tiempo_2-tiempo_1;
///// resto del código
}
void MPU_6050() {
Wire.beginTransmission(gyro_address);
Wire.write(0x3B);
Wire.endTransmission();
Wire.requestFrom(gyro_address, 12);
while (Wire.available() < 12);
AcX = Wire.read() << 8 | Wire.read();
AcY = Wire.read() << 8 | Wire.read();
AcZ = Wire.read() << 8 | Wire.read();
GyX = Wire.read() << 8 | Wire.read();
GyY = Wire.read() << 8 | Wire.read();
GyZ = Wire.read() << 8 | Wire.read();
if (cal_int == 2000) { // Calibración
GyX = GyX - gyro_X_cal;
GyY = GyY - gyro_Y_cal;
GyZ = GyZ - gyro_Z_cal;
AcX = AcX - acc_X_cal;
AcY = AcY - acc_Y_cal;
AcZ = AcZ - acc_Z_cal;
}
//Calculo de la velocidad angular del Giroscopio
Gy[0] = GyX / G_R;
Gy[1] = GyY / G_R;
Gy[2] = GyZ / G_R;
}
Estoy midiendo el tiempo que tarda en hacer la lectura utilizando las variables tiempo_1, tiempo_2 y tiempo_MPU, y estoy midiendo casi 1.9ms. Mi pregunta es, es normal que en hacer esas lecturas tarde 1900us (1.9ms)? Lo esperaba mucho mas rápido.
Estoy utilizando un arduino Mega. El conexionado es el tipico VCC, GND, I2C.