Plant Monitoring Project

Dependencies:   mbed SHT21_ncleee WakeUp SSD1306 DHT Adafruit_TCS34725 DS1820

Revision:
20:79f4ef29eafd
Parent:
19:d6236253bf5f
Child:
21:4a18c9f1eb5e
--- a/main.cpp	Mon Nov 04 09:00:13 2019 +0000
+++ b/main.cpp	Tue Nov 19 14:22:34 2019 +0000
@@ -4,7 +4,7 @@
 #include "Adafruit_TCS34725.h"
 #include "ssd1306.h"
 
-#define DUREE_MESURE 10         // Durée en seconde entre deux mesures
+#define DUREE_MESURE 4         // Durée en seconde entre deux mesures
 #define DUREE_ECRAN_ON  5      // Durée en seconde d'éveil de l'écran
 
 #define I2C_SDA D4
@@ -46,7 +46,7 @@
 void    readData(void);
 void    interruption_bouton(void);
 void    turnOffScreen(void);
-
+void    enter_Standby(void);
 
 float temperature_sol;
 unsigned char humidity_sol;
@@ -58,7 +58,7 @@
     
 int main() {
     //Initialisation de l'interruption
-    bouton.fall(interruption_bouton);
+    bouton.rise(interruption_bouton);
     
     // Affichage logo pour initialisation
     oled.wake();
@@ -73,7 +73,7 @@
         
     while(1) {
       readData();
-      wait(DUREE_MESURE);
+      enter_Standby();
     }
 }
 
@@ -82,8 +82,9 @@
 {
     DS.convertTemperature(true, DS1820::all_devices);
     if (DS.unassignedProbe(D3)){
-        //pc.printf( "D3 not assigned\n\r");
+        printf( "D3 not assigned\n\r");
     }
+    printf("temp sol: %.1f\n\r", DS.temperature());
     return DS.temperature();
 }
 
@@ -94,6 +95,7 @@
     float mesure, mesure_etalonnee;
     mesure = capteur_humidity_sol.read();
     mesure_etalonnee = (1-((mesure - val_min)/(val_max - val_min)))*100;
+    printf("hum sol: %d\n\r", (int) mesure_etalonnee);
     return (int) mesure_etalonnee;
 }
 
@@ -112,6 +114,8 @@
         pg = green*100/somme;
         pb = blue*100/somme;
         lum = clear;
+        printf("luminosité : %d \n\r", lum);
+        printf("rouge:%d vert:%d bleu:%d \n\r", pr, pg, pb);
 }
 
 void sendDataSigfox(void){
@@ -149,9 +153,12 @@
 void readData(void){
     temperature_sol = temp_sol();
     humidity_sol = fct_humidity_sol();
-    temperature_air = sht.readTemp();      
-    humidity_air = sht.readHumidity();      
+    temperature_air = sht.readTemp(); 
+    printf("temp air: %.1f\n\r", temperature_air);     
+    humidity_air = sht.readHumidity();
+    printf("hum air: %d\n\r", humidity_air);      
     fct_RGB();
+    printf("\n\r");
     sendDataSigfox();
     if(oled_on)
         oledData();
@@ -172,3 +179,21 @@
     oled_on = 0;
     oled.sleep();
 }
+
+void enter_Standby( void )
+{
+    /* Enable Clocks */
+    RCC->APB1ENR |= RCC_APB1ENR_PWREN;
+     
+    /* Prepare for Standby */
+    // if WKUP pins are already high, the WUF bit will be set
+    PWR->CSR |= PWR_CSR_EWUP1 | PWR_CSR_EWUP2;
+     
+    PWR->CR |= PWR_CR_CWUF; // clear the WUF flag after 2 clock cycles
+    PWR->CR |= PWR_CR_ULP;   // V_{REFINT} is off in low-power mode
+    PWR->CR |= PWR_CR_PDDS; // Enter Standby mode when the CPU enters deepsleep
+     
+    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; // low-power mode = stop mode
+    printf("Enter standby mode\n\r");
+    __WFE(); // enter low-power mode
+}
\ No newline at end of file