Demo of the sample LCD class and BMP280 Sensor

Dependencies:   BME280 BMP280 TextLCD ELEC350-Practicals-FZ429

Fork of ELEC350-Coursework-Template by Plymouth University UK SoCEM Staff

Committer:
noutram
Date:
Wed Dec 06 17:00:37 2017 +0000
Revision:
2:40403785b690
Parent:
1:e1cf7663f5ff
updated for 5.6.6

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 0:36e89e3ed7c4 1 #include "mbed.h"
noutram 0:36e89e3ed7c4 2 #include "TextLCD.h"
noutram 1:e1cf7663f5ff 3 #include "SDBlockDevice.h"
noutram 1:e1cf7663f5ff 4 #include "FATFileSystem.h"
noutram 1:e1cf7663f5ff 5 #include "sample_hardware.hpp"
noutram 0:36e89e3ed7c4 6
noutram 2:40403785b690 7
noutram 2:40403785b690 8
noutram 0:36e89e3ed7c4 9 //#define BME
noutram 0:36e89e3ed7c4 10 #ifdef BME
noutram 0:36e89e3ed7c4 11 #include "BME280.h"
noutram 0:36e89e3ed7c4 12 #else
noutram 0:36e89e3ed7c4 13 #include "BMP280.h"
noutram 0:36e89e3ed7c4 14 #endif
noutram 0:36e89e3ed7c4 15
noutram 0:36e89e3ed7c4 16 //LCD Driver
noutram 0:36e89e3ed7c4 17 //RS D9
noutram 0:36e89e3ed7c4 18 //E D8
noutram 0:36e89e3ed7c4 19 //D7,6,4,2 are the 4 bit for d4-7
noutram 0:36e89e3ed7c4 20 TextLCD lcd(D9, D8, D7, D6, D4, D2); // rs, e, d4-d7
noutram 1:e1cf7663f5ff 21 SDBlockDevice sd(PB_5, D12, D13, D10); // mosi, miso, sclk, cs
noutram 1:e1cf7663f5ff 22
noutram 1:e1cf7663f5ff 23 int main() {
noutram 1:e1cf7663f5ff 24 //Greeting
noutram 1:e1cf7663f5ff 25 lcd.printf("Testing\n\n");
noutram 1:e1cf7663f5ff 26
noutram 1:e1cf7663f5ff 27 //Power on self test
noutram 1:e1cf7663f5ff 28 post();
noutram 1:e1cf7663f5ff 29
noutram 1:e1cf7663f5ff 30 //Initialise the SD card
noutram 1:e1cf7663f5ff 31 if ( sd.init() != 0) {
noutram 1:e1cf7663f5ff 32 printf("Init failed \n");
noutram 1:e1cf7663f5ff 33 errorCode(FATAL);
noutram 1:e1cf7663f5ff 34 }
noutram 1:e1cf7663f5ff 35
noutram 1:e1cf7663f5ff 36 //Create a filing system for SD Card
noutram 1:e1cf7663f5ff 37 FATFileSystem fs("sd", &sd);
noutram 0:36e89e3ed7c4 38
noutram 1:e1cf7663f5ff 39 //Open to WRITE
noutram 1:e1cf7663f5ff 40 FILE* fp = fopen("/sd/test.csv","a");
noutram 1:e1cf7663f5ff 41 if (fp == NULL) {
noutram 1:e1cf7663f5ff 42 error("Could not open file for write\n");
noutram 1:e1cf7663f5ff 43 errorCode(FATAL);
noutram 1:e1cf7663f5ff 44 }
noutram 1:e1cf7663f5ff 45
noutram 1:e1cf7663f5ff 46 //Press either switch to unmount
noutram 1:e1cf7663f5ff 47 while ((SW1 == 0) && (SW2 == 0)) {
noutram 0:36e89e3ed7c4 48 double temp = sensor.getTemperature();
noutram 0:36e89e3ed7c4 49 double pressure = sensor.getPressure();
noutram 0:36e89e3ed7c4 50 lcd.printf("Temp Pressure\n");
noutram 0:36e89e3ed7c4 51 lcd.printf("%6.1f ",temp);
noutram 0:36e89e3ed7c4 52 lcd.printf("%.2f\n",pressure);
noutram 1:e1cf7663f5ff 53
noutram 1:e1cf7663f5ff 54 //Write to SD
noutram 1:e1cf7663f5ff 55 fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure);
noutram 1:e1cf7663f5ff 56
noutram 1:e1cf7663f5ff 57 wait(1.0);
noutram 1:e1cf7663f5ff 58 }
noutram 1:e1cf7663f5ff 59
noutram 1:e1cf7663f5ff 60 //Close File
noutram 1:e1cf7663f5ff 61 fclose(fp);
noutram 1:e1cf7663f5ff 62
noutram 1:e1cf7663f5ff 63 //Close down
noutram 1:e1cf7663f5ff 64 sd.deinit();
noutram 1:e1cf7663f5ff 65 printf("Unmounted...\n");
noutram 1:e1cf7663f5ff 66 lcd.cls();
noutram 1:e1cf7663f5ff 67 lcd.printf("Unmounted...\n\n");
noutram 1:e1cf7663f5ff 68
noutram 1:e1cf7663f5ff 69 //Flash to indicate goodness
noutram 1:e1cf7663f5ff 70 while(true) {
noutram 1:e1cf7663f5ff 71 greenLED = 1;
noutram 1:e1cf7663f5ff 72 wait(0.5);
noutram 1:e1cf7663f5ff 73 greenLED = 0;
noutram 1:e1cf7663f5ff 74 wait(0.1);
noutram 0:36e89e3ed7c4 75 }
noutram 0:36e89e3ed7c4 76 }
noutram 0:36e89e3ed7c4 77
noutram 1:e1cf7663f5ff 78
noutram 1:e1cf7663f5ff 79