Demo of the sample LCD class, BMP280 Sensor and network with power on self test. Requires a network connectionb

Dependencies:   BMP280 TextLCD BME280

Committer:
noutram
Date:
Wed Dec 06 15:59:28 2017 +0000
Revision:
1:e1cf7663f5ff
Parent:
0:36e89e3ed7c4
Child:
2:40403785b690
Now writes to the SD card

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