We are a group of 3 students at Polytech Sorbonne specializing in EI2I (electronics and computer science)
The goal of our project is to create a module composed of several sensors to help students from another specialty (AGRAL : agro-food industry) in the follow-up of their plantations.
A microcontroller displays in real time on the screen the information sent by the sensors of temperature (air and soil), humidity (air and soil), luminosity. At the same time, it sends the data to an online server Ubidots through Sigfox, a LPWAN network..
1) Use of sensors- 1. DHT22 - Temperature and Humidity Of The Air Sensor
The DHT22 temperature and humidity sensor communicates with a microcontroller via a serial port. The sensor is calibrated and does not require any additional components to be used.
Power supply: 3.3 to 6 Vdc
Measuring range:
- temperature: -40 to +80 °C
- humidity: 0 to 100% RH
Precision:
- temperature: ± 0.5 °C
- humidity: ± 2% RH
To use this sensor we used predefined functions in Mbed
- DHT22.h
/*
* DHT Library for Digital-output Humidity and Temperature sensors
*
* Works with DHT11, DHT21, DHT22
* SEN11301P, Grove - Temperature&Humidity Sensor (Seeed Studio)
* SEN51035P, Grove - Temperature&Humidity Sensor Pro (Seeed Studio)
* AM2302 , temperature-humidity sensor
* RHT01,RHT02, RHT03 , Humidity and Temperature Sensor (Sparkfun)
*
* Copyright (C) Wim De Roeve
* based on DHT22 sensor library by HO WING KIT
* Arduino DHT11 library
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documnetation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MBED_DHT_H
#define MBED_DHT_H
#include "mbed.h"
typedef enum eType eType;
enum eType {
DHT11 = 11,
SEN11301P = 11,
RHT01 = 11,
DHT22 = 22,
AM2302 = 22,
SEN51035P = 22,
RHT02 = 22,
RHT03 = 22
};
typedef enum eError eError;
enum eError {
ERROR_NONE = 0,
BUS_BUSY,
ERROR_NOT_PRESENT,
ERROR_ACK_TOO_LONG,
ERROR_SYNC_TIMEOUT,
ERROR_DATA_TIMEOUT,
ERROR_CHECKSUM,
ERROR_NO_PATIENCE
};
typedef enum eScale eScale;
enum eScale {
CELCIUS = 0,
FARENHEIT,
KELVIN
};
class DHT
{
public:
DHT(PinName pin, eType DHTtype);
~DHT();
eError readData(void);
float ReadHumidity(void);
float ReadTemperature(eScale const Scale);
float CalcdewPoint(float const celsius, float const humidity);
float CalcdewPointFast(float const celsius, float const humidity);
private:
time_t _lastReadTime;
float _lastTemperature;
float _lastHumidity;
PinName _pin;
bool _firsttime;
eType _DHTtype;
uint8_t DHT_data[5];
float CalcTemperature();
float CalcHumidity();
float ConvertCelciustoFarenheit(float const);
float ConvertCelciustoKelvin(float const);
eError stall(DigitalInOut &io, int const level, int const max_time);
};
#endif
- DHT22.cpp
#include "DHT22.h"
DHT22::DHT22(PinName pin) {
_data_pin = pin;
}
int DHT22::getTemperature() {
return _temperature;
}
int DHT22::getHumidity() {
return _humidity;
}
bool DHT22::sample() {
DigitalInOut DHT22(_data_pin);
int dht22_dat [5];
DHT22.output();
DHT22.write(0);
wait_ms(18);
DHT22.write(1);
DHT22.input();
wait_us(40);
wait_us(80);
int i,j,result=0;
for (i=0; i<5; i++) {
result=0;
for (j=0; j<8; j++) {
while (DHT22);
while (!DHT22);
wait_us(50);
int p;
p=DHT22;
p=p <<(7-j);
result=result|p;
}
dht22_dat[i] = result;
}
int dht22_check_sum;
dht22_check_sum=dht22_dat[0]+dht22_dat[1]+dht22_dat[2]+dht22_dat[3];
dht22_check_sum= dht22_check_sum%256;
if (dht22_check_sum==dht22_dat[4]) {
_humidity=dht22_dat[0]*256+dht22_dat[1];
_temperature=dht22_dat[2]*256+dht22_dat[3];
return true;
}
return false;
}
First of all you need to define the pins to which the sensors are connected.
For this sensor you need to choose pins for the alimentation and the data.
//DHT22 (Temperature and humidity of the air)
#define pinDHT22 D9 //PA_8
#define modeleDHT AM2302
Now you can use the fonctions of the sensor.
#ifdef MesureDHT22
void mesuresDHT22(){
CaptDHT.readData();
TemperatureAir = CaptDHT.ReadTemperature(CELCIUS);
HumiditeAir = CaptDHT.ReadHumidity();
}
#endif
- 2. Luminosity Sensor
Luminosity sensor based on a TSL2561 allowing to measure a luminosity from 0.1 to 40000 Lux. It communicates with a microcontroller.
Power supply: 2.7 to 3.6 VDC
- TSL2561.h
/*
* mbed library program
* Luminosity sensor -- LIGHT-TO-DIGITAL CONVERTER (light intensity to a digital signal output)
* TSL2561 by Texas Advanced Optoelectronic Solutions Inc.
*
* Copyright (c) 2015,'17 Kenji Arai / JH1PJL
* http://www.page.sannet.ne.jp/kenjia/index.html
* http://mbed.org/users/kenjiArai/
* Created: Feburary 21st, 2015
* Revised: August 23rd, 2017
*/
/*
*---------------- REFERENCE ----------------------------------------------------------------------
* https://docs.google.com/viewer?url=http%3A%2F%2Fwww.adafruit.com%2Fdatasheets%2FTSL256x.pdf
* https://learn.adafruit.com/tsl2561?view=all
* http://www.adafruit.com/products/439
* http://akizukidenshi.com/catalog/g/gM-08219/
*/
#ifndef TSL2561_H
#define TSL2561_H
#include "mbed.h"
// Luminosity sensor, TSL2561
// Address b7=0,b6=1,b5=1,b4=1,b3=0,b2=0,b1=1, b0=R/W
#define TSL2561_ADDRESS_GND (0x29 << 1)
#define TSL2561_ADDRESS_FLOAT (0x39 << 1)
#define TSL2561_ADDRESS_VDD (0x49 << 1)
////////////// Registers //////////////////////////////////
// Register definition
#define TSL2561_CONTROL 0x00
#define TSL2561_TIMING 0x01
#define TSL2561_THRESHLOWLOW 0x02
#define TSL2561_THRESHHIGHLOW 0x04
#define TSL2561_INTERRUPT 0x06
#define TSL2561_CRC 0x08
#define TSL2561_ID 0x0A
#define TSL2561_DATA0LOW 0x0C
#define TSL2561_DATA0HIGH 0x0D
#define TSL2561_DATA1LOW 0x0E
#define TSL2561_DATA1HIGH 0x0F
////////////// TIMING PARAMETER ///////////////////////////
#define TIMING_GAIN_1 (0UL << 4)
#define TIMING_GAIN_16 (1UL << 4)
#define TIMING_TIME_13R7 (0x0)
#define TIMING_TIME_101 (0x1)
#define TIMING_TIME_402 (0x2)
#define TIMING_TIME_MANU (0x3)
#define TIMING_DEFAULT (TIMING_GAIN_1 + TIMING_TIME_402)
////////////// ID /////////////////////////////////////////
#define I_AM_TSL2561 0x50
#define REG_NO_MASK 0x0F
////////////// COMMAND ////////////////////////////////////
#define CMD_CMDMODE (1UL << 7)
#define CMD_CLEAR (1UL << 6)
#define CMD_WORD (1UL << 5)
#define CMD_BLOCK (1UL << 4)
#define CMD_SINGLE (CMD_CMDMODE)
#define CMD_MULTI (CMD_CMDMODE + CMD_WORD)
/** Interface for Luminosity sensor, TSL2561
* @code
* #include "mbed.h"
* #include "TSL2561.h"
*
* // I2C Communication
* TSL2561 lum(dp5,dp27); // TSL2561 SDA, SCL
* // If you connected I2C line not only this device but also other devices,
* // you need to declare following method.
* I2C i2c(dp5,dp27); // SDA, SCL
* TSL2561 lum(i2c); // TSL2561 SDA, SCL (Data available every 400mSec)
*
* int main() {;
* while(true){
* printf("Illuminance: %+7.2f [Lux]\r\n", lum.lux());
* wait(1.0);
* }
* }
* @endcode
*/
class TSL2561
{
public:
/** Configure data pin
* @param data SDA and SCL pins
*/
TSL2561(PinName p_sda, PinName p_scl);
TSL2561(PinName p_sda, PinName p_scl, uint8_t addr);
/** Configure data pin (with other devices on I2C line)
* @param I2C previous definition
*/
TSL2561(I2C& p_i2c);
TSL2561(I2C& p_i2c, uint8_t addr);
/** Get approximates the human eye response
* in the commonly used Illuminance unit of Lux
* @param none
* @return Lux
*/
float lux(void);
/** Set timing register
* @param timing parameter
* @return timing read data
*/
uint8_t set_timing_reg(uint8_t parameter);
/** Read timing register
* @param timing parameter
* @return timing read data
*/
uint8_t read_timing_reg(void);
/** Set I2C clock frequency
* @param freq.
* @return none
*/
void frequency(int hz);
/** check Device ID number
* @param none
* @return TSL2561 = 1, others 0
*/
uint8_t who_am_i(void);
/** Read ID and Revision Number
* @param none
* @return ID + REVNO
*/
uint16_t read_ID(void);
/** Power Up/Down
* @param none
* @return none
*/
void power_up(void);
void power_down(void);
protected:
I2C *_i2c_p;
I2C &_i2c;
void init(void);
private:
bool TSL2561Initialised;
uint8_t TSL2561_addr;
uint8_t dt[4];
uint32_t ch0;
uint32_t ch1;
int8_t gain;
uint8_t id_number;
double integ_time;
};
#endif // TSL2561_H
- TSL2561.cpp
/*
* mbed library program
* Luminosity sensor -- LIGHT-TO-DIGITAL CONVERTER (light intensity to a digital signal output)
* TSL2561 by Texas Advanced Optoelectronic Solutions Inc.
*
* Copyright (c) 2015,'17 Kenji Arai / JH1PJL
* http://www.page.sannet.ne.jp/kenjia/index.html
* http://mbed.org/users/kenjiArai/
* Created: Feburary 21st, 2015
* Revised: August 23rd, 2017
*/
#include "TSL2561.h"
TSL2561::TSL2561 (PinName p_sda, PinName p_scl)
: _i2c_p(new I2C(p_sda, p_scl)), _i2c(*_i2c_p)
{
TSL2561_addr = TSL2561_ADDRESS_GND;
init();
}
TSL2561::TSL2561 (PinName p_sda, PinName p_scl, uint8_t addr)
: _i2c_p(new I2C(p_sda, p_scl)), _i2c(*_i2c_p)
{
TSL2561_addr = addr;
init();
}
TSL2561::TSL2561 (I2C& p_i2c)
: _i2c(p_i2c)
{
TSL2561_addr = TSL2561_ADDRESS_GND;
init();
}
TSL2561::TSL2561 (I2C& p_i2c, uint8_t addr)
: _i2c(p_i2c)
{
TSL2561_addr = addr;
init();
}
/////////////// Read Lux from sensor //////////////////////
/*
For 0 < CH1/CH0 < 0.50 Lux = 0.0304 x CH0-0.062 x CH0 x ((CH1/CH0)1.4)
For 0.50 < CH1/CH0 < 0.61 Lux = 0.0224 x CH0-0.031 x CH1
For 0.61 < CH1/CH0 < 0.80 Lux = 0.0128 x CH0-0.0153 x CH1
For 0.80 < CH1/CH0 < 1.30 Lux = 0.00146 x CH0-0.00112x CH1
For CH1/CH0 > 1.30 Lux = 0
*/
float TSL2561::lux()
{
double lux0, lux1;
double ratio;
double dlux;
dt[0] = CMD_MULTI + TSL2561_DATA0LOW;
_i2c.write((int)TSL2561_addr, (char *)dt, 1, true);
_i2c.read(TSL2561_addr, (char *)dt, 2, false);
ch0 = dt[1] << 8 | dt[0];
dt[0] = CMD_MULTI + TSL2561_DATA1LOW;
_i2c.write((int)TSL2561_addr, (char *)dt, 1, true);
_i2c.read(TSL2561_addr, (char *)dt, 2, false);
ch1 = dt[1] << 8 | dt[0];
if (ch0 == 0xFFFF) {
return 2500.0;
}
lux0 = (double)ch0;
lux1 = (double)ch1;
ratio = lux1 / lux0;
read_timing_reg();
lux0 *= (402.0/integ_time);
lux1 *= (402.0/integ_time);
lux0 /= gain;
lux1 /= gain;
if (ratio <= 0.5) {
dlux = 0.03040 * lux0 - 0.06200 * lux0 * pow(ratio,1.4);
} else if (ratio <= 0.61) {
dlux = 0.02240 * lux0 - 0.03100 * lux1;
} else if (ratio <= 0.80) {
dlux = 0.01280 * lux0 - 0.01530 * lux1;
} else if (ratio <= 1.30) {
dlux = 0.00146 * lux0 - 0.00112 * lux1;
} else {
dlux = 0;
}
return (float)dlux;
}
/////////////// Initialize ////////////////////////////////
void TSL2561::init()
{
_i2c.frequency(100000);
power_up();
set_timing_reg(TIMING_DEFAULT);
}
/////////////// Timing Register ///////////////////////////
uint8_t TSL2561::set_timing_reg(uint8_t parameter)
{
dt[0] = CMD_SINGLE + TSL2561_TIMING;
dt[1] = parameter;
_i2c.write((int)TSL2561_addr, (char *)dt, 2, false);
dt[0] = CMD_SINGLE + TSL2561_TIMING;
_i2c.write((int)TSL2561_addr, (char *)dt, 1, true);
_i2c.read(TSL2561_addr, (char *)dt, 1, false);
return dt[0];
}
uint8_t TSL2561::read_timing_reg(void)
{
uint8_t i;
dt[0] = CMD_SINGLE + TSL2561_TIMING;
_i2c.write((int)TSL2561_addr, (char *)dt, 1, true);
_i2c.read(TSL2561_addr, (char *)dt, 1, false);
if (dt[0] & TIMING_GAIN_16){
gain = 16;
} else {
gain = 1;
}
i = dt[0] & 0x3;
switch (i) {
case 0:
integ_time = 13.7;
break;
case 1:
integ_time = 101.0;
break;
case 2:
integ_time = 402.0;
break;
default:
integ_time = 0;
break;
}
return dt[0];
}
/////////////// ID ////////////////////////////////////////
uint16_t TSL2561::read_ID()
{
dt[0] = CMD_SINGLE + TSL2561_ID;
_i2c.write((int)TSL2561_addr, (char *)dt, 1, true);
_i2c.read(TSL2561_addr, (char *)dt, 2, false);
id_number = dt[0] << 8 | dt[1];
return id_number;
}
uint8_t TSL2561::who_am_i()
{
read_ID();
if ((id_number >> 4) == I_AM_TSL2561) {
return 1;
} else {
return 0;
}
}
/////////////// Power ON/OFF //////////////////////////////
void TSL2561::power_up()
{
dt[0] = CMD_SINGLE + TSL2561_CONTROL;
dt[1] = 3;
_i2c.write((int)TSL2561_addr, (char *)dt, 2, false);
}
void TSL2561::power_down()
{
dt[0] = CMD_SINGLE + TSL2561_CONTROL;
dt[1] = 0;
_i2c.write((int)TSL2561_addr, (char *)dt, 2, false);
}
/////////////// I2C Freq. /////////////////////////////////
void TSL2561::frequency(int hz)
{
_i2c.frequency(hz);
}
For this sensor you need to choose pins for the alimentation and for the I2C (SCA,SDL)
//I2C
#define pinSDA D0
#define pinSCL D1
#ifdef MesureIntensiteLumineuse
void MesureLux(){
//int i;
Lux = 0;
for(int i = 0; i < NombreDeMesures; i++){
Lux += COEF_TSL*Lumiere.lux();
wait_ms(DelaiEntreMesures);
}
Lux /= NombreDeMesures;
}
#endif
- 3. RGB Sensor
This module is used to detect the color of a light source or object. It is based on the TCS34725 sensor and communicates via an I2C port. The sensor is used to detect RGB colours as well as white.
Power supply: 3.3 to 5 Vdc
I2C Protocol
For this sensor you need to choose pins for the alimentation and for the I2C (SCA,SDL) the same as for Luminosity Sensor.
#if defined(MesureIntensiteLumineuse) || defined(MesureRGB)
I2C i2c(pinSDA, pinSCL);
#endif
#ifdef MesureRGB
void mesureRGB(){
CaptRGB.getRawData(&Red, &Green, &Blue, &Clear);
uint32_t Sum = Clear;
RedValue = Red; RedValue /= Sum;
GreenValue = Green; GreenValue /= Sum;
BlueValue = Blue; BlueValue /= Sum;
RedValue *= 256; GreenValue *= 256; BlueValue *= 256;
}
#endif
- 4. Temperature Of The Ground
The Temperature Probe is an accurate, waterproof temperature sensor with an operating temperature range of -40C to 105C.
Unlike other temperature sensors it accurately reports temperature in degrees and doesn't require any other components.
For this sensor you need to choose pins for the alimentation and the data.
//DS1820 (Temperature of the ground)
#define pinDS1820 D12
#ifdef MesureTemperatureSol
void mesureTemperatureSonde(){
TemperatureSonde.convertTemperature(true, DS1820::all_devices);
TemperatureSol = TemperatureSonde.temperature();
}
#endif
- 5. Humidity of the Ground
Our soil moisture sensor measures soil mositure levels by capacitive sensing rather than resistive sensing like other sensors
This module includes an on-board voltage regulator which gives it an operating voltage range of 3.3 ~ 5.5V.
For this sensor you need to choose pins for the alimentation and the data.
//CSMS (Humidite du sol)
#define pinCSMS A0
// Mesure de l'humidité du sol
#ifdef MesureHumiditeSol
void mesureHumiditeCSMS(){
float a = -0.005312;
float b = 0.92265;
float SommeMesures = 0;
for(int i = 0; i < NombreDeMesures; i++){
HumiditeSol = CSMS.read();
HumiditeSol = (1/a)*(HumiditeSol-b);
if (HumiditeSol < 0)
HumiditeSol = 0;
if (HumiditeSol > 100)
HumiditeSol = 100;
SommeMesures += HumiditeSol;
wait_ms(DelaiEntreMesures);
}
SommeMesures /= NombreDeMesures;
HumiditeSol = SommeMesures;
}
#endif
- 6. STM32 Nucleo-32 L432KC
All sensors are connected to this card as follows.
To develop our project, we used Mbed compiler, a software on internet that allows us to work from any computer, very usefull to work on the project at home.
We have developed a very structured code in order to be able to debug very easily. Some #define and #ifdef are used so you can easily turn off a sensor by commenting only one line on a header filewhich contains a lot of global variables like pin name where sensors are connected to change it quickly.
The advantage of Mbed is that there are many reusable libraries for each sensors.
The program will record values from each sensors then display them on a LCD screen and send those records with Sigfox to display them later.
- Mapping.h
#ifndef __MAPPING_H__
#define __MAPPING_H__
// Commenter pour désactiver certaines mesures ou fonctions
#define MesureDHT22
#define MesureIntensiteLumineuse //I2C
#define MesureRGB //I2C
#define MesureTemperatureSol
#define MesureHumiditeSol
#define AffichageOLED
#define Debug
//#define SigfoxActif
//#define DeepSleepEnable
//Moyenne de mesures
#define NombreDeMesures 10
#define DelaiEntreMesures 25 // exprimé en ms
//Luxmètre
#define COEF_TSL 10
//CSMS (Humidite du sol)
#define pinCSMS A0
//DS1820 (Temperature du sol)
#define pinDS1820 D12
//DHT22 (Temperature et humidite de l'air)
#define pinDHT22 D9 //PA_8
#define modeleDHT AM2302
//I2C
#define pinSDA D0
#define pinSCL D1
//Sigfox
#define SigfoxTX D5
#define SigfoxRX D4
/*#define SigfoxTX A7
#define SigfoxRX A2*/
#define DelaiEnvoi 30 //Délai entre 2 envois en secondes
//Deep Sleep
#define DureeDeepSleep 3000 //Duree en secondes
//Ecran OLED
#define pinCS D6
#define pinRS D3
#define pinDC A5
#define pinCLK A4
#define pinDATA D2
#endif
- Main.cpp
#include "mbed.h"
#include "mapping.h"
#include "ssd1306.h"
#include "standard_font.h"
#include "bold_font.h"
#include "DHT.h"
#include "TSL2561.h"
#include "Adafruit_TCS34725.h"
#include "DS1820.h"
#include "WakeUp.h"
/************************************
* Declaration des objets
***********************************/
#ifdef SigfoxActif
Serial Sigfox(SigfoxTX, SigfoxRX);
#endif
#ifdef AffichageOLED
SSD1306 oled(pinCS, pinRS, pinDC, pinCLK, pinDATA);
#endif
#if defined(MesureIntensiteLumineuse) || defined(MesureRGB)
I2C i2c(pinSDA, pinSCL);
#endif
#ifdef MesureIntensiteLumineuse
TSL2561 Lumiere(i2c,TSL2561_ADDRESS_FLOAT);
#endif
#ifdef MesureRGB
Adafruit_TCS34725 CaptRGB(&i2c, TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
#endif
#ifdef MesureDHT22
DHT CaptDHT(pinDHT22, modeleDHT);
#endif
#ifdef MesureTemperatureSol
DS1820 TemperatureSonde(pinDS1820);
#endif
#ifdef MesureHumiditeSol
AnalogIn CSMS(pinCSMS);
#endif
DigitalOut myled(LED1);
#ifdef Debug
Serial pc(USBTX,USBRX);
#endif
/*
#ifdef DeepSleepEnable
WakeUp ModeVeille;
ModeVeille.calibrate();
#endif
*/
/************************************
* Declaration des variables globales
************************************/
int TemperatureAir, HumiditeAir;
int RGB;
float Lux;
float TemperatureSol;
float HumiditeSol;
float RedValue, GreenValue, BlueValue;
uint16_t Clear, Red, Green, Blue;
/************************************
* Fonctions de mesures ou affichage
***********************************/
// Fonction permettant l'affichage des mesures sur l'ecran
#ifdef AffichageOLED
void affichageOLED(){
oled.clear();
oled.set_font(bold_font, 8);
oled.printf("Projet AGRAL\r\n");
oled.printf("\r\n");
oled.set_font(standard_font, 6);
#ifdef MesureDHT22
oled.printf("Tempe Air : %d\r\n", TemperatureAir);
oled.printf("Humidite : %d %%\r\n", HumiditeAir);
#endif
#ifdef MesureIntensiteLumineuse
oled.printf("Lux : %.0f lux\r\n", Lux);
#endif
#ifdef MesureRGB
oled.printf("RGB : %d %d %d\r\n", int(RedValue),int(GreenValue),int(BlueValue));
#endif
#ifdef MesureTemperatureSol
oled.printf("Temp Sol : %3.0f\r\n", TemperatureSol);
#endif
#ifdef MesureHumiditeSol
oled.printf("Hum Sol : %.0f %%\r\n", HumiditeSol);
#endif
oled.update();
}
#endif
#ifdef Debug
void debugPrintf(void){
#ifdef MesureDHT22
pc.printf("Temperature : %d\r\n", TemperatureAir);
pc.printf("Humidite : %d %%\r\n", HumiditeAir);
#endif
#ifdef MesureTemperatureSol
pc.printf("Temp Sol : %3.0f\r\n", TemperatureSol);
#endif
#ifdef MesureHumiditeSol
pc.printf("Hum Sol : %.0f %%\r\n", HumiditeSol);
#endif
#ifdef MesureIntensiteLumineuse
pc.printf("Lux : %.0f lux\r\n", Lux);
#endif
#ifdef MesureRGB
pc.printf("RGB : %d %d %d\r\n", int(RedValue),int(GreenValue),int(BlueValue));
#endif
#ifdef SigfoxActif
pc.printf("\r\n");
pc.printf("AT$SF=%02x%02x%04x%02x%02x%02x%02x%02x\n\r", (int)TemperatureAir, (int)HumiditeAir, (int)Lux, (int)TemperatureSol, (int)HumiditeSol, (int)RedValue, (int)GreenValue, (int)BlueValue);
pc.printf("\r\n");
#endif
pc.printf("---------------------------------------------------\r\n");
}
#endif
// Mesure de la température et de l'humidité de l'air
#ifdef MesureDHT22
void mesuresDHT22(){
CaptDHT.readData();
TemperatureAir = CaptDHT.ReadTemperature(CELCIUS);
HumiditeAir = CaptDHT.ReadHumidity();
}
#endif
// Mesure du spectre de la lumière
#ifdef MesureRGB
void mesureRGB(){
CaptRGB.getRawData(&Red, &Green, &Blue, &Clear);
uint32_t Sum = Clear;
RedValue = Red; RedValue /= Sum;
GreenValue = Green; GreenValue /= Sum;
BlueValue = Blue; BlueValue /= Sum;
RedValue *= 256; GreenValue *= 256; BlueValue *= 256;
}
#endif
// Mesure de l'intensité lumineuse en Lux
#ifdef MesureIntensiteLumineuse
void MesureLux(){
//int i;
Lux = 0;
for(int i = 0; i < NombreDeMesures; i++){
Lux += COEF_TSL*Lumiere.lux();
wait_ms(DelaiEntreMesures);
}
Lux /= NombreDeMesures;
}
#endif
// Mesure de la temperature du sol
#ifdef MesureTemperatureSol
void mesureTemperatureSonde(){
TemperatureSonde.convertTemperature(true, DS1820::all_devices);
TemperatureSol = TemperatureSonde.temperature();
}
#endif
// Mesure de l'humidité du sol
#ifdef MesureHumiditeSol
void mesureHumiditeCSMS(){
float a = -0.005312;
float b = 0.92265;
float SommeMesures = 0;
for(int i = 0; i < NombreDeMesures; i++){
HumiditeSol = CSMS.read();
HumiditeSol = (1/a)*(HumiditeSol-b);
if (HumiditeSol < 0)
HumiditeSol = 0;
if (HumiditeSol > 100)
HumiditeSol = 100;
SommeMesures += HumiditeSol;
wait_ms(DelaiEntreMesures);
}
SommeMesures /= NombreDeMesures;
HumiditeSol = SommeMesures;
}
#endif
void ClignotementLED(int duree){
myled = !myled;
wait_ms(duree);
myled = !myled;
wait_ms(duree);
myled = !myled;
wait_ms(duree);
myled = !myled;
wait_ms(duree);
}
#ifdef AffichageOLED
void eteindreEcran(){
oled.clear();
}
#endif
/***********************************
* Fonction main
************************************/
int main()
{
// Initialisation de l'écran
#ifdef AffichageOLED
oled.initialise();
oled.set_contrast(255);
oled.clear();
#endif
while (1)
{
#ifdef MesureDHT22
mesuresDHT22();
#endif
#ifdef MesureIntensiteLumineuse
MesureLux();
#endif
#ifdef MesureRGB
mesureRGB();
#endif
#ifdef MesureTemperatureSol
mesureTemperatureSonde();
#endif
#ifdef MesureHumiditeSol
mesureHumiditeCSMS();
#endif
#ifdef AffichageOLED
affichageOLED();
#endif
#ifdef SigfoxActif
Sigfox.printf("AT$SF=");
//Sigfox.printf("15290107141f675e47");
//Sigfox.printf("65");
//Sigfox.printf("%02x%02x%04x%02x%02x%02x%02x%02x", (int)TemperatureAir, (int)HumiditeAir, (int)Lux, (int)TemperatureSol, (int)HumiditeSol, (int)RedValue, (int)GreenValue, (int)BlueValue);
Sigfox.printf("%02x%02x%04x%02x", (int)TemperatureAir, (int)HumiditeAir, (int)Lux, (int)HumiditeSol);
Sigfox.printf("\n\r");
ClignotementLED(40); //On indique quand un message est envoyé par Sigfox
#endif
#ifdef Debug
debugPrintf();
#endif
#ifdef SigfoxActif
wait(DelaiEnvoi);
#endif
#ifdef DeepSleepEnable
wait(2);
eteindreEcran();
ClignotementLED(40);
//ModeVeille.set(DureeDeepSleep);
WakeUp::set_ms(30000);
deepsleep();
#endif
//NVIC_SystemReset();
}
}
2) UbidotsUbidots is a IoT plateform that enables to develop and deploy Internet-connected applications and solutions thanks to an easy-to-use Interface. Thanks to a REST API, the Cloud Plateform is able to receive and handle HTTP requests.
- Variables
The variables correspond to data that are encapsulated into the JSON String. The variables must bear the same name as the sensors' data so that the data will be well parsed. Consequently, we create as many variables as they are data from sensors.
To develop our project, we used Ubidots for education a cloud database which collects all sensor data comming from Sigfox. hanks to a Json script all values are automatically detected, then we just have to put some widgets and tell which data is related to it.
Finally, we chose EASYEDA to create our PCB.EASYEDA is also an online sharing tool, each member can edit the project as well as from any computer making it private or public. Once the shematic is done the software will generate a PCB where you have to find the correct way to connect the pin of the sensor to its pin on the board. Obviously you can't cross the electronic strips.
Comments
Please log in or sign up to comment.