Plant Monitoring Project

Dependencies:   mbed SHT21_ncleee WakeUp SSD1306 DHT Adafruit_TCS34725 DS1820

Revision:
2:0bfe25431e8e
Parent:
1:3fc11a745984
Child:
3:fc704c1d3087
--- a/main.cpp	Mon Oct 07 18:13:11 2019 +0000
+++ b/main.cpp	Tue Oct 08 13:14:07 2019 +0000
@@ -4,9 +4,14 @@
 #include "Adafruit_TCS34725.h"
 #include "ssd1306.h"
 
-Serial pc(SERIAL_TX, SERIAL_RX);
+#define I2C_SDA D4
+#define I2C_SCL D5
+
+//Serial pc(SERIAL_TX, SERIAL_RX);
 Serial nucleo(D1,D0);
-I2C i2c(D4, D5);
+
+I2C i2c(I2C_SDA, I2C_SCL);
+SSD1306 oled(I2C_SDA, I2C_SCL);
 
 // capteur temperature sol
 DS1820 DS(D3); 
@@ -29,6 +34,7 @@
 void    fct_RGB(unsigned char *pr, unsigned char *pg, unsigned char *pb);
 float   fct_lumiere(void);
 void    sendDataSigfox(float tempSol, unsigned char *humSol, float tempAir, unsigned char *humAir, unsigned short *lux, unsigned char *R, unsigned char *G, unsigned char *B);
+void    oledData(void);
 
 
     float temperature_sol;
@@ -40,31 +46,36 @@
     
     
 int main() {
-    
+    oled.speed (SSD1306::Medium);  // set working frequency
+    oled.init();                   // initialize SSD1306
+    oled.cls();                    // clear frame buffer
+    oled.set_contrast(200);
         
     while(1) {
       
       temperature_sol = temp_sol();
-      pc.printf("T sol = %.2f\n\r", temperature_sol);
+      //pc.printf("T sol = %.2f\n\r", temperature_sol);
       
       humidity_sol = fct_humidity_sol();
-      pc.printf("H sol = %d\n\r", humidity_sol);
+      //pc.printf("H sol = %d\n\r", humidity_sol);
       
       temperature_air = sht.readTemp();
-      pc.printf("temperature_air = %.2f\n\r", temperature_air);
+      //pc.printf("temperature_air = %.2f\n\r", temperature_air);
+      
       humidity_air = sht.readHumidity();
-      pc.printf("humidity_air = %d\n\r", humidity_air);
+      //pc.printf("humidity_air = %d\n\r", humidity_air);
       
       fct_RGB(&pr, &pg, &pb);
-      pc.printf("red=%d green=%d blue=%d\n\r", pr, pg, pb);
+      //pc.printf("red=%d green=%d blue=%d\n\r", pr, pg, pb);
       
       lum = fct_lumiere();
-      pc.printf("lumiere = %d\n\r", lum);
+      //pc.printf("lumiere = %d\n\r", lum);
         
+      oledData();
       sendDataSigfox(temperature_sol, &humidity_sol, temperature_air, &humidity_air, &lum, &pr, &pg, &pb);
     
-      pc.printf("\n\r");
-      wait(30);
+      //pc.printf("\n\r");
+      wait(10);
     }
 }
 
@@ -73,7 +84,7 @@
 {
     DS.convertTemperature(true, DS1820::all_devices);
     if (DS.unassignedProbe(D3)){
-        pc.printf( "D3 not assigned\n\r");
+        //pc.printf( "D3 not assigned\n\r");
     }
     return DS.temperature();
 }
@@ -94,7 +105,7 @@
     uint16_t clear, red, green, blue;
     if (!RGBsens.begin())
     {
-        pc.printf("No TCS34725 found ... check your connections");
+        //pc.printf("No TCS34725 found ... check your connections");
         while (1); // halt!
     }
         RGBsens.getRawData(&red, &green, &blue, &clear);
@@ -126,5 +137,23 @@
 
         nucleo.printf("AT$SF=%04x%02x%04x%02x%04x%02x%02x%02x\r\n",tempSol_short, *humSol, tempAir_short, *humAir, *lux, *R, *G, *B);
     }
+    
+void oledData(void){
+    oled.cls();
+    oled.locate(0,0);
+    oled.printf("AIR T : %.1f", temperature_air);
+    oled.locate(1,0);
+    oled.printf("AIR H : %d", humidity_air);
+    oled.locate(3,0);
+    oled.printf("FLOOR T : %.1f", temperature_sol);
+    oled.locate(4,0);
+    oled.printf("FLOOR H : %d", humidity_sol);
+    oled.locate(6,0);
+    oled.printf("Light : %d", lum);
+    oled.locate(7,0);
+    oled.printf("R %d G %d B %d", pr, pg, pb);
+    
+    oled.redraw();
+}