Coursework template

Dependencies:   BMP280 TextLCD BME280

Committer:
noutram
Date:
Sat Nov 24 09:35:51 2018 +0000
Revision:
0:57d39f966513
updated for 2018;

Who changed what in which revision?

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