mbed and recording data

12 Jul 2010

Hi,

It is not clear to me how one would store data from an input (I'm looking to observe voltage) on the mbed. I have not much experience in C, is there a command that will tell the controller to log data after a trigger (say when the voltage jumps above a limit?)

 

thanks guys

12 Jul 2010

James,

There is no command for this. You will have to write a small routine that continously polls the analog inputs of interest, and then trigger your own code to begin storing the analog data. You can either store the data on-chip using the LocalFileSystem, or write it to a removable SD card. There are plently of good examples in the CookBook section.

Doug

14 Jul 2010

thanks for the reply

 

as a place to start I have hacked together a few provided sample programs

basically I have tried to get the mbed to write and save a small message in local memory when a condition is satisfied (the voltage on pin 20 is above 0.6). I don't fully understand the way the localfilesystem works, and I guess neither does my computer because I get an infinite string of messages informing me that the mbed device has been disconnected. I assume in trying to satisfy the conditions of the program the device disconnects itself.

I guess I'm asking, what mistakes have I made? Also, is there a hard restart for the mbed to pruge a looping program from memory?

#include "mbed.h"

LocalFileSystem local("local");
AnalogIn myinput(p20);
DigitalOut myled(p5);

int main() {
    while(1) {
        if(myinput >0.6) {
            FILE *fp = fopen("/local/out.txt","w");
            fprintf(fp, "hello world");
            fclose(fp);
            remove("/local/out.txt");
            
            DIR *d = opendir("/local");
            struct dirent *p;
            while((p = readdir(d)) != NULL){
                printf("%s\n", p->d_name);
            }
            closedir(d);
            myled=1;
        } else {
            myled = 0;
        }
    }    
} 
 

14 Jul 2010

James:

The most obvious is that you need some sort of delay between analog sample reads. I took the pieces of your code and fit them together into an example program. You can import it into your compiler from:

http://mbed.org/users/YouTahDoug/programs/AnalogReadStore

By the way, a good way to learn this system is to compile and run the many code examples and try to understand how each works. Try making some simple changes to each and observe what happens.

Good luck on your project.

Doug

14 Jul 2010

great, thanks for the help!