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
00001 #include "mbed.h" 00002 #include "LIS331.h" 00003 #include "ITG3200.h" 00004 #include "SDHCFileSystem.h" 00005 00006 // Define binary expansions if needed 00007 //#define Ob(x) ((unsigned)Ob_(0 ## x ## uL)) 00008 //#define Ob_(x) (x & 1 | x >> 2 & 2 | x >> 4 & 4 | x >> 6 & 8 | \ 00009 // x >> 8 & 16 | x >> 10 & 32 | x >> 12 & 64 | x >> 14 & 128) 00010 00011 00012 00013 SDFileSystem sd(p5, p6, p7, p8, "sd"); 00014 //Serial pc(USBTX, USBRX); 00015 LIS331 accel(p9, p10); 00016 ITG3200 gyro(p9, p10); 00017 Timer t; 00018 DigitalOut success_led(LED4); 00019 DigitalOut progress_led(LED3); 00020 00021 int main() { 00022 success_led = 0; 00023 //pc.printf("Now starting LIS331/ITG-3200 acceptance test...\n\r"); 00024 00025 // Set Highest Gyro Bandwidth 00026 gyro.setLpBandwidth(LPFBW_256HZ); 00027 00028 // Set 8g range on accel 00029 accel.setFullScaleRange8g(); 00030 00031 FILE *fp = fopen("/sd/data.txt", "w"); 00032 if(fp == NULL) { 00033 error("Could not open file for write\n"); 00034 } 00035 success_led = 1; // file is open for writing! 00036 00037 00038 //pc.printf("Accel Address:%x\n\r",accel.getWhoAmI()); 00039 //pc.printf("Gyro Address:%x\n\r",gyro.getWhoAmI()); 00040 //pc.printf("Temp(C):%f\n\r",gyro.getTemperature()); 00041 00042 wait(0.9); 00043 00044 00045 00046 00047 t.start(); // Start our microsecond timer 00048 while (1) { 00049 progress_led = 1; 00050 //Arbitrary wait for printf clarity. 00051 //wait(0.1); 00052 fprintf(fp,"\n\r%f,", t.read()); // get current time in seconds 00053 fprintf(fp,"%f,%f,%f,", ((float)accel.getAccelX() / 16384.0), ((float)accel.getAccelY() / 16384.0), ((float)accel.getAccelZ() / 16384.0)); 00054 fprintf(fp,"%f,%f,%f", (float)gyro.getGyroX() / 14.375, (float)gyro.getGyroY() / 14.375, (float)gyro.getGyroZ() / 14.375); 00055 00056 // uncomment next line to enable output of mag values 00057 //fprintf(fp,"%f,%f,%f", (float)compass.getCompassX(), (float)compass.getCompassY(), (float)compass.getCompassZ()); 00058 00059 progress_led = 0; 00060 if (t.read() > 60) { // quit after 60 seconds, change to however long you want to record for 00061 break; // LED3 will remain off when done writing to card 00062 } 00063 } 00064 00065 00066 fclose(fp); // Need to add Physical_Switch --> DigitalIn --> Int --> fclose() 00067 }
Generated on Mon Jul 25 2022 03:24:27 by 1.7.2