Skip to content

Commit

Permalink
Merge pull request #128 from kike-canaries/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
hpsaturn authored Feb 4, 2022
2 parents 3519a01 + b5d3b8d commit c77c900
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 29 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void setup() {
sensors.setSampleTime(15); // [optional] sensors sample time (default 5s)
sensors.setTempOffset(cfg.toffset); // [optional] temperature compensation
sensors.setCO2AltitudeOffset(cfg.altoffset); // [optional] CO2 altitude compensation
sensors.setSeaLevelPressure(1036.25); // [optional] Set sea level pressure in hpa
sensors.setDebugMode(false); // [optional] debug mode to get detailed msgs
sensors.detectI2COnly(true); // [optional] force to only i2c sensors
sensors.init(); // Auto detection to UART and i2c sensors
Expand Down Expand Up @@ -149,10 +150,17 @@ On your serial monitor you should have something like that:

## Multivariable demo

In this [demo](https://www.youtube.com/watch?v=-5Va47Bap48) with two devices and multiple sensors, you can choose the possible sub sensors units:

In this [demo](https://www.youtube.com/watch?v=-5Va47Bap48) on two different devices with multiple sensors, you can choose the possible sub sensors units or variables:

[![CanAirIO multivariable demo](https://img.youtube.com/vi/-5Va47Bap48/0.jpg)](https://www.youtube.com/watch?v=-5Va47Bap48)

In this [demo](https://www.youtube.com/watch?v=uxlmP905-FE) on a simple sketch you could have a dinamyc list of variables of multiple sensors brands:

[![CanAirIO Sensors Lib DEMO with M5CoreInk](https://img.youtube.com/vi/i15iEF47CbY/0.jpg)](https://youtu.be/i15iEF47CbY)



## Multivariable alternative implementation

The last version added new getters to have the current status of each unit of each sensor connected to the device in real time. Also you can retrieve the list of device names and other stuff:
Expand Down
14 changes: 7 additions & 7 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CanAirIO Air Quality Sensors Library",
"version": "0.5.1",
"version": "0.5.2",
"homepage":"https://canair.io",
"keywords":
[
Expand Down Expand Up @@ -75,19 +75,19 @@
"dependencies":
[
{"name":"Adafruit Unified Sensor", "owner":"adafruit", "version":"1.1.4"},
{"name":"Adafruit BME280 Library", "owner":"adafruit","version":"2.2.1"},
{"name":"Adafruit BME280 Library", "owner":"adafruit","version":"2.2.2"},
{"name":"Adafruit BMP280 Library", "owner":"adafruit","version":"2.6.1"},
{"name":"Adafruit BME680 Library","owner":"adafruit","version":"2.0.1"},
{"name":"Adafruit BusIO", "owner":"adafruit","version":"1.9.8"},
{"name":"Adafruit BusIO", "owner":"adafruit","version":"1.11.0"},
{"name":"Adafruit SHT31 Library", "owner":"adafruit","version":"2.0.0"},
{"name":"AM232X", "owner":"robtillaart", "version":"0.3.3"},
{"name":"AM232X", "owner":"robtillaart", "version":"0.4.0"},
{"name":"AHT10", "owner":"enjoyneering","version":"1.1.0"},
{"name":"sps30", "owner":"paulvha","version":"1.4.11"},
{"name":"sps30", "owner":"paulvha","version":"1.4.12"},
{"name":"MH-Z19", "owner":"wifwaf", "version":"1.5.3"},
{"name":"SparkFun SCD30 Arduino Library","owner":"sparkfun","version":"1.0.16"},
{"name":"SparkFun SCD30 Arduino Library","owner":"sparkfun","version":"1.0.17"},
{"name":"Sensirion Core","owner":"sensirion","version":"0.5.3"},
{"name":"Sensirion I2C SCD4x","owner":"sensirion","version":"0.3.1"},
{"name":"DHT_nonblocking", "version":"https://github.com/hpsaturn/DHT_nonblocking/archive/master.zip"},
{"name":"DHT_nonblocking", "version":"https://github.com/hpsaturn/DHT_nonblocking.git"},
{"name":"SN-GCJA5", "version":"https://github.com/paulvha/SN-GCJA5.git"},
{"name":"S8_UART", "version":"https://github.com/jcomas/S8_UART.git"},
{"name":"CM1106_UART", "version":"https://github.com/jcomas/CM1106_UART.git"}
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=CanAirIO Air Quality Sensors Library
version=0.5.1
version=0.5.2
author=@hpsaturn, CanAirIO project <[email protected]>
maintainer=Antonio Vanegas <[email protected]>
url=https://github.com/kike-canaries/canairio_sensorlib
Expand Down
10 changes: 5 additions & 5 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ build_flags =
-D CORE_DEBUG_LEVEL=0
lib_deps =
adafruit/Adafruit Unified Sensor @ 1.1.4
adafruit/Adafruit BME280 Library @ 2.2.1
adafruit/Adafruit BME280 Library @ 2.2.2
adafruit/Adafruit BMP280 Library @ 2.6.1
adafruit/Adafruit BME680 Library @ 2.0.1
adafruit/Adafruit BusIO @ 1.9.8
adafruit/Adafruit BusIO @ 1.11.0
adafruit/Adafruit SHT31 Library @ 2.0.0
robtillaart/AM232X @ 0.3.3
robtillaart/AM232X @ 0.4.0
enjoyneering/AHT10 @ 1.1.0
paulvha/sps30 @ 1.4.11
paulvha/sps30 @ 1.4.12
wifwaf/MH-Z19 @ 1.5.3
sparkfun/SparkFun SCD30 Arduino Library @ 1.0.16
sparkfun/SparkFun SCD30 Arduino Library @ 1.0.17
sensirion/Sensirion Core @ 0.5.3
sensirion/Sensirion I2C SCD4x @ 0.3.1
https://github.com/hpsaturn/DHT_nonblocking.git
Expand Down
43 changes: 34 additions & 9 deletions src/Sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void Sensors::loop() {
if (dataReady && (_onDataCb != nullptr)) {
_onDataCb(); // if any sensor reached any data, dataReady is true.
} else if (!dataReady && (_onErrorCb != nullptr))
_onErrorCb("[W][SLIB] No data from any sensor!");
_onErrorCb("[W][SLIB] Sensorslib error msg\t: No data from any sensor!");
}

dhtRead(); // DHT2x sensors need check fastest
Expand All @@ -60,9 +60,9 @@ bool Sensors::readAllSensors() {
DEBUG("-->[SLIB] UART data ready \t:", dataReady ? "true" : "false");
}
enableWire1();
CO2scd30Read();
GCJA5Read();
sps30Read();
CO2scd30Read();
CO2scd4xRead();
am2320Read();
sht31Read();
Expand Down Expand Up @@ -99,15 +99,16 @@ void Sensors::init(int pms_type, int pms_rx, int pms_tx) {

Serial.println("-->[SLIB] temperature offset\t: " + String(toffset));
Serial.println("-->[SLIB] altitude offset \t: " + String(altoffset));
Serial.println("-->[SLIB] sea level pressure\t: " + String(sealevel) + " hPa");
Serial.printf("-->[SLIB] only i2c sensors \t: %s\n", i2conly ? "true" : "false");

if (!i2conly && !sensorSerialInit(pms_type, pms_rx, pms_tx)) {
DEBUG("-->[SLIB] UART sensors detected\t:", "0");
}
startI2C();
CO2scd30Init();
sps30I2CInit();
GCJA5Init();
CO2scd30Init();
CO2scd4xInit();
bme680Init();
bmp280Init();
Expand All @@ -129,7 +130,13 @@ void Sensors::setSampleTime(int seconds) {
}
}

/// set CO2 recalibration PPM value (400 to 2000)
/**
* @brief set CO2 recalibration PPM value (400 to 2000)
* @param ppmValue the ppm value to set, normally 400.
*
* This method is used to set the CO2 recalibration value, please use it only on outdoor conditions.
* Please see the documentation of each sensor for more information.
*/
void Sensors::setCO2RecalibrationFactor(int ppmValue) {
if (isSensorRegistered(SENSORS::SSCD30)) {
Serial.println("-->[SLIB] SCD30 calibration to\t: " + String(ppmValue));
Expand Down Expand Up @@ -160,7 +167,12 @@ void Sensors::setCO2RecalibrationFactor(int ppmValue) {
}
}

/// set CO2 Altitude offset, recommended on high altitude
/**
* @brief set CO2 altitude offset (m)
* @param altitude (m)
*
* This method is used to compensate the CO2 value with the altitude. Recommended on high altitude.
*/
void Sensors::setCO2AltitudeOffset(float altitude){
this->altoffset = altitude;
this->hpa = hpaCalculation(altitude); //hPa hectopascal calculation based on altitude
Expand All @@ -177,6 +189,16 @@ void Sensors::setCO2AltitudeOffset(float altitude){
}
}

/**
* @brief set the sea level pressure (hPa)
* @param hpa (hPa)
*
* This method is used to set the sea level pressure for some sensors that need it.
*/
void Sensors::setSeaLevelPressure(float hpa) {
sealevel = hpa;
}

/// restart and re-init all sensors (not recommended)
void Sensors::restart() {
_serial->flush();
Expand Down Expand Up @@ -759,7 +781,7 @@ bool Sensors::CO2Mhz19Read() {
}

bool Sensors::CO2CM1106Read() {
CO2Val = cm1106->get_co2();;
CO2Val = cm1106->get_co2();
if (CO2Val > 0) {
dataReady = true;
if(altoffset != 0) CO2correctionAlt();
Expand Down Expand Up @@ -849,17 +871,18 @@ void Sensors::bme280Read() {
humi = humi1;
temp = temp1-toffset;
pres = bme280.readPressure();
alt = bme280.readAltitude(SEALEVELPRESSURE_HPA);
alt = bme280.readAltitude(sealevel);
dataReady = true;
DEBUG("-->[SLIB] BME280 read\t\t: done!");
unitRegister(UNIT::TEMP);
unitRegister(UNIT::HUM);
unitRegister(UNIT::ALT);
}

void Sensors::bmp280Read() {
float temp1 = bmp280.readTemperature();
float press1 = bmp280.readPressure();
float alt1 = bmp280.readAltitude(SEALEVELPRESSURE_HPA);
float alt1 = bmp280.readAltitude(sealevel);
if (press1 == 0 || isnan(temp1) || isnan(alt1)) return;
temp = temp1-toffset;
pres = press1/100; // convert to hPa
Expand All @@ -880,13 +903,14 @@ void Sensors::bme680Read() {
humi = bme680.humidity;
pres = bme680.pressure / 100.0;
gas = bme680.gas_resistance / 1000.0;
alt = bme680.readAltitude(SEALEVELPRESSURE_HPA);
alt = bme680.readAltitude(sealevel);
dataReady = true;
DEBUG("-->[SLIB] BME680 read\t\t: done!");
unitRegister(UNIT::TEMP);
unitRegister(UNIT::HUM);
unitRegister(UNIT::PRESS);
unitRegister(UNIT::GAS);
unitRegister(UNIT::ALT);
}

void Sensors::aht10Read() {
Expand Down Expand Up @@ -916,6 +940,7 @@ void Sensors::sht31Read() {
}

void Sensors::CO2scd30Read() {
if (!scd30.isConnected()) return;
uint16_t tCO2 = scd30.getCO2(); // we need temp var, without it override CO2
if (tCO2 > 0) {
CO2Val = tCO2;
Expand Down
14 changes: 8 additions & 6 deletions src/Sensors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include <s8_uart.h>
#include <sps30.h>

#define CSL_VERSION "0.5.1"
#define CSL_REVISION 352
#define CSL_VERSION "0.5.2"
#define CSL_REVISION 355

/***************************************************************
* S E T U P E S P 3 2 B O A R D S A N D F I E L D S
Expand Down Expand Up @@ -77,10 +77,7 @@
#define SENSOR_RETRY 1000 // Max Serial characters

// Sensirion SPS30 sensor
#define SENSOR_COMMS SERIALPORT2 // UART OR I2C

//H&T definitions
#define SEALEVELPRESSURE_HPA 1036.25
#define SENSOR_COMMS SERIALPORT2 // UART OR I2C

#define SENSOR_UNITS \
X(NUNIT, "NUNIT", "NUNIT") \
Expand Down Expand Up @@ -151,6 +148,9 @@ class Sensors {
// Altitud compensation variable
float altoffset = 0.0;

// Sea level pressure (hPa)
float sealevel = 1013.25;

// Altitud hpa calculation
float hpa = 0.0;

Expand Down Expand Up @@ -247,6 +247,8 @@ class Sensors {

void setCO2AltitudeOffset(float altitude);

void setSeaLevelPressure(float hpa);

String getFormatTemp();

String getFormatPress();
Expand Down

0 comments on commit c77c900

Please sign in to comment.