Grreenhouse project

Dependencies:   DHT DS1820 publishhhhh SSD1306 TSL2561_I2C mbed

Fork of Seeed_Grove_Moisture_Sensor_Example by Seeed

Committer:
cricbis
Date:
Fri Nov 24 15:50:54 2017 +0000
Revision:
1:280672cfee6b
Parent:
0:780321a3f63a
Child:
2:72e1b9689366
avf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cricbis 1:280672cfee6b 1 #include "mbed.h"
cricbis 1:280672cfee6b 2 #include <stdint.h>
sam_grove 0:780321a3f63a 3
cricbis 1:280672cfee6b 4 #include "DHT.h" //1.Temp & Hum Sensor White Block -- DHT22 --> A3
cricbis 1:280672cfee6b 5 #include "DS1820.h" //2.One Wire Temperature Sensor -- DS18B20 --> A1
cricbis 1:280672cfee6b 6 //3.Grove Moisture :: no library --> A0
cricbis 1:280672cfee6b 7 #include "TSL2561_I2C.h"//4.Flat Light Sensor -- TSL2561 --> SDA : D4, SCL : D5
cricbis 1:280672cfee6b 8
cricbis 1:280672cfee6b 9 //1. White block
cricbis 1:280672cfee6b 10 DHT sensor(A3,DHT22);
cricbis 1:280672cfee6b 11 void task_DHT();
cricbis 1:280672cfee6b 12
cricbis 1:280672cfee6b 13 int air_hum, air_celsius,f;
cricbis 1:280672cfee6b 14 float dp = 0.0f;
cricbis 1:280672cfee6b 15
cricbis 1:280672cfee6b 16 //2. One Wire Temperature DS18B20
cricbis 1:280672cfee6b 17 #define DATA_PIN A1
cricbis 1:280672cfee6b 18 #define MAX_PROBES 16
cricbis 1:280672cfee6b 19 DS1820* probe[MAX_PROBES];
cricbis 1:280672cfee6b 20 float temp;
sam_grove 0:780321a3f63a 21
cricbis 1:280672cfee6b 22 //3. Grove Moisture
cricbis 1:280672cfee6b 23 Serial pc(SERIAL_TX, SERIAL_RX);
sam_grove 0:780321a3f63a 24 AnalogIn moisture(A0);
sam_grove 0:780321a3f63a 25
cricbis 1:280672cfee6b 26 //4. Flat Light Sensor
cricbis 1:280672cfee6b 27 TSL2561_I2C lum_sensor( D4, D5 );
cricbis 1:280672cfee6b 28 float air_lum;
cricbis 1:280672cfee6b 29
cricbis 1:280672cfee6b 30
cricbis 1:280672cfee6b 31 Serial sigfox(PA_2, PA_3);
cricbis 1:280672cfee6b 32
cricbis 1:280672cfee6b 33 void txData(int a ,int b,int c,int d,int e)
cricbis 1:280672cfee6b 34 {
cricbis 1:280672cfee6b 35 pc.printf("Envoie sur le Sigfox : AT$SS:%d %d %d %d %d\r\n",a,b,c,d,e);
cricbis 1:280672cfee6b 36
cricbis 1:280672cfee6b 37 //sigfox.printf("AT$SS=%d",valeur);
cricbis 1:280672cfee6b 38 sigfox.printf("AT$SS=%02x %02x %02x %02x %02x\r\n", a,b,c,d,e);
cricbis 1:280672cfee6b 39
cricbis 1:280672cfee6b 40 }
cricbis 1:280672cfee6b 41
cricbis 1:280672cfee6b 42
sam_grove 0:780321a3f63a 43 int main(void)
sam_grove 0:780321a3f63a 44 {
cricbis 1:280672cfee6b 45 printf("\r\n\n\n");
cricbis 1:280672cfee6b 46
cricbis 1:280672cfee6b 47 //1. Temp & Humidity sensor -- White block
cricbis 1:280672cfee6b 48 //No more init
cricbis 1:280672cfee6b 49
cricbis 1:280672cfee6b 50 //2. Temperature Probe -- One Wire Temperature Sensor
cricbis 1:280672cfee6b 51 int num_devices = 0;
cricbis 1:280672cfee6b 52 while(DS1820::unassignedProbe(DATA_PIN)) {
cricbis 1:280672cfee6b 53 probe[num_devices] = new DS1820(DATA_PIN);
cricbis 1:280672cfee6b 54 num_devices++;
cricbis 1:280672cfee6b 55 if (num_devices == MAX_PROBES) break;
cricbis 1:280672cfee6b 56 }
cricbis 1:280672cfee6b 57 printf(" %d probe found\r\n", num_devices);
cricbis 1:280672cfee6b 58
cricbis 1:280672cfee6b 59 //3. Grove Moisture
cricbis 1:280672cfee6b 60 float moisture_value = 0.0f;
cricbis 1:280672cfee6b 61
cricbis 1:280672cfee6b 62 //4.
cricbis 1:280672cfee6b 63 lum_sensor.enablePower();
cricbis 1:280672cfee6b 64 // Nothing else
cricbis 1:280672cfee6b 65
cricbis 1:280672cfee6b 66
cricbis 1:280672cfee6b 67 printf("Inits ended\r\n\n");
sam_grove 0:780321a3f63a 68 while(1) {
cricbis 1:280672cfee6b 69 printf("\r\n\n\nNew loop\r\n\n");
cricbis 1:280672cfee6b 70
cricbis 1:280672cfee6b 71 //1. Temp & Humidity sensor -- White block
cricbis 1:280672cfee6b 72 printf("DHT22 White Block : \r\n");
cricbis 1:280672cfee6b 73 task_DHT();
cricbis 1:280672cfee6b 74
cricbis 1:280672cfee6b 75 //2. Temperature Probe -- One Wire Temperature Sensor
cricbis 1:280672cfee6b 76 printf("DS18B20 Probe : \r\n");
cricbis 1:280672cfee6b 77 probe[0]->convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready
cricbis 1:280672cfee6b 78 for (int i = 0; i<num_devices; i++){
cricbis 1:280672cfee6b 79 temp = probe[i]->temperature();
cricbis 1:280672cfee6b 80 printf("Device %d returns %3.1f oC\r\n\n", i, temp);
cricbis 1:280672cfee6b 81 }
cricbis 1:280672cfee6b 82
cricbis 1:280672cfee6b 83 //3. Grove Moisture
cricbis 1:280672cfee6b 84 moisture_value = moisture;
cricbis 1:280672cfee6b 85 printf("Grove Moisture : \r\nMoisture reading is %2.2f\r\n\n", moisture_value);
cricbis 1:280672cfee6b 86
cricbis 1:280672cfee6b 87 //4. TSL2561 Flat Light Sensor
cricbis 1:280672cfee6b 88 air_lum = lum_sensor.getLux();
cricbis 1:280672cfee6b 89 printf( "Luminosity: %4.2f\r\n", air_lum );
cricbis 1:280672cfee6b 90
cricbis 1:280672cfee6b 91
cricbis 1:280672cfee6b 92
cricbis 1:280672cfee6b 93
cricbis 1:280672cfee6b 94
cricbis 1:280672cfee6b 95 txData((int)air_celsius,(int)air_hum,(int)air_lum,(int)temp,(int)moisture_value);
cricbis 1:280672cfee6b 96 wait(3); // 1 lecture toutes les 3 secondes
cricbis 1:280672cfee6b 97
sam_grove 0:780321a3f63a 98 }
cricbis 1:280672cfee6b 99
cricbis 1:280672cfee6b 100
sam_grove 0:780321a3f63a 101 }
cricbis 1:280672cfee6b 102
cricbis 1:280672cfee6b 103
cricbis 1:280672cfee6b 104 //txData((int)air_temp,(int)air_moisture,(int)sol_moisture,(int)illuminance,(int)temp_sol);
cricbis 1:280672cfee6b 105
cricbis 1:280672cfee6b 106
cricbis 1:280672cfee6b 107
cricbis 1:280672cfee6b 108
cricbis 1:280672cfee6b 109 //1.
cricbis 1:280672cfee6b 110 void task_DHT(){
cricbis 1:280672cfee6b 111 int error = 0;
cricbis 1:280672cfee6b 112
cricbis 1:280672cfee6b 113 wait(2.0f);
cricbis 1:280672cfee6b 114 error = sensor.readData();
cricbis 1:280672cfee6b 115 if (0 == error) {
cricbis 1:280672cfee6b 116 air_celsius = sensor.ReadTemperature(CELCIUS);
cricbis 1:280672cfee6b 117 f = sensor.ReadTemperature(FARENHEIT);
cricbis 1:280672cfee6b 118 air_hum = sensor.ReadHumidity();
cricbis 1:280672cfee6b 119 dp = sensor.CalcdewPoint(air_celsius, air_hum);
cricbis 1:280672cfee6b 120
cricbis 1:280672cfee6b 121 printf("Temperature in Celcius: %d, Farenheit %d\r\n", air_celsius, f);
cricbis 1:280672cfee6b 122 printf("Humidity is %d, Dewpoint: %4.2f\r\n\n", air_hum, dp);
cricbis 1:280672cfee6b 123 } else {
cricbis 1:280672cfee6b 124 printf("Error: %d\r\n", error);
cricbis 1:280672cfee6b 125 }
cricbis 1:280672cfee6b 126 }
cricbis 1:280672cfee6b 127
cricbis 1:280672cfee6b 128 //4.
cricbis 1:280672cfee6b 129 /*
cricbis 1:280672cfee6b 130 void setup(void){
cricbis 1:280672cfee6b 131 if (tsl2561.begin()) {
cricbis 1:280672cfee6b 132 PC_PRINTLNX(1,"TSL2561 Sensor Found");
cricbis 1:280672cfee6b 133 } else {
cricbis 1:280672cfee6b 134 PC_PRINTLNX(1,"TSL2561 Sensor not Found");
cricbis 1:280672cfee6b 135 }
cricbis 1:280672cfee6b 136 // You can change the gain on the fly, to adapt to brighter/dimmer tsl2561 situations
cricbis 1:280672cfee6b 137 tsl2561.setGain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
cricbis 1:280672cfee6b 138 //tsl2561.setGain(TSL2561_GAIN_16X); // set 16x gain (for dim situations)
cricbis 1:280672cfee6b 139
cricbis 1:280672cfee6b 140 // Changing the integration time gives you a longer time over which to sense tsl2561
cricbis 1:280672cfee6b 141 // longer timelines are slower, but are good in very low tsl2561 situtations!
cricbis 1:280672cfee6b 142 //tsl2561.setTiming(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright tsl2561)
cricbis 1:280672cfee6b 143 //tsl2561.setTiming(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium tsl2561)
cricbis 1:280672cfee6b 144 tsl2561.setTiming(TSL2561_INTEGRATIONTIME_402MS); // longest integration time (dim tsl2561)
cricbis 1:280672cfee6b 145 }
cricbis 1:280672cfee6b 146
cricbis 1:280672cfee6b 147 */
cricbis 1:280672cfee6b 148
cricbis 1:280672cfee6b 149