Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SmartHome
NodeManager_BME280_EasyPCB
Commits
6664b5eb
Commit
6664b5eb
authored
Jul 15, 2017
by
user2684
Committed by
GitHub
Jul 15, 2017
Browse files
Added support for BMP280 sensor (#88)
parent
eacaaab9
Changes
5
Show whitespace changes
Inline
Side-by-side
NodeManager.cpp
View file @
6664b5eb
...
@@ -1710,7 +1710,7 @@ void SensorMLX90614::onInterrupt() {
...
@@ -1710,7 +1710,7 @@ void SensorMLX90614::onInterrupt() {
/*
/*
SensorBosch
SensorBosch
*/
*/
#if MODULE_BME280 == 1 || MODULE_BMP085 == 1
#if MODULE_BME280 == 1 || MODULE_BMP085 == 1
|| MODULE_BMP280 == 1
// contructor
// contructor
SensorBosch
::
SensorBosch
(
NodeManager
*
node_manager
,
int
child_id
,
int
sensor_type
)
:
Sensor
(
node_manager
,
child_id
,
A4
)
{
SensorBosch
::
SensorBosch
(
NodeManager
*
node_manager
,
int
child_id
,
int
sensor_type
)
:
Sensor
(
node_manager
,
child_id
,
A4
)
{
_sensor_type
=
sensor_type
;
_sensor_type
=
sensor_type
;
...
@@ -1998,6 +1998,54 @@ void SensorBMP085::onLoop() {
...
@@ -1998,6 +1998,54 @@ void SensorBMP085::onLoop() {
}
}
#endif
#endif
/*
* SensorBMP280
*/
#if MODULE_BMP280 == 1
SensorBMP280
::
SensorBMP280
(
NodeManager
*
node_manager
,
int
child_id
,
Adafruit_BMP280
*
bmp
,
int
sensor_type
)
:
SensorBosch
(
node_manager
,
child_id
,
sensor_type
)
{
_bmp
=
bmp
;
}
void
SensorBMP280
::
onLoop
()
{
// temperature sensor
if
(
_sensor_type
==
SensorBMP280
::
TEMPERATURE
)
{
// read the temperature
float
temperature
=
_bmp
->
readTemperature
();
// convert it
temperature
=
_node_manager
->
celsiusToFahrenheit
(
temperature
);
#if DEBUG == 1
Serial
.
print
(
F
(
"BMP I="
));
Serial
.
print
(
_child_id
);
Serial
.
print
(
F
(
" T="
));
Serial
.
println
(
temperature
);
#endif
if
(
isnan
(
temperature
))
return
;
// store the value
_value_float
=
temperature
;
}
// Pressure Sensor
else
if
(
_sensor_type
==
SensorBMP280
::
PRESSURE
)
{
// read pressure
float
pressure
=
_bmp
->
readPressure
()
/
100.0
F
;
if
(
isnan
(
pressure
))
return
;
#if DEBUG == 1
Serial
.
print
(
F
(
"BMP I="
));
Serial
.
print
(
_child_id
);
Serial
.
print
(
F
(
" P="
));
Serial
.
println
(
pressure
);
#endif
if
(
isnan
(
pressure
))
return
;
// store the value
_value_float
=
pressure
;
}
// Forecast Sensor
else
if
(
_sensor_type
==
SensorBMP280
::
FORECAST
)
{
float
pressure
=
_bmp
->
readPressure
()
/
100.0
F
;
_forecast
(
pressure
);
}
}
#endif
/*
/*
SensorHCSR04
SensorHCSR04
*/
*/
...
@@ -3025,6 +3073,26 @@ int NodeManager::registerSensor(int sensor_type, int pin, int child_id) {
...
@@ -3025,6 +3073,26 @@ int NodeManager::registerSensor(int sensor_type, int pin, int child_id) {
return
registerSensor
(
new
SensorBME280
(
this
,
child_id
,
bme
,
SensorBME280
::
FORECAST
));
return
registerSensor
(
new
SensorBME280
(
this
,
child_id
,
bme
,
SensorBME280
::
FORECAST
));
}
}
#endif
#endif
#if MODULE_BMP280 == 1
else
if
(
sensor_type
==
SENSOR_BMP280
)
{
Adafruit_BMP280
*
bmp
=
new
Adafruit_BMP280
();
if
(
!
bmp
->
begin
(
SensorBosch
::
GetI2CAddress
(
0x58
)))
{
#if DEBUG == 1
Serial
.
println
(
F
(
"NO BMP"
));
#endif
return
-
1
;
}
// register temperature sensor
registerSensor
(
new
SensorBMP280
(
this
,
child_id
,
bmp
,
SensorBMP280
::
TEMPERATURE
));
child_id
=
_getAvailableChildId
();
// register pressure sensor
child_id
=
_getAvailableChildId
();
registerSensor
(
new
SensorBMP280
(
this
,
child_id
,
bmp
,
SensorBMP280
::
PRESSURE
));
// register forecast sensor
child_id
=
_getAvailableChildId
();
return
registerSensor
(
new
SensorBMP280
(
this
,
child_id
,
bmp
,
SensorBMP280
::
FORECAST
));
}
#endif
#if MODULE_SONOFF == 1
#if MODULE_SONOFF == 1
else
if
(
sensor_type
==
SENSOR_SONOFF
)
{
else
if
(
sensor_type
==
SENSOR_SONOFF
)
{
return
registerSensor
(
new
SensorSonoff
(
this
,
child_id
));
return
registerSensor
(
new
SensorSonoff
(
this
,
child_id
));
...
...
NodeManager.h
View file @
6664b5eb
...
@@ -187,6 +187,10 @@
...
@@ -187,6 +187,10 @@
#ifndef MODULE_PT100
#ifndef MODULE_PT100
#define SENSOR_PT100 0
#define SENSOR_PT100 0
#endif
#endif
// Enable this module to use one of the following sensors: SENSOR_BMP280
#ifndef MODULE_BMP280
#define MODULE_BMP280 0
#endif
/***********************************
/***********************************
Supported Sensors
Supported Sensors
...
@@ -254,7 +258,7 @@ enum supported_sensors {
...
@@ -254,7 +258,7 @@ enum supported_sensors {
SENSOR_MLX90614
,
SENSOR_MLX90614
,
#endif
#endif
#if MODULE_BME280 == 1
#if MODULE_BME280 == 1
//
MLX90614
sensor,
contactless
temperature
sensor
//
BME280
sensor,
return
temperature
, humidity and pressure
SENSOR_BME280
,
SENSOR_BME280
,
#endif
#endif
#if MODULE_SONOFF == 1
#if MODULE_SONOFF == 1
...
@@ -293,6 +297,10 @@ enum supported_sensors {
...
@@ -293,6 +297,10 @@ enum supported_sensors {
// High temperature sensor associated with DFRobot Driver, return the temperature in C° from the attached PT100 sensor
// High temperature sensor associated with DFRobot Driver, return the temperature in C° from the attached PT100 sensor
SENSOR_PT100
,
SENSOR_PT100
,
#endif
#endif
#if MODULE_BMP280 == 1
// BMP280 sensor, return temperature and pressure
SENSOR_BMP280
,
#endif
};
};
/***********************************
/***********************************
...
@@ -363,7 +371,12 @@ enum supported_sensors {
...
@@ -363,7 +371,12 @@ enum supported_sensors {
#include <Wire.h>
#include <Wire.h>
#endif
#endif
#if MODULE_PT100 == 1
#if MODULE_PT100 == 1
#include<DFRobotHighTemperatureSensor.h>
#include <DFRobotHighTemperatureSensor.h>
#endif
#if MODULE_BMP280 == 1
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#endif
#endif
/*******************************************************************
/*******************************************************************
...
@@ -984,7 +997,7 @@ class SensorMLX90614: public Sensor {
...
@@ -984,7 +997,7 @@ class SensorMLX90614: public Sensor {
* SensorBosch
* SensorBosch
*/
*/
#if MODULE_BME280 == 1 || MODULE_BMP085 == 1
#if MODULE_BME280 == 1 || MODULE_BMP085 == 1
|| MODULE_BMP280 == 1
class
SensorBosch
:
public
Sensor
{
class
SensorBosch
:
public
Sensor
{
public:
public:
SensorBosch
(
NodeManager
*
node_manager
,
int
child_id
,
int
sensor_type
);
SensorBosch
(
NodeManager
*
node_manager
,
int
child_id
,
int
sensor_type
);
...
@@ -1044,6 +1057,19 @@ class SensorBMP085: public SensorBosch {
...
@@ -1044,6 +1057,19 @@ class SensorBMP085: public SensorBosch {
};
};
#endif
#endif
/*
SensorBMP280
*/
#if MODULE_BMP280 == 1
class
SensorBMP280
:
public
SensorBosch
{
public:
SensorBMP280
(
NodeManager
*
node_manager
,
int
child_id
,
Adafruit_BMP280
*
bmp
,
int
sensor_type
);
void
onLoop
();
protected:
Adafruit_BMP280
*
_bmp
;
};
#endif
/*
/*
SensorHCSR04
SensorHCSR04
*/
*/
...
...
NodeManager.ino
View file @
6664b5eb
...
@@ -34,10 +34,6 @@ void before() {
...
@@ -34,10 +34,6 @@ void before() {
*/
*/
/*
* Register below your sensors
*/
/*
/*
* Register above your sensors
* Register above your sensors
...
...
README.md
View file @
6664b5eb
...
@@ -179,6 +179,11 @@ Those NodeManager's directives in the `config.h` file control which module/libra
...
@@ -179,6 +179,11 @@ Those NodeManager's directives in the `config.h` file control which module/libra
#define MODULE_AM2320 0
#define MODULE_AM2320 0
// Enable this module to use one of the following sensors: SENSOR_TSL2561
// Enable this module to use one of the following sensors: SENSOR_TSL2561
#define MODULE_TSL2561 0
#define MODULE_TSL2561 0
// Enable this module to use one of the following sensors: SENSOR_PT100
#define MODULE_PT100 0
// Enable this module to use one of the following sensors: SENSOR_BMP280
#define MODULE_BMP280 0
~~~
~~~
### Installing the dependencies
### Installing the dependencies
...
@@ -199,6 +204,7 @@ MODULE_HCSR04 | https://github.com/mysensors/MySensorsArduinoExamples/tree/maste
...
@@ -199,6 +204,7 @@ MODULE_HCSR04 | https://github.com/mysensors/MySensorsArduinoExamples/tree/maste
MODULE_MCP9808 | https://github.com/adafruit/Adafruit_MCP9808_Library
MODULE_MCP9808 | https://github.com/adafruit/Adafruit_MCP9808_Library
MODULE_AM2320 | https://github.com/thakshak/AM2320
MODULE_AM2320 | https://github.com/thakshak/AM2320
MODULE_TSL2561 | https://github.com/adafruit/TSL2561-Arduino-Library
MODULE_TSL2561 | https://github.com/adafruit/TSL2561-Arduino-Library
MODULE_BMP280 | https://github.com/adafruit/Adafruit_BMP280_Library
### Configure NodeManager
### Configure NodeManager
...
@@ -348,6 +354,8 @@ SENSOR_SOIL_MOISTURE | Soil moisture sensor, return the percentage of moisture f
...
@@ -348,6 +354,8 @@ SENSOR_SOIL_MOISTURE | Soil moisture sensor, return the percentage of moisture f
SENSOR_MHZ19 | MH-Z19 CO2 sensor via UART (SoftwareSerial, default on pins 6(Rx) and 7(Tx)
SENSOR_MHZ19 | MH-Z19 CO2 sensor via UART (SoftwareSerial, default on pins 6(Rx) and 7(Tx)
SENSOR_TSL2561 | TSL2561 sensor, return light in lux
SENSOR_TSL2561 | TSL2561 sensor, return light in lux
SENSOR_AM2320 | AM2320 sensors, return temperature/humidity based on the attached AM2320 sensor
SENSOR_AM2320 | AM2320 sensors, return temperature/humidity based on the attached AM2320 sensor
SENSOR_PT100 | High temperature sensor associated with DFRobot Driver, return the temperature in C° from the attached PT100 sensor
SENSOR_BMP280 | BMP280 sensor, return temperature/pressure based on the attached BMP280 sensor
To register a sensor simply call the NodeManager instance with the sensory type and the pin the sensor is conncted to. For example:
To register a sensor simply call the NodeManager instance with the sensory type and the pin the sensor is conncted to. For example:
~~~
c
~~~
c
...
@@ -578,7 +586,7 @@ Each sensor class can expose additional methods.
...
@@ -578,7 +586,7 @@ Each sensor class can expose additional methods.
DeviceAddress
*
getDeviceAddress
();
DeviceAddress
*
getDeviceAddress
();
~~~
~~~
*
SensorBME280 / SensorBMP085
*
SensorBME280 / SensorBMP085
/ SensorBMP280
~~~
c
~~~
c
// [101] define how many pressure samples to keep track of for calculating the forecast (default: 5)
// [101] define how many pressure samples to keep track of for calculating the forecast (default: 5)
void
setForecastSamplesCount
(
int
value
);
void
setForecastSamplesCount
(
int
value
);
...
...
config.h
View file @
6664b5eb
...
@@ -148,5 +148,8 @@
...
@@ -148,5 +148,8 @@
#define MODULE_TSL2561 0
#define MODULE_TSL2561 0
// Enable this module to use one of the following sensors: SENSOR_PT100
// Enable this module to use one of the following sensors: SENSOR_PT100
#define MODULE_PT100 0
#define MODULE_PT100 0
// Enable this module to use one of the following sensors: SENSOR_BMP280
#define MODULE_BMP280 0
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment