data logging
Boblow45
Posts: 7
I am still new to the prop. I am trying to do some data logging with the prop and do some post processing in MatLab. The current code I have saves to binary. I want to know is there a way to save to an SD Card in ASCII. I have code that reads .CSV files in MatLab from old Arduino code I had for data logging. Any help would be great. Below is my current code
#include "simpletools.h" // Include simpletools header int MISO = 12; int SCLK = 13; int MOSI = 14; int SS = 15; // SD card pins on Propeller BOE // DO = MISO // DI = MOSI // CLK = SCLK // CS = SS // red wire is DO : pin 12 (MISO) // black wire is SCLK : pin 13 (SCLK) // yellow wire is DI : pin 14 (MOSI) // green wire is CS : pin 15 (SS) int main(void) // main function { char data [8] = {'2', '3' , '5', '7', '11', '13'}; int mout = sd_mount (MISO, SCLK, MOSI, SS); print("%d \n", mout); FILE* fp = fopen("test.txt", "w"); // Open a file for writing //fwrite("Hello World....", 1, 15, fp); // Add contents to the file for (int i=0;i<3;i++) { fwrite(&data, 4, 8, fp); // Add contents to the file } fclose(fp); // Close the file char s[8]; // Buffer for characters fp = fopen("test.txt", "r"); // Reopen file for reading fread(&s, 4, 8, fp); // Read 15 characters fclose(fp); // Close the file print("First 15 chars in test.txt:\n"); // Display heading print("%s", s); // Display characters print("\n"); pause(500); while (1) { } }
Comments
fwrite is going to be smaller than fprintf - but as you noticed, it needs a little bit of help to put the data in a more meaningful format. My suggestion: if you're trying to get every last byte of RAM back, then write your own function to convert integers to strings then log the data with repeated calls to fwrite. If the only format character you ever use is %d, then fprintf is going to pull in a lot more than you need.
PropWare's Printer class could help you with this actually. Instructions for using PropWare's Printer class follow:
Create a file named sdprinter.h with the following contents:
To use it, you'll also need to copy the file "printer.h" from PropWare into your project (assuming you're building using SimpleIDE)
You'll need to rename your main class from *.c to *.cpp, since it now uses C++ classes. And here's the Printer class in action.
You can save more space by eliminating the use of Parallax's print and switching it out for another Printer/PrintCapable object like so:
Notice how writing to the SD card and writing to the serial terminal use the same PropWare class: the PropWare:: Printer. This means the formatting functions (converting ints to strings, converting floats to strings, etc) are shared. This saves a lot of code space.
You could bring it all together with a main file like so: