Green Team / Mbed 2 deprecated greenhouse_proj

Dependencies:   DHT DS1820 publishhhhh SSD1306 TSL2561_I2C mbed

Fork of Seeed_Grove_Moisture_Sensor_Example by Seeed

Revision:
1:280672cfee6b
Parent:
0:780321a3f63a
Child:
2:72e1b9689366
--- a/main.cpp	Sat Aug 16 00:34:43 2014 +0000
+++ b/main.cpp	Fri Nov 24 15:50:54 2017 +0000
@@ -1,15 +1,149 @@
+#include "mbed.h"
+#include <stdint.h>
 
-#include "mbed.h"
+#include "DHT.h"        //1.Temp & Hum Sensor White Block   -- DHT22    --> A3
+#include "DS1820.h"     //2.One Wire Temperature Sensor     -- DS18B20  --> A1
+                        //3.Grove Moisture :: no library                --> A0
+#include "TSL2561_I2C.h"//4.Flat Light Sensor               -- TSL2561  --> SDA : D4, SCL : D5
+
+//1. White block
+DHT sensor(A3,DHT22);
+void task_DHT();
+
+int air_hum, air_celsius,f;
+float dp = 0.0f;
+
+//2. One Wire Temperature DS18B20
+#define DATA_PIN        A1
+#define MAX_PROBES      16
+DS1820* probe[MAX_PROBES];
+float temp;
 
+//3. Grove Moisture
+Serial pc(SERIAL_TX, SERIAL_RX);
 AnalogIn moisture(A0);
 
+//4. Flat Light Sensor
+TSL2561_I2C lum_sensor( D4, D5 );
+float air_lum;
+
+
+Serial sigfox(PA_2, PA_3);
+
+void txData(int a ,int b,int c,int d,int e)
+{
+    pc.printf("Envoie sur le Sigfox : AT$SS:%d %d %d %d %d\r\n",a,b,c,d,e);
+    
+    //sigfox.printf("AT$SS=%d",valeur);
+    sigfox.printf("AT$SS=%02x %02x %02x %02x %02x\r\n", a,b,c,d,e);
+
+}
+
+
 int main(void)
 {
-    float value = 0.0f;
-
+    printf("\r\n\n\n");
+        
+    //1. Temp & Humidity sensor -- White block
+    //No more init
+    
+    //2. Temperature Probe -- One Wire Temperature Sensor
+    int num_devices = 0;
+    while(DS1820::unassignedProbe(DATA_PIN)) {
+        probe[num_devices] = new DS1820(DATA_PIN);
+        num_devices++;
+        if (num_devices == MAX_PROBES) break;
+    }
+    printf(" %d probe found\r\n", num_devices);
+    
+    //3. Grove Moisture
+    float moisture_value = 0.0f;
+    
+    //4.
+    lum_sensor.enablePower();
+    // Nothing else
+    
+    
+    printf("Inits ended\r\n\n");
     while(1) {
-        value = moisture;
-        printf("Moisture reading is %2.2f\n", value);
-        wait(1.0f);
+        printf("\r\n\n\nNew loop\r\n\n");
+        
+        //1. Temp & Humidity sensor -- White block
+        printf("DHT22 White Block : \r\n");
+        task_DHT();
+        
+        //2. Temperature Probe -- One Wire Temperature Sensor
+        printf("DS18B20 Probe : \r\n");
+        probe[0]->convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
+        for (int i = 0; i<num_devices; i++){
+            temp = probe[i]->temperature();
+            printf("Device %d returns %3.1f  oC\r\n\n", i, temp);
+        }
+        
+        //3. Grove Moisture
+        moisture_value = moisture;
+        printf("Grove Moisture : \r\nMoisture reading is %2.2f\r\n\n", moisture_value);
+        
+        //4. TSL2561 Flat Light Sensor
+        air_lum = lum_sensor.getLux();
+        printf( "Luminosity: %4.2f\r\n", air_lum );
+        
+        
+        
+
+        
+        txData((int)air_celsius,(int)air_hum,(int)air_lum,(int)temp,(int)moisture_value);
+        wait(3); // 1 lecture toutes les 3 secondes
+        
     }
+    
+    
 }
+
+
+        //txData((int)air_temp,(int)air_moisture,(int)sol_moisture,(int)illuminance,(int)temp_sol);
+        
+        
+        
+        
+//1.
+void task_DHT(){
+    int error = 0;
+ 
+        wait(2.0f);
+        error = sensor.readData();
+        if (0 == error) {
+            air_celsius   = sensor.ReadTemperature(CELCIUS);
+            f   = sensor.ReadTemperature(FARENHEIT);
+            air_hum  = sensor.ReadHumidity();
+            dp  = sensor.CalcdewPoint(air_celsius, air_hum);
+    
+            printf("Temperature in Celcius: %d, Farenheit %d\r\n", air_celsius, f);
+            printf("Humidity is %d, Dewpoint: %4.2f\r\n\n", air_hum, dp);
+        } else {
+            printf("Error: %d\r\n", error);
+        }
+}
+
+//4.
+/*
+void setup(void){
+    if (tsl2561.begin()) {    
+        PC_PRINTLNX(1,"TSL2561 Sensor Found");        
+    } else {    
+        PC_PRINTLNX(1,"TSL2561 Sensor not Found");   
+    }
+    // You can change the gain on the fly, to adapt to brighter/dimmer tsl2561 situations
+  tsl2561.setGain(TSL2561_GAIN_0X);         // set no gain (for bright situtations)
+  //tsl2561.setGain(TSL2561_GAIN_16X);      // set 16x gain (for dim situations)
+  
+  // Changing the integration time gives you a longer time over which to sense tsl2561
+  // longer timelines are slower, but are good in very low tsl2561 situtations!
+  //tsl2561.setTiming(TSL2561_INTEGRATIONTIME_13MS);  // shortest integration time (bright tsl2561)
+  //tsl2561.setTiming(TSL2561_INTEGRATIONTIME_101MS);  // medium integration time (medium tsl2561)
+  tsl2561.setTiming(TSL2561_INTEGRATIONTIME_402MS);  // longest integration time (dim tsl2561)
+}
+
+*/
+
+