I have been working on mpu6050 stuff but I still am not sure on how to code it myself. Using just the dmp6 demo on the library, I found myself lost because I was confused on initializing variables like quaternions, VectorFloat/VectorInt16 and the other values/angles.
I wish to be able to declare and write variables and code without having to rip off code from the library, or be staring at it.
I guess doing this will also allow me to understand the whole gyro/accel thing better. I just want to write my own code and know intuitively what words to type in a program for my project(s)
Thanks in advanced!
1. The MPU6050 sensor does the following jobs:
(1) Gyro measurements (change in angular velocity = change in rotational angle/unit time).
(2) Acceleration measurements.
(3) Temperature measurement.
2. MPU6050 sensor is an I2C Bus compatible sensor. Therefore, you must include the Wire.h Library in your Arduino IDE.
3. You can operate MPU6050 sensor in two ways:
(1) Use the functions/methods of the Wire.h Library to prepare codes to --
(a) Perform read/write operations on the registers of the sensor data;
(b) Compute information based on the values of the above registers.
(c) Simple Example -- Temperature Measurement (tested in UNO)
#include<Wire.h>
#define MPUaddr 0x69
void setup()
{
Serial.begin(9600);
Wire.begin();
}
void loop()
{
Wire.beginTransmission(MPUaddr); //Start communication with the MPU-6050.
Wire.write(0x6B); //We want to write to the PWR_MGMT_1 register (6B hex).
Wire.write(0x00); //enable temp sensor
Wire.endTransmission();
//----pointing temp sensor-----------------
Wire.beginTransmission(MPUaddr);
Wire.write(0x41); //pointing Temp_Out_High Reg
Wire.endTransmission();
Wire.requestFrom(MPUaddr, 2); //two-byte temp data from Temp_H and Temp_L
byte x1 = Wire.read();
byte x2 = Wire.read();
int x = (int)(x1<<8)|(int)x2;
//------compute temp from x-----
float mpuTemp = (float)(x/340.0 + 36.53); //formula from data sheets
Serial.print("Temp = ");
Serial.print(mpuTemp, 2); //2-digit after decimal point
Serial.println(" degC");
delay(1000);
}
(2) Use the functions/methods of the MPU6050.h Library (it calls/uses Wire.h Library) to --
(a) Perform read/write operations on the registers of the sensor data;
(b) Compute information based on the values of the above registers.
(c) Simple Example -- Temperature Measurement (tested in UNO)
#include <MPU6050.h>
MPU6050 mpu; //device address 0x69 keyed in Library AD0=LH
void setup()
{
Serial.begin(9600);
Serial.println("Initialize MPU6050");
while (!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
{
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
delay(1000);
}
}
void loop()
{
float temp = mpu.readTemperature();
Serial.print("Temp = ");
Serial.print(temp, 2);
Serial.println(" degC");
//-------------------------
delay(1000);
}
I'm glad that this was given to me; I read, but didnt reply, sorry
I got this so far; it's pretty raw but I hope I can fill it in to make it more
Any ideas what I'm missing here in terms of #includes, constants, etc
#include <I2Cdev.h>
#include <MPU6050.h>
// declaring sensor module
MPU6050 mpu;
// defining vars for raw values
int16_t
rawaccx, rawaccy, rawaccz,
rawgyrx, rawgyry, rawgyrz;
// real angle
// "u" is theta here (i.e. angle)
float
uaccx, uaccy,
ugyrx, ugyry,
usumx, usumy;
float
elapsedtime, time, timeprev;
int i;
float pi = 180/3.141592654;
//acceleration conversion factor; raw_value / 1671 = m/s2 value
const int convraw = 1671;
//real values
int
realaccx, realaccy, realaccz;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
getaccel(rawaccx, rawaccy);
getangle(); // still don't know what to put here....I'll need to look into datasheet or something
gettime();
}
// converts raw accelerometer data to m/s/s
int getaccel(int x, int y){
realaccx = x / convraw;
realaccy = y / convraw;
}
int gettime(){
timeprev = time; //the previous time is stored before the actual time read
time = millis(); // actual time read
elapsedtime = (time - timeprev) / 1000;
}