Grreenhouse project

Dependencies:   DHT DS1820 publishhhhh SSD1306 TSL2561_I2C mbed

Fork of Seeed_Grove_Moisture_Sensor_Example by Seeed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include <stdint.h>
00003 
00004 #include "DHT.h"            //1.Temp & Hum Sensor White Block   -- DHT22    --> A3
00005 #include "DS1820.h"         //2.One Wire Temperature Sensor     -- DS18B20  --> A1
00006                             //3.Grove Moisture :: no library                --> A0
00007 #include "TSL2561_I2C.h"    //4.Flat Light Sensor               -- TSL2561  --> SDA : D4, SCL : D5
00008 
00009 #include "bold_font.h"      // 6. lcd OLDE Display 128x64 
00010 #include "standard_font.h"  // 6. lcd OLDE Display 128x64 
00011 #include "ssd1306.h"        // 6. lcd OLDE Display 128x64 
00012 
00013 Serial pc(SERIAL_TX, SERIAL_RX);
00014 
00015 //1. White block DHT22
00016 DHT sensor(A3,DHT22);
00017 void task_DHT();
00018 int air_hum, air_temp,farenheit;
00019 float dp = 0.0f;
00020 
00021 //6.OLED
00022 SSD1306 ecran(D3 /* cs */, D6/* reset */, A5 /* dc */, A4 /* clock */, D2 /* data */); // original
00023 //SSD1306 ecran(D7 /* cs */, D4/* reset */, A5 /* dc */, A4 /* clock */, D8 /* data */);
00024 
00025 //2. One Wire Temperature DS18B20
00026 #define DATA_PIN        A1
00027 #define MAX_PROBES      16
00028 DS1820* probe[MAX_PROBES];
00029 float gnd_temp;
00030 
00031 //3. Grove Moisture
00032 AnalogIn moisture(A0);
00033 float gnd_hum = 0.0f;
00034 
00035 //4. Flat Light Sensor TSL2561
00036 TSL2561_I2C lum_sensor( D0, D1 );//SDA, SCL
00037 //TSL2561_I2C lum_sensor( D3, D2 );//SDA, SCL
00038 float float_air_light;
00039 int air_light ;
00040 
00041 //5. Sigfox
00042 Serial sigfox(D1, D0); //Rx Sigfox, Tx Sigfox
00043 void txData(int a ,int b,int c,int d,int e)
00044 {
00045     //air_light ; air_temp ; air_hum ; gnd_temp ; gnd_hum
00046     pc.printf("Envoie sur le Sigfox : AT$SS:%d %d %d %d %d\r\n",a,b,c,d,e);
00047     //sigfox.printf("AT$SS=%d",valeur);
00048     sigfox.printf("AT$SS=%02x %02x %02x %02x %02x\r\n", a,b,c,d,e);
00049 }
00050 
00051 
00052 int main(void)
00053 {
00054     printf("\r\n\nHello World!\r\n");
00055         
00056     //1. Temp & Humidity sensor -- White block
00057     //No more init
00058     
00059     //2. Temperature Probe -- One Wire Temperature Sensor
00060     int num_devices = 0;
00061     while(DS1820::unassignedProbe(DATA_PIN)) {
00062         probe[num_devices] = new DS1820(DATA_PIN);
00063         num_devices++;
00064         if (num_devices == MAX_PROBES) break;
00065     }
00066     printf("%d probe found\r\n", num_devices);
00067     
00068     //3. Grove Moisture
00069     
00070     //4.
00071     lum_sensor.enablePower();
00072     
00073     //6.
00074 /*      lcd.speed (SSD1306::Medium);  // set working frequency
00075       lcd.init();                   // initialize SSD1306
00076       lcd.cls();                    // clear frame buffer
00077       lcd.locate (3,1);             // set text cursor to line 3, column 1
00078       lcd.printf ("Hello, world!"); // print to frame buffer
00079       lcd.line (  6, 22, 114, 22, SSD1306::Normal); //
00080       lcd.line (114, 22, 114, 33, SSD1306::Normal); // Surrounds text with 
00081       lcd.line (114, 33,   6, 33, SSD1306::Normal); // a rectangle
00082       lcd.line (  6, 33,   6, 22, SSD1306::Normal); //
00083       lcd.fill (0, 0);              // fills screen outside rectangle
00084       lcd.redraw();                 // updates actual display transferring frame buffer over I2C bus
00085 */
00086 
00087 
00088     ecran.initialise();
00089     ecran.clear();
00090     ecran.set_contrast(255);
00091     ecran.set_font(bold_font, 8);    
00092 
00093     // Nothing else
00094     
00095     
00096     printf("Inits ended");
00097     while(1) {
00098         printf("\r\n\n\nNew loop\r\n\n");
00099         
00100         //1. Temp & Humidity sensor -- White block
00101         printf("DHT22 White Block : \r\n");
00102         task_DHT();
00103         
00104         //2. Temperature Probe -- One Wire Temperature Sensor
00105         printf("DS18B20 Probe : \r\n");
00106         probe[0]->convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
00107         for (int i = 0; i<num_devices; i++){
00108             gnd_temp = probe[i]->temperature();
00109             printf("Temperature : %3.1f  oC\r\n\n", gnd_temp);
00110         }
00111         
00112         //3. Grove Moisture
00113         gnd_hum = moisture;
00114         gnd_hum *= 100 ; // resultat 
00115         printf("Grove Moisture : \r\nMoisture reading is %2.2f\r\n\n", gnd_hum);
00116         
00117         //4. TSL2561 Flat Light Sensor
00118         float_air_light = lum_sensor.getLux();
00119         air_light = (int)float_air_light ;
00120         printf( "TSL2561 :\r\nLuminosity: %4.2f float\r\n\n", float_air_light );
00121         printf( "TSL2561 :\r\nLuminosity: %d int\r\n\n", air_light );
00122         //printf( "TSL2561 :\r\nLuminosity: %d\r\n\n", air_light );
00123         //int air_light = 1 ;
00124         
00125         
00126         //5.Transmission data par Sigfox
00127         txData((int)air_light,(int)air_temp,(int)air_hum,(int)gnd_temp,(int)gnd_hum);
00128         
00129         //6.Ecriture sur lcd OLED
00130 /*        unsigned char level = 255*moisture.read();  // reads pot. Scales to 0-255
00131         lcd.set_contrast (level);               // set contrast
00132         printf("\r\nWriting on lcd done!\r\n");
00133 */
00134 
00135         ecran.set_font(bold_font, 8);
00136         ecran.printf("Valeurs");
00137         ecran.printf("\r\n"); 
00138         ecran.update();
00139         ecran.set_font(standard_font, 6);
00140         ecran.printf("Air Lum = %d", (int)air_light);
00141         ecran.printf("\r\n");
00142         ecran.printf("Air Temp = %d", (int)air_temp);
00143         ecran.printf("\r\n");
00144         ecran.printf("Ait Hum = %d", (int)air_hum);
00145         ecran.printf("\r\n");
00146         ecran.printf("Gnd Temp = %d", (int)gnd_temp);
00147         ecran.printf("\r\n");
00148         ecran.printf("Gnd Hum = %d", (int)gnd_hum);
00149         ecran.printf("\r\n");
00150         ecran.update();
00151         ecran.clear();
00152 
00153         wait(10000); // 1 lecture toutes les 30 secondes
00154         
00155     }
00156     
00157     
00158 }
00159 
00160 /**********************************************
00161     Transmission max de la sigfox : 240 octets/jour
00162 ***********************************************/
00163         
00164         
00165         
00166         
00167 //1.
00168 void task_DHT(){
00169     int error = 0;
00170  
00171         wait(2.0f);
00172         error = sensor.readData();
00173         if (0 == error) {
00174             air_temp   = sensor.ReadTemperature(CELCIUS);
00175             farenheit   = sensor.ReadTemperature(FARENHEIT);
00176             air_hum  = sensor.ReadHumidity();
00177             dp  = sensor.CalcdewPoint(air_temp, air_hum);
00178     
00179             printf("Air Temperature : %d oC\r\n", air_temp);
00180             printf("Air Humidity %d /100\r\nDewpoint: %4.2f\r\n\n", air_hum, dp);
00181         } else {
00182             printf("Error: %d\r\n", error);
00183         }
00184 }
00185 
00186