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@69:9ad4bce37c63, 2018-10-09 (annotated)
- Committer:
- MathieuM
- Date:
- Tue Oct 09 15:28:58 2018 +0000
- Revision:
- 69:9ad4bce37c63
- Parent:
- 67:3ccbc6a532eb
- Parent:
- 68:26938422fa0c
- Child:
- 71:b31e3ee29dd0
merge changes
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 | |
MathieuM | 0:fa6e7dd26ef2 | 9 | |
MathieuM | 45:60f602ecd59b | 10 | Serial wisol(SERIAL_PORT); |
MathieuM | 49:b1ac7ebb715f | 11 | Serial pc(USBTX, USBRX); |
MathieuM | 46:40b6bbf6167e | 12 | DHT sensor(PIN_NAME, DHTtype); |
SBACCARI | 66:cbfcea17a3c5 | 13 | HP20x_dev barometre(HP20X_I2C_PORT); |
MathieuM | 52:d49b6f468b97 | 14 | HMC5883L hmc5883(HMC5883_I2C_PORT); |
SBACCARI | 67:3ccbc6a532eb | 15 | DS1820 probe(SOIL_T_PIN); |
SBACCARI | 67:3ccbc6a532eb | 16 | AnalogIn humidSensor(SOIL_H_PIN); |
MathieuM | 0:fa6e7dd26ef2 | 17 | |
MathieuM | 0:fa6e7dd26ef2 | 18 | int main() { |
SBACCARI | 67:3ccbc6a532eb | 19 | if(initSoilTemp(probe,PA_5)) |
SBACCARI | 67:3ccbc6a532eb | 20 | pc.printf("unassigned Probe\r\n"); |
SBACCARI | 67:3ccbc6a532eb | 21 | float airValue(AIR_SOIL_HUMIDITY); |
SBACCARI | 67:3ccbc6a532eb | 22 | float waterValue(WATER_SOIL_HUMIDITY); |
MathieuM | 0:fa6e7dd26ef2 | 23 | while(1) { |
SBACCARI | 62:d902b1e77094 | 24 | float airH = 0,airT = 0; |
MathieuM | 52:d49b6f468b97 | 25 | int16_t magXYZ[3]; |
SBACCARI | 66:cbfcea17a3c5 | 26 | long P = 0; |
MathieuM | 33:2a6476c33e74 | 27 | /* |
MathieuM | 33:2a6476c33e74 | 28 | read T&H air |
MathieuM | 33:2a6476c33e74 | 29 | read T sol |
MathieuM | 33:2a6476c33e74 | 30 | read H sol |
MathieuM | 33:2a6476c33e74 | 31 | read Pressure |
MathieuM | 33:2a6476c33e74 | 32 | read Magnetic |
MathieuM | 33:2a6476c33e74 | 33 | |
MathieuM | 33:2a6476c33e74 | 34 | m = genMessage(T_air, H_air, T_sol, H_sol, Pressure, Mag) |
MathieuM | 33:2a6476c33e74 | 35 | sendMessage(m) |
SBACCARI | 54:61d003e0754d | 36 | |
SBACCARI | 54:61d003e0754d | 37 | airH = airHumidity(sensor); |
SBACCARI | 54:61d003e0754d | 38 | airT = airTemperature(sensor); |
SBACCARI | 54:61d003e0754d | 39 | message = genMessage(airT, airH); |
SBACCARI | 54:61d003e0754d | 40 | wisol.printf("AT$SF=%s\r\n", message); |
MathieuM | 33:2a6476c33e74 | 41 | */ |
SBACCARI | 54:61d003e0754d | 42 | |
SBACCARI | 54:61d003e0754d | 43 | //collect data |
MathieuM | 52:d49b6f468b97 | 44 | hmc5883.getXYZ(magXYZ); |
SBACCARI | 65:3f898ad77cb5 | 45 | get_T_H_air(&airT, &airH, sensor); // takes 2s to execute |
SBACCARI | 67:3ccbc6a532eb | 46 | P = pression(&barometre); |
SBACCARI | 67:3ccbc6a532eb | 47 | float soilH = getSoilHumidity( humidSensor, airValue,waterValue, true); |
SBACCARI | 67:3ccbc6a532eb | 48 | float soilT = getSoilTemperature(probe); |
SBACCARI | 67:3ccbc6a532eb | 49 | |
SBACCARI | 67:3ccbc6a532eb | 50 | if(soilT == DS1820::invalid_conversion) |
SBACCARI | 67:3ccbc6a532eb | 51 | pc.printf("Error with soil temperature probe : not connected\n\r"); |
MathieuM | 55:887edb961698 | 52 | |
MathieuM | 55:887edb961698 | 53 | // Display |
MathieuM | 55:887edb961698 | 54 | pc.printf("\n=====| Data |=====\n"); |
SBACCARI | 67:3ccbc6a532eb | 55 | pc.printf("H air : %.2f %%\r\n", airH); |
SBACCARI | 67:3ccbc6a532eb | 56 | pc.printf("T air : %.2f oC\r\n", airT); |
SBACCARI | 67:3ccbc6a532eb | 57 | pc.printf("H soil : %.2f %%\r\n", soilH); |
SBACCARI | 67:3ccbc6a532eb | 58 | pc.printf("T soil : %.2f oC\r\n", soilT); |
SBACCARI | 67:3ccbc6a532eb | 59 | pc.printf("Pression : %lu m\n", P); |
MathieuM | 52:d49b6f468b97 | 60 | pc.printf("Mag : X:%d ; Y:%d ; Z:%d\n", magXYZ[0], magXYZ[1], magXYZ[2]); |
MathieuM | 53:a0752606d02c | 61 | wait(5); |
MathieuM | 0:fa6e7dd26ef2 | 62 | } |
MathieuM | 0:fa6e7dd26ef2 | 63 | } |