Implement a SD card into HW6
Dependencies: SDFileSystem mbed
Fork of shomberg_hw_6 by
Revision 20:fc1690076f87, committed 2018-11-01
- Comitter:
- rshomberg
- Date:
- Thu Nov 01 18:03:25 2018 +0000
- Parent:
- 19:1f4dd59bbe6b
- Commit message:
- working code. Needs to be modularized more
Changed in this revision
--- a/OCE360Input.cpp Wed Oct 31 23:32:01 2018 +0000 +++ b/OCE360Input.cpp Thu Nov 01 18:03:25 2018 +0000 @@ -18,11 +18,11 @@ #include "OCE360Input.h" // DEFINES -#define VREF 3.5 +#define VREF 3.3 #define TEMP_CALIBRATION_A 0.1 -#define TEMP_CALIBRATION_B 0 +#define TEMP_CALIBRATION_B -50 -DigitalIn myswitch(p7); +DigitalIn myswitch(p9); AnalogIn Ain(p20); int switchPosition;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDWrite.h Thu Nov 01 18:03:25 2018 +0000 @@ -0,0 +1,14 @@ +#ifndef SDWRITE_H +#define SDWRITE_H + +// Write time based data to an SDCard +// Record data to multiple files +//// Use a time-stamp naming convention + +#include "mbed.h" +#include "SDFileSystem.h" + +// + + +#endif \ No newline at end of file
--- a/main.cpp Wed Oct 31 23:32:01 2018 +0000 +++ b/main.cpp Thu Nov 01 18:03:25 2018 +0000 @@ -12,7 +12,7 @@ @revised 2018-10-31 @version 0.0 - Issues: + Issues: SD Card Writing functions need to be in a seperate file */ @@ -36,9 +36,10 @@ char file_name [20]; Timer t; FILE *fp; +unsigned char c; // a single byte buffer // Initialize SDFileSystem -SDFileSystem sd(p12,p13,p14,p15,"sd"); +SDFileSystem sd(p5,p6,p7,p8,"sd"); @@ -48,10 +49,12 @@ t.start(); // Mount the sd and - printf("Mounting SD Card\n\r"); + printf("\n\r\n\rMounting SD Card\n\r"); sd.mount(); while(1) { + while(!read_switch()) {} + while(read_switch()) { // skip everything if switch is off // Initialize a file @@ -70,8 +73,9 @@ // start a loop that logging // exiting this loop will initialize data save procedures + printf("Logging data....\n\r"); while(read_switch()) { // Main loop for logging - printf("Logging data....\n\r"); + // Get data for logging current_time = t.read(); current_voltage = read_sensor(); @@ -81,28 +85,35 @@ wait(1); } + + // This code runs when the switch is toggled off + // Close out file + printf("Logging complete! \n\r Saving file \n\r"); + fclose(fp); + + // Print to USB serial + printf("Uploading data to USB \n\r"); + // + fp = fopen(file_name,"r"); + if (fp!=NULL) { // Don't procede if there is an issue + while (!feof(fp)) { // while not end of file + c=fgetc(fp); // get a character/byte from the file + printf("%c",c); // and show it in hex format + } + } else { // runs if there was a issue opening the file + printf("Issue with opening file\n\r"); + fclose(fp); + } + + } else { // runs if there was a issue opening the file printf("Issue with opening file\n\r"); } - - // This code runs when the switch is toggled off - // Close out file - printf("Logging complete! \n\r Saving file \n\r"); - fclose(fp); + } - // Print to USB serial - printf("Uploading data to USB"); - // - fp = fopen(file_name,"r"); - if (fp!=NULL) { // Don't procede if there is an issue - printf("I don't know how to do this"); - } else { // runs if there was a issue opening the file - printf("Issue with opening file\n\r"); - fclose(fp); - file_counter++; - } - } // Re-enter main while loop //continuously check for switch to turn on again + file_counter++; + printf("waiting..."); } } \ No newline at end of file