Sigfox project
Dependencies: mbed TCS34725 WakeUp DHT TSL2561_I2C DS1820
main.cpp@5:59c1c70635c3, 2020-01-20 (annotated)
- Committer:
- ran_ghe
- Date:
- Mon Jan 20 12:41:12 2020 +0000
- Revision:
- 5:59c1c70635c3
- Parent:
- 4:0b63b5897827
final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
youdllo5 | 0:cfed96a14467 | 1 | #include "mbed.h" |
ran_ghe | 1:07835f780c89 | 2 | #include "DS1820.h" |
youdllo5 | 0:cfed96a14467 | 3 | #include "DHT.h" |
ran_ghe | 3:a5b1e083ffd2 | 4 | #include "TSL2561_I2C.h" |
ran_ghe | 3:a5b1e083ffd2 | 5 | #include "Adafruit_TCS34725.h" |
ran_ghe | 4:0b63b5897827 | 6 | #include "WakeUp.h" |
ran_ghe | 3:a5b1e083ffd2 | 7 | #define commonAnode true |
youdllo5 | 0:cfed96a14467 | 8 | |
ran_ghe | 3:a5b1e083ffd2 | 9 | |
ran_ghe | 3:a5b1e083ffd2 | 10 | Serial wisol(D1, D0); // tx, rx |
ran_ghe | 5:59c1c70635c3 | 11 | |
ran_ghe | 5:59c1c70635c3 | 12 | //debug |
youdllo5 | 0:cfed96a14467 | 13 | Serial pc(USBTX, USBRX); |
ran_ghe | 3:a5b1e083ffd2 | 14 | |
ran_ghe | 3:a5b1e083ffd2 | 15 | //tempAir et humAir |
ran_ghe | 4:0b63b5897827 | 16 | DHT dht(D9, 22); |
ran_ghe | 3:a5b1e083ffd2 | 17 | |
ran_ghe | 3:a5b1e083ffd2 | 18 | |
ran_ghe | 5:59c1c70635c3 | 19 | //RGB + luminosite |
ran_ghe | 3:a5b1e083ffd2 | 20 | I2C i2c(PB_7, PB_6); |
ran_ghe | 3:a5b1e083ffd2 | 21 | Adafruit_TCS34725 tcs = Adafruit_TCS34725(&i2c, TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X); |
ran_ghe | 3:a5b1e083ffd2 | 22 | |
ran_ghe | 4:0b63b5897827 | 23 | //tempSol |
ran_ghe | 4:0b63b5897827 | 24 | DS1820 temp_sol(A4); |
ran_ghe | 3:a5b1e083ffd2 | 25 | |
ran_ghe | 3:a5b1e083ffd2 | 26 | //humSol |
ran_ghe | 3:a5b1e083ffd2 | 27 | AnalogIn ain(A3); |
youdllo5 | 0:cfed96a14467 | 28 | |
youdllo5 | 0:cfed96a14467 | 29 | int main(){ |
youdllo5 | 0:cfed96a14467 | 30 | |
ran_ghe | 4:0b63b5897827 | 31 | //WakeUp::calibrate(); |
ran_ghe | 4:0b63b5897827 | 32 | |
ran_ghe | 4:0b63b5897827 | 33 | |
ran_ghe | 3:a5b1e083ffd2 | 34 | //DHT22 |
youdllo5 | 0:cfed96a14467 | 35 | int data; |
ran_ghe | 3:a5b1e083ffd2 | 36 | float tempAir, humAir; |
youdllo5 | 0:cfed96a14467 | 37 | |
ran_ghe | 5:59c1c70635c3 | 38 | //humiditeSol |
ran_ghe | 5:59c1c70635c3 | 39 | int hum_sol; |
ran_ghe | 5:59c1c70635c3 | 40 | |
ran_ghe | 5:59c1c70635c3 | 41 | //luminosite |
ran_ghe | 5:59c1c70635c3 | 42 | float lux; |
ran_ghe | 5:59c1c70635c3 | 43 | |
ran_ghe | 3:a5b1e083ffd2 | 44 | //temp_sol |
ran_ghe | 4:0b63b5897827 | 45 | if(temp_sol.unassignedProbe(A4)) |
ran_ghe | 1:07835f780c89 | 46 | { |
ran_ghe | 1:07835f780c89 | 47 | pc.printf("error temperature_sol"); |
ran_ghe | 1:07835f780c89 | 48 | } |
ran_ghe | 1:07835f780c89 | 49 | |
ran_ghe | 5:59c1c70635c3 | 50 | //capteur RGB/luminosite |
ran_ghe | 3:a5b1e083ffd2 | 51 | if(!tcs.begin()) |
ran_ghe | 3:a5b1e083ffd2 | 52 | { |
ran_ghe | 3:a5b1e083ffd2 | 53 | pc.printf("No TCS34725 found ... check your connections"); |
ran_ghe | 3:a5b1e083ffd2 | 54 | } |
ran_ghe | 3:a5b1e083ffd2 | 55 | |
youdllo5 | 0:cfed96a14467 | 56 | while(1){ |
ran_ghe | 1:07835f780c89 | 57 | //Capteur air |
ran_ghe | 3:a5b1e083ffd2 | 58 | data = dht.readData(); |
ran_ghe | 3:a5b1e083ffd2 | 59 | humAir = dht.ReadHumidity(); |
ran_ghe | 3:a5b1e083ffd2 | 60 | tempAir = dht.ReadTemperature(CELCIUS); |
ran_ghe | 3:a5b1e083ffd2 | 61 | pc.printf("tempAir = %1.f, humAir = %1.f\n", tempAir, humAir); |
ran_ghe | 4:0b63b5897827 | 62 | |
ran_ghe | 1:07835f780c89 | 63 | |
Mohamed_Sadialiou | 2:e153d5219f93 | 64 | //capteur humidite sol |
Mohamed_Sadialiou | 2:e153d5219f93 | 65 | hum_sol = (int)(((0.78 - ain.read())*100)/0.38); |
ran_ghe | 3:a5b1e083ffd2 | 66 | pc.printf ("humSol = %d%\n", hum_sol); |
Mohamed_Sadialiou | 2:e153d5219f93 | 67 | |
ran_ghe | 1:07835f780c89 | 68 | //Capteur temperature sol |
ran_ghe | 1:07835f780c89 | 69 | temp_sol.convertTemperature(true, DS1820::all_devices); |
ran_ghe | 3:a5b1e083ffd2 | 70 | pc.printf("tempSol : %.1f\n", temp_sol.temperature()); |
ran_ghe | 3:a5b1e083ffd2 | 71 | |
ran_ghe | 3:a5b1e083ffd2 | 72 | |
ran_ghe | 3:a5b1e083ffd2 | 73 | |
ran_ghe | 3:a5b1e083ffd2 | 74 | /////////////// |
ran_ghe | 5:59c1c70635c3 | 75 | //////RGB////// |
ran_ghe | 3:a5b1e083ffd2 | 76 | /////////////// |
ran_ghe | 3:a5b1e083ffd2 | 77 | |
ran_ghe | 3:a5b1e083ffd2 | 78 | uint16_t clear, red, green, blue; |
ran_ghe | 3:a5b1e083ffd2 | 79 | tcs.setInterrupt(false); // turn on LED |
ran_ghe | 3:a5b1e083ffd2 | 80 | tcs.getRawData(&red, &green, &blue, &clear); |
ran_ghe | 3:a5b1e083ffd2 | 81 | tcs.setInterrupt(true); // turn off LED |
ran_ghe | 3:a5b1e083ffd2 | 82 | //pc.printf("clear = %d, red = %d, green = %d, blue = %d\r\n", clear, red, green, blue); |
ran_ghe | 3:a5b1e083ffd2 | 83 | |
ran_ghe | 5:59c1c70635c3 | 84 | //get hexa value |
ran_ghe | 3:a5b1e083ffd2 | 85 | uint32_t sum = clear; |
ran_ghe | 3:a5b1e083ffd2 | 86 | float r, g, b; |
ran_ghe | 3:a5b1e083ffd2 | 87 | r = red; r /= sum; |
ran_ghe | 3:a5b1e083ffd2 | 88 | g = green; g /= sum; |
ran_ghe | 3:a5b1e083ffd2 | 89 | b = blue; b /= sum; |
ran_ghe | 3:a5b1e083ffd2 | 90 | r *= 256; g *= 256; b *= 256; |
ran_ghe | 3:a5b1e083ffd2 | 91 | pc.printf("clear = %d, red = %d, green = %d, blue = %d\r\n\n", clear, (int)r, (int)g, (int)b); |
ran_ghe | 3:a5b1e083ffd2 | 92 | |
ran_ghe | 4:0b63b5897827 | 93 | |
ran_ghe | 4:0b63b5897827 | 94 | |
ran_ghe | 4:0b63b5897827 | 95 | |
ran_ghe | 4:0b63b5897827 | 96 | //luminosite |
ran_ghe | 4:0b63b5897827 | 97 | lux = (int)tcs.calculateLux(red,green,blue); |
ran_ghe | 4:0b63b5897827 | 98 | pc.printf("lux = %d\n", (int)lux); |
ran_ghe | 4:0b63b5897827 | 99 | |
ran_ghe | 4:0b63b5897827 | 100 | |
ran_ghe | 4:0b63b5897827 | 101 | wisol.printf("AT$SF=%06X%02X%02X%02X%04X%02X%04X%02X\r\n", (int)lux, (int)r, (int)g, (int)b, (int)(10 * temp_sol.temperature()), (int)(hum_sol), (int)(10 * tempAir), (int)(humAir)); |
ran_ghe | 4:0b63b5897827 | 102 | |
ran_ghe | 5:59c1c70635c3 | 103 | |
ran_ghe | 3:a5b1e083ffd2 | 104 | //lux : 3 octets |
ran_ghe | 3:a5b1e083ffd2 | 105 | //r, g, b : 1 octet |
ran_ghe | 3:a5b1e083ffd2 | 106 | //tempSol, tempAir : 2 octets |
ran_ghe | 3:a5b1e083ffd2 | 107 | //humSol, humAir : 1 octet |
ran_ghe | 3:a5b1e083ffd2 | 108 | |
ran_ghe | 4:0b63b5897827 | 109 | wait(10); |
ran_ghe | 4:0b63b5897827 | 110 | |
ran_ghe | 5:59c1c70635c3 | 111 | //Set wakeup time for 600 seconds = 10min |
ran_ghe | 5:59c1c70635c3 | 112 | WakeUp::set_ms(600000); |
ran_ghe | 4:0b63b5897827 | 113 | deepsleep(); |
ran_ghe | 4:0b63b5897827 | 114 | wait(1); |
youdllo5 | 0:cfed96a14467 | 115 | |
youdllo5 | 0:cfed96a14467 | 116 | } |
youdllo5 | 0:cfed96a14467 | 117 | } |