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: BMP280 TextLCD BME280
Revision 1:e1cf7663f5ff, committed 2017-12-06
- Comitter:
- noutram
- Date:
- Wed Dec 06 15:59:28 2017 +0000
- Parent:
- 0:36e89e3ed7c4
- Child:
- 2:40403785b690
- Commit message:
- Now writes to the SD card
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ELEC350-Practicals-FZ429.lib Wed Dec 06 15:59:28 2017 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/University-of-Plymouth-Stage-2-and-3/code/ELEC350-Practicals-FZ429/#d0e445a97c60
--- a/main.cpp Wed Sep 13 11:03:52 2017 +0000
+++ b/main.cpp Wed Dec 06 15:59:28 2017 +0000
@@ -1,5 +1,8 @@
#include "mbed.h"
#include "TextLCD.h"
+#include "SDBlockDevice.h"
+#include "FATFileSystem.h"
+#include "sample_hardware.hpp"
//#define BME
#ifdef BME
@@ -13,23 +16,62 @@
//E D8
//D7,6,4,2 are the 4 bit for d4-7
TextLCD lcd(D9, D8, D7, D6, D4, D2); // rs, e, d4-d7
+SDBlockDevice sd(PB_5, D12, D13, D10); // mosi, miso, sclk, cs
+
+int main() {
+ //Greeting
+ lcd.printf("Testing\n\n");
+
+ //Power on self test
+ post();
+
+ //Initialise the SD card
+ if ( sd.init() != 0) {
+ printf("Init failed \n");
+ errorCode(FATAL);
+ }
+
+ //Create a filing system for SD Card
+ FATFileSystem fs("sd", &sd);
-//Sensor driver
-#ifdef BME
-BME280 sensor(D14, D15);
-#else
-BMP280 sensor(D14, D15);
-#endif
-
-int main() {
-
- while(1) {
+ //Open to WRITE
+ FILE* fp = fopen("/sd/test.csv","a");
+ if (fp == NULL) {
+ error("Could not open file for write\n");
+ errorCode(FATAL);
+ }
+
+ //Press either switch to unmount
+ while ((SW1 == 0) && (SW2 == 0)) {
double temp = sensor.getTemperature();
double pressure = sensor.getPressure();
lcd.printf("Temp Pressure\n");
lcd.printf("%6.1f ",temp);
lcd.printf("%.2f\n",pressure);
- wait(2.0);
+
+ //Write to SD
+ fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure);
+
+ wait(1.0);
+ }
+
+ //Close File
+ fclose(fp);
+
+ //Close down
+ sd.deinit();
+ printf("Unmounted...\n");
+ lcd.cls();
+ lcd.printf("Unmounted...\n\n");
+
+ //Flash to indicate goodness
+ while(true) {
+ greenLED = 1;
+ wait(0.5);
+ greenLED = 0;
+ wait(0.1);
}
}
+
+
--- a/mbed-os.lib Wed Sep 13 11:03:52 2017 +0000 +++ b/mbed-os.lib Wed Dec 06 15:59:28 2017 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#98ba8acb83cfc65f30a8a0771a27c71443ab093a +https://github.com/ARMmbed/mbed-os/#5f6572179d66ce4c09d6517b659ac51133cc980d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sd-driver.lib Wed Dec 06 15:59:28 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/sd-driver/#ae7e7440054c9447f8255bdccbcc523b3f6dffe4