![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Plant Monitoring Project
Dependencies: mbed SHT21_ncleee WakeUp SSD1306 DHT Adafruit_TCS34725 DS1820
main.cpp@7:deb5dbe9e23d, 2019-10-08 (annotated)
- Committer:
- Germaint
- Date:
- Tue Oct 08 18:22:15 2019 +0000
- Revision:
- 7:deb5dbe9e23d
- Parent:
- 6:cd98294b2e5e
- Child:
- 8:cbce19ac54b3
there has been a prolem while commiting your project mbed
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 | 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); |
Germaint | 7:deb5dbe9e23d | 38 | void readData(void); |
jufray | 0:e030be8f0310 | 39 | |
Germaint | 1:3fc11a745984 | 40 | |
Germaint | 1:3fc11a745984 | 41 | float temperature_sol; |
Germaint | 1:3fc11a745984 | 42 | unsigned char humidity_sol; |
Germaint | 1:3fc11a745984 | 43 | float temperature_air; |
Germaint | 1:3fc11a745984 | 44 | unsigned char humidity_air; |
jufray | 0:e030be8f0310 | 45 | unsigned char pr, pg, pb; |
jufray | 0:e030be8f0310 | 46 | unsigned short lum; |
jufray | 0:e030be8f0310 | 47 | |
jufray | 0:e030be8f0310 | 48 | |
Germaint | 1:3fc11a745984 | 49 | int main() { |
Germaint | 7:deb5dbe9e23d | 50 | // Initialisation de l'écran |
Germaint | 7:deb5dbe9e23d | 51 | oled.speed (SSD1306::Medium); |
Germaint | 7:deb5dbe9e23d | 52 | oled.init(); |
Germaint | 7:deb5dbe9e23d | 53 | oled.cls(); |
Germaint | 2:0bfe25431e8e | 54 | oled.set_contrast(200); |
Germaint | 7:deb5dbe9e23d | 55 | |
Germaint | 7:deb5dbe9e23d | 56 | // Initialisation WakeUp |
Germaint | 7:deb5dbe9e23d | 57 | //WakeUp::calibrate(); |
Germaint | 7:deb5dbe9e23d | 58 | //WakeUp::set(10); // Durée entre deux envois à modifier |
Germaint | 7:deb5dbe9e23d | 59 | //WakeUp::attach(&readData); |
Germaint | 1:3fc11a745984 | 60 | |
jufray | 0:e030be8f0310 | 61 | while(1) { |
jufray | 0:e030be8f0310 | 62 | |
Germaint | 7:deb5dbe9e23d | 63 | // Mesures des grandeurs physiques |
Germaint | 7:deb5dbe9e23d | 64 | readData(); |
Germaint | 7:deb5dbe9e23d | 65 | |
Germaint | 7:deb5dbe9e23d | 66 | // Affichage des données sur l'écran |
Germaint | 7:deb5dbe9e23d | 67 | oledData(); |
jufray | 0:e030be8f0310 | 68 | |
Germaint | 7:deb5dbe9e23d | 69 | // Envoi des données sur le cloud |
Germaint | 1:3fc11a745984 | 70 | sendDataSigfox(temperature_sol, &humidity_sol, temperature_air, &humidity_air, &lum, &pr, &pg, &pb); |
jufray | 0:e030be8f0310 | 71 | |
Germaint | 2:0bfe25431e8e | 72 | wait(10); |
jufray | 0:e030be8f0310 | 73 | } |
jufray | 0:e030be8f0310 | 74 | } |
jufray | 0:e030be8f0310 | 75 | |
jufray | 0:e030be8f0310 | 76 | |
jufray | 0:e030be8f0310 | 77 | float temp_sol() |
jufray | 0:e030be8f0310 | 78 | { |
jufray | 0:e030be8f0310 | 79 | DS.convertTemperature(true, DS1820::all_devices); |
jufray | 0:e030be8f0310 | 80 | if (DS.unassignedProbe(D3)){ |
Germaint | 2:0bfe25431e8e | 81 | //pc.printf( "D3 not assigned\n\r"); |
jufray | 0:e030be8f0310 | 82 | } |
jufray | 0:e030be8f0310 | 83 | return DS.temperature(); |
jufray | 0:e030be8f0310 | 84 | } |
jufray | 0:e030be8f0310 | 85 | |
Germaint | 1:3fc11a745984 | 86 | int fct_humidity_sol(void) |
jufray | 0:e030be8f0310 | 87 | { |
jufray | 0:e030be8f0310 | 88 | float val_min = 0.377; |
jufray | 0:e030be8f0310 | 89 | float val_max = 0.772; |
jufray | 0:e030be8f0310 | 90 | float mesure, mesure_etalonnee; |
Germaint | 1:3fc11a745984 | 91 | mesure = capteur_humidity_sol.read(); |
jufray | 0:e030be8f0310 | 92 | mesure_etalonnee = (1-((mesure - val_min)/(val_max - val_min)))*100; |
jufray | 0:e030be8f0310 | 93 | return (int) mesure_etalonnee; |
jufray | 0:e030be8f0310 | 94 | } |
jufray | 0:e030be8f0310 | 95 | |
Germaint | 3:fc704c1d3087 | 96 | void fct_RGB(unsigned char *pr, unsigned char *pg, unsigned char *pb, unsigned short *lux) |
jufray | 0:e030be8f0310 | 97 | { |
jufray | 0:e030be8f0310 | 98 | int somme; |
jufray | 0:e030be8f0310 | 99 | uint16_t clear, red, green, blue; |
jufray | 0:e030be8f0310 | 100 | if (!RGBsens.begin()) |
jufray | 0:e030be8f0310 | 101 | { |
Germaint | 2:0bfe25431e8e | 102 | //pc.printf("No TCS34725 found ... check your connections"); |
jufray | 0:e030be8f0310 | 103 | while (1); // halt! |
jufray | 0:e030be8f0310 | 104 | } |
jufray | 0:e030be8f0310 | 105 | RGBsens.getRawData(&red, &green, &blue, &clear); |
jufray | 0:e030be8f0310 | 106 | somme = red + green + blue; |
jufray | 0:e030be8f0310 | 107 | *pr = red*100/somme; |
jufray | 0:e030be8f0310 | 108 | *pg = green*100/somme; |
jufray | 0:e030be8f0310 | 109 | *pb = blue*100/somme; |
Germaint | 3:fc704c1d3087 | 110 | *lux = clear; |
jufray | 0:e030be8f0310 | 111 | } |
jufray | 0:e030be8f0310 | 112 | |
jufray | 0:e030be8f0310 | 113 | 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 | 114 | short tempSol_short, tempAir_short; |
jufray | 0:e030be8f0310 | 115 | tempSol *= 10; |
jufray | 0:e030be8f0310 | 116 | tempAir *= 10; |
jufray | 0:e030be8f0310 | 117 | tempSol_short = (short) tempSol; |
jufray | 0:e030be8f0310 | 118 | tempAir_short = (short) tempAir; |
jufray | 0:e030be8f0310 | 119 | |
jufray | 0:e030be8f0310 | 120 | 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 | 121 | } |
Germaint | 2:0bfe25431e8e | 122 | |
Germaint | 2:0bfe25431e8e | 123 | void oledData(void){ |
Germaint | 2:0bfe25431e8e | 124 | oled.cls(); |
Germaint | 2:0bfe25431e8e | 125 | oled.locate(0,0); |
Germaint | 2:0bfe25431e8e | 126 | oled.printf("AIR T : %.1f", temperature_air); |
Germaint | 2:0bfe25431e8e | 127 | oled.locate(1,0); |
Germaint | 2:0bfe25431e8e | 128 | oled.printf("AIR H : %d", humidity_air); |
Germaint | 2:0bfe25431e8e | 129 | oled.locate(3,0); |
Germaint | 2:0bfe25431e8e | 130 | oled.printf("FLOOR T : %.1f", temperature_sol); |
Germaint | 2:0bfe25431e8e | 131 | oled.locate(4,0); |
Germaint | 2:0bfe25431e8e | 132 | oled.printf("FLOOR H : %d", humidity_sol); |
Germaint | 2:0bfe25431e8e | 133 | oled.locate(6,0); |
Germaint | 2:0bfe25431e8e | 134 | oled.printf("Light : %d", lum); |
Germaint | 2:0bfe25431e8e | 135 | oled.locate(7,0); |
Germaint | 2:0bfe25431e8e | 136 | oled.printf("R %d G %d B %d", pr, pg, pb); |
Germaint | 2:0bfe25431e8e | 137 | |
Germaint | 2:0bfe25431e8e | 138 | oled.redraw(); |
Germaint | 2:0bfe25431e8e | 139 | } |
jufray | 0:e030be8f0310 | 140 | |
Germaint | 7:deb5dbe9e23d | 141 | void readData(void){ |
Germaint | 7:deb5dbe9e23d | 142 | temperature_sol = temp_sol(); |
Germaint | 7:deb5dbe9e23d | 143 | humidity_sol = fct_humidity_sol(); |
Germaint | 7:deb5dbe9e23d | 144 | temperature_air = sht.readTemp(); |
Germaint | 7:deb5dbe9e23d | 145 | humidity_air = sht.readHumidity(); |
Germaint | 7:deb5dbe9e23d | 146 | fct_RGB(&pr, &pg, &pb, &lum); |
Germaint | 7:deb5dbe9e23d | 147 | } |
jufray | 0:e030be8f0310 | 148 | |
Germaint | 7:deb5dbe9e23d | 149 |