Skip to content

Commit

Permalink
Merge pull request #118 from kike-canaries/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
hpsaturn authored Jan 7, 2022
2 parents 22db523 + 8dd7886 commit de7324e
Show file tree
Hide file tree
Showing 12 changed files with 635 additions and 111 deletions.
130 changes: 107 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ NOTE: DHT22 is supported but is not recommended
- Unified variables for all sensors
- Auto UART port selection (Hw, Sw, UART1, UART2, etc)
- Multiple i2c reads and one UART sensor read support
- Real time registry of sensors unit registered (see multivariable)
- Preselected main stream UART pins from popular boards
- Auto config UART port for Plantower, Honeywell and Panasonic sensors
- Unified calibration trigger for all CO2 sensors
- Unified CO2 Altitude compensation
- Unified temperature offset for CO2 and environment sensors
- Public access to main objects of each library (full methods access)
- Get unit symbol and name and each sub-sensor
- Get the main sensor detected. Two main groups: CO2 and PM
- Basic debug mode support toggle in execution
- Basic power saving management with sample time > 30s on SPS30

Expand All @@ -67,14 +70,6 @@ Full list of all sub libraries supported [here](https://github.com/kike-canaries
```Java
sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback
sensors.init(); // start all sensors and
// try to detect UART sensors like:
// Panasonic, Honeywell or Plantower.
// For special UART sensors try select it:
// init(sensors.Sensirion)
// init(sensors.Mhz19)
// init(sensors.CM1106)
// init(sensors.SENSEAIRS8)
// For I2C sensors, with empty parameter is enough.
```

# Full implementation
Expand Down Expand Up @@ -104,10 +99,19 @@ void setup() {
sensors.setCO2AltitudeOffset(cfg.altoffset); // [optional] CO2 altitude compensation
sensors.setDebugMode(false); // [optional] debug mode enable/disable
sensors.detectI2COnly(true); // [optional] force to only i2c sensors
sensors.init(); // start all sensors with auto detection mode.
// Also you can try to select one:
// sensors.init(sensors.Sensirion);
// All i2c sensors are autodetected.
sensors.init(); // Auto detection to UART and i2c sensors

// Alternatives only for UART sensors (TX/RX):

// sensors.init(sensors.Auto); // Auto detection to UART sensors (Honeywell, Plantower, Panasonic)
// sensors.init(sensors.Panasonic); // Force UART detection to Panasonic sensor
// sensors.init(sensors.Sensirion); // Force UART detection to Sensirion sensor
// sensors.init(sensors.Mhz19); // Force UART detection to Mhz14 or Mhz19 CO2 sensor
// sensors.init(sensors.SDS011); // Force UART detection to SDS011 sensor
// sensors.init(sensors.CM1106); // Force UART detection to CM1106 CO2 sensor
// sensors.init(sensors.SENSEAIRS8); // Force UART detection to SenseAirS8 CO2 sensor
// sensors.init(sensors.Auto,PMS_RX,PMS_TX); // Auto detection on custom RX,TX


// Also you can access to sub library objects, and perform for example calls like next:

Expand Down Expand Up @@ -141,7 +145,73 @@ On your serial monitor you should have something like that:
-->[MAIN] PM1.0: 002 PM2.5: 002 PM10: 002
```

# Demo
# Multivariable demo

In this demo with two devices and multiple sensors, you can choose the possible sub sensors units:

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

# Multivariable 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.

For example:

```cpp
/**
* Example or alternative of the selection of the main sensor unit
*/

void getMainValue() {
// If the main sensor (CO2 or PM2.5) was not detected but the temperature is registered
if (sensors.getMainDeviceSelected().isEmpty() && sensors.isUnitRegistered(UNIT::TEMP)) {
mainValue = (uint32_t) sensors.getTemperature();
uName = sensors.getUnitName(UNIT::TEMP);
uSymbol = sensors.getUnitSymbol(UNIT::TEMP);
// The main sensor is a particle meter device
} else if (sensors.getMainSensorTypeSelected() == Sensors::SENSOR_PM) {
mainValue = sensors.getPM25();
uName = sensors.getUnitName(UNIT::PM25);
uSymbol = sensors.getUnitSymbol(UNIT::PM25);
// The main sensor is a CO2 device
} else if (sensors.getMainSensorTypeSelected() == Sensors::SENSOR_CO2) {
mainValue = sensors.getCO2();
uName = sensors.getUnitName(UNIT::CO2);
uSymbol = sensors.getUnitSymbol(UNIT::CO2);
}
}

/**
* Example or alternative of the selection of the minor sensor unit
*/

void getMinorValue(UNIT mainUnit) {
minorValue = (uint32_t)sensors.getUnitValue(mainUnit);
uName = sensors.getUnitName(mainUnit);
uSymbol = sensors.getUnitSymbol(mainUnit);
}


void onSensorDataOk() {

Serial.println("");

getMainValue(); // choose the main sensor possible
Serial.println ("-->[MAIN] Main sensor unit \t: "+uName+": "+String(mainValue)+" "+uSymbol);

getMinorValue(nextUnit); // Load values ot the minor sensor. (see the loop)
Serial.println ("-->[MAIN] Secondary sensor unit\t: "+uName+": "+String(minorValue)+" "+uSymbol);

Serial.println("");

// example for choose and change the next unit able:
nextUnit = (UNIT)sensors.getNextUnit(); // Change the minor sensor

}
```
# UART detection demo
[![CanAirIO auto configuration demo](https://img.youtube.com/vi/hmukAmG5Eec/0.jpg)](https://www.youtube.com/watch?v=hmukAmG5Eec)
Expand All @@ -152,25 +222,38 @@ CanAirIO sensorlib auto configuration demo on [Youtube](https://www.youtube.com/
The current version of library supports 3 kinds of wiring connection, UART, i2c and TwoWire, in the main boards the library using the defaults pins of each board, but in some special cases the pins are:
### UART
## UART
### Predefined UART
The library has [pre-defined some UART pin configs](https://github.com/kike-canaries/canairio_sensorlib/blob/master/src/Sensors.hpp#L19-L52), these are selected on compiling time. Maybe you don't need change anything with your board.
The library has [pre-defined some UART pin configs](https://github.com/kike-canaries/canairio_sensorlib/blob/master/src/Sensors.hpp#L19-L52), these are selected on compiling time. Maybe you don't need change anything with your board, and maybe the nexts alternatives works for you:
Also you can define the UART pins in the init() method, please see below.
| Board model | TX | RX | Notes
|:---------------|:---:|:---:|:------------------:|
| ESP32GENERIC | 1 | 3 | ESP32 Pio defaults
| TTGOT7 / ESP32DEVKIT / D1MINI / NODEFINED | 16 | 17 | CanAirIO devices **
| TTGO_TDISPLAY | 12 | 13 | |
| M5COREINK | 14 | 13 | |
| TTGO TQ | 18 | 13 | |
| HELTEC | 18 | 17 | |
| WEMOSOLED | 15 | 13 | |
| ESP32PICOD4 | 3 | 1 | |
** This pines are when you compile your project without specific any build variable or you board isn't in the list.
#### Custom UART RX/TX:
### Custom UART:
You can pass the custom pins if it isn't autodected:
Also you could define a custom UART pins in the init() method if it isn't autodected:
```cpp
sensors.init(sensors.Auto,RX,TX); // custom RX, custom TX pines.
```

### I2C (recommended)
## I2C (recommended)

We are using the default pins for each board, some times it's pins are 21,22, please check your board schematic.

### TwoWire (deprecated soon)
## TwoWire (deprecated soon)

For now we are using it only for DHT sensors in PIN 23. For more info please review the next lines [here](https://github.com/kike-canaries/canairio_sensorlib/blob/master/src/Sensors.hpp#L19-L52).

Expand Down Expand Up @@ -252,24 +335,25 @@ Also you can make a donation, be a patreon or buy a device:
- [x] Auto detection for UART sensors (Honeywell, Panasonic and Plantower)
- [x] Added SPS30 library with auto UART detection
- [x] Disable/enable logs (debug mode flag)
- [x] Added bme280, aht10, sht31, am2320 i2c sensors
- [x] Added bme280, bmp280, aht10, sht31, am2320 i2c sensors
- [x] Exposed public sub-libraries objects, sps30, aht10, etc.
- [x] Added old DHT sensors
- [x] Added CO2 sensors: MHZ19, SCD30, CM1106 via UART
- [x] Added SDS011 particle metter
- [x] BME680 support (from TTGO-T7 CanAirIO version)
- [x] BME680 support
- [x] Added Sensirion SPS30 and Panasonic SN-GCJA5 via i2c
- [x] Enable/Disable UART detection for force only i2c
- [x] Temperature and Altitude compensation
- [x] SenseAir S8 via UART support
- [x] Multivariable selection (getNextUnit(),getUnitName(),etc)
- [ ] Improve to sensor dynamic registry
- [ ] IAQ indicator from BME680 Bosch library

# Projects using this Library

- [CanAirIO Device](https://github.com/kike-canaries/canairio_firmware): ESP32 Air quality device for mobile and fixed stations. (PM2.5 and CO2)
- [Medidor de CO2](https://emariete.com/medidor-co2-display-tft-color-ttgo-t-display-sensirion-scd30): Un medidor de CO2 de alta calidad con pantalla en color. (CO2)


# Credits

Thanks to all collaborators and [CanAirIO](https://canair.io) community for testing and reports.
Expand Down
34 changes: 34 additions & 0 deletions examples/advanced_multivariable/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
src_dir = .

[common_env_data]
framework = arduino
upload_speed = 1500000
monitor_speed = 115200
lib_deps =
hpsaturn/CanAirIO Air Quality Sensors Library

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = ${common_env_data.framework}
upload_speed = ${common_env_data.upload_speed}
monitor_speed = ${common_env_data.monitor_speed}
lib_deps = ${common_env_data.lib_deps}

[env:esp8266]
platform = espressif8266
board = esp12e
framework = ${common_env_data.framework}
monitor_speed = ${common_env_data.monitor_speed}
lib_deps = ${common_env_data.lib_deps}
120 changes: 120 additions & 0 deletions examples/advanced_multivariable/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* @file main.cpp
* @author Antonio Vanegas @hpsaturn
* @date June 2018 - 2022
* @brief CanAirIO Sensorslib tests
* @license GPL3
*
* Full documentation:
* https://github.com/kike-canaries/canairio_sensorlib#canairio-air-quality-sensors-library
*
* Full implementation for WiFi and Bluetooth Air Quality fixed and mobile station:
* https://github.com/kike-canaries/canairio_firmware#canairio-firmware
*
* CanAirIO project documentation:
* https://canair.io/docs
*/

#include <Arduino.h>
#include <Sensors.hpp>

uint16_t mainValue = 0;
uint16_t minorValue = 0;
String uSymbol = "";
String uName = "";
UNIT nextUnit = UNIT::NUNIT;

/**
* Example or alternative of the selection of the main sensor unit
*/
void getMainValue() {
// If the main sensor (CO2 or PM2.5) was not detected and temperature is registered
if (sensors.getMainDeviceSelected().isEmpty() && sensors.isUnitRegistered(UNIT::TEMP)) {
mainValue = (uint32_t) sensors.getTemperature();
uName = sensors.getUnitName(UNIT::TEMP);
uSymbol = sensors.getUnitSymbol(UNIT::TEMP);
// The main sensor is a particle meter device
} else if (sensors.getMainSensorTypeSelected() == Sensors::SENSOR_PM) {
mainValue = sensors.getPM25();
uName = sensors.getUnitName(UNIT::PM25);
uSymbol = sensors.getUnitSymbol(UNIT::PM25);
// The main sensor is a CO2 device
} else if (sensors.getMainSensorTypeSelected() == Sensors::SENSOR_CO2) {
mainValue = sensors.getCO2();
uName = sensors.getUnitName(UNIT::CO2);
uSymbol = sensors.getUnitSymbol(UNIT::CO2);
}
}

/**
* Example or alternative of the selection of the minor sensor unit
*/

void getMinorValue(UNIT mainUnit) {
minorValue = (uint32_t)sensors.getUnitValue(mainUnit);
uName = sensors.getUnitName(mainUnit);
uSymbol = sensors.getUnitSymbol(mainUnit);
}


void onSensorDataOk() {

Serial.println("");

getMainValue(); // choose the main sensor possible
Serial.println ("-->[MAIN] Main sensor unit \t: "+uName+": "+String(mainValue)+" "+uSymbol);

getMinorValue(nextUnit); // Load values ot the minor sensor. (see the loop)
Serial.println ("-->[MAIN] Secondary sensor unit\t: "+uName+": "+String(minorValue)+" "+uSymbol);

Serial.println("");

nextUnit = (UNIT)sensors.getNextUnit(); // Change the minor sensor

}

void onSensorDataError(const char * msg){
Serial.println(msg);
}

/******************************************************************************
* M A I N
******************************************************************************/

void setup() {
Serial.begin(115200);
delay(200);
Serial.println("\n== Sensor test setup ==\n");

Serial.println("-->[SETUP] Detecting sensors..");

// enable possible sensors on pin 27
pinMode(27, OUTPUT);
digitalWrite(27, HIGH);

sensors.setSampleTime(5); // config sensors sample time interval
sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback
sensors.setOnErrorCallBack(&onSensorDataError); // [optional] error callback
sensors.setDebugMode(true); // [optional] debug mode
sensors.detectI2COnly(false); // disable force to only i2c sensors
sensors.init(); // Auto detection to UART and i2c sensors

// Alternatives only for UART sensors (TX/RX):

// sensors.init(sensors.Auto); // Auto detection to UART sensors (Honeywell, Plantower, Panasonic)
// sensors.init(sensors.Panasonic); // Force UART detection to Panasonic sensor
// sensors.init(sensors.Sensirion); // Force UART detection to Sensirion sensor
// sensors.init(sensors.Mhz19); // Force UART detection to Mhz14 or Mhz19 CO2 sensor
// sensors.init(sensors.SDS011); // Force UART detection to SDS011 sensor
// sensors.init(sensors.CM1106); // Force UART detection to CM1106 CO2 sensor
// sensors.init(sensors.SENSEAIRS8); // Force UART detection to SenseAirS8 CO2 sensor
// sensors.init(sensors.Auto,PMS_RX,PMS_TX); // Auto detection on custom RX,TX

Serial.println("-->[SETUP] Main sensor configured: " + sensors.getMainDeviceSelected());

delay(500);
}

void loop() {
sensors.loop(); // read sensor data and showed it
}
27 changes: 13 additions & 14 deletions examples/basic/basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,19 @@ void setup() {
sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback
sensors.setOnErrorCallBack(&onSensorDataError); // [optional] error callback
sensors.setDebugMode(false); // [optional] debug mode

// sensors.init(); // Auto detection of PM sensors (Honeywell, Plantower, Panasonic)
// sensors.init(sensors.Auto); // Auto detection of PM sensors (Honeywell, Plantower, Panasonic)
// sensors.init(sensors.Panasonic); // Force detection to Panasonic sensor
// sensors.init(sensors.Sensirion); // Force detection to Sensirion sensor
// sensors.init(sensors.Mhz19); // Force detection to Mhz14 or Mhz19 CO2 sensor
// sensors.init(sensors.SDS011); // Force detection to SDS011 sensor
// sensors.init(sensors.CM1006); // Force detection to CM1106 CO2 sensor
// sensors.init(sensors.Auto,mRX,mTX); // Auto detection and custom RX, TX pines
// sensors.init(sensors.Auto,PMS_RX,PMS_TX); // Auto detection, custom RX,TX and custom DHT config
// sensors.detectI2COnly(true); // Force only i2c sensors

sensors.init(); // Force detection to Sensirion sensor

sensors.init(); // Auto detection to UART and i2c sensors

// Alternatives only for UART sensors (TX/RX):

// sensors.init(sensors.Auto); // Auto detection to UART sensors (Honeywell, Plantower, Panasonic)
// sensors.init(sensors.Panasonic); // Force UART detection to Panasonic sensor
// sensors.init(sensors.Sensirion); // Force UART detection to Sensirion sensor
// sensors.init(sensors.Mhz19); // Force UART detection to Mhz14 or Mhz19 CO2 sensor
// sensors.init(sensors.SDS011); // Force UART detection to SDS011 sensor
// sensors.init(sensors.CM1106); // Force UART detection to CM1106 CO2 sensor
// sensors.init(sensors.SENSEAIRS8); // Force UART detection to SenseAirS8 CO2 sensor
// sensors.init(sensors.Auto,PMS_RX,PMS_TX); // Auto detection on custom RX,TX

Serial.println("-->[SETUP] Sensor configured: " + sensors.getMainDeviceSelected());

delay(500);
Expand Down
Loading

0 comments on commit de7324e

Please sign in to comment.