Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HP206C mbed HMC5883L DHT DS1820
main.cpp@77:67faccef7f14, 2018-12-04 (annotated)
- Committer:
- MathieuM
- Date:
- Tue Dec 04 13:12:52 2018 +0000
- Revision:
- 77:67faccef7f14
- Parent:
- 76:04941d128fff
- Child:
- 78:ab7595f2133b
WIP
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| MathieuM | 0:fa6e7dd26ef2 | 1 | #include "mbed.h" |
| MathieuM | 45:60f602ecd59b | 2 | #include "config.h" |
| MathieuM | 45:60f602ecd59b | 3 | #include "communication.h" |
| MathieuM | 46:40b6bbf6167e | 4 | #include "T_H_air.h" |
| SBACCARI | 67:3ccbc6a532eb | 5 | #include "T_H_soil.h" |
| MathieuM | 49:b1ac7ebb715f | 6 | #include "altitude.h" |
| MathieuM | 52:d49b6f468b97 | 7 | #include "HMC5883L.h" |
| MathieuM | 49:b1ac7ebb715f | 8 | |
| Fayge | 73:bc3b0ee46dfc | 9 | DS1820 probe(SOIL_T_PIN); |
| Fayge | 73:bc3b0ee46dfc | 10 | AnalogIn humidSensor(SOIL_H_PIN); |
| MathieuM | 45:60f602ecd59b | 11 | Serial wisol(SERIAL_PORT); |
| MathieuM | 49:b1ac7ebb715f | 12 | Serial pc(USBTX, USBRX); |
| MathieuM | 46:40b6bbf6167e | 13 | DHT sensor(PIN_NAME, DHTtype); |
| SBACCARI | 66:cbfcea17a3c5 | 14 | HP20x_dev barometre(HP20X_I2C_PORT); |
| MathieuM | 52:d49b6f468b97 | 15 | HMC5883L hmc5883(HMC5883_I2C_PORT); |
| MathieuM | 0:fa6e7dd26ef2 | 16 | |
| SBACCARI | 72:f678052af558 | 17 | int main() |
| SBACCARI | 72:f678052af558 | 18 | { |
| SBACCARI | 72:f678052af558 | 19 | float airH = 0,airT = 0, solT = 0, solH = 0;; |
| SBACCARI | 72:f678052af558 | 20 | long P = 0; |
| SBACCARI | 72:f678052af558 | 21 | float airValue(AIR_SOIL_HUMIDITY); |
| SBACCARI | 72:f678052af558 | 22 | float waterValue(WATER_SOIL_HUMIDITY); |
| Fayge | 73:bc3b0ee46dfc | 23 | char* msg; |
| SBACCARI | 72:f678052af558 | 24 | |
| SBACCARI | 72:f678052af558 | 25 | |
| Fayge | 73:bc3b0ee46dfc | 26 | if(initSoilTemp(probe,SOIL_T_PIN)) { |
| SBACCARI | 72:f678052af558 | 27 | pc.printf("unassigned Probe\r\n"); |
| SBACCARI | 72:f678052af558 | 28 | } |
| SBACCARI | 70:1e2e21c377ed | 29 | barometre.reset(); |
| MathieuM | 0:fa6e7dd26ef2 | 30 | while(1) { |
| SBACCARI | 72:f678052af558 | 31 | float temp = 0; |
| MathieuM | 52:d49b6f468b97 | 32 | int16_t magXYZ[3]; |
| SBACCARI | 54:61d003e0754d | 33 | //collect data |
| MathieuM | 52:d49b6f468b97 | 34 | hmc5883.getXYZ(magXYZ); |
| SBACCARI | 65:3f898ad77cb5 | 35 | get_T_H_air(&airT, &airH, sensor); // takes 2s to execute |
| SBACCARI | 72:f678052af558 | 36 | P = pression(&barometre); // takes 5s to execute |
| SBACCARI | 72:f678052af558 | 37 | temp = getSoilTemperature(probe); |
| SBACCARI | 72:f678052af558 | 38 | if(temp == DS1820::invalid_conversion) { |
| SBACCARI | 72:f678052af558 | 39 | pc.printf("Error with soil temperature probe : not connected\n\r"); |
| SBACCARI | 72:f678052af558 | 40 | } |
| SBACCARI | 72:f678052af558 | 41 | else{ |
| SBACCARI | 72:f678052af558 | 42 | solT = temp; |
| SBACCARI | 72:f678052af558 | 43 | } |
| MathieuM | 77:67faccef7f14 | 44 | solH = getSoilHumidity( humidSensor, airValue,waterValue, true); |
| Fayge | 73:bc3b0ee46dfc | 45 | |
| Fayge | 73:bc3b0ee46dfc | 46 | msg = genMessage( solH, airH, solT, airT, P,magXYZ); |
| MathieuM | 55:887edb961698 | 47 | // Display |
| Fayge | 73:bc3b0ee46dfc | 48 | pc.printf("\n\r=====| Data |=====\n\r"); |
| Fayge | 73:bc3b0ee46dfc | 49 | pc.printf("H sol : %.2f %%\r\n", solH); |
| SBACCARI | 67:3ccbc6a532eb | 50 | pc.printf("H air : %.2f %%\r\n", airH); |
| SBACCARI | 72:f678052af558 | 51 | pc.printf("T sol : %.2f C\r\n", solT); |
| Fayge | 73:bc3b0ee46dfc | 52 | pc.printf("T air : %.2f C\r\n", airT); |
| Fayge | 73:bc3b0ee46dfc | 53 | pc.printf("Mag : X:%d ; Y:%d ; Z:%d\n\r", magXYZ[0], magXYZ[1], magXYZ[2]); |
| MathieuM | 76:04941d128fff | 54 | pc.printf("Pression : %u Pa\r\n", P); |
| MathieuM | 76:04941d128fff | 55 | pc.printf("AT$SF=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\r\n", msg[0], msg[1], msg[2], msg[3], msg[4], msg[5], msg[6], msg[7], msg[8], msg[9], msg[10], msg[11]); |
| MathieuM | 77:67faccef7f14 | 56 | //wisol.printf("AT$SF=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\r\n", msg[0], msg[1], msg[2], msg[3], msg[4], msg[5], msg[6], msg[7], msg[8], msg[9], msg[10], msg[11]); |
| Fayge | 73:bc3b0ee46dfc | 57 | pc.printf("\n\r"); |
| MathieuM | 77:67faccef7f14 | 58 | free(msg); |
| MathieuM | 77:67faccef7f14 | 59 | msg = NULL; |
| MathieuM | 77:67faccef7f14 | 60 | wait(3); |
| MathieuM | 77:67faccef7f14 | 61 | //wait(WAIT_TIME - 7); |
| MathieuM | 77:67faccef7f14 | 62 | //comment |
| MathieuM | 0:fa6e7dd26ef2 | 63 | } |
| MathieuM | 0:fa6e7dd26ef2 | 64 | } |
