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
main.cpp
- Committer:
- atommota
- Date:
- 2011-01-07
- Revision:
- 1:9bde03950fa7
- Parent:
- 0:17954bae143d
File content as of revision 1:9bde03950fa7:
#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() }