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