Dependencies: SSD1306 TSL2561 mbed DHT22 OneWire
main.cpp@3:4e142bba2a8e, 2017-11-10 (annotated)
- Committer:
- Aureb29
- Date:
- Fri Nov 10 16:47:25 2017 +0000
- Revision:
- 3:4e142bba2a8e
- Parent:
- 2:34f81c0f5176
- Child:
- 4:5ba5931b57db
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Aureb29 | 0:9904b68365e4 | 1 | #include "mbed.h" |
Aureb29 | 0:9904b68365e4 | 2 | #define p_scl PA_9 |
Aureb29 | 0:9904b68365e4 | 3 | #define p_sda PA_10 |
Aureb29 | 0:9904b68365e4 | 4 | #include "TSL2561.h" |
Aureb29 | 0:9904b68365e4 | 5 | #include "ssd1306.h" |
Aureb29 | 0:9904b68365e4 | 6 | #include "standard_font.h" |
Aureb29 | 0:9904b68365e4 | 7 | #include "bold_font.h" |
Aureb29 | 2:34f81c0f5176 | 8 | #include "DHT22.h" |
Aureb29 | 3:4e142bba2a8e | 9 | #include "OneWire.h" |
Aureb29 | 3:4e142bba2a8e | 10 | #include "OneWireDevice.h" |
Aureb29 | 3:4e142bba2a8e | 11 | #include "OneWireDeviceFactory.h" |
Aureb29 | 3:4e142bba2a8e | 12 | #include "OneWireDeviceTemperature.h" |
Aureb29 | 0:9904b68365e4 | 13 | |
Aureb29 | 3:4e142bba2a8e | 14 | DigitalOut myled(LED1); |
Aureb29 | 0:9904b68365e4 | 15 | SSD1306 oled(D3 /* cs */, A0 /* reset */, A7 /* dc */, |
Aureb29 | 0:9904b68365e4 | 16 | A1 /* clock */, A6 /* data */); |
Aureb29 | 3:4e142bba2a8e | 17 | Serial serial(USBTX, USBRX); |
Aureb29 | 0:9904b68365e4 | 18 | TSL2561 lum(PA_10,PA_9); |
Aureb29 | 3:4e142bba2a8e | 19 | AnalogIn moisture(A3); |
Aureb29 | 2:34f81c0f5176 | 20 | Serial sigfox(PB_6, PB_7); |
Aureb29 | 2:34f81c0f5176 | 21 | DHT22 Capt_temp_hum(A2); |
Aureb29 | 3:4e142bba2a8e | 22 | OneWire OneWire(A4); // substitute A4 with actual mbed pin name connected to the DS1820 data pin |
Aureb29 | 0:9904b68365e4 | 23 | |
Aureb29 | 0:9904b68365e4 | 24 | int main() |
Aureb29 | 0:9904b68365e4 | 25 | { |
Aureb29 | 0:9904b68365e4 | 26 | oled.initialise(); |
Aureb29 | 0:9904b68365e4 | 27 | oled.clear(); |
Aureb29 | 0:9904b68365e4 | 28 | oled.set_contrast(255); // max contrast |
Aureb29 | 0:9904b68365e4 | 29 | oled.set_font(bold_font, 8); |
Aureb29 | 0:9904b68365e4 | 30 | oled.update(); |
Aureb29 | 3:4e142bba2a8e | 31 | DeviceAddresses* devAddresses = OneWire.getFoundDevAddresses(); |
Aureb29 | 3:4e142bba2a8e | 32 | uint8_t foundNum = OneWire.getFoundDevNum(); |
Aureb29 | 3:4e142bba2a8e | 33 | printf("OneWire: found %d devices\r\n", foundNum); |
Aureb29 | 3:4e142bba2a8e | 34 | char _id[16]; |
Aureb29 | 3:4e142bba2a8e | 35 | int temp, hum, temp_sol, lumi, moist; |
Aureb29 | 2:34f81c0f5176 | 36 | char a; |
Aureb29 | 0:9904b68365e4 | 37 | while (1) |
Aureb29 | 0:9904b68365e4 | 38 | { |
Aureb29 | 3:4e142bba2a8e | 39 | myled = 1; // LED is ON |
Aureb29 | 3:4e142bba2a8e | 40 | //temp = (int) (Capt_temp_hum.getTemperature()/10); |
Aureb29 | 3:4e142bba2a8e | 41 | //hum = (int) (Capt_temp_hum.getHumidity()/10); |
Aureb29 | 3:4e142bba2a8e | 42 | moist = (int) (moisture*100); |
Aureb29 | 3:4e142bba2a8e | 43 | lumi = (int) lum.lux(); |
Aureb29 | 3:4e142bba2a8e | 44 | lumi=((lumi & 0xff)<<8) | ((lumi & 0xff00)>>8); //Swipping bytes for Actoboard reception |
Aureb29 | 3:4e142bba2a8e | 45 | OneWireDeviceTemperature::startConversationForAll(&OneWire, OWTEMP_11_BIT); |
Aureb29 | 3:4e142bba2a8e | 46 | for (uint8_t i = 0; i < foundNum; i++) { |
Aureb29 | 3:4e142bba2a8e | 47 | OneWireDevice* owDevice = OneWireDeviceFactory::init(&OneWire, (*devAddresses)[i]); |
Aureb29 | 3:4e142bba2a8e | 48 | |
Aureb29 | 3:4e142bba2a8e | 49 | if (owDevice->getFamily() != ONEWIRE_DS18B20_FAMILY) // currently only DS18B20 supports |
Aureb29 | 3:4e142bba2a8e | 50 | continue; |
Aureb29 | 3:4e142bba2a8e | 51 | |
Aureb29 | 3:4e142bba2a8e | 52 | owDevice->generateId(_id); |
Aureb29 | 3:4e142bba2a8e | 53 | temp_sol = (int) owDevice->sendGetCommand(GET_TEMPERATURE); |
Aureb29 | 3:4e142bba2a8e | 54 | oled.printf("OneWire: device #%s = %.4f*C\r\n", _id, (float) owDevice->sendGetCommand(GET_TEMPERATURE)); |
Aureb29 | 3:4e142bba2a8e | 55 | delete owDevice; |
Aureb29 | 3:4e142bba2a8e | 56 | } |
Aureb29 | 2:34f81c0f5176 | 57 | a='%'; |
Aureb29 | 3:4e142bba2a8e | 58 | oled.set_font(bold_font, 8); |
Aureb29 | 0:9904b68365e4 | 59 | oled.scroll_up(); |
Aureb29 | 0:9904b68365e4 | 60 | oled.update(); |
Aureb29 | 2:34f81c0f5176 | 61 | Capt_temp_hum.sample(); |
Aureb29 | 3:4e142bba2a8e | 62 | oled.printf("Moisture is %2.2f\r\n", (float) moisture); |
Aureb29 | 3:4e142bba2a8e | 63 | oled.printf("Lum : %+4.1f lux\r\n", lum.lux()); |
Aureb29 | 2:34f81c0f5176 | 64 | oled.printf("Temp : %d oC\r\n", temp); |
Aureb29 | 2:34f81c0f5176 | 65 | oled.printf("Humidite : %d%c\r\n", hum, a); |
Aureb29 | 2:34f81c0f5176 | 66 | oled.printf("Temp sol : %d\r\n", temp_sol); |
Aureb29 | 3:4e142bba2a8e | 67 | oled.printf("\n"); |
Aureb29 | 2:34f81c0f5176 | 68 | sigfox.printf("AT$SF="); |
Aureb29 | 3:4e142bba2a8e | 69 | sigfox.printf("%02x ", temp); |
Aureb29 | 3:4e142bba2a8e | 70 | sigfox.printf("%02x ", hum); |
Aureb29 | 3:4e142bba2a8e | 71 | sigfox.printf("%02x ", temp_sol); |
Aureb29 | 3:4e142bba2a8e | 72 | sigfox.printf("%02x ", moist); |
Aureb29 | 3:4e142bba2a8e | 73 | sigfox.printf("%04x ", lumi); |
Aureb29 | 2:34f81c0f5176 | 74 | sigfox.printf("\r\n"); |
Aureb29 | 3:4e142bba2a8e | 75 | wait(15); |
Aureb29 | 3:4e142bba2a8e | 76 | myled = 0; // LED is OFF |
Aureb29 | 3:4e142bba2a8e | 77 | wait(15); |
Aureb29 | 0:9904b68365e4 | 78 | } |
Aureb29 | 0:9904b68365e4 | 79 | } |