Dependencies:   SSD1306 TSL2561 mbed DHT22 OneWire

Committer:
Aureb29
Date:
Mon Oct 30 15:53:56 2017 +0000
Revision:
2:34f81c0f5176
Parent:
0:9904b68365e4
Child:
3:4e142bba2a8e

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Aureb29 0:9904b68365e4 1 #include "mbed.h"
Aureb29 0:9904b68365e4 2 #define MOIST_PIN A3
Aureb29 0:9904b68365e4 3 #define p_scl PA_9
Aureb29 0:9904b68365e4 4 #define p_sda PA_10
Aureb29 0:9904b68365e4 5 #include "TSL2561.h"
Aureb29 0:9904b68365e4 6 #include "ssd1306.h"
Aureb29 0:9904b68365e4 7 #include "standard_font.h"
Aureb29 0:9904b68365e4 8 #include "bold_font.h"
Aureb29 2:34f81c0f5176 9 #include "DHT22.h"
Aureb29 2:34f81c0f5176 10 #include "DS1820.h"
Aureb29 0:9904b68365e4 11
Aureb29 0:9904b68365e4 12 SSD1306 oled(D3 /* cs */, A0 /* reset */, A7 /* dc */,
Aureb29 0:9904b68365e4 13 A1 /* clock */, A6 /* data */);
Aureb29 0:9904b68365e4 14 TSL2561 lum(PA_10,PA_9);
Aureb29 0:9904b68365e4 15 AnalogIn moisture(MOIST_PIN);
Aureb29 2:34f81c0f5176 16 Serial sigfox(PB_6, PB_7);
Aureb29 2:34f81c0f5176 17 DHT22 Capt_temp_hum(A2);
Aureb29 2:34f81c0f5176 18 DS1820 ds1820(A4); // substitute A4 with actual mbed pin name connected to the DS1820 data pin
Aureb29 0:9904b68365e4 19
Aureb29 0:9904b68365e4 20 int main()
Aureb29 0:9904b68365e4 21 {
Aureb29 0:9904b68365e4 22 oled.initialise();
Aureb29 0:9904b68365e4 23 oled.clear();
Aureb29 0:9904b68365e4 24 oled.set_contrast(255); // max contrast
Aureb29 0:9904b68365e4 25 oled.set_font(bold_font, 8);
Aureb29 2:34f81c0f5176 26 if(ds1820.begin()){
Aureb29 2:34f81c0f5176 27 ds1820.startConversion(); // start temperature conversion
Aureb29 2:34f81c0f5176 28 oled.printf("DS1820 Conversion started");
Aureb29 2:34f81c0f5176 29 wait(1.0);
Aureb29 2:34f81c0f5176 30 }
Aureb29 2:34f81c0f5176 31 else oled.printf("No DS1820 sensor found!\r\n");
Aureb29 0:9904b68365e4 32 oled.update();
Aureb29 2:34f81c0f5176 33 int temp, hum, temp_sol;
Aureb29 2:34f81c0f5176 34 char a;
Aureb29 0:9904b68365e4 35 while (1)
Aureb29 0:9904b68365e4 36 {
Aureb29 2:34f81c0f5176 37 wait(10);
Aureb29 2:34f81c0f5176 38 temp = (int) (Capt_temp_hum.getTemperature()/10);
Aureb29 2:34f81c0f5176 39 hum = (int) (Capt_temp_hum.getHumidity()/10);
Aureb29 2:34f81c0f5176 40 temp_sol = (int) ds1820.read();
Aureb29 2:34f81c0f5176 41 ds1820.startConversion();
Aureb29 2:34f81c0f5176 42 wait(1);
Aureb29 2:34f81c0f5176 43 a='%';
Aureb29 0:9904b68365e4 44 oled.scroll_up();
Aureb29 0:9904b68365e4 45 oled.update();
Aureb29 0:9904b68365e4 46 oled.set_font(bold_font, 8);
Aureb29 2:34f81c0f5176 47 Capt_temp_hum.sample();
Aureb29 2:34f81c0f5176 48 //oled.printf("Moisture is %2.2f\r\n", (float) moisture);
Aureb29 2:34f81c0f5176 49 //oled.printf("Lum : %+5.1f lux\r\n", lum.lux());
Aureb29 2:34f81c0f5176 50 oled.printf("Temp : %d oC\r\n", temp);
Aureb29 2:34f81c0f5176 51 oled.printf("Humidite : %d%c\r\n", hum, a);
Aureb29 2:34f81c0f5176 52 oled.printf("Temp sol : %d\r\n", temp_sol);
Aureb29 2:34f81c0f5176 53 //oled.printf("\n");
Aureb29 2:34f81c0f5176 54 sigfox.printf("AT$SF=");
Aureb29 2:34f81c0f5176 55 sigfox.printf("%02x %02x %02x", temp_sol);
Aureb29 2:34f81c0f5176 56 sigfox.printf("\r\n");
Aureb29 0:9904b68365e4 57 }
Aureb29 0:9904b68365e4 58 }