Dependencies:   SSD1306 TSL2561 mbed DHT22 OneWire

Revision:
3:4e142bba2a8e
Parent:
2:34f81c0f5176
Child:
4:5ba5931b57db
--- a/main.cpp	Mon Oct 30 15:53:56 2017 +0000
+++ b/main.cpp	Fri Nov 10 16:47:25 2017 +0000
@@ -1,5 +1,4 @@
 #include "mbed.h"
-#define MOIST_PIN       A3
 #define p_scl PA_9
 #define p_sda PA_10
 #include "TSL2561.h"
@@ -7,15 +6,20 @@
 #include "standard_font.h"
 #include "bold_font.h"
 #include "DHT22.h"
-#include "DS1820.h"
+#include "OneWire.h"
+#include "OneWireDevice.h"
+#include "OneWireDeviceFactory.h"
+#include "OneWireDeviceTemperature.h"
  
+DigitalOut myled(LED1);
 SSD1306 oled(D3 /* cs */, A0 /* reset */, A7 /* dc */,
              A1 /* clock */, A6 /* data */);
+Serial serial(USBTX, USBRX);
 TSL2561      lum(PA_10,PA_9);
-AnalogIn moisture(MOIST_PIN);
+AnalogIn moisture(A3);
 Serial sigfox(PB_6, PB_7);
 DHT22 Capt_temp_hum(A2);
-DS1820  ds1820(A4);    // substitute A4 with actual mbed pin name connected to the DS1820 data pin
+OneWire OneWire(A4);    // substitute A4 with actual mbed pin name connected to the DS1820 data pin
 
 int main()
 {
@@ -23,36 +27,53 @@
     oled.clear();
     oled.set_contrast(255); // max contrast
     oled.set_font(bold_font, 8);
-    if(ds1820.begin()){
-        ds1820.startConversion(); // start temperature conversion
-        oled.printf("DS1820 Conversion started");
-        wait(1.0);
-    } 
-    else oled.printf("No DS1820 sensor found!\r\n");
     oled.update();
-    int temp, hum, temp_sol;
+    DeviceAddresses* devAddresses = OneWire.getFoundDevAddresses();
+    uint8_t foundNum = OneWire.getFoundDevNum();
+    printf("OneWire: found %d devices\r\n", foundNum);
+    char _id[16];
+    int temp, hum, temp_sol, lumi, moist;
     char a;
     while (1)
     {
-        wait(10);
-        temp = (int) (Capt_temp_hum.getTemperature()/10);
-        hum = (int) (Capt_temp_hum.getHumidity()/10);
-        temp_sol = (int) ds1820.read();
-        ds1820.startConversion();
-        wait(1);
+        myled = 1; // LED is ON
+        //temp = (int) (Capt_temp_hum.getTemperature()/10);
+        //hum = (int) (Capt_temp_hum.getHumidity()/10);
+        moist = (int) (moisture*100);
+        lumi = (int) lum.lux();
+        lumi=((lumi & 0xff)<<8) | ((lumi & 0xff00)>>8); //Swipping bytes for Actoboard reception
+        OneWireDeviceTemperature::startConversationForAll(&OneWire, OWTEMP_11_BIT);
+        for (uint8_t i = 0; i < foundNum; i++) {
+            OneWireDevice* owDevice = OneWireDeviceFactory::init(&OneWire, (*devAddresses)[i]);
+            
+            if (owDevice->getFamily() != ONEWIRE_DS18B20_FAMILY)    // currently only DS18B20 supports
+                continue;
+ 
+            owDevice->generateId(_id);
+            temp_sol = (int) owDevice->sendGetCommand(GET_TEMPERATURE);
+            oled.printf("OneWire: device #%s = %.4f*C\r\n", _id, (float) owDevice->sendGetCommand(GET_TEMPERATURE));
+            delete owDevice;
+        }
         a='%';
+        oled.set_font(bold_font, 8);
         oled.scroll_up();
         oled.update();
-        oled.set_font(bold_font, 8);
         Capt_temp_hum.sample();
-        //oled.printf("Moisture is %2.2f\r\n", (float) moisture);
-        //oled.printf("Lum : %+5.1f lux\r\n", lum.lux());
+        oled.printf("Moisture is %2.2f\r\n", (float) moisture);
+        oled.printf("Lum : %+4.1f lux\r\n", lum.lux());
         oled.printf("Temp : %d oC\r\n", temp);
         oled.printf("Humidite : %d%c\r\n", hum, a);
         oled.printf("Temp sol : %d\r\n", temp_sol);
-        //oled.printf("\n");
+        oled.printf("\n");
         sigfox.printf("AT$SF=");
-        sigfox.printf("%02x %02x %02x", temp_sol);
+        sigfox.printf("%02x ", temp);
+        sigfox.printf("%02x ", hum);
+        sigfox.printf("%02x ", temp_sol);
+        sigfox.printf("%02x ", moist);
+        sigfox.printf("%04x ", lumi);
         sigfox.printf("\r\n");
+        wait(15);
+        myled = 0; // LED is OFF
+        wait(15);
     }
 }
\ No newline at end of file