Slightly modified version (to work with processing GUI)
Fork of 6DoF_IMU_readvalue by
Diff: main.cpp
- Revision:
- 2:39468ef68358
- Parent:
- 1:c85175226571
- Child:
- 3:04df9b19199b
--- a/main.cpp Tue Feb 12 02:31:21 2013 +0000 +++ b/main.cpp Fri Oct 11 00:09:31 2013 +0000 @@ -1,16 +1,19 @@ #include "ITG3200.h" #include "ADXL345_I2C.h" -Serial pc(USBTX, USBRX); +//Serial pc(USBTX, USBRX); +Serial rn42(p9, p10); + ITG3200 gyro(p28, p27); ADXL345_I2C accel(p28, p27); int main() { char str[512]; + rn42.baud(115200); 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: 0x%02x\n", gyro.getWhoAmI()); + //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: 0x%02x\n", gyro.getWhoAmI()); int accel_read[3] = {0, 0, 0}; @@ -18,41 +21,41 @@ // 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"); + rn42.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"); + rn42.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"); + rn42.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"); + rn42.printf("didn't set the power control to measurement\n"); return 0; } // Gyro setup - gyro.setLpBandwidth(LPFBW_42HZ); + gyro.setLpBandwidth(LPFBW_256HZ); while (1) { - wait(0.1); + //wait(0.1); accel.getOutput(accel_read); - sprintf(str, "%i,%i,%i,%i,%i,%i,%i\n", (int16_t)accel_read[0], (int16_t)accel_read[1], (int16_t)accel_read[2], + 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], gyro.getGyroX(), gyro.getGyroY(), gyro.getGyroZ(), (int16_t)gyro.getTemperature()); - pc.printf(str); + rn42.printf(str); /* pc.printf("Gyro[%5i, %5i, %5i] Accel[%4i, %4i, %4i]\n\t",