Slightly modified version (to work with processing GUI)

Dependencies:   ITG3200 mbed

Fork of 6DoF_IMU_readvalue by Ryo Nakabayashi

Committer:
Vigneshwar
Date:
Wed Feb 05 22:12:32 2014 +0000
Revision:
5:e4a11d519322
Parent:
4:c7d5863b2576
adsf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ryought 0:cda6d9f5a43c 1 #include "ITG3200.h"
ryought 0:cda6d9f5a43c 2 #include "ADXL345_I2C.h"
ryought 0:cda6d9f5a43c 3
Vigneshwar 2:39468ef68358 4 //Serial pc(USBTX, USBRX);
Vigneshwar 2:39468ef68358 5 Serial rn42(p9, p10);
Vigneshwar 2:39468ef68358 6
Vigneshwar 1:c85175226571 7 ITG3200 gyro(p28, p27);
Vigneshwar 1:c85175226571 8 ADXL345_I2C accel(p28, p27);
ryought 0:cda6d9f5a43c 9
ryought 0:cda6d9f5a43c 10 int main() {
Vigneshwar 5:e4a11d519322 11 char str[296];
Vigneshwar 2:39468ef68358 12 rn42.baud(115200);
ryought 0:cda6d9f5a43c 13 gyro.setWhoAmI(0x68);
Vigneshwar 2:39468ef68358 14 //pc.printf("Now starting 6-degrees-of-freedom (ITG-3200 ADXL345) test...\n");
Vigneshwar 2:39468ef68358 15 //pc.printf("Accelerometer Device ID is: 0x%02x\n", accel.getDeviceID());
Vigneshwar 2:39468ef68358 16 //pc.printf("Gyro Devide ID is: 0x%02x\n", gyro.getWhoAmI());
Vigneshwar 1:c85175226571 17
Vigneshwar 1:c85175226571 18
Vigneshwar 5:e4a11d519322 19 short int accel_read[3] = {0, 0, 0};
ryought 0:cda6d9f5a43c 20
ryought 0:cda6d9f5a43c 21 // Accel setup
ryought 0:cda6d9f5a43c 22 // These are here to test whether any of the initialization fails. It will print the failure
ryought 0:cda6d9f5a43c 23 if (accel.setPowerControl(0x00)){
Vigneshwar 2:39468ef68358 24 rn42.printf("didn't intitialize power control\n");
ryought 0:cda6d9f5a43c 25 return 0; }
ryought 0:cda6d9f5a43c 26 //Full resolution, +/-16g, 4mg/LSB.
Vigneshwar 5:e4a11d519322 27 //wait(.001);
ryought 0:cda6d9f5a43c 28
Vigneshwar 5:e4a11d519322 29 //if(accel.setDataFormatControl(0x0B)){
Vigneshwar 5:e4a11d519322 30 // rn42.printf("didn't set data format\n");
Vigneshwar 5:e4a11d519322 31 // return 0; }
Vigneshwar 5:e4a11d519322 32 //wait(.001);
ryought 0:cda6d9f5a43c 33
ryought 0:cda6d9f5a43c 34 //3.2kHz data rate.
Vigneshwar 5:e4a11d519322 35 //if(accel.setDataRate(ADXL345_3200HZ)){
Vigneshwar 5:e4a11d519322 36 // rn42.printf("didn't set data rate\n");
Vigneshwar 5:e4a11d519322 37 // return 0; }
Vigneshwar 5:e4a11d519322 38 //wait(.001);
Vigneshwar 3:04df9b19199b 39
ryought 0:cda6d9f5a43c 40 //Measurement mode.
ryought 0:cda6d9f5a43c 41
Vigneshwar 5:e4a11d519322 42 //if(accel.setPowerControl(MeasurementMode)) {
Vigneshwar 5:e4a11d519322 43 // rn42.printf("didn't set the power control to measurement\n");
Vigneshwar 5:e4a11d519322 44 // return 0;
Vigneshwar 5:e4a11d519322 45 //}
ryought 0:cda6d9f5a43c 46
ryought 0:cda6d9f5a43c 47 // Gyro setup
Vigneshwar 2:39468ef68358 48 gyro.setLpBandwidth(LPFBW_256HZ);
ryought 0:cda6d9f5a43c 49
Vigneshwar 1:c85175226571 50 while (1)
Vigneshwar 1:c85175226571 51 {
Vigneshwar 2:39468ef68358 52 //wait(0.1);
ryought 0:cda6d9f5a43c 53
ryought 0:cda6d9f5a43c 54 accel.getOutput(accel_read);
ryought 0:cda6d9f5a43c 55
Vigneshwar 5:e4a11d519322 56 /*sprintf(str, "%i,%i,%i,%i,%i,%i,%i,A", (int16_t)accel_read[0], (int16_t)accel_read[1], (int16_t)accel_read[2],
Vigneshwar 5:e4a11d519322 57 gyro.getGyroX(), gyro.getGyroY(), gyro.getGyroZ(), (int16_t)gyro.getTemperature());*/
Vigneshwar 5:e4a11d519322 58
Vigneshwar 5:e4a11d519322 59 sprintf(str, "%i,%i,%i,%i,%i,%iA", (int16_t)accel_read[0], (int16_t)accel_read[1], (int16_t)accel_read[2],
Vigneshwar 5:e4a11d519322 60 gyro.getGyroX(), gyro.getGyroY(), gyro.getGyroZ());
Vigneshwar 2:39468ef68358 61 rn42.printf(str);
Vigneshwar 1:c85175226571 62
Vigneshwar 1:c85175226571 63 /*
Vigneshwar 1:c85175226571 64 pc.printf("Gyro[%5i, %5i, %5i] Accel[%4i, %4i, %4i]\n\t",
ryought 0:cda6d9f5a43c 65 gyro.getGyroX(), gyro.getGyroY(), gyro.getGyroZ(),
ryought 0:cda6d9f5a43c 66 (int16_t)accel_read[0], (int16_t)accel_read[1], (int16_t)accel_read[2]);
Vigneshwar 1:c85175226571 67 */
ryought 0:cda6d9f5a43c 68 }
ryought 0:cda6d9f5a43c 69
ryought 0:cda6d9f5a43c 70 }