Hi guys,
I've got the mpu 6050 and I want to use it for a project.
I want to start off by just using a code that involves a complementary filter that figures out the x-axis angle of the mpu 6050 and then prints that out to a serial monitor.
I've got the basis of the code from a few different sources so I've tried to combine them so that I can understand it myself.
Here's the code:
#include<Wire.h>
#define DT 0.01:
#define AA 0.98:
#define A_GAIN 0.0573;
#define G_GAIN 0.00875;
float angle_pitch = 0.0;
float rate_pitch = 0.0;
signed int accel_x_zero = 0;
signed int gyro_x_zero = 0;
const int MPU=0x68; // I2C address of the MPU-6050
int16_t AcX,Tmp,GyX;
void setup(){
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop(){
signed int a_pitch = 0;
signed int g_pitch = 0;
signed int vref = 0;
float pitch_error = 0.0;
Wire.beginTransmission(MPU);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU,14,true); // request a total of 14 registers
AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
a_pitch = (accel_x_zero - AcX);
g_pitch = (GyX - gyro_x_zero);
rate_pitch = (float) g_pitch * G_GAIN;
angle = (AA)*(angle + rate_pitch *DT) + (0.02) * (a_pitch); //complementary filter (error located here)
Serial.print ("Tmp = "); Serial.print (Tmp/340.00 + 36.53);
Serial.print (" | angle = ") Serial.println(angle);
delay (500);
}
It keeps coming up with an error on the line marked saying:
expected `)' before ':' token
I'm not sure what this error means.
I need to put the term 'angle' at the start of the code somewhere as well but I'm not sure where it is supposed to go.
My programming skills are quite limited so any help would be appreciated!
Thanks,
nathman11