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