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:
Fri Jan 07 16:59:09 2011 +0000
Revision:
1:9bde03950fa7
Parent:
0:17954bae143d
Fixed SDHC support. Set accel range to +/-8g\s

Who changed what in which revision?

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