![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Plant Monitoring Project
Dependencies: mbed SHT21_ncleee WakeUp SSD1306 DHT Adafruit_TCS34725 DS1820
main.cpp@9:e4bed14db901, 2019-10-14 (annotated)
- Committer:
- Germaint
- Date:
- Mon Oct 14 08:32:58 2019 +0000
- Revision:
- 9:e4bed14db901
- Parent:
- 8:cbce19ac54b3
Etalonnage;
Who changed what in which revision?
User | Revision | Line number | New 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 | 9:e4bed14db901 | 11 | // Commenter ALIM_BASSE si alimenté en 5V / ALIM_HAUTE si alimenté en 3.3V |
Germaint | 9:e4bed14db901 | 12 | // Permet le bon focntionnement du capteur d'humidité (sol) |
Germaint | 9:e4bed14db901 | 13 | /*#define ALIM_BASSE |
Germaint | 9:e4bed14db901 | 14 | //#define ALIM_HAUTE |
Germaint | 9:e4bed14db901 | 15 | |
Germaint | 9:e4bed14db901 | 16 | #ifdef ALIM_BASSE |
Germaint | 9:e4bed14db901 | 17 | #define VAL_MIN |
Germaint | 9:e4bed14db901 | 18 | #define VAL_MAX |
Germaint | 9:e4bed14db901 | 19 | #endif |
Germaint | 9:e4bed14db901 | 20 | |
Germaint | 9:e4bed14db901 | 21 | #ifdef ALIM_HAUTE |
Germaint | 9:e4bed14db901 | 22 | #define VAL_MIN 0.377 |
Germaint | 9:e4bed14db901 | 23 | #define VAL_MAX 0.772 |
Germaint | 9:e4bed14db901 | 24 | #endif */ |
Germaint | 9:e4bed14db901 | 25 | |
Germaint | 2:0bfe25431e8e | 26 | //Serial pc(SERIAL_TX, SERIAL_RX); |
Germaint | 1:3fc11a745984 | 27 | Serial nucleo(D1,D0); |
Germaint | 2:0bfe25431e8e | 28 | |
Germaint | 2:0bfe25431e8e | 29 | I2C i2c(I2C_SDA, I2C_SCL); |
Germaint | 2:0bfe25431e8e | 30 | SSD1306 oled(I2C_SDA, I2C_SCL); |
jufray | 0:e030be8f0310 | 31 | |
Germaint | 1:3fc11a745984 | 32 | // capteur temperature sol |
Germaint | 1:3fc11a745984 | 33 | DS1820 DS(D3); |
jufray | 0:e030be8f0310 | 34 | |
Germaint | 1:3fc11a745984 | 35 | // capteur humidité sol |
Germaint | 1:3fc11a745984 | 36 | AnalogIn capteur_humidity_sol(A0); |
jufray | 0:e030be8f0310 | 37 | |
Germaint | 1:3fc11a745984 | 38 | // capteur humidité + température air |
jufray | 0:e030be8f0310 | 39 | SHT21 sht(&i2c); |
jufray | 0:e030be8f0310 | 40 | |
Germaint | 1:3fc11a745984 | 41 | // capteur RGB |
ludollaoo | 5:256a143ab0c2 | 42 | Adafruit_TCS34725 RGBsens = Adafruit_TCS34725(&i2c, TCS34725_INTEGRATIONTIME_154MS, TCS34725_GAIN_1X); |
jufray | 0:e030be8f0310 | 43 | |
Germaint | 1:3fc11a745984 | 44 | // capteur lumière |
Germaint | 1:3fc11a745984 | 45 | AnalogIn ain(A1); |
jufray | 0:e030be8f0310 | 46 | |
Germaint | 1:3fc11a745984 | 47 | // Définition de fonctions |
Germaint | 1:3fc11a745984 | 48 | float temp_sol(void); |
Germaint | 1:3fc11a745984 | 49 | int fct_humidity_sol(void); |
Germaint | 8:cbce19ac54b3 | 50 | void fct_RGB(void); |
Germaint | 8:cbce19ac54b3 | 51 | void sendDataSigfox(void); |
Germaint | 2:0bfe25431e8e | 52 | void oledData(void); |
Germaint | 7:deb5dbe9e23d | 53 | void readData(void); |
jufray | 0:e030be8f0310 | 54 | |
Germaint | 1:3fc11a745984 | 55 | |
Germaint | 1:3fc11a745984 | 56 | float temperature_sol; |
Germaint | 1:3fc11a745984 | 57 | unsigned char humidity_sol; |
Germaint | 1:3fc11a745984 | 58 | float temperature_air; |
Germaint | 1:3fc11a745984 | 59 | unsigned char humidity_air; |
jufray | 0:e030be8f0310 | 60 | unsigned char pr, pg, pb; |
jufray | 0:e030be8f0310 | 61 | unsigned short lum; |
jufray | 0:e030be8f0310 | 62 | |
jufray | 0:e030be8f0310 | 63 | |
Germaint | 1:3fc11a745984 | 64 | int main() { |
Germaint | 7:deb5dbe9e23d | 65 | // Initialisation de l'écran |
Germaint | 7:deb5dbe9e23d | 66 | oled.speed (SSD1306::Medium); |
Germaint | 7:deb5dbe9e23d | 67 | oled.init(); |
Germaint | 7:deb5dbe9e23d | 68 | oled.cls(); |
Germaint | 2:0bfe25431e8e | 69 | oled.set_contrast(200); |
Germaint | 7:deb5dbe9e23d | 70 | |
Germaint | 7:deb5dbe9e23d | 71 | // Initialisation WakeUp |
Germaint | 7:deb5dbe9e23d | 72 | //WakeUp::calibrate(); |
Germaint | 7:deb5dbe9e23d | 73 | //WakeUp::set(10); // Durée entre deux envois à modifier |
Germaint | 7:deb5dbe9e23d | 74 | //WakeUp::attach(&readData); |
Germaint | 1:3fc11a745984 | 75 | |
jufray | 0:e030be8f0310 | 76 | while(1) { |
jufray | 0:e030be8f0310 | 77 | |
Germaint | 7:deb5dbe9e23d | 78 | // Mesures des grandeurs physiques |
Germaint | 7:deb5dbe9e23d | 79 | readData(); |
Germaint | 7:deb5dbe9e23d | 80 | |
Germaint | 7:deb5dbe9e23d | 81 | // Affichage des données sur l'écran |
Germaint | 7:deb5dbe9e23d | 82 | oledData(); |
jufray | 0:e030be8f0310 | 83 | |
Germaint | 7:deb5dbe9e23d | 84 | // Envoi des données sur le cloud |
Germaint | 8:cbce19ac54b3 | 85 | sendDataSigfox(); |
jufray | 0:e030be8f0310 | 86 | |
Germaint | 2:0bfe25431e8e | 87 | wait(10); |
jufray | 0:e030be8f0310 | 88 | } |
jufray | 0:e030be8f0310 | 89 | } |
jufray | 0:e030be8f0310 | 90 | |
jufray | 0:e030be8f0310 | 91 | |
jufray | 0:e030be8f0310 | 92 | float temp_sol() |
jufray | 0:e030be8f0310 | 93 | { |
jufray | 0:e030be8f0310 | 94 | DS.convertTemperature(true, DS1820::all_devices); |
jufray | 0:e030be8f0310 | 95 | if (DS.unassignedProbe(D3)){ |
Germaint | 2:0bfe25431e8e | 96 | //pc.printf( "D3 not assigned\n\r"); |
jufray | 0:e030be8f0310 | 97 | } |
jufray | 0:e030be8f0310 | 98 | return DS.temperature(); |
jufray | 0:e030be8f0310 | 99 | } |
jufray | 0:e030be8f0310 | 100 | |
Germaint | 1:3fc11a745984 | 101 | int fct_humidity_sol(void) |
jufray | 0:e030be8f0310 | 102 | { |
jufray | 0:e030be8f0310 | 103 | float mesure, mesure_etalonnee; |
Germaint | 1:3fc11a745984 | 104 | mesure = capteur_humidity_sol.read(); |
Germaint | 9:e4bed14db901 | 105 | mesure_etalonnee = 100*mesure; |
Germaint | 9:e4bed14db901 | 106 | //mesure_etalonnee = (1-((mesure - VAL_MIN)/(VAL_MAX - VAL_MIN)))*100; |
jufray | 0:e030be8f0310 | 107 | return (int) mesure_etalonnee; |
jufray | 0:e030be8f0310 | 108 | } |
jufray | 0:e030be8f0310 | 109 | |
Germaint | 8:cbce19ac54b3 | 110 | void fct_RGB(void) |
jufray | 0:e030be8f0310 | 111 | { |
jufray | 0:e030be8f0310 | 112 | int somme; |
jufray | 0:e030be8f0310 | 113 | uint16_t clear, red, green, blue; |
jufray | 0:e030be8f0310 | 114 | if (!RGBsens.begin()) |
jufray | 0:e030be8f0310 | 115 | { |
Germaint | 2:0bfe25431e8e | 116 | //pc.printf("No TCS34725 found ... check your connections"); |
jufray | 0:e030be8f0310 | 117 | while (1); // halt! |
jufray | 0:e030be8f0310 | 118 | } |
jufray | 0:e030be8f0310 | 119 | RGBsens.getRawData(&red, &green, &blue, &clear); |
jufray | 0:e030be8f0310 | 120 | somme = red + green + blue; |
Germaint | 8:cbce19ac54b3 | 121 | pr = red*100/somme; |
Germaint | 8:cbce19ac54b3 | 122 | pg = green*100/somme; |
Germaint | 8:cbce19ac54b3 | 123 | pb = blue*100/somme; |
Germaint | 8:cbce19ac54b3 | 124 | lum = clear; |
jufray | 0:e030be8f0310 | 125 | } |
jufray | 0:e030be8f0310 | 126 | |
Germaint | 8:cbce19ac54b3 | 127 | void sendDataSigfox(void){ |
jufray | 0:e030be8f0310 | 128 | short tempSol_short, tempAir_short; |
Germaint | 8:cbce19ac54b3 | 129 | tempSol_short = (short)(temperature_sol*10); |
Germaint | 8:cbce19ac54b3 | 130 | tempAir_short = (short)(temperature_air*10); |
jufray | 0:e030be8f0310 | 131 | |
Germaint | 8:cbce19ac54b3 | 132 | nucleo.printf("AT$SF=%04x%02x%04x%02x%04x%02x%02x%02x\r\n",tempSol_short, humidity_sol, tempAir_short, humidity_air, lum, pr, pg, pb); |
jufray | 0:e030be8f0310 | 133 | } |
Germaint | 2:0bfe25431e8e | 134 | |
Germaint | 2:0bfe25431e8e | 135 | void oledData(void){ |
Germaint | 2:0bfe25431e8e | 136 | oled.cls(); |
Germaint | 2:0bfe25431e8e | 137 | oled.locate(0,0); |
Germaint | 2:0bfe25431e8e | 138 | oled.printf("AIR T : %.1f", temperature_air); |
Germaint | 2:0bfe25431e8e | 139 | oled.locate(1,0); |
Germaint | 2:0bfe25431e8e | 140 | oled.printf("AIR H : %d", humidity_air); |
Germaint | 2:0bfe25431e8e | 141 | oled.locate(3,0); |
Germaint | 2:0bfe25431e8e | 142 | oled.printf("FLOOR T : %.1f", temperature_sol); |
Germaint | 2:0bfe25431e8e | 143 | oled.locate(4,0); |
Germaint | 2:0bfe25431e8e | 144 | oled.printf("FLOOR H : %d", humidity_sol); |
Germaint | 2:0bfe25431e8e | 145 | oled.locate(6,0); |
Germaint | 2:0bfe25431e8e | 146 | oled.printf("Light : %d", lum); |
Germaint | 2:0bfe25431e8e | 147 | oled.locate(7,0); |
Germaint | 2:0bfe25431e8e | 148 | oled.printf("R %d G %d B %d", pr, pg, pb); |
Germaint | 2:0bfe25431e8e | 149 | |
Germaint | 2:0bfe25431e8e | 150 | oled.redraw(); |
Germaint | 2:0bfe25431e8e | 151 | } |
jufray | 0:e030be8f0310 | 152 | |
Germaint | 7:deb5dbe9e23d | 153 | void readData(void){ |
Germaint | 7:deb5dbe9e23d | 154 | temperature_sol = temp_sol(); |
Germaint | 7:deb5dbe9e23d | 155 | humidity_sol = fct_humidity_sol(); |
Germaint | 7:deb5dbe9e23d | 156 | temperature_air = sht.readTemp(); |
Germaint | 7:deb5dbe9e23d | 157 | humidity_air = sht.readHumidity(); |
Germaint | 8:cbce19ac54b3 | 158 | fct_RGB(); |
Germaint | 7:deb5dbe9e23d | 159 | } |
jufray | 0:e030be8f0310 | 160 | |
Germaint | 7:deb5dbe9e23d | 161 |