Plant Monitoring Project

Dependencies:   mbed SHT21_ncleee WakeUp SSD1306 DHT Adafruit_TCS34725 DS1820

Committer:
Germaint
Date:
Tue Oct 08 15:49:46 2019 +0000
Revision:
6:cd98294b2e5e
Parent:
5:256a143ab0c2
Child:
7:deb5dbe9e23d
Ajout WakeUp lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jufray 0:e030be8f0310 1 #include "mbed.h"
Germaint 1:3fc11a745984 2 #include "DS1820.h"
Germaint 1:3fc11a745984 3 #include "SHT21_ncleee.h"
Germaint 1:3fc11a745984 4 #include "Adafruit_TCS34725.h"
Germaint 1:3fc11a745984 5 #include "ssd1306.h"
Germaint 6:cd98294b2e5e 6 #include "WakeUp.h"
jufray 0:e030be8f0310 7
Germaint 2:0bfe25431e8e 8 #define I2C_SDA D4
Germaint 2:0bfe25431e8e 9 #define I2C_SCL D5
Germaint 2:0bfe25431e8e 10
Germaint 2:0bfe25431e8e 11 //Serial pc(SERIAL_TX, SERIAL_RX);
Germaint 1:3fc11a745984 12 Serial nucleo(D1,D0);
Germaint 2:0bfe25431e8e 13
Germaint 2:0bfe25431e8e 14 I2C i2c(I2C_SDA, I2C_SCL);
Germaint 2:0bfe25431e8e 15 SSD1306 oled(I2C_SDA, I2C_SCL);
jufray 0:e030be8f0310 16
Germaint 1:3fc11a745984 17 // capteur temperature sol
Germaint 1:3fc11a745984 18 DS1820 DS(D3);
jufray 0:e030be8f0310 19
Germaint 1:3fc11a745984 20 // capteur humidité sol
Germaint 1:3fc11a745984 21 AnalogIn capteur_humidity_sol(A0);
jufray 0:e030be8f0310 22
Germaint 1:3fc11a745984 23 // capteur humidité + température air
jufray 0:e030be8f0310 24 SHT21 sht(&i2c);
jufray 0:e030be8f0310 25
Germaint 1:3fc11a745984 26 // capteur RGB
ludollaoo 5:256a143ab0c2 27 Adafruit_TCS34725 RGBsens = Adafruit_TCS34725(&i2c, TCS34725_INTEGRATIONTIME_154MS, TCS34725_GAIN_1X);
jufray 0:e030be8f0310 28
Germaint 1:3fc11a745984 29 // capteur lumière
Germaint 1:3fc11a745984 30 AnalogIn ain(A1);
jufray 0:e030be8f0310 31
Germaint 1:3fc11a745984 32 // Définition de fonctions
Germaint 1:3fc11a745984 33 float temp_sol(void);
Germaint 1:3fc11a745984 34 int fct_humidity_sol(void);
ludollaoo 4:d7e305e06e1a 35 void fct_RGB(unsigned char *pr, unsigned char *pg, unsigned char *pb, unsigned short *lux);
Germaint 1:3fc11a745984 36 void sendDataSigfox(float tempSol, unsigned char *humSol, float tempAir, unsigned char *humAir, unsigned short *lux, unsigned char *R, unsigned char *G, unsigned char *B);
Germaint 2:0bfe25431e8e 37 void oledData(void);
jufray 0:e030be8f0310 38
Germaint 1:3fc11a745984 39
Germaint 1:3fc11a745984 40 float temperature_sol;
Germaint 1:3fc11a745984 41 unsigned char humidity_sol;
Germaint 1:3fc11a745984 42 float temperature_air;
Germaint 1:3fc11a745984 43 unsigned char humidity_air;
jufray 0:e030be8f0310 44 unsigned char pr, pg, pb;
jufray 0:e030be8f0310 45 unsigned short lum;
jufray 0:e030be8f0310 46
jufray 0:e030be8f0310 47
Germaint 1:3fc11a745984 48 int main() {
Germaint 2:0bfe25431e8e 49 oled.speed (SSD1306::Medium); // set working frequency
Germaint 2:0bfe25431e8e 50 oled.init(); // initialize SSD1306
Germaint 2:0bfe25431e8e 51 oled.cls(); // clear frame buffer
Germaint 2:0bfe25431e8e 52 oled.set_contrast(200);
Germaint 1:3fc11a745984 53
jufray 0:e030be8f0310 54 while(1) {
jufray 0:e030be8f0310 55
Germaint 1:3fc11a745984 56 temperature_sol = temp_sol();
Germaint 2:0bfe25431e8e 57 //pc.printf("T sol = %.2f\n\r", temperature_sol);
jufray 0:e030be8f0310 58
Germaint 1:3fc11a745984 59 humidity_sol = fct_humidity_sol();
Germaint 2:0bfe25431e8e 60 //pc.printf("H sol = %d\n\r", humidity_sol);
jufray 0:e030be8f0310 61
Germaint 1:3fc11a745984 62 temperature_air = sht.readTemp();
Germaint 2:0bfe25431e8e 63 //pc.printf("temperature_air = %.2f\n\r", temperature_air);
Germaint 2:0bfe25431e8e 64
Germaint 1:3fc11a745984 65 humidity_air = sht.readHumidity();
Germaint 2:0bfe25431e8e 66 //pc.printf("humidity_air = %d\n\r", humidity_air);
jufray 0:e030be8f0310 67
Germaint 3:fc704c1d3087 68 fct_RGB(&pr, &pg, &pb, &lum);
Germaint 2:0bfe25431e8e 69 //pc.printf("red=%d green=%d blue=%d\n\r", pr, pg, pb);
jufray 0:e030be8f0310 70
Germaint 2:0bfe25431e8e 71 oledData();
Germaint 1:3fc11a745984 72 sendDataSigfox(temperature_sol, &humidity_sol, temperature_air, &humidity_air, &lum, &pr, &pg, &pb);
jufray 0:e030be8f0310 73
Germaint 2:0bfe25431e8e 74 //pc.printf("\n\r");
Germaint 2:0bfe25431e8e 75 wait(10);
jufray 0:e030be8f0310 76 }
jufray 0:e030be8f0310 77 }
jufray 0:e030be8f0310 78
jufray 0:e030be8f0310 79
jufray 0:e030be8f0310 80 float temp_sol()
jufray 0:e030be8f0310 81 {
jufray 0:e030be8f0310 82 DS.convertTemperature(true, DS1820::all_devices);
jufray 0:e030be8f0310 83 if (DS.unassignedProbe(D3)){
Germaint 2:0bfe25431e8e 84 //pc.printf( "D3 not assigned\n\r");
jufray 0:e030be8f0310 85 }
jufray 0:e030be8f0310 86 return DS.temperature();
jufray 0:e030be8f0310 87 }
jufray 0:e030be8f0310 88
Germaint 1:3fc11a745984 89 int fct_humidity_sol(void)
jufray 0:e030be8f0310 90 {
jufray 0:e030be8f0310 91 float val_min = 0.377;
jufray 0:e030be8f0310 92 float val_max = 0.772;
jufray 0:e030be8f0310 93 float mesure, mesure_etalonnee;
Germaint 1:3fc11a745984 94 mesure = capteur_humidity_sol.read();
jufray 0:e030be8f0310 95 mesure_etalonnee = (1-((mesure - val_min)/(val_max - val_min)))*100;
jufray 0:e030be8f0310 96 return (int) mesure_etalonnee;
jufray 0:e030be8f0310 97 }
jufray 0:e030be8f0310 98
Germaint 3:fc704c1d3087 99 void fct_RGB(unsigned char *pr, unsigned char *pg, unsigned char *pb, unsigned short *lux)
jufray 0:e030be8f0310 100 {
jufray 0:e030be8f0310 101 int somme;
jufray 0:e030be8f0310 102 uint16_t clear, red, green, blue;
jufray 0:e030be8f0310 103 if (!RGBsens.begin())
jufray 0:e030be8f0310 104 {
Germaint 2:0bfe25431e8e 105 //pc.printf("No TCS34725 found ... check your connections");
jufray 0:e030be8f0310 106 while (1); // halt!
jufray 0:e030be8f0310 107 }
jufray 0:e030be8f0310 108 RGBsens.getRawData(&red, &green, &blue, &clear);
jufray 0:e030be8f0310 109 somme = red + green + blue;
jufray 0:e030be8f0310 110 *pr = red*100/somme;
jufray 0:e030be8f0310 111 *pg = green*100/somme;
jufray 0:e030be8f0310 112 *pb = blue*100/somme;
Germaint 3:fc704c1d3087 113 *lux = clear;
jufray 0:e030be8f0310 114 }
jufray 0:e030be8f0310 115
jufray 0:e030be8f0310 116 void sendDataSigfox(float tempSol, unsigned char *humSol, float tempAir, unsigned char *humAir, unsigned short *lux, unsigned char *R, unsigned char *G, unsigned char *B){
jufray 0:e030be8f0310 117 short tempSol_short, tempAir_short;
jufray 0:e030be8f0310 118 tempSol *= 10;
jufray 0:e030be8f0310 119 tempAir *= 10;
jufray 0:e030be8f0310 120 tempSol_short = (short) tempSol;
jufray 0:e030be8f0310 121 tempAir_short = (short) tempAir;
jufray 0:e030be8f0310 122
jufray 0:e030be8f0310 123 nucleo.printf("AT$SF=%04x%02x%04x%02x%04x%02x%02x%02x\r\n",tempSol_short, *humSol, tempAir_short, *humAir, *lux, *R, *G, *B);
jufray 0:e030be8f0310 124 }
Germaint 2:0bfe25431e8e 125
Germaint 2:0bfe25431e8e 126 void oledData(void){
Germaint 2:0bfe25431e8e 127 oled.cls();
Germaint 2:0bfe25431e8e 128 oled.locate(0,0);
Germaint 2:0bfe25431e8e 129 oled.printf("AIR T : %.1f", temperature_air);
Germaint 2:0bfe25431e8e 130 oled.locate(1,0);
Germaint 2:0bfe25431e8e 131 oled.printf("AIR H : %d", humidity_air);
Germaint 2:0bfe25431e8e 132 oled.locate(3,0);
Germaint 2:0bfe25431e8e 133 oled.printf("FLOOR T : %.1f", temperature_sol);
Germaint 2:0bfe25431e8e 134 oled.locate(4,0);
Germaint 2:0bfe25431e8e 135 oled.printf("FLOOR H : %d", humidity_sol);
Germaint 2:0bfe25431e8e 136 oled.locate(6,0);
Germaint 2:0bfe25431e8e 137 oled.printf("Light : %d", lum);
Germaint 2:0bfe25431e8e 138 oled.locate(7,0);
Germaint 2:0bfe25431e8e 139 oled.printf("R %d G %d B %d", pr, pg, pb);
Germaint 2:0bfe25431e8e 140
Germaint 2:0bfe25431e8e 141 oled.redraw();
Germaint 2:0bfe25431e8e 142 }
jufray 0:e030be8f0310 143
jufray 0:e030be8f0310 144