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: DHT DS1820 publishhhhh SSD1306 TSL2561_I2C mbed
Fork of Seeed_Grove_Moisture_Sensor_Example by
Diff: main.cpp
- Revision:
- 2:72e1b9689366
- Parent:
- 1:280672cfee6b
- Child:
- 3:201cb66d7bd5
--- a/main.cpp Fri Nov 24 15:50:54 2017 +0000 +++ b/main.cpp Sun Jan 21 18:06:57 2018 +0000 @@ -1,48 +1,59 @@ #include "mbed.h" #include <stdint.h> -#include "DHT.h" //1.Temp & Hum Sensor White Block -- DHT22 --> A3 -#include "DS1820.h" //2.One Wire Temperature Sensor -- DS18B20 --> A1 - //3.Grove Moisture :: no library --> A0 -#include "TSL2561_I2C.h"//4.Flat Light Sensor -- TSL2561 --> SDA : D4, SCL : D5 +#include "DHT.h" //1.Temp & Hum Sensor White Block -- DHT22 --> A3 +#include "DS1820.h" //2.One Wire Temperature Sensor -- DS18B20 --> A1 + //3.Grove Moisture :: no library --> A0 +#include "TSL2561_I2C.h" //4.Flat Light Sensor -- TSL2561 --> SDA : D4, SCL : D5 + +#include "bold_font.h" // 6. lcd OLDE Display 128x64 +#include "standard_font.h" // 6. lcd OLDE Display 128x64 +#include "ssd1306.h" // 6. lcd OLDE Display 128x64 + +Serial pc(SERIAL_TX, SERIAL_RX); //1. White block DHT sensor(A3,DHT22); void task_DHT(); +int air_hum, air_temp,farenheit; +float dp = 0.0f; -int air_hum, air_celsius,f; -float dp = 0.0f; +//6.OLED +//SSD1306 ecran(D3 /* cs */, D6/* reset */, A5 /* dc */, A4 /* clock */, D2 /* data */); +SSD1306 ecran(D7 /* cs */, D4/* reset */, A5 /* dc */, A4 /* clock */, D8 /* data */); //2. One Wire Temperature DS18B20 #define DATA_PIN A1 #define MAX_PROBES 16 DS1820* probe[MAX_PROBES]; -float temp; +float gnd_temp; //3. Grove Moisture -Serial pc(SERIAL_TX, SERIAL_RX); AnalogIn moisture(A0); +float gnd_hum = 0.0f; //4. Flat Light Sensor -TSL2561_I2C lum_sensor( D4, D5 ); -float air_lum; +TSL2561_I2C lum_sensor( D3, D2 );//SDA, SCL +float float_air_light; +int air_light ; + +//5. Sigfox +Serial sigfox(A7, A2); +void txData(int a ,int b,int c,int d,int e) +{ + //air_light ; air_temp ; air_hum ; gnd_temp ; gnd_hum + pc.printf("Envoie sur le Sigfox : AT$SS:%d %d %d %d %d\r\n",a,b,c,d,e); + //sigfox.printf("AT$SS=%d",valeur); + sigfox.printf("AT$SS=%02x %02x %02x %02x %02x\r\n", a,b,c,d,e); +} -Serial sigfox(PA_2, PA_3); -void txData(int a ,int b,int c,int d,int e) -{ - pc.printf("Envoie sur le Sigfox : AT$SS:%d %d %d %d %d\r\n",a,b,c,d,e); - - //sigfox.printf("AT$SS=%d",valeur); - sigfox.printf("AT$SS=%02x %02x %02x %02x %02x\r\n", a,b,c,d,e); - -} int main(void) { - printf("\r\n\n\n"); + printf("\r\n\nHello World!\r\n"); //1. Temp & Humidity sensor -- White block //No more init @@ -54,17 +65,37 @@ num_devices++; if (num_devices == MAX_PROBES) break; } - printf(" %d probe found\r\n", num_devices); + printf("%d probe found\r\n", num_devices); //3. Grove Moisture - float moisture_value = 0.0f; //4. lum_sensor.enablePower(); + + //6. +/* lcd.speed (SSD1306::Medium); // set working frequency + lcd.init(); // initialize SSD1306 + lcd.cls(); // clear frame buffer + lcd.locate (3,1); // set text cursor to line 3, column 1 + lcd.printf ("Hello, world!"); // print to frame buffer + lcd.line ( 6, 22, 114, 22, SSD1306::Normal); // + lcd.line (114, 22, 114, 33, SSD1306::Normal); // Surrounds text with + lcd.line (114, 33, 6, 33, SSD1306::Normal); // a rectangle + lcd.line ( 6, 33, 6, 22, SSD1306::Normal); // + lcd.fill (0, 0); // fills screen outside rectangle + lcd.redraw(); // updates actual display transferring frame buffer over I2C bus +*/ + + + ecran.initialise(); + ecran.clear(); + ecran.set_contrast(255); + ecran.set_font(bold_font, 8); + // Nothing else - printf("Inits ended\r\n\n"); + printf("Inits ended"); while(1) { printf("\r\n\n\nNew loop\r\n\n"); @@ -76,32 +107,61 @@ printf("DS18B20 Probe : \r\n"); probe[0]->convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready for (int i = 0; i<num_devices; i++){ - temp = probe[i]->temperature(); - printf("Device %d returns %3.1f oC\r\n\n", i, temp); + gnd_temp = probe[i]->temperature(); + printf("Temperature : %3.1f oC\r\n\n", gnd_temp); } //3. Grove Moisture - moisture_value = moisture; - printf("Grove Moisture : \r\nMoisture reading is %2.2f\r\n\n", moisture_value); + gnd_hum = moisture; + gnd_hum *= 100 ; // resultat + printf("Grove Moisture : \r\nMoisture reading is %2.2f\r\n\n", gnd_hum); //4. TSL2561 Flat Light Sensor - air_lum = lum_sensor.getLux(); - printf( "Luminosity: %4.2f\r\n", air_lum ); + float_air_light = lum_sensor.getLux(); + air_light = (int)float_air_light ; + printf( "TSL2561 :\r\nLuminosity: %4.2f\r\n\n", float_air_light ); + printf( "TSL2561 :\r\nLuminosity: %d int\r\n\n", air_light ); + //printf( "TSL2561 :\r\nLuminosity: %d\r\n\n", air_light ); - + //5.Transmission data par Sigfox + txData((int)air_light,(int)air_temp,(int)air_hum,(int)gnd_temp,(int)gnd_hum); - txData((int)air_celsius,(int)air_hum,(int)air_lum,(int)temp,(int)moisture_value); - wait(3); // 1 lecture toutes les 3 secondes + //6.Ecriture sur lcd OLED +/* unsigned char level = 255*moisture.read(); // reads pot. Scales to 0-255 + lcd.set_contrast (level); // set contrast + printf("\r\nWriting on lcd done!\r\n"); +*/ + + ecran.set_font(bold_font, 8); + ecran.printf("Valeurs"); + ecran.printf("\r\n"); + ecran.update(); + ecran.set_font(standard_font, 6); + ecran.printf("Air Lum = %d", (int)air_light); + ecran.printf("\r\n"); + ecran.printf("Air Temp = %d", (int)air_temp); + ecran.printf("\r\n"); + ecran.printf("Ait Hum = %d", (int)air_hum); + ecran.printf("\r\n"); + ecran.printf("Gnd Temp = %d", (int)gnd_temp); + ecran.printf("\r\n"); + ecran.printf("Gnd Hum = %d", (int)gnd_hum); + ecran.printf("\r\n"); + ecran.update(); + ecran.clear(); + + wait(10000); // 1 lecture toutes les 30 secondes } } - - //txData((int)air_temp,(int)air_moisture,(int)sol_moisture,(int)illuminance,(int)temp_sol); +/********************************************** + Transmission max de la sigfox : 240 octets/jour +***********************************************/ @@ -113,37 +173,16 @@ wait(2.0f); error = sensor.readData(); if (0 == error) { - air_celsius = sensor.ReadTemperature(CELCIUS); - f = sensor.ReadTemperature(FARENHEIT); + air_temp = sensor.ReadTemperature(CELCIUS); + farenheit = sensor.ReadTemperature(FARENHEIT); air_hum = sensor.ReadHumidity(); - dp = sensor.CalcdewPoint(air_celsius, air_hum); + dp = sensor.CalcdewPoint(air_temp, air_hum); - printf("Temperature in Celcius: %d, Farenheit %d\r\n", air_celsius, f); - printf("Humidity is %d, Dewpoint: %4.2f\r\n\n", air_hum, dp); + printf("Air Temperature : %d oC\r\n", air_temp); + printf("Air Humidity %d /100\r\nDewpoint: %4.2f\r\n\n", air_hum, dp); } else { printf("Error: %d\r\n", error); } } -//4. -/* -void setup(void){ - if (tsl2561.begin()) { - PC_PRINTLNX(1,"TSL2561 Sensor Found"); - } else { - PC_PRINTLNX(1,"TSL2561 Sensor not Found"); - } - // You can change the gain on the fly, to adapt to brighter/dimmer tsl2561 situations - tsl2561.setGain(TSL2561_GAIN_0X); // set no gain (for bright situtations) - //tsl2561.setGain(TSL2561_GAIN_16X); // set 16x gain (for dim situations) - - // Changing the integration time gives you a longer time over which to sense tsl2561 - // longer timelines are slower, but are good in very low tsl2561 situtations! - //tsl2561.setTiming(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright tsl2561) - //tsl2561.setTiming(TSL2561_INTEGRATIONTIME_101MS); // medium integration time (medium tsl2561) - tsl2561.setTiming(TSL2561_INTEGRATIONTIME_402MS); // longest integration time (dim tsl2561) -} -*/ - -