Minor fixes
Dependencies: LSM9DS1_Library SDFileSystem mbed nrf51_rtc
Fork of LSM303DLHTest by
Diff: main.cpp
- Revision:
- 6:9db9f4bfaf98
- Parent:
- 5:b1a689c55f59
- Child:
- 7:cbfdcc57f110
diff -r b1a689c55f59 -r 9db9f4bfaf98 main.cpp --- a/main.cpp Thu Jul 14 20:24:09 2016 +0000 +++ b/main.cpp Fri Jul 15 22:39:42 2016 +0000 @@ -4,8 +4,7 @@ // for the Adafruit 9DOF Modulke and the Sparkfun microSD card shield #include "mbed.h" -#include "LSM303DLHC.h" -#include "L3GD20.h" +#include "LSM9DS1.h" #include "SDFileSystem.h" #include "nrf51_rtc.h" @@ -14,8 +13,7 @@ // Create objects Serial debug(USBTX,USBRX); // For Nordic -LSM303DLHC compass(p7, p30); -L3GD20 gyro(p7, p30); +LSM9DS1 lol(p30, p7, 0xD6, 0x3C); // Create the SD filesystem SDFileSystem sd(p25, p28, p29, p20, "sd"); // MOSI, MISO, SCLK, SSEL @@ -58,9 +56,6 @@ int main() { - int acc[3]; - int mag[3]; - float g[3]; led1= 1; char filename[256]; char secs_str[256]; @@ -69,23 +64,25 @@ time_t seconds; FILE *fp; - + // Attach functions to interrupts btn1.rise(&start_smpl); btn2.rise(&stop_smpl); flipper.attach(&flip, 1.0); // the address of the function to be attached (flip) and the interval (2 seconds) - + // Enable serial port debug.format(8,Serial::None,1); debug.baud(115200); debug.printf("LSM303DLH Test\x0d\x0a"); - - // Initialize compass - compass.init(); - compass.setOffset(0.00,0.00,0.00); // example calibration - compass.setScale(1.00,1.00,1.00); // example calibration -// // Initialize current time if needed + // Initialize 9DOF + lol.begin(); + if (!lol.begin()) { + debug.printf("Failed to communicate with LSM9DS1.\n"); + } + lol.calibrate(); + +// // Initialize current time if needed // printf("Enter current date and time:\n"); // printf("YYYY MM DD HH MM SS[enter]\n"); // scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday @@ -109,7 +106,7 @@ led1 = 0; debug.printf("Started sampling\n\r"); // Get the time and create a file with the number of seconds in hex appended - seconds = rtc.time(); + seconds = rtc.time(); sprintf(secs_str, "%s", ctime(&seconds)); printf("Started at: %s\n\r", secs_str ); sprintf(filename, "/sd/latch9DOF_%08x",seconds); @@ -124,14 +121,19 @@ } } else debug.printf("File %s created successfully\n\r", filename); - - // Sample until button 2 is pressed + + // Sample until button 2 is pressed while(!stop) { led1 = 0; - compass.read(acc,mag); - gyro.read(&g[0],&g[1],&g[2]); - debug.printf("%6d,\t%6d,\t%6d,\t%6d,\t%6d,\t%6d,\t%6.2f,\t%6.2f,\t%6.2f\n\r",acc[0],acc[1],acc[2],mag[0],mag[1],mag[2],g[0],g[1],g[2]); - fprintf(fp, "%6d,\t%6d,\t%6d,\t%6d,\t%6d,\t%6d,\t%6.2f,\t%6.2f,\t%6.2f\n\r",acc[0],acc[1],acc[2],mag[0],mag[1],mag[2],g[0],g[1],g[2]); + lol.readAccel(); + lol.readMag(); + lol.readGyro(); + debug.printf("%d, %d, %d, ", lol.ax, lol.ay, lol.az); + debug.printf("%d, %d, %d,", lol.mx, lol.my, lol.mz); + debug.printf("%d, %d, %d\n\r", lol.gx, lol.gy, lol.gz); + fprintf(fp, "%d, %d, %d, ", lol.ax, lol.ay, lol.az); + fprintf(fp, "%d, %d, %d,", lol.mx, lol.my, lol.mz); + fprintf(fp, "%d, %d, %d\n\r", lol.gx, lol.gy, lol.gz); wait(0.1); } // Stop Sampling and close file @@ -139,5 +141,5 @@ debug.printf("Stopped sampling\n\r"); debug.printf("Results stored in %s\n\r", filename); fclose(fp); - } + } }