Slightly modified version (to work with processing GUI)
Fork of 6DoF_IMU_readvalue by
Diff: main.cpp
- Revision:
- 0:cda6d9f5a43c
- Child:
- 1:c85175226571
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Nov 26 05:34:56 2012 +0000 @@ -0,0 +1,55 @@ +#include "ITG3200.h" +#include "ADXL345_I2C.h" + +Serial pc(USBTX, USBRX); +ITG3200 gyro(p9, p10); +ADXL345_I2C accel(p9, p10); + +int main() { + gyro.setWhoAmI(0x68); + pc.printf("Now starting 6-degrees-of-freedom (ITG-3200 ADXL345) test...\n"); + pc.printf("Accelerometer Device ID is: 0x%02x\n", accel.getDeviceID()); + pc.printf("Gyro Devide ID is: 0x02x\n", gyro.getWhoAmI()); + + int accel_read[3] = {0, 0, 0}; + + // Accel setup + // These are here to test whether any of the initialization fails. It will print the failure + if (accel.setPowerControl(0x00)){ + pc.printf("didn't intitialize power control\n"); + return 0; } + //Full resolution, +/-16g, 4mg/LSB. + wait(.001); + + if(accel.setDataFormatControl(0x0B)){ + pc.printf("didn't set data format\n"); + return 0; } + wait(.001); + + //3.2kHz data rate. + if(accel.setDataRate(ADXL345_3200HZ)){ + pc.printf("didn't set data rate\n"); + return 0; } + wait(.001); + + //Measurement mode. + + if(accel.setPowerControl(MeasurementMode)) { + pc.printf("didn't set the power control to measurement\n"); + return 0; + } + + // Gyro setup + gyro.setLpBandwidth(LPFBW_42HZ); + + while (1) { + wait(0.1); + + accel.getOutput(accel_read); + + pc.printf("Gyro[%5i, %5i, %5i] Accel[%4i, %4i, %4i]\n", + gyro.getGyroX(), gyro.getGyroY(), gyro.getGyroZ(), + (int16_t)accel_read[0], (int16_t)accel_read[1], (int16_t)accel_read[2]); + } + +}