sensor

Committer:
noutram
Date:
Thu Nov 23 10:54:10 2017 +0000
Revision:
5:58ba1a6dbf60
Parent:
4:d884f14069c6
Child:
6:d95616e645bb
Now includes support for the pressure sensor. Depends on the BMP280 driver (see Task690)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 0:6f9f2e93a0be 1 #include "mbed.h"
noutram 0:6f9f2e93a0be 2 #include "sample_hardware.hpp"
noutram 0:6f9f2e93a0be 3
noutram 0:6f9f2e93a0be 4 #define RED_DONE 1
noutram 0:6f9f2e93a0be 5 #define YELLOW_DONE 2
noutram 0:6f9f2e93a0be 6
noutram 0:6f9f2e93a0be 7 //Digital outputs
noutram 0:6f9f2e93a0be 8 DigitalOut onBoardLED(LED1);
noutram 0:6f9f2e93a0be 9 DigitalOut redLED(PE_15);
noutram 0:6f9f2e93a0be 10 DigitalOut yellowLED(PB_10);
noutram 0:6f9f2e93a0be 11 DigitalOut greenLED(PB_11);
noutram 0:6f9f2e93a0be 12
noutram 0:6f9f2e93a0be 13 //Inputs
noutram 0:6f9f2e93a0be 14 DigitalIn onBoardSwitch(USER_BUTTON);
noutram 0:6f9f2e93a0be 15 DigitalIn SW1(PE_12);
noutram 0:6f9f2e93a0be 16 DigitalIn SW2(PE_14);
noutram 0:6f9f2e93a0be 17 //Serial pc(USBTX, USBRX);
noutram 2:24eb98cf2376 18 AnalogIn adcIn(PA_0);
noutram 0:6f9f2e93a0be 19
noutram 5:58ba1a6dbf60 20 //Environmental Sensor driver
noutram 5:58ba1a6dbf60 21 #ifdef BME
noutram 5:58ba1a6dbf60 22 BME280 sensor(D14, D15);
noutram 5:58ba1a6dbf60 23 #else
noutram 5:58ba1a6dbf60 24 BMP280 sensor(D14, D15);
noutram 5:58ba1a6dbf60 25 #endif
noutram 3:768d30157488 26
noutram 0:6f9f2e93a0be 27 //POWER ON SELF TEST
noutram 0:6f9f2e93a0be 28 void post()
noutram 0:6f9f2e93a0be 29 {
noutram 0:6f9f2e93a0be 30 //POWER ON TEST (POT)
noutram 5:58ba1a6dbf60 31 puts("**********STARTING POWER ON SELF TEST (POST)**********");
noutram 5:58ba1a6dbf60 32
noutram 5:58ba1a6dbf60 33 //Test LEDs
noutram 3:768d30157488 34 puts("ALL LEDs should be blinking");
noutram 0:6f9f2e93a0be 35 for (unsigned int n=0; n<10; n++) {
noutram 0:6f9f2e93a0be 36 redLED = 1;
noutram 0:6f9f2e93a0be 37 yellowLED = 1;
noutram 0:6f9f2e93a0be 38 greenLED = 1;
noutram 0:6f9f2e93a0be 39 wait(0.05);
noutram 0:6f9f2e93a0be 40 redLED = 0;
noutram 0:6f9f2e93a0be 41 yellowLED = 0;
noutram 0:6f9f2e93a0be 42 greenLED = 0;
noutram 0:6f9f2e93a0be 43 wait(0.05);
noutram 3:768d30157488 44 }
noutram 3:768d30157488 45
noutram 3:768d30157488 46 //Output the switch states (hold them down to test)
noutram 3:768d30157488 47 printf("SW1: %d\tSW2: %d\n\r", SW1.read(), SW2.read());
noutram 3:768d30157488 48
noutram 3:768d30157488 49 //Output the ADC
noutram 3:768d30157488 50 printf("ADC: %f\n\r", adcIn.read());
noutram 5:58ba1a6dbf60 51
noutram 5:58ba1a6dbf60 52 //Read Sensors (I2C)
noutram 5:58ba1a6dbf60 53 float temp = sensor.getTemperature();
noutram 5:58ba1a6dbf60 54 float pressure = sensor.getPressure();
noutram 5:58ba1a6dbf60 55 #ifdef BME
noutram 5:58ba1a6dbf60 56 float humidity = sensor.getHumidity();
noutram 5:58ba1a6dbf60 57 #endif
noutram 5:58ba1a6dbf60 58
noutram 5:58ba1a6dbf60 59 //Display in PuTTY
noutram 5:58ba1a6dbf60 60 printf("Temperature: %5.1f\n", temp);
noutram 5:58ba1a6dbf60 61 printf("Pressure: %5.1f\n", pressure);
noutram 5:58ba1a6dbf60 62 #ifdef BME
noutram 5:58ba1a6dbf60 63 printf("Pressure: %5.1f\n", humidity);
noutram 5:58ba1a6dbf60 64 #endif
noutram 5:58ba1a6dbf60 65
noutram 5:58ba1a6dbf60 66 puts("**********POST END**********");
noutram 5:58ba1a6dbf60 67
noutram 4:d884f14069c6 68 }
noutram 4:d884f14069c6 69
noutram 4:d884f14069c6 70 void errorCode(ELEC350_ERROR_CODE err)
noutram 4:d884f14069c6 71 {
noutram 4:d884f14069c6 72 switch (err) {
noutram 4:d884f14069c6 73 case OK:
noutram 4:d884f14069c6 74 greenLED = 1;
noutram 4:d884f14069c6 75 wait(1.0);
noutram 4:d884f14069c6 76 greenLED = 0;
noutram 4:d884f14069c6 77 return;
noutram 4:d884f14069c6 78 case FATAL:
noutram 4:d884f14069c6 79 while(1) {
noutram 4:d884f14069c6 80 redLED = 1;
noutram 4:d884f14069c6 81 wait(0.1);
noutram 4:d884f14069c6 82 redLED = 0;
noutram 4:d884f14069c6 83 wait(0.1);
noutram 4:d884f14069c6 84 }
noutram 4:d884f14069c6 85 };
noutram 0:6f9f2e93a0be 86 }