Greetings all!
I have been doing this awesome game controller project now for a few months, and now everything is together and working pretty darn well! The problem that I am having is with the Gyroscopic movement that I am getting. It moves well slow, and in medium to medium fast movement , but if I try a really quick turn the rotation rate drops to zero! Its very strange. At first i thought this was the arduino just not being fast enough, so I bought a Due, (which is awesome BTW), but before I even changed out the board for it...OH BTW I am using a "Leonardo" :O)....
Here is the IMU:
and here is the CODE I am using :
and here is the datasheet for the Gyro(The other datasheets links are on the IMU page) :
So as I was saying, I had not put in the new board, and I was looking over the data sheet and I noticed a few things...take alook:
void Gyro_Init()
{
// Power up reset defaults
Wire.beginTransmission(GYRO_ADDRESS);
WIRE_SEND(0x3E);
WIRE_SEND(0x80);
Wire.endTransmission();
delay(5);
// Select full-scale range of the gyro sensors
// Set LP filter bandwidth to 42Hz
Wire.beginTransmission(GYRO_ADDRESS);
WIRE_SEND(0x16);
WIRE_SEND(0x1B); // DLPF_CFG = 3, FS_SEL = 3
Wire.endTransmission();
delay(5);
// Set sample rato to 50Hz
Wire.beginTransmission(GYRO_ADDRESS);
WIRE_SEND(0x15);
WIRE_SEND(0x0A); // SMPLRT_DIV = 10 (50Hz)
Wire.endTransmission();
delay(5);
// Set clock to PLL with z gyro reference
Wire.beginTransmission(GYRO_ADDRESS);
WIRE_SEND(0x3E);
WIRE_SEND(0x00);
Wire.endTransmission();
delay(5);
}
// Reads x, y and z gyroscope registers
void Read_Gyro()
{
int i = 0;
byte buff[6];
Wire.beginTransmission(GYRO_ADDRESS);
WIRE_SEND(0x1D); // Sends address to read from
Wire.endTransmission();
Wire.beginTransmission(GYRO_ADDRESS);
Wire.requestFrom(GYRO_ADDRESS, 6); // Request 6 bytes
while(Wire.available()) // ((Wire.available())&&(i<6))
{
buff[i] = WIRE_RECEIVE(); // Read one byte
i++;
}
Wire.endTransmission();
if (i == 6) // All bytes received?
{
gyro[0] = -1 * ((((int) buff[2]) << 8) | buff[3]); // X axis (internal sensor -y axis)
gyro[1] = -1 * ((((int) buff[0]) << 8) | buff[1]); // Y axis (internal sensor -x axis)
gyro[2] = -1 * ((((int) buff[4]) << 8) | buff[5]); // Z axis (internal sensor -z axis)
}
else
{
num_gyro_errors++;
if (output_errors) Serial.println("!ERR: reading gyroscope");
}
}
I notice they don't use the Sensitivity Scale Factor of 14.375 anywhere in this so shouldn't the recieved bytes look like this?:
gyro[0] = -1 * ((((int) buff[2]) << 8) | buff[3]) / 14.375; // X axis (internal sensor -y axis)
gyro[1] = -1 * ((((int) buff[0]) << 8) | buff[1]) / 14.375; // Y axis (internal sensor -x axis)
gyro[2] = -1 * ((((int) buff[4]) << 8) | buff[5]) / 14.375; // Z axis (internal sensor -z axis)
...and after looking closer I think that some of the register values are wrong, but not being very familiar with this type of thing I thought i should lay this all out and ask for help.
What I NEED is to make this run as fast as possible sampling as many time per sec so I can track very fast movements. Would someone help me set this Gyro code up so that it is doing just that, I would very much appreciate it!
~Bobby