Slightly modified version (to work with processing GUI)
Fork of 6DoF_IMU_readvalue by
main.cpp@1:c85175226571, 2013-02-12 (annotated)
- Committer:
- Vigneshwar
- Date:
- Tue Feb 12 02:31:21 2013 +0000
- Revision:
- 1:c85175226571
- Parent:
- 0:cda6d9f5a43c
- Child:
- 2:39468ef68358
Final Version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ryought | 0:cda6d9f5a43c | 1 | #include "ITG3200.h" |
ryought | 0:cda6d9f5a43c | 2 | #include "ADXL345_I2C.h" |
ryought | 0:cda6d9f5a43c | 3 | |
ryought | 0:cda6d9f5a43c | 4 | Serial pc(USBTX, USBRX); |
Vigneshwar | 1:c85175226571 | 5 | ITG3200 gyro(p28, p27); |
Vigneshwar | 1:c85175226571 | 6 | ADXL345_I2C accel(p28, p27); |
ryought | 0:cda6d9f5a43c | 7 | |
ryought | 0:cda6d9f5a43c | 8 | int main() { |
Vigneshwar | 1:c85175226571 | 9 | char str[512]; |
ryought | 0:cda6d9f5a43c | 10 | gyro.setWhoAmI(0x68); |
ryought | 0:cda6d9f5a43c | 11 | pc.printf("Now starting 6-degrees-of-freedom (ITG-3200 ADXL345) test...\n"); |
ryought | 0:cda6d9f5a43c | 12 | pc.printf("Accelerometer Device ID is: 0x%02x\n", accel.getDeviceID()); |
Vigneshwar | 1:c85175226571 | 13 | pc.printf("Gyro Devide ID is: 0x%02x\n", gyro.getWhoAmI()); |
Vigneshwar | 1:c85175226571 | 14 | |
Vigneshwar | 1:c85175226571 | 15 | |
ryought | 0:cda6d9f5a43c | 16 | int accel_read[3] = {0, 0, 0}; |
ryought | 0:cda6d9f5a43c | 17 | |
ryought | 0:cda6d9f5a43c | 18 | // Accel setup |
ryought | 0:cda6d9f5a43c | 19 | // These are here to test whether any of the initialization fails. It will print the failure |
ryought | 0:cda6d9f5a43c | 20 | if (accel.setPowerControl(0x00)){ |
ryought | 0:cda6d9f5a43c | 21 | pc.printf("didn't intitialize power control\n"); |
ryought | 0:cda6d9f5a43c | 22 | return 0; } |
ryought | 0:cda6d9f5a43c | 23 | //Full resolution, +/-16g, 4mg/LSB. |
ryought | 0:cda6d9f5a43c | 24 | wait(.001); |
ryought | 0:cda6d9f5a43c | 25 | |
ryought | 0:cda6d9f5a43c | 26 | if(accel.setDataFormatControl(0x0B)){ |
ryought | 0:cda6d9f5a43c | 27 | pc.printf("didn't set data format\n"); |
ryought | 0:cda6d9f5a43c | 28 | return 0; } |
ryought | 0:cda6d9f5a43c | 29 | wait(.001); |
ryought | 0:cda6d9f5a43c | 30 | |
ryought | 0:cda6d9f5a43c | 31 | //3.2kHz data rate. |
ryought | 0:cda6d9f5a43c | 32 | if(accel.setDataRate(ADXL345_3200HZ)){ |
ryought | 0:cda6d9f5a43c | 33 | pc.printf("didn't set data rate\n"); |
ryought | 0:cda6d9f5a43c | 34 | return 0; } |
ryought | 0:cda6d9f5a43c | 35 | wait(.001); |
ryought | 0:cda6d9f5a43c | 36 | |
ryought | 0:cda6d9f5a43c | 37 | //Measurement mode. |
ryought | 0:cda6d9f5a43c | 38 | |
ryought | 0:cda6d9f5a43c | 39 | if(accel.setPowerControl(MeasurementMode)) { |
ryought | 0:cda6d9f5a43c | 40 | pc.printf("didn't set the power control to measurement\n"); |
ryought | 0:cda6d9f5a43c | 41 | return 0; |
ryought | 0:cda6d9f5a43c | 42 | } |
ryought | 0:cda6d9f5a43c | 43 | |
ryought | 0:cda6d9f5a43c | 44 | // Gyro setup |
ryought | 0:cda6d9f5a43c | 45 | gyro.setLpBandwidth(LPFBW_42HZ); |
ryought | 0:cda6d9f5a43c | 46 | |
Vigneshwar | 1:c85175226571 | 47 | while (1) |
Vigneshwar | 1:c85175226571 | 48 | { |
ryought | 0:cda6d9f5a43c | 49 | wait(0.1); |
ryought | 0:cda6d9f5a43c | 50 | |
ryought | 0:cda6d9f5a43c | 51 | accel.getOutput(accel_read); |
ryought | 0:cda6d9f5a43c | 52 | |
Vigneshwar | 1:c85175226571 | 53 | 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], |
Vigneshwar | 1:c85175226571 | 54 | gyro.getGyroX(), gyro.getGyroY(), gyro.getGyroZ(), (int16_t)gyro.getTemperature()); |
Vigneshwar | 1:c85175226571 | 55 | pc.printf(str); |
Vigneshwar | 1:c85175226571 | 56 | |
Vigneshwar | 1:c85175226571 | 57 | /* |
Vigneshwar | 1:c85175226571 | 58 | pc.printf("Gyro[%5i, %5i, %5i] Accel[%4i, %4i, %4i]\n\t", |
ryought | 0:cda6d9f5a43c | 59 | gyro.getGyroX(), gyro.getGyroY(), gyro.getGyroZ(), |
ryought | 0:cda6d9f5a43c | 60 | (int16_t)accel_read[0], (int16_t)accel_read[1], (int16_t)accel_read[2]); |
Vigneshwar | 1:c85175226571 | 61 | */ |
ryought | 0:cda6d9f5a43c | 62 | } |
ryought | 0:cda6d9f5a43c | 63 | |
ryought | 0:cda6d9f5a43c | 64 | } |