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

Committer:
atommota
Date:
Thu Jan 06 22:14:14 2011 +0000
Revision:
0:17954bae143d
Child:
1:9bde03950fa7

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
atommota 0:17954bae143d 1 #include "mbed.h"
atommota 0:17954bae143d 2 #include "LIS331.h"
atommota 0:17954bae143d 3 #include "ITG3200.h"
atommota 0:17954bae143d 4 #include "SDFileSystem.h"
atommota 0:17954bae143d 5
atommota 0:17954bae143d 6 // Define binary expansions if needed
atommota 0:17954bae143d 7 //#define Ob(x) ((unsigned)Ob_(0 ## x ## uL))
atommota 0:17954bae143d 8 //#define Ob_(x) (x & 1 | x >> 2 & 2 | x >> 4 & 4 | x >> 6 & 8 | \
atommota 0:17954bae143d 9 // x >> 8 & 16 | x >> 10 & 32 | x >> 12 & 64 | x >> 14 & 128)
atommota 0:17954bae143d 10
atommota 0:17954bae143d 11
atommota 0:17954bae143d 12
atommota 0:17954bae143d 13 SDFileSystem sd(p5, p6, p7, p8, "sd");
atommota 0:17954bae143d 14 Serial pc(USBTX, USBRX);
atommota 0:17954bae143d 15 LIS331 accel(p9, p10);
atommota 0:17954bae143d 16 ITG3200 gyro(p9, p10);
atommota 0:17954bae143d 17 Timer t;
atommota 0:17954bae143d 18 DigitalOut success_led(LED4);
atommota 0:17954bae143d 19 DigitalOut progress_led(LED3);
atommota 0:17954bae143d 20
atommota 0:17954bae143d 21 int main() {
atommota 0:17954bae143d 22 success_led = 0;
atommota 0:17954bae143d 23 //pc.printf("Now starting LIS331/ITG-3200 acceptance test...\n\r");
atommota 0:17954bae143d 24
atommota 0:17954bae143d 25 // Set Highest Gyro Bandwidth
atommota 0:17954bae143d 26 gyro.setLpBandwidth(LPFBW_256HZ);
atommota 0:17954bae143d 27
atommota 0:17954bae143d 28 FILE *fp = fopen("/sd/data.txt", "w");
atommota 0:17954bae143d 29 if(fp == NULL) {
atommota 0:17954bae143d 30 error("Could not open file for write\n");
atommota 0:17954bae143d 31 }
atommota 0:17954bae143d 32 success_led = 1; // file is open for writing!
atommota 0:17954bae143d 33
atommota 0:17954bae143d 34
atommota 0:17954bae143d 35 //pc.printf("Accel Address:%x\n\r",accel.getWhoAmI());
atommota 0:17954bae143d 36 //pc.printf("Gyro Address:%x\n\r",gyro.getWhoAmI());
atommota 0:17954bae143d 37 //pc.printf("Temp(C):%f\n\r",gyro.getTemperature());
atommota 0:17954bae143d 38
atommota 0:17954bae143d 39 wait(0.9);
atommota 0:17954bae143d 40
atommota 0:17954bae143d 41
atommota 0:17954bae143d 42 t.start(); // Start our microsecond timer
atommota 0:17954bae143d 43 while (1) {
atommota 0:17954bae143d 44 progress_led = 1;
atommota 0:17954bae143d 45 //Arbitrary wait for printf clarity.
atommota 0:17954bae143d 46 //wait(0.1);
atommota 0:17954bae143d 47 fprintf(fp,"\n\r%f,", t.read()); // get current time in seconds
atommota 0:17954bae143d 48 fprintf(fp,"%f,%f,%f,", ((float)accel.getAccelX() / 16384.0), ((float)accel.getAccelY() / 16384.0), ((float)accel.getAccelZ() / 16384.0));
atommota 0:17954bae143d 49 fprintf(fp,"%f,%f,%f", (float)gyro.getGyroX() / 14.375, (float)gyro.getGyroY() / 14.375, (float)gyro.getGyroZ() / 14.375);
atommota 0:17954bae143d 50
atommota 0:17954bae143d 51 // uncomment next line to enable output of mag values
atommota 0:17954bae143d 52 //fprintf(fp,"%f,%f,%f", (float)compass.getCompassX(), (float)compass.getCompassY(), (float)compass.getCompassZ());
atommota 0:17954bae143d 53
atommota 0:17954bae143d 54 progress_led = 0;
atommota 0:17954bae143d 55 if (t.read() > 60) { // quit after 60 seconds, change to however long you want to record for
atommota 0:17954bae143d 56 break; // LED3 will remain off when done writing to card
atommota 0:17954bae143d 57 }
atommota 0:17954bae143d 58 }
atommota 0:17954bae143d 59 fclose(fp); // Need to add Physical_Switch --> DigitalIn --> Int --> fclose()
atommota 0:17954bae143d 60 }