Daniel Blomdahl / Mbed 2 deprecated multiple_variable_temp

Dependencies:   MAX31855 SDFileSystem mbed

Committer:
DanielBlomdahl
Date:
Wed Apr 13 20:14:37 2016 +0000
Revision:
9:c97cd10b11ac
Parent:
8:882ccc7bbc8a
Before Larkin Intervention on 30 minute timer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DanielBlomdahl 3:9339e7b93415 1 /* Program demonstrating data logging to SD card Analog data is read in (from a potentiometer). The time since program start and the voltage are written to a tab-delimited data file.
DanielBlomdahl 3:9339e7b93415 2 */
DanielBlomdahl 3:9339e7b93415 3 #include "mbed.h"
DanielBlomdahl 3:9339e7b93415 4 #include "SDFileSystem.h"
JLarkin 5:a85aa204463b 5 #include "SDSaveFunction.h"
DanielBlomdahl 3:9339e7b93415 6
DanielBlomdahl 3:9339e7b93415 7 //Create an SDFileSystem object
DanielBlomdahl 3:9339e7b93415 8
DanielBlomdahl 7:9032b52be810 9 SDFileSystem fs(PTE3, PTE1, PTE2, PTE4, "fs");
DanielBlomdahl 3:9339e7b93415 10 FILE *fp;
JLarkin 5:a85aa204463b 11
JLarkin 5:a85aa204463b 12 extern Serial pc;
JLarkin 5:a85aa204463b 13
JLarkin 5:a85aa204463b 14 int mountSDCard() {
JLarkin 5:a85aa204463b 15 //Mount the filesystem
JLarkin 5:a85aa204463b 16 int mountFailure = fs.mount();
JLarkin 5:a85aa204463b 17 if (mountFailure != 0) {
JLarkin 5:a85aa204463b 18 pc.printf("Failed to mount the SD card.\n\r");
JLarkin 5:a85aa204463b 19 return -1; // ends function with error status
JLarkin 5:a85aa204463b 20 }
JLarkin 5:a85aa204463b 21 else
JLarkin 5:a85aa204463b 22 return 0;
DanielBlomdahl 3:9339e7b93415 23 }
JLarkin 5:a85aa204463b 24
JLarkin 5:a85aa204463b 25 int openDataFile() {
JLarkin 5:a85aa204463b 26 fp = fopen("/fs/dataLog.txt", "w"); // Open file and prepare to write
JLarkin 5:a85aa204463b 27 if (fp == NULL) {
JLarkin 5:a85aa204463b 28 pc.printf("Failed to open file.\n\r");
JLarkin 5:a85aa204463b 29 return -1;
JLarkin 5:a85aa204463b 30 }
JLarkin 5:a85aa204463b 31 // Write a header row
DanielBlomdahl 9:c97cd10b11ac 32 fprintf(fp, "Time (s) \t Temp1 (C) \t Temp2 (C) \t Voltage (V)\n\r"); // Needs to be modified for your particular experiment
JLarkin 5:a85aa204463b 33 return 0;
DanielBlomdahl 3:9339e7b93415 34 }
JLarkin 5:a85aa204463b 35
DanielBlomdahl 6:76e8649a643f 36 int closeDataFile() { // Close the file and unmount the file system so the SD card is happy
JLarkin 5:a85aa204463b 37 fclose(fp);
JLarkin 5:a85aa204463b 38 fs.unmount();
JLarkin 5:a85aa204463b 39 pc.printf("It is now safe to remove the memory card.\r\n");
DanielBlomdahl 9:c97cd10b11ac 40
JLarkin 5:a85aa204463b 41 return 0;
DanielBlomdahl 3:9339e7b93415 42 }
JLarkin 5:a85aa204463b 43
DanielBlomdahl 9:c97cd10b11ac 44 void writeData(float time, float temp1, float temp2, float voltage) {
DanielBlomdahl 9:c97cd10b11ac 45 fprintf(fp, "%.2f \t %.2f \t %.2f \t %.2f \n\r", time , temp1 , temp2 , voltage);
JLarkin 5:a85aa204463b 46 }