A project similar to http://mbed.org/users/lhiggs/code/UM6_IMU_AHRS_2012/, where I'm trying to log data from a UM6 (CH Robotics orientation sensor) and a GPS transceiver to an sd card. I've adapted LHiggs code to include ModGPS. For sum reason a soon as I pick up a gps signal the UM6 data freezes i.e. the time and gps signals continue to print out but the UM6 signals fixes on a single value.

Dependencies:   MODGPS MODSERIAL SDFileSystem mbed

main.cpp

Committer:
njewin
Date:
2013-05-24
Revision:
4:8dcf0bdc25c8
Parent:
3:b3358ec2f57c
Child:
5:ac633cdbb75c

File content as of revision 4:8dcf0bdc25c8:

#include "mbed.h"
#include "SDFileSystem.h"    // SD file system header from handbook/cookbook offical mbed library
#include "MODSERIAL.h"   


//------------ system and interface setup ----------------------------//
LocalFileSystem local("local");  // sets up local file on mbed
MODSERIAL pc(USBTX, USBRX);  // sets up serial connection to pc terminal

//------------ Hardware setup ----------------------------------------//
DigitalOut led1(LED1);    // debug LED
DigitalIn enable(p10);    // enable signal for logging data to file
AnalogIn log1(p18);       // dummy log signal1
AnalogIn log2(p19);       // dummy log signal2
SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board


//------------ interrupt and variable setup --------------------------//
Ticker tick;
Timer t;
int counter=0;
int flag=0;

//------------ LogData interrupt function ----------------------------//
void LogData() {
            counter++;
            flag=1;
} 

//============= Main Program =========================================//
int main() {
    pc.baud(115200);  // baud rate to pc interface
    
    //---------- setup sd card -----------------------------// 
    mkdir("/sd/mydir", 0777);    
    FILE *fp = fopen("/sd/mydir/sdtest.csv", "w");
    if(fp == NULL) {
        error("Could not open file for write\n");
    }
//    FILE *fp = fopen("/local/ticker4.csv", "w");
    fprintf(fp,"time,counter,log1,log2 \r");
     
    t.start();
    tick.attach(&LogData, 0.01); // attaches LogData function to 'tick' ticker interrupt every 0.5s

    while(1) {
            if(flag==1) {  // prints counter value every interrupt raises flag
                led1=1;              
                fprintf(fp,"%.3f,%d,%f,%f \r",t.read(),counter,log1,log2);
                pc.printf("%.3f, %d, %f, %f \n",t.read(),counter,log1,log2);
                flag=0;
            }    // end if(flag=1) loop
         
            if(enable==0) {       
            break;             // breaks while loop in enable switched off
            }
    } // end while(1) loop
    fclose(fp);
    led1=0; // turns off LED when enable switch off
} // end main() loop