Sigfox project

Dependencies:   mbed TCS34725 WakeUp DHT TSL2561_I2C DS1820

Committer:
ran_ghe
Date:
Mon Jan 20 12:30:17 2020 +0000
Revision:
4:0b63b5897827
Parent:
3:a5b1e083ffd2
Child:
5:59c1c70635c3
final code

Who changed what in which revision?

UserRevisionLine numberNew 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
youdllo5 0:cfed96a14467 11 Serial pc(USBTX, USBRX);
ran_ghe 3:a5b1e083ffd2 12
ran_ghe 3:a5b1e083ffd2 13 //tempAir et humAir
ran_ghe 4:0b63b5897827 14 DHT dht(D9, 22);
ran_ghe 3:a5b1e083ffd2 15
ran_ghe 3:a5b1e083ffd2 16
ran_ghe 3:a5b1e083ffd2 17 //RGB
ran_ghe 3:a5b1e083ffd2 18 I2C i2c(PB_7, PB_6);
ran_ghe 3:a5b1e083ffd2 19 Adafruit_TCS34725 tcs = Adafruit_TCS34725(&i2c, TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
ran_ghe 3:a5b1e083ffd2 20
ran_ghe 4:0b63b5897827 21 //tempSol
ran_ghe 4:0b63b5897827 22 DS1820 temp_sol(A4);
ran_ghe 3:a5b1e083ffd2 23
ran_ghe 3:a5b1e083ffd2 24
ran_ghe 3:a5b1e083ffd2 25 //luminosite
ran_ghe 4:0b63b5897827 26 //TSL2561_I2C lum (PB_4, PA_7);
ran_ghe 3:a5b1e083ffd2 27
ran_ghe 3:a5b1e083ffd2 28
ran_ghe 3:a5b1e083ffd2 29 //humSol
ran_ghe 3:a5b1e083ffd2 30 AnalogIn ain(A3);
youdllo5 0:cfed96a14467 31
youdllo5 0:cfed96a14467 32 int main(){
youdllo5 0:cfed96a14467 33
ran_ghe 4:0b63b5897827 34 //WakeUp::calibrate();
ran_ghe 4:0b63b5897827 35
ran_ghe 4:0b63b5897827 36
ran_ghe 3:a5b1e083ffd2 37 //DHT22
youdllo5 0:cfed96a14467 38 int data;
ran_ghe 3:a5b1e083ffd2 39 float tempAir, humAir;
youdllo5 0:cfed96a14467 40
ran_ghe 3:a5b1e083ffd2 41 //temp_sol
ran_ghe 4:0b63b5897827 42 if(temp_sol.unassignedProbe(A4))
ran_ghe 1:07835f780c89 43 {
ran_ghe 1:07835f780c89 44 pc.printf("error temperature_sol");
ran_ghe 1:07835f780c89 45 }
ran_ghe 1:07835f780c89 46
ran_ghe 3:a5b1e083ffd2 47
ran_ghe 3:a5b1e083ffd2 48 //humiditeSol
ran_ghe 3:a5b1e083ffd2 49 int hum_sol;
ran_ghe 3:a5b1e083ffd2 50
ran_ghe 3:a5b1e083ffd2 51 //luminosite
ran_ghe 3:a5b1e083ffd2 52 float lux;
ran_ghe 4:0b63b5897827 53 /*if(!lum.enablePower())
ran_ghe 3:a5b1e083ffd2 54 {
ran_ghe 3:a5b1e083ffd2 55 pc.printf("error luminosite");
ran_ghe 4:0b63b5897827 56 }*/
ran_ghe 3:a5b1e083ffd2 57
ran_ghe 3:a5b1e083ffd2 58
ran_ghe 3:a5b1e083ffd2 59
ran_ghe 3:a5b1e083ffd2 60 /////////////////////////////////////////
ran_ghe 3:a5b1e083ffd2 61 ////////////////////RGB//////////////////
ran_ghe 3:a5b1e083ffd2 62 /////////////////////////////////////////
ran_ghe 3:a5b1e083ffd2 63
ran_ghe 4:0b63b5897827 64 //char gammatable[256];
ran_ghe 3:a5b1e083ffd2 65 if(!tcs.begin())
ran_ghe 3:a5b1e083ffd2 66 {
ran_ghe 3:a5b1e083ffd2 67 pc.printf("No TCS34725 found ... check your connections");
ran_ghe 3:a5b1e083ffd2 68 }
ran_ghe 3:a5b1e083ffd2 69
youdllo5 0:cfed96a14467 70 while(1){
ran_ghe 1:07835f780c89 71 //Capteur air
ran_ghe 3:a5b1e083ffd2 72 data = dht.readData();
ran_ghe 3:a5b1e083ffd2 73 humAir = dht.ReadHumidity();
ran_ghe 3:a5b1e083ffd2 74 tempAir = dht.ReadTemperature(CELCIUS);
ran_ghe 3:a5b1e083ffd2 75 pc.printf("tempAir = %1.f, humAir = %1.f\n", tempAir, humAir);
ran_ghe 4:0b63b5897827 76
ran_ghe 1:07835f780c89 77
Mohamed_Sadialiou 2:e153d5219f93 78 //capteur humidite sol
Mohamed_Sadialiou 2:e153d5219f93 79 hum_sol = (int)(((0.78 - ain.read())*100)/0.38);
ran_ghe 3:a5b1e083ffd2 80 pc.printf ("humSol = %d%\n", hum_sol);
Mohamed_Sadialiou 2:e153d5219f93 81
ran_ghe 1:07835f780c89 82 //Capteur temperature sol
ran_ghe 1:07835f780c89 83 temp_sol.convertTemperature(true, DS1820::all_devices);
ran_ghe 3:a5b1e083ffd2 84 pc.printf("tempSol : %.1f\n", temp_sol.temperature());
ran_ghe 3:a5b1e083ffd2 85
ran_ghe 3:a5b1e083ffd2 86
ran_ghe 3:a5b1e083ffd2 87
ran_ghe 3:a5b1e083ffd2 88 ///////////////
ran_ghe 3:a5b1e083ffd2 89 //Capteur RGB//
ran_ghe 3:a5b1e083ffd2 90 ///////////////
ran_ghe 3:a5b1e083ffd2 91
ran_ghe 3:a5b1e083ffd2 92 uint16_t clear, red, green, blue;
ran_ghe 3:a5b1e083ffd2 93 tcs.setInterrupt(false); // turn on LED
ran_ghe 3:a5b1e083ffd2 94 tcs.getRawData(&red, &green, &blue, &clear);
ran_ghe 3:a5b1e083ffd2 95 tcs.setInterrupt(true); // turn off LED
ran_ghe 3:a5b1e083ffd2 96 //pc.printf("clear = %d, red = %d, green = %d, blue = %d\r\n", clear, red, green, blue);
ran_ghe 3:a5b1e083ffd2 97
ran_ghe 3:a5b1e083ffd2 98 //obtenir valeur en hexa
ran_ghe 3:a5b1e083ffd2 99 uint32_t sum = clear;
ran_ghe 3:a5b1e083ffd2 100 float r, g, b;
ran_ghe 3:a5b1e083ffd2 101 r = red; r /= sum;
ran_ghe 3:a5b1e083ffd2 102 g = green; g /= sum;
ran_ghe 3:a5b1e083ffd2 103 b = blue; b /= sum;
ran_ghe 3:a5b1e083ffd2 104 r *= 256; g *= 256; b *= 256;
ran_ghe 3:a5b1e083ffd2 105 pc.printf("clear = %d, red = %d, green = %d, blue = %d\r\n\n", clear, (int)r, (int)g, (int)b);
ran_ghe 3:a5b1e083ffd2 106
ran_ghe 4:0b63b5897827 107
ran_ghe 4:0b63b5897827 108
ran_ghe 4:0b63b5897827 109
ran_ghe 4:0b63b5897827 110 //luminosite
ran_ghe 4:0b63b5897827 111 //lux = lum.getLux();
ran_ghe 4:0b63b5897827 112 lux = (int)tcs.calculateLux(red,green,blue);
ran_ghe 4:0b63b5897827 113 pc.printf("lux = %d\n", (int)lux);
ran_ghe 4:0b63b5897827 114
ran_ghe 4:0b63b5897827 115
ran_ghe 4:0b63b5897827 116 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 117
ran_ghe 4:0b63b5897827 118 //wisol.printf("AT$SF=%06X%02X%02X%02X%04X%02X%04X%02X\r\n", (int)lux, (int)r, (int)g, (int)b, temp_solT, (int)(hum_sol*10), (int)(tempAir*10), (int)(humAir*10));
ran_ghe 3:a5b1e083ffd2 119 //lux : 3 octets
ran_ghe 3:a5b1e083ffd2 120 //r, g, b : 1 octet
ran_ghe 3:a5b1e083ffd2 121 //tempSol, tempAir : 2 octets
ran_ghe 3:a5b1e083ffd2 122 //humSol, humAir : 1 octet
ran_ghe 3:a5b1e083ffd2 123
ran_ghe 4:0b63b5897827 124 wait(10);
ran_ghe 4:0b63b5897827 125
ran_ghe 4:0b63b5897827 126 //Set wakeup time for 500 seconds
ran_ghe 4:0b63b5897827 127 WakeUp::set_ms(10000);
ran_ghe 4:0b63b5897827 128 deepsleep();
ran_ghe 4:0b63b5897827 129 wait(1);
youdllo5 0:cfed96a14467 130
youdllo5 0:cfed96a14467 131 }
youdllo5 0:cfed96a14467 132 }