Hi, I'm building self balanced robot and I want to use MPU6050 (GY-521 board) instead of my analog sensors. I have Arduino UNO R2.
The problem is with Timer1 because I use this timer for interrupt ( reading values from sensor and do PID() function). I think, that FreeIMU library using the same timer and could change his settings.
//-------- MPU6050 ----------
#include <I2Cdev.h>
#include <MPU60X0.h>
#include <EEPROM.h>
//#define DEBUG
#include "DebugUtils.h"
#include "CommunicationUtils.h"
#include "FreeIMU.h"
#include <Wire.h>
#include <SPI.h>
int raw_values[9];
float ypr[3]; // yaw pitch roll
// Set the FreeIMU object
FreeIMU my3IMU = FreeIMU();
float reading = 0;
void setup(){
Serial.begin(115200);
Serial.println("A");
Wire.begin();
my3IMU.init(); // the parameter enable or disable fast mode
Serial.println("B");
noInterrupts();
Serial.println("C);
//set timer1 interrupt or 256Hz
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1 = 0;//initialize counter value to 0
// set compare match register for 1hz increments
OCR1A = 0xF423;// = (16*10^6) / (1*4) - 1 (must be <65536) //256Hz
// turn on CTC mode
TCCR1B |= (1 << WGM12);
TCCR1B |= (1 << CS10); // for 1 for 256Hz or 512 Hz
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
interrupts();
}
void loop(){
Serial.println("D");
}
ISR(TIMER1_COMPA_vect){//timer1 256Hz
Serial.println("E");
my3IMU.getYawPitchRoll(ypr);
reading = ypr[2];
Serial.println("F");
}
The result of code is:
A
B
How to fix it?