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:
Sat Nov 24 08:44:15 2018 +0000
Revision:
6:9a95a39d1cce
simplify;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 6:9a95a39d1cce 1 #include "mbed.h"
noutram 6:9a95a39d1cce 2 #include "sample_hardware.hpp"
noutram 6:9a95a39d1cce 3 #include "Networkbits.hpp"
noutram 6:9a95a39d1cce 4
noutram 6:9a95a39d1cce 5 #define RED_DONE 1
noutram 6:9a95a39d1cce 6 #define YELLOW_DONE 2
noutram 6:9a95a39d1cce 7
noutram 6:9a95a39d1cce 8 //Digital outputs
noutram 6:9a95a39d1cce 9 DigitalOut onBoardLED(LED1);
noutram 6:9a95a39d1cce 10 DigitalOut redLED(PE_15);
noutram 6:9a95a39d1cce 11 DigitalOut yellowLED(PB_10);
noutram 6:9a95a39d1cce 12 DigitalOut greenLED(PB_11);
noutram 6:9a95a39d1cce 13
noutram 6:9a95a39d1cce 14 //Inputs
noutram 6:9a95a39d1cce 15 DigitalIn onBoardSwitch(USER_BUTTON);
noutram 6:9a95a39d1cce 16 DigitalIn SW1(PE_12);
noutram 6:9a95a39d1cce 17 DigitalIn SW2(PE_14);
noutram 6:9a95a39d1cce 18 //Serial pc(USBTX, USBRX);
noutram 6:9a95a39d1cce 19 AnalogIn adcIn(PA_0);
noutram 6:9a95a39d1cce 20
noutram 6:9a95a39d1cce 21 //Environmental Sensor driver
noutram 6:9a95a39d1cce 22 #ifdef BME
noutram 6:9a95a39d1cce 23 BME280 sensor(D14, D15);
noutram 6:9a95a39d1cce 24 #else
noutram 6:9a95a39d1cce 25 BMP280 sensor(D14, D15);
noutram 6:9a95a39d1cce 26 #endif
noutram 6:9a95a39d1cce 27
noutram 6:9a95a39d1cce 28 //LCD Driver (provided via mbed repository)
noutram 6:9a95a39d1cce 29 //RS D9
noutram 6:9a95a39d1cce 30 //E D8
noutram 6:9a95a39d1cce 31 //D7,6,4,2 are the 4 bit for d4-7
noutram 6:9a95a39d1cce 32 TextLCD lcd(D9, D8, D7, D6, D4, D2); // rs, e, d4-d7
noutram 6:9a95a39d1cce 33
noutram 6:9a95a39d1cce 34 //SD Card
noutram 6:9a95a39d1cce 35 SDBlockDevice sd(PB_5, D12, D13, D10); // mosi, miso, sclk, cs
noutram 6:9a95a39d1cce 36
noutram 6:9a95a39d1cce 37 //POWER ON SELF TEST
noutram 6:9a95a39d1cce 38 void post()
noutram 6:9a95a39d1cce 39 {
noutram 6:9a95a39d1cce 40 //POWER ON TEST (POT)
noutram 6:9a95a39d1cce 41 puts("**********STARTING POWER ON SELF TEST (POST)**********");
noutram 6:9a95a39d1cce 42
noutram 6:9a95a39d1cce 43 //Test LEDs
noutram 6:9a95a39d1cce 44 puts("ALL LEDs should be blinking");
noutram 6:9a95a39d1cce 45 for (unsigned int n=0; n<10; n++) {
noutram 6:9a95a39d1cce 46 redLED = 1;
noutram 6:9a95a39d1cce 47 yellowLED = 1;
noutram 6:9a95a39d1cce 48 greenLED = 1;
noutram 6:9a95a39d1cce 49 wait(0.05);
noutram 6:9a95a39d1cce 50 redLED = 0;
noutram 6:9a95a39d1cce 51 yellowLED = 0;
noutram 6:9a95a39d1cce 52 greenLED = 0;
noutram 6:9a95a39d1cce 53 wait(0.05);
noutram 6:9a95a39d1cce 54 }
noutram 6:9a95a39d1cce 55
noutram 6:9a95a39d1cce 56 //Output the switch states (hold them down to test)
noutram 6:9a95a39d1cce 57 printf("SW1: %d\tSW2: %d\n\r", SW1.read(), SW2.read());
noutram 6:9a95a39d1cce 58 printf("USER: %d\n\r", onBoardSwitch.read());
noutram 6:9a95a39d1cce 59
noutram 6:9a95a39d1cce 60 //Output the ADC
noutram 6:9a95a39d1cce 61 printf("ADC: %f\n\r", adcIn.read());
noutram 6:9a95a39d1cce 62
noutram 6:9a95a39d1cce 63 //Read Sensors (I2C)
noutram 6:9a95a39d1cce 64 float temp = sensor.getTemperature();
noutram 6:9a95a39d1cce 65 float pressure = sensor.getPressure();
noutram 6:9a95a39d1cce 66 #ifdef BME
noutram 6:9a95a39d1cce 67 float humidity = sensor.getHumidity();
noutram 6:9a95a39d1cce 68 #endif
noutram 6:9a95a39d1cce 69
noutram 6:9a95a39d1cce 70 //Display in PuTTY
noutram 6:9a95a39d1cce 71 printf("Temperature: %5.1f\n", temp);
noutram 6:9a95a39d1cce 72 printf("Pressure: %5.1f\n", pressure);
noutram 6:9a95a39d1cce 73 #ifdef BME
noutram 6:9a95a39d1cce 74 printf("Pressure: %5.1f\n", humidity);
noutram 6:9a95a39d1cce 75 #endif
noutram 6:9a95a39d1cce 76
noutram 6:9a95a39d1cce 77 //Display on LCD
noutram 6:9a95a39d1cce 78 redLED = 1;
noutram 6:9a95a39d1cce 79 lcd.cls();
noutram 6:9a95a39d1cce 80 lcd.printf("LCD TEST...");
noutram 6:9a95a39d1cce 81 wait(0.5);
noutram 6:9a95a39d1cce 82 redLED = 0;
noutram 6:9a95a39d1cce 83
noutram 6:9a95a39d1cce 84 //Network test (if BOTH switches are held down)
noutram 6:9a95a39d1cce 85 networktest();
noutram 6:9a95a39d1cce 86
noutram 6:9a95a39d1cce 87 puts("**********POST END**********");
noutram 6:9a95a39d1cce 88
noutram 6:9a95a39d1cce 89 }
noutram 6:9a95a39d1cce 90
noutram 6:9a95a39d1cce 91 void errorCode(ELEC350_ERROR_CODE err)
noutram 6:9a95a39d1cce 92 {
noutram 6:9a95a39d1cce 93 switch (err) {
noutram 6:9a95a39d1cce 94 case OK:
noutram 6:9a95a39d1cce 95 greenLED = 1;
noutram 6:9a95a39d1cce 96 wait(1.0);
noutram 6:9a95a39d1cce 97 greenLED = 0;
noutram 6:9a95a39d1cce 98 return;
noutram 6:9a95a39d1cce 99 case FATAL:
noutram 6:9a95a39d1cce 100 while(1) {
noutram 6:9a95a39d1cce 101 redLED = 1;
noutram 6:9a95a39d1cce 102 wait(0.1);
noutram 6:9a95a39d1cce 103 redLED = 0;
noutram 6:9a95a39d1cce 104 wait(0.1);
noutram 6:9a95a39d1cce 105 }
noutram 6:9a95a39d1cce 106 };
noutram 6:9a95a39d1cce 107 }