Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX31855 SDFileSystem mbed
SDSaveFunction.cpp@7:9032b52be810, 2016-03-31 (annotated)
- Committer:
- DanielBlomdahl
- Date:
- Thu Mar 31 17:30:45 2016 +0000
- Revision:
- 7:9032b52be810
- Parent:
- 6:76e8649a643f
- Child:
- 8:882ccc7bbc8a
Success! First successful save of time, voltage, and temperature to the SD card and print on Terminal;
Who changed what in which revision?
| User | Revision | Line number | New 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 | 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 | } |
