Daniel Blomdahl / Mbed 2 deprecated multiple_variable_temp

Dependencies:   MAX31855 SDFileSystem mbed

Committer:
DanielBlomdahl
Date:
Thu Mar 17 17:23:51 2016 +0000
Revision:
6:76e8649a643f
Parent:
5:a85aa204463b
Child:
7:9032b52be810
created readingData.h, giving the ability to reference measuring temp and voltage in main.cpp. Also added mountSDCard, openDataFile, etc functions into main. edited openDataFile on .h file for header row

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 6:76e8649a643f 9 SDFileSystem fs(PTD2, PTD3, PTD1, PTC4, "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 6:76e8649a643f 32 fprintf(fp, "Time (s) \t Temperature (t) \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");
JLarkin 5:a85aa204463b 40 return 0;
DanielBlomdahl 3:9339e7b93415 41 }
JLarkin 5:a85aa204463b 42
DanielBlomdahl 6:76e8649a643f 43 void writeData(float time, float temperature, float voltage) { // Need to modify for your particular experiment
DanielBlomdahl 6:76e8649a643f 44 fprintf(fp, "%.2f \t %.2f \t %.2f\n\r", time, temperature, voltage);
JLarkin 5:a85aa204463b 45 }