Motion Processor
This is a complex device using I2C communication, which almost always frustrates beginners. If you want to use an accellerometer I recommend using the ADXL-335 analog sensor since it is much easier to interface with and does not require a library. The accuracy is lower for the ADXL-335 but lower level of frustration is well worth it.
Code for Motion Processor
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"
// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
#define OUTPUT_READABLE_ACCELGYRO
void setup() {
Wire.begin();
Serial.begin(38400);
accelgyro.initialize();
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
}
void loop()
{
accelgyro.getAcceleration(&ax, &ay, &az);
Serial.print("a/g:\t");
Serial.print((ax/256)+128); Serial.print("\t"); //Dividing decreases accuracy we should truncate MSBs
Serial.print(ay); Serial.print("\t");
Serial.print(az); Serial.print("\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.println(gz);
}
#include "MPU6050.h"
#include "Wire.h"
// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
#define OUTPUT_READABLE_ACCELGYRO
void setup() {
Wire.begin();
Serial.begin(38400);
accelgyro.initialize();
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
}
void loop()
{
accelgyro.getAcceleration(&ax, &ay, &az);
Serial.print("a/g:\t");
Serial.print((ax/256)+128); Serial.print("\t"); //Dividing decreases accuracy we should truncate MSBs
Serial.print(ay); Serial.print("\t");
Serial.print(az); Serial.print("\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.println(gz);
}
No comments:
Post a Comment