hiroya taura
/
MPU6050IMU
mpuうごくん?
Fork of MPU6050IMU by
Revision 3:b7223a307029, committed 2016-01-06
- Comitter:
- taurin
- Date:
- Wed Jan 06 12:04:32 2016 +0000
- Parent:
- 2:e0381ca0edac
- Commit message:
- mpu?????
Changed in this revision
diff -r e0381ca0edac -r b7223a307029 MPU6050.h --- a/MPU6050.h Sun Jun 29 21:53:23 2014 +0000 +++ b/MPU6050.h Wed Jan 06 12:04:32 2016 +0000 @@ -153,7 +153,7 @@ int Ascale = AFS_2G; //Set up I2C, (SDA,SCL) -I2C i2c(I2C_SDA, I2C_SCL); +I2C i2c(p28,p27); DigitalOut myled(LED1);
diff -r e0381ca0edac -r b7223a307029 N5110.lib --- a/N5110.lib Sun Jun 29 21:53:23 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/onehorse/code/MPU60506-axisMotionSensor/#313c258ada8a
diff -r e0381ca0edac -r b7223a307029 main.cpp --- a/main.cpp Sun Jun 29 21:53:23 2014 +0000 +++ b/main.cpp Wed Jan 06 12:04:32 2016 +0000 @@ -28,7 +28,6 @@ #include "mbed.h" #include "MPU6050.h" -#include "N5110.h" // Using NOKIA 5110 monochrome 84 x 48 pixel display // pin 9 - Serial clock out (SCLK) @@ -48,7 +47,6 @@ Serial pc(USBTX, USBRX); // tx, rx // VCC, SCE, RST, D/C, MOSI,S CLK, LED - N5110 lcd(PA_8, PB_10, PA_9, PA_6, PA_7, PA_5, PC_7); int main() { @@ -56,66 +54,43 @@ //Set up I2C i2c.frequency(400000); // use fast (400 kHz) I2C - t.start(); - - lcd.init(); - lcd.setBrightness(0.05); - - // Read the WHO_AM_I register, this is a good test of communication uint8_t whoami = mpu6050.readByte(MPU6050_ADDRESS, WHO_AM_I_MPU6050); // Read WHO_AM_I register for MPU-6050 - pc.printf("I AM 0x%x\n\r", whoami); pc.printf("I SHOULD BE 0x68\n\r"); + //pc.printf("I AM 0x%x\n\r", whoami); pc.printf("I SHOULD BE 0x68\n\r"); if (whoami == 0x68) // WHO_AM_I should always be 0x68 { - pc.printf("MPU6050 is online..."); + //pc.printf("MPU6050 is online..."); wait(1); - lcd.clear(); - lcd.printString("MPU6050 OK", 0, 0); - mpu6050.MPU6050SelfTest(SelfTest); // Start by performing self test and reporting values - pc.printf("x-axis self test: acceleration trim within : "); pc.printf("%f", SelfTest[0]); pc.printf("% of factory value \n\r"); - pc.printf("y-axis self test: acceleration trim within : "); pc.printf("%f", SelfTest[1]); pc.printf("% of factory value \n\r"); - pc.printf("z-axis self test: acceleration trim within : "); pc.printf("%f", SelfTest[2]); pc.printf("% of factory value \n\r"); - pc.printf("x-axis self test: gyration trim within : "); pc.printf("%f", SelfTest[3]); pc.printf("% of factory value \n\r"); - pc.printf("y-axis self test: gyration trim within : "); pc.printf("%f", SelfTest[4]); pc.printf("% of factory value \n\r"); - pc.printf("z-axis self test: gyration trim within : "); pc.printf("%f", SelfTest[5]); pc.printf("% of factory value \n\r"); + //pc.printf("x-axis self test: acceleration trim within : "); pc.printf("%f", SelfTest[0]); pc.printf("% of factory value \n\r"); + //pc.printf("y-axis self test: acceleration trim within : "); pc.printf("%f", SelfTest[1]); pc.printf("% of factory value \n\r"); + //pc.printf("z-axis self test: acceleration trim within : "); pc.printf("%f", SelfTest[2]); pc.printf("% of factory value \n\r"); + //pc.printf("x-axis self test: gyration trim within : "); pc.printf("%f", SelfTest[3]); pc.printf("% of factory value \n\r"); + //pc.printf("y-axis self test: gyration trim within : "); pc.printf("%f", SelfTest[4]); pc.printf("% of factory value \n\r"); + //pc.printf("z-axis self test: gyration trim within : "); pc.printf("%f", SelfTest[5]); pc.printf("% of factory value \n\r"); wait(1); if(SelfTest[0] < 1.0f && SelfTest[1] < 1.0f && SelfTest[2] < 1.0f && SelfTest[3] < 1.0f && SelfTest[4] < 1.0f && SelfTest[5] < 1.0f) { mpu6050.resetMPU6050(); // Reset registers to default in preparation for device calibration mpu6050.calibrateMPU6050(gyroBias, accelBias); // Calibrate gyro and accelerometers, load biases in bias registers - mpu6050.initMPU6050(); pc.printf("MPU6050 initialized for active data mode....\n\r"); // Initialize device for active mode read of acclerometer, gyroscope, and temperature + mpu6050.initMPU6050(); //pc.printf("MPU6050 initialized for active data mode....\n\r"); // Initialize device for active mode read of acclerometer, gyroscope, and temperature - lcd.clear(); - lcd.printString("MPU6050", 0, 0); - lcd.printString("pass self test", 0, 1); - lcd.printString("initializing", 0, 2); wait(2); } else { - pc.printf("Device did not the pass self-test!\n\r"); + //pc.printf("Device did not the pass self-test!\n\r"); - lcd.clear(); - lcd.printString("MPU6050", 0, 0); - lcd.printString("no pass", 0, 1); - lcd.printString("self test", 0, 2); } } else { - pc.printf("Could not connect to MPU6050: \n\r"); - pc.printf("%#x \n", whoami); - - lcd.clear(); - lcd.printString("MPU6050", 0, 0); - lcd.printString("no connection", 0, 1); - lcd.printString("0x", 0, 2); lcd.setXYAddress(20, 2); lcd.printChar(whoami); - + //pc.printf("Could not connect to MPU6050: \n\r"); + //pc.printf("%#x \n", whoami); while(1) ; // Loop forever if communication doesn't happen } @@ -164,28 +139,20 @@ delt_t = t.read_ms() - count; if (delt_t > 500) { // update LCD once per half-second independent of read rate - pc.printf("ax = %f", 1000*ax); - pc.printf(" ay = %f", 1000*ay); - pc.printf(" az = %f mg\n\r", 1000*az); + //pc.printf("ax = %f", 1000*ax); + //pc.printf(" ay = %f", 1000*ay); + //pc.printf(" az = %f mg\n\r", 1000*az); - pc.printf("gx = %f", gx); - pc.printf(" gy = %f", gy); - pc.printf(" gz = %f deg/s\n\r", gz); - - pc.printf(" temperature = %f C\n\r", temperature); + //pc.printf("gx = %f", gx); + //pc.printf(" gy = %f", gy); + //pc.printf(" gz = %f deg/s\n\r", gz); - pc.printf("q0 = %f\n\r", q[0]); - pc.printf("q1 = %f\n\r", q[1]); - pc.printf("q2 = %f\n\r", q[2]); - pc.printf("q3 = %f\n\r", q[3]); + //pc.printf(" temperature = %f C\n\r", temperature); - lcd.clear(); - lcd.printString("MPU6050", 0, 0); - lcd.printString("x y z", 0, 1); - lcd.setXYAddress(0, 2); lcd.printChar((char)(1000*ax)); - lcd.setXYAddress(20, 2); lcd.printChar((char)(1000*ay)); - lcd.setXYAddress(40, 2); lcd.printChar((char)(1000*az)); lcd.printString("mg", 66, 2); - + //pc.printf("q0 = %f\n\r", q[0]); + //pc.printf("q1 = %f\n\r", q[1]); + //pc.printf("q2 = %f\n\r", q[2]); + //pc.printf("q3 = %f\n\r", q[3]); // Define output variables from updated quaternion---these are Tait-Bryan angles, commonly used in aircraft orientation. // In this coordinate system, the positive z-axis is down toward Earth. @@ -212,7 +179,7 @@ // pc.printf("average rate = "); pc.printf("%f", (sumCount/sum)); pc.printf(" Hz\n\r"); pc.printf("Yaw, Pitch, Roll: %f %f %f\n\r", yaw, pitch, roll); - pc.printf("average rate = %f\n\r", (float) sumCount/sum); + //pc.printf("average rate = %f\n\r", (float) sumCount/sum); myled= !myled; count = t.read_ms();