projet capteur connecté ST/SE

Dependencies:   HP206C mbed HMC5883L DHT DS1820

Files at this revision

API Documentation at this revision

Comitter:
Fayge
Date:
Mon Oct 08 21:36:02 2018 +0000
Parent:
54:61d003e0754d
Child:
60:8b65fdf54d56
Commit message:
Temperature and soil sensors reading functions update

Changed in this revision

H_sol.cpp Show diff for this revision Revisions of this file
H_sol.h Show diff for this revision Revisions of this file
T_H_soil.cpp Show annotated file Show diff for this revision Revisions of this file
T_H_soil.h Show annotated file Show diff for this revision Revisions of this file
--- a/H_sol.cpp	Mon Oct 08 10:33:30 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-//florent
-#include "H_sol.h"
-#include "mbed.h"
-
-float getSoilHumidity(AnalogIn sensor)
-{ 
-    return sensor.read()/((float)3.0);
-}
\ No newline at end of file
--- a/H_sol.h	Mon Oct 08 10:33:30 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-#ifndef H_SOL
-#define H_SOL
-
-#include "mbed.h"
-#include "config.h"
-
-//AnalogIn moisture(A0);//( A0 -> A7 )
-float getSoilHumidity(AnalogIn sensor);
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/T_H_soil.cpp	Mon Oct 08 21:36:02 2018 +0000
@@ -0,0 +1,54 @@
+#include "T_H_soil.h"
+
+bool initSoilTemp(DS1820& probe, PinName pin)
+{
+    //check that a DS1820 is connected at its port and init it
+    return probe.unassignedProbe(pin);
+}
+
+float getSoilTemperature(DS1820& probe)
+{
+    bool wait(true);// if true, waits up to 750ms before returning
+    //return the ms_delay until the conversion will complete (=0 if wait == true)
+    int ms_delay = probe.convertTemperature(wait, DS1820::this_device);
+    if(ms_delay > 0)
+        wait_ms(ms_delay);
+        
+    //grab and return the conversion result
+    return probe.temperature();
+}
+
+float getSoilHumidity(AnalogIn& probe, float& airValue, float& waterValue, bool adaptiveCalibration)
+{
+        float HumidSensorVal = probe.read();
+        float onePercent = (airValue - waterValue)/100;
+        float humidityPercentage = 100-(HumidSensorVal-waterValue)/onePercent;
+        if(humidityPercentage < 0 && adaptiveCalibration)// in case its drier than we expected at max
+        {
+            humidityPercentage = 0;
+            airValue = HumidSensorVal;
+        }
+        else if(humidityPercentage > 100 && adaptiveCalibration)// in case its wetter than we expected at max
+        {
+            humidityPercentage = 100;
+            waterValue = HumidSensorVal;
+        }
+    return humidityPercentage;
+}
+/*
+int main() {
+    if(probe.unassignedProbe(PA_5))
+            pc.printf("unassigned Probe");
+    float airH = 0.77, waterH = 0.38;
+    float onePercent = (airH - waterH)/100;
+    while(1) {
+            
+        probe.convertTemperature(true, DS1820::this_device);
+        /*while(temp == DS1820::invalid_conversion)
+            temp = probe.temperature();
+        float temp = probe.temperature();
+        
+        
+        pc.printf("Soil ## T:%.2foC ## H:.2%f | calcH :%.2f%% ##\r\n", temp, humidSensor.read(), humidityPercentage);
+        wait(1);
+    }*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/T_H_soil.h	Mon Oct 08 21:36:02 2018 +0000
@@ -0,0 +1,36 @@
+#ifndef T_H_SOIL_H
+#define T_H_SOIL_H
+
+#include "mbed.h"
+#include "DS1820.h"
+ 
+#define   AIR_SOIL_HUMIDITY 0.77
+#define WATER_SOIL_HUMIDITY 0.38
+
+
+bool initSoilTemp(DS1820& probe);
+
+float getSoilTemperature(DS1820& probe);
+
+float getSoilHumidity(AnalogIn& probe, 
+                      float& airValue, 
+                      float& waterValue, 
+                      bool adaptiveCalibration = true);
+/*
+DS1820 probe(PA_5);
+Serial pc(USBTX, USBRX);
+AnalogIn humidSensor(PA_6);// max: 0.77 min:0.38
+
+int main() {
+    initSoilTemp(probe);
+    float airValue(AIR_SOIL_HUMIDITY);
+    float waterValue(WATER_SOIL_HUMIDITY);
+    while(1) {
+        float humid = getSoilHumidity( humidSensor, airValue,waterValue, true);
+        float temp  = getSoilTemperature(probe);
+        pc.printf("Soil ## T:%.2foC ## H :%.2f%% ##\r\n", temp, humid);
+        wait(1);
+    }
+}
+*/
+#endif
\ No newline at end of file