Data logger for my IMU Board. Writes a time stamp in seconds, 3 accel values in G\\\'s, and 3 gyro values in radians/sec to the SD card. Uncomment one one to add Magnetometer values. Records for 60 seconds. Change on line 55 if necessary. Updates LEDs to display status such as opening and closing file, and errors.Also supports SD cards up to 32GB (SDHC)
Dependencies: mbed ITG3200_lib
Revision 1:9bde03950fa7, committed 2011-01-07
- Comitter:
- atommota
- Date:
- Fri Jan 07 16:59:09 2011 +0000
- Parent:
- 0:17954bae143d
- Commit message:
- Fixed SDHC support. Set accel range to +/-8g\s
Changed in this revision
diff -r 17954bae143d -r 9bde03950fa7 LIS331_lib.lib --- a/LIS331_lib.lib Thu Jan 06 22:14:14 2011 +0000 +++ b/LIS331_lib.lib Fri Jan 07 16:59:09 2011 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/atommota/code/LIS331_lib/#147d95b7a525 +http://mbed.org/users/atommota/code/LIS331_lib/#3443fb9646bd
diff -r 17954bae143d -r 9bde03950fa7 SDHCFileSystem.lib --- a/SDHCFileSystem.lib Thu Jan 06 22:14:14 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/xxll/code/SDHCFileSystem/#90601632692f
diff -r 17954bae143d -r 9bde03950fa7 SDHC_Lib.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDHC_Lib.lib Fri Jan 07 16:59:09 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/atommota/code/SDHC_Lib/#5e21e22ef223
diff -r 17954bae143d -r 9bde03950fa7 main.cpp --- a/main.cpp Thu Jan 06 22:14:14 2011 +0000 +++ b/main.cpp Fri Jan 07 16:59:09 2011 +0000 @@ -1,60 +1,67 @@ -#include "mbed.h" -#include "LIS331.h" -#include "ITG3200.h" -#include "SDFileSystem.h" - -// Define binary expansions if needed -//#define Ob(x) ((unsigned)Ob_(0 ## x ## uL)) -//#define Ob_(x) (x & 1 | x >> 2 & 2 | x >> 4 & 4 | x >> 6 & 8 | \ -// x >> 8 & 16 | x >> 10 & 32 | x >> 12 & 64 | x >> 14 & 128) - - - -SDFileSystem sd(p5, p6, p7, p8, "sd"); -Serial pc(USBTX, USBRX); -LIS331 accel(p9, p10); -ITG3200 gyro(p9, p10); -Timer t; -DigitalOut success_led(LED4); -DigitalOut progress_led(LED3); - -int main() { - success_led = 0; - //pc.printf("Now starting LIS331/ITG-3200 acceptance test...\n\r"); - - // Set Highest Gyro Bandwidth - gyro.setLpBandwidth(LPFBW_256HZ); - - FILE *fp = fopen("/sd/data.txt", "w"); - if(fp == NULL) { - error("Could not open file for write\n"); - } - success_led = 1; // file is open for writing! - - - //pc.printf("Accel Address:%x\n\r",accel.getWhoAmI()); - //pc.printf("Gyro Address:%x\n\r",gyro.getWhoAmI()); - //pc.printf("Temp(C):%f\n\r",gyro.getTemperature()); - - wait(0.9); - - - t.start(); // Start our microsecond timer - while (1) { - progress_led = 1; - //Arbitrary wait for printf clarity. - //wait(0.1); - fprintf(fp,"\n\r%f,", t.read()); // get current time in seconds - fprintf(fp,"%f,%f,%f,", ((float)accel.getAccelX() / 16384.0), ((float)accel.getAccelY() / 16384.0), ((float)accel.getAccelZ() / 16384.0)); - fprintf(fp,"%f,%f,%f", (float)gyro.getGyroX() / 14.375, (float)gyro.getGyroY() / 14.375, (float)gyro.getGyroZ() / 14.375); - - // uncomment next line to enable output of mag values - //fprintf(fp,"%f,%f,%f", (float)compass.getCompassX(), (float)compass.getCompassY(), (float)compass.getCompassZ()); - - progress_led = 0; - if (t.read() > 60) { // quit after 60 seconds, change to however long you want to record for - break; // LED3 will remain off when done writing to card - } - } -fclose(fp); // Need to add Physical_Switch --> DigitalIn --> Int --> fclose() +#include "mbed.h" +#include "LIS331.h" +#include "ITG3200.h" +#include "SDHCFileSystem.h" + +// Define binary expansions if needed +//#define Ob(x) ((unsigned)Ob_(0 ## x ## uL)) +//#define Ob_(x) (x & 1 | x >> 2 & 2 | x >> 4 & 4 | x >> 6 & 8 | \ +// x >> 8 & 16 | x >> 10 & 32 | x >> 12 & 64 | x >> 14 & 128) + + + +SDFileSystem sd(p5, p6, p7, p8, "sd"); +//Serial pc(USBTX, USBRX); +LIS331 accel(p9, p10); +ITG3200 gyro(p9, p10); +Timer t; +DigitalOut success_led(LED4); +DigitalOut progress_led(LED3); + +int main() { + success_led = 0; + //pc.printf("Now starting LIS331/ITG-3200 acceptance test...\n\r"); + + // Set Highest Gyro Bandwidth + gyro.setLpBandwidth(LPFBW_256HZ); + + // Set 8g range on accel + accel.setFullScaleRange8g(); + + FILE *fp = fopen("/sd/data.txt", "w"); + if(fp == NULL) { + error("Could not open file for write\n"); + } + success_led = 1; // file is open for writing! + + + //pc.printf("Accel Address:%x\n\r",accel.getWhoAmI()); + //pc.printf("Gyro Address:%x\n\r",gyro.getWhoAmI()); + //pc.printf("Temp(C):%f\n\r",gyro.getTemperature()); + + wait(0.9); + + + + + t.start(); // Start our microsecond timer + while (1) { + progress_led = 1; + //Arbitrary wait for printf clarity. + //wait(0.1); + fprintf(fp,"\n\r%f,", t.read()); // get current time in seconds + fprintf(fp,"%f,%f,%f,", ((float)accel.getAccelX() / 16384.0), ((float)accel.getAccelY() / 16384.0), ((float)accel.getAccelZ() / 16384.0)); + fprintf(fp,"%f,%f,%f", (float)gyro.getGyroX() / 14.375, (float)gyro.getGyroY() / 14.375, (float)gyro.getGyroZ() / 14.375); + + // uncomment next line to enable output of mag values + //fprintf(fp,"%f,%f,%f", (float)compass.getCompassX(), (float)compass.getCompassY(), (float)compass.getCompassZ()); + + progress_led = 0; + if (t.read() > 60) { // quit after 60 seconds, change to however long you want to record for + break; // LED3 will remain off when done writing to card + } + } + + +fclose(fp); // Need to add Physical_Switch --> DigitalIn --> Int --> fclose() } \ No newline at end of file