Slightly modified version (to work with processing GUI)

Dependencies:   ITG3200 mbed

Fork of 6DoF_IMU_readvalue by Ryo Nakabayashi

Committer:
Vigneshwar
Date:
Thu Oct 24 20:31:54 2013 +0000
Revision:
4:c7d5863b2576
Parent:
3:04df9b19199b
Child:
5:e4a11d519322
adad

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 1:c85175226571 11 char str[512];
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
ryought 0:cda6d9f5a43c 19 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.
ryought 0:cda6d9f5a43c 27 wait(.001);
ryought 0:cda6d9f5a43c 28
ryought 0:cda6d9f5a43c 29 if(accel.setDataFormatControl(0x0B)){
Vigneshwar 2:39468ef68358 30 rn42.printf("didn't set data format\n");
ryought 0:cda6d9f5a43c 31 return 0; }
ryought 0:cda6d9f5a43c 32 wait(.001);
ryought 0:cda6d9f5a43c 33
ryought 0:cda6d9f5a43c 34 //3.2kHz data rate.
Vigneshwar 4:c7d5863b2576 35 if(accel.setDataRate(ADXL345_1600HZ)){
Vigneshwar 2:39468ef68358 36 rn42.printf("didn't set data rate\n");
ryought 0:cda6d9f5a43c 37 return 0; }
ryought 0:cda6d9f5a43c 38 wait(.001);
Vigneshwar 3:04df9b19199b 39
ryought 0:cda6d9f5a43c 40 //Measurement mode.
ryought 0:cda6d9f5a43c 41
ryought 0:cda6d9f5a43c 42 if(accel.setPowerControl(MeasurementMode)) {
Vigneshwar 2:39468ef68358 43 rn42.printf("didn't set the power control to measurement\n");
ryought 0:cda6d9f5a43c 44 return 0;
ryought 0:cda6d9f5a43c 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 2:39468ef68358 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 1:c85175226571 57 gyro.getGyroX(), gyro.getGyroY(), gyro.getGyroZ(), (int16_t)gyro.getTemperature());
Vigneshwar 2:39468ef68358 58 rn42.printf(str);
Vigneshwar 1:c85175226571 59
Vigneshwar 1:c85175226571 60 /*
Vigneshwar 1:c85175226571 61 pc.printf("Gyro[%5i, %5i, %5i] Accel[%4i, %4i, %4i]\n\t",
ryought 0:cda6d9f5a43c 62 gyro.getGyroX(), gyro.getGyroY(), gyro.getGyroZ(),
ryought 0:cda6d9f5a43c 63 (int16_t)accel_read[0], (int16_t)accel_read[1], (int16_t)accel_read[2]);
Vigneshwar 1:c85175226571 64 */
ryought 0:cda6d9f5a43c 65 }
ryought 0:cda6d9f5a43c 66
ryought 0:cda6d9f5a43c 67 }