I used the auto formatted code but it still does not compile.
Anyway here is the my code.
[code]
#include "quaternionFilters.h"
#include "MPU9250.h"
#include <EEPROM.h>
#include <Arduino.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include "Wire.h"
#define MPU9250_ADDRESS 0x68
#define ACC_FULL_SCALE_2_G 0x00
#define SerialPort Serial
Adafruit_SSD1306 display = Adafruit_SSD1306();
#include <SparkFunMPU9250-DMP.h>
MPU9250_DMP imu;
double roll , pitch, yaw;
long int pre_ts=0;
void setup()
{
{
SerialPort.begin(115200);
if (imu.begin() != INV_SUCCESS)
{
while (1)
{
SerialPort.println("Unable to communicate with MPU-9250");
SerialPort.println("Check connections, and try again.");
SerialPort.println();
delay(3000);
}
}
void I2Cread(uint8_t Address, uint8_t Register, uint8_t Nbytes, uint8_t* Data);
// Set register address
Wire.beginTransmission(Address);
Wire.write(Register);
Wire.endTransmission();
// Read Nbytes
Wire.requestFrom(Address, Nbytes);
uint8_t index = 0;
while (Wire.available())
Data[index++] = Wire.read();
void I2CwriteByte(uint8_t Address, uint8_t Register, uint8_t Data);
// Set register address
Wire.beginTransmission(Address);
Wire.write(Register);
Wire.write(Data);
Wire.endTransmission();
void setup()
{
Wire.begin()
I2CwriteByte(MPU9250_ADDRESS, 29, 0x06);
I2CwriteByte(MPU9250_ADDRESS, 28, ACC_FULL_SCALE_2_G);
I2CwriteByte(MPU9250_ADDRESS, 108, 0x2F);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(3);
display.setTextColor(WHITE);
imu.setSensors(INV_XYZ_GYRO | INV_XYZ_ACCEL | INV_XYZ_COMPASS);
imu.setGyroFSR(250); // Set gyro to 2000 dps
// Accel options are +/- 2, 4, 8, or 16 g
imu.setAccelFSR(2); // Set accel to +/-2g
imu.setLPF(10); // Set LPF corner frequency to 5Hz
imu.setSampleRate(10); // Set sample rate to 10Hz
imu.setCompassSampleRate(50); // Set mag rate to 10Hz
}
pre_ts=millis();
{
//}
void loop()
{
if ( imu.dataReady() )
{
imu.update(UPDATE_ACCEL | UPDATE_GYRO | UPDATE_COMPASS);
printIMUData(millis()-pre_ts);
pre_ts=millis();
}
}
void printIMUData(long int dt)
{
float accelX = imu.calcAccel(imu.ax);
float accelY = imu.calcAccel(imu.ay);
float accelZ = imu.calcAccel(imu.az);
float gyroX = imu.calcGyro(imu.gx)/57.3;
float gyroY = imu.calcGyro(imu.gy)/57.3;
float gyroZ = imu.calcGyro(imu.gz)/57.3;
float magX = imu.calcMag(imu.mx);
float magY = imu.calcMag(imu.my);
float magZ = imu.calcMag(imu.mz);
SerialPort.println("Accel: " + String(accelX) + ", " + String(accelY) + ", " + String(accelZ) + " g");
SerialPort.println("Gyro: " + String(gyroX) + ", " + String(gyroY) + ", " + String(gyroZ) + " dps");
SerialPort.println("Mag: " + String(magX) + ", " + String(magY) + ", " + String(magZ) + " uT");
SerialPort.println("Time: " + String(imu.time) + " ms");
//Euler angle from accel
pitch = atan2 (accelY ,( sqrt ((accelX * accelX) + (accelZ * accelZ))));
roll = atan2(-accelX ,( sqrt((accelY * accelY) + (accelZ * accelZ))));
// yaw from mag
float Yh = (magY * cos(roll)) - (magZ * sin(roll));
float Xh = (magX * cos(pitch))+(magY * sin(roll)*sin(pitch)) + (magZ * cos(roll) * sin(pitch));
yaw = atan2(Yh, Xh);
roll = roll*57.3;
pitch = pitch*57.3;
yaw = yaw*57.3;
Serial.println("pitch" + String( pitch) );
Serial.println("yaw" + String( yaw ));
Serial.println("roll" + String( roll));
}
void loop() {
I2Cread(MPU9250_ADDRESS, 0x3B, 14, Buf);
int16_t ay = -(Buf[2] << 8 | Buf[3]);
yangle = ay / 182.04;
display.clearDisplay();
display.setCursor(0, 10);
display.print(yangle);
display.display();
delay(100);
}
[/code]
this is the error message
Arduino: 1.8.2 (Windows XP), Board: "Arduino Pro or Pro Mini, ATmega328 (3.3V, 8 MHz)"
WARNING: library SparkFun_MPU-9250-DMP_Arduino_Library-master claims to run on (samd) architecture(s) and may be incompatible with your current board which runs on (avr) architecture(s).
C:\Documents and Settings\INDIAN\My Documents\Arduino\sketch_newapr10a\sketch_newapr10a.ino: In function 'void setup()':
sketch_newapr10a:37: error: 'Address' was not declared in this scope
Wire.beginTransmission(Address);
^
sketch_newapr10a:38: error: 'Register' was not declared in this scope
Wire.write(Register);
^
sketch_newapr10a:42: error: 'Nbytes' was not declared in this scope
Wire.requestFrom(Address, Nbytes);
^
sketch_newapr10a:45: error: 'Data' was not declared in this scope
Data[index++] = Wire.read();
^
sketch_newapr10a:52: error: 'Data' was not declared in this scope
Wire.write(Data);
^
sketch_newapr10a:58: error: a function-definition is not allowed here before '{' token
{
^
sketch_newapr10a:84: error: a function-definition is not allowed here before '{' token
{
^
sketch_newapr10a:144: error: expected '}' at end of input
}
^
sketch_newapr10a:144: error: expected '}' at end of input
sketch_newapr10a:144: error: expected '}' at end of input
exit status 1
'Address' was not declared in this scope