Commit 6664b5eb authored by user2684's avatar user2684 Committed by GitHub
Browse files

Added support for BMP280 sensor (#88)

parent eacaaab9
......@@ -1710,7 +1710,7 @@ void SensorMLX90614::onInterrupt() {
/*
SensorBosch
*/
#if MODULE_BME280 == 1 || MODULE_BMP085 == 1
#if MODULE_BME280 == 1 || MODULE_BMP085 == 1 || MODULE_BMP280 == 1
// contructor
SensorBosch::SensorBosch(NodeManager* node_manager, int child_id, int sensor_type): Sensor(node_manager, child_id,A4) {
_sensor_type = sensor_type;
......@@ -1998,6 +1998,54 @@ void SensorBMP085::onLoop() {
}
#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.0F;
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.0F;
_forecast(pressure);
}
}
#endif
/*
SensorHCSR04
*/
......@@ -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));
}
#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
else if (sensor_type == SENSOR_SONOFF) {
return registerSensor(new SensorSonoff(this,child_id));
......
......@@ -187,6 +187,10 @@
#ifndef MODULE_PT100
#define SENSOR_PT100 0
#endif
// Enable this module to use one of the following sensors: SENSOR_BMP280
#ifndef MODULE_BMP280
#define MODULE_BMP280 0
#endif
/***********************************
Supported Sensors
......@@ -254,7 +258,7 @@ enum supported_sensors {
SENSOR_MLX90614,
#endif
#if MODULE_BME280 == 1
// MLX90614 sensor, contactless temperature sensor
// BME280 sensor, return temperature, humidity and pressure
SENSOR_BME280,
#endif
#if MODULE_SONOFF == 1
......@@ -293,6 +297,10 @@ enum supported_sensors {
// High temperature sensor associated with DFRobot Driver, return the temperature in C° from the attached PT100 sensor
SENSOR_PT100,
#endif
#if MODULE_BMP280 == 1
// BMP280 sensor, return temperature and pressure
SENSOR_BMP280,
#endif
};
/***********************************
......@@ -363,7 +371,12 @@ enum supported_sensors {
#include <Wire.h>
#endif
#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
/*******************************************************************
......@@ -984,7 +997,7 @@ class SensorMLX90614: public Sensor {
* SensorBosch
*/
#if MODULE_BME280 == 1 || MODULE_BMP085 == 1
#if MODULE_BME280 == 1 || MODULE_BMP085 == 1 || MODULE_BMP280 == 1
class SensorBosch: public Sensor {
public:
SensorBosch(NodeManager* node_manager, int child_id, int sensor_type);
......@@ -1044,6 +1057,19 @@ class SensorBMP085: public SensorBosch {
};
#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
*/
......
......@@ -33,10 +33,6 @@ void before() {
* Register below your sensors
*/
/*
* Register below your sensors
*/
/*
......
......@@ -179,6 +179,11 @@ Those NodeManager's directives in the `config.h` file control which module/libra
#define MODULE_AM2320 0
// Enable this module to use one of the following sensors: SENSOR_TSL2561
#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
......@@ -199,6 +204,7 @@ MODULE_HCSR04 | https://github.com/mysensors/MySensorsArduinoExamples/tree/maste
MODULE_MCP9808 | https://github.com/adafruit/Adafruit_MCP9808_Library
MODULE_AM2320 | https://github.com/thakshak/AM2320
MODULE_TSL2561 | https://github.com/adafruit/TSL2561-Arduino-Library
MODULE_BMP280 | https://github.com/adafruit/Adafruit_BMP280_Library
### Configure NodeManager
......@@ -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_TSL2561 | TSL2561 sensor, return light in lux
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:
~~~c
......@@ -578,7 +586,7 @@ Each sensor class can expose additional methods.
DeviceAddress* getDeviceAddress();
~~~
* SensorBME280 / SensorBMP085
* SensorBME280 / SensorBMP085 / SensorBMP280
~~~c
// [101] define how many pressure samples to keep track of for calculating the forecast (default: 5)
void setForecastSamplesCount(int value);
......
......@@ -148,5 +148,8 @@
#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
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment