Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sngcja5l i2c #74

Merged
merged 10 commits into from
Jun 9, 2021
138 changes: 83 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,44 @@

# CanAirIO Air Quality Sensors Library

Particle meter (PM) sensor manager for multiple (PM) sensors: Honeywell, Plantower, Panasonic, Sensirion, etc, also it handling others like AM2320 sensor.
Particle meter (PM) sensor manager for multiple (PM) sensors: Honeywell, Plantower, Panasonic, Sensirion, etc and CO2 sensors. Also it handling others environment sensors.

## Features
# Supported sensors

### PM sensors

| Sensor model | UART | I2C | Detection mode | Status |
|:----------------------- |:-----:|:-----:|:-------:|:----------:|
| Honeywell HPMA115S0 | Yes | --- | Auto | DEPRECATED |
| Panasonic SN-GCJA5L | Yes | Yes | Auto | STABLE |
| Plantower models | Yes | --- | Auto | STABLE |
| Nova SDS011 | Yes | --- | Auto | STABLE |
| Sensirion SPS30 | Yes | Yes | Select / Auto | STABLE |

NOTE: Panasonic via UART in ESP8266 maybe needs select in detection

### CO2 sensors

| Sensor model | UART | i2c | Detection mode | Status |
|:----------------------- |:-----:|:-----:|:-------:|:----------:|
| Sensirion SCD30 | --- | Yes | Auto | STABLE |
| MHZ19 | Yes | --- | Select | TESTING |
| CMS1106 | Yes | --- | Select | TESTING |


### Environmental sensors

| Sensor model | Protocol | Detection mode | Status |
|:----------------------- |:-----:|:-------:|:----------:|
| AM2320 | i2c | Auto | STABLE |
| SHT31 | i2c | Auto | STABLE |
| AHT10 | i2c | Auto | STABLE |
| BME280 | i2c | Auto | STABLE |
| BME680 | i2c | Auto | STABLE |
| DHT2x | TwoWire | Auto | DEPRECATED |

NOTE: DHT22 is supported but is not recommended

- [x] Auto detection for Generic sensors (Honeywell, Panasonic and Plantower sensors)
- [x] Implemented `Sensirion` autodection flow (for original library)
- [x] Disable/enable logs (debug mode flag)
- [x] Added bme280, 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
- [x] Added SDS011 particle metter
- [x] BME680 support (from TTGO-T7 CanAirIO version)
- [ ] IAQ indicator from BME680 Bosch library

## Usage

Expand Down Expand Up @@ -53,7 +77,9 @@ void setup() {
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.setSampleTime(15); // [optional] sensors sample time (default 5s)
sensors.setDebugMode(false); // [optional] debug mode enable/disable
sensors.detectI2COnly(true); // [optional] force to only i2c sensors
sensors.init(); // start all sensors and
// force to try autodetection,
// you can try to select one:
Expand Down Expand Up @@ -92,15 +118,41 @@ On your serial monitor you should have something like that:
-->[MAIN] PM1.0: 002 PM2.5: 002 PM10: 002
```

## Demo
# Demo

[![CanAirIO auto configuration demo](https://img.youtube.com/vi/hmukAmG5Eec/0.jpg)](https://www.youtube.com/watch?v=hmukAmG5Eec)

CanAirIO sensorlib auto configuration demo on [Youtube](https://www.youtube.com/watch?v=hmukAmG5Eec)

---

## Examples
# Wiring

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

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.

Also you can define the UART pins in the init() method, please see below.

#### Custom UART RX/TX:

You can pass the custom pins if it isn't autodected:

```cpp
sensors.init(sensors.Auto,RX,TX); // custom RX, custom TX pines.
```

### 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)

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).


# Examples

### PlatformIO (recommended)

Expand Down Expand Up @@ -146,50 +198,26 @@ arduino-cli upload --fqbn esp32:esp32:lolin32:UploadSpeed=115200 -p /dev/ttyUSB0

where `basic` is the basic example on examples directory.

## Wiring

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

```cpp
#ifdef WEMOSOLED
#define PMS_RX 13 // config for Wemos board & TTGO18650
#define PMS_TX 15 // some old TTGO18650 have PMS_RX 18 & PMS_TX 17
#elif HELTEC
#define PMS_RX 17 // config for Heltec board, ESP32Sboard & ESPDUINO-32
#define PMS_TX 18 // some old ESP32Sboard have PMS_RX 27 & PMS_TX 25
#elif TTGO_TQ
#define PMS_RX 13 // config for TTGO_TQ board
#define PMS_TX 18
#else
#define PMS_RX 17 // config for D1MIN1 board (Default for main ESP32 dev boards)
#define PMS_TX 16
#endif
```
Also you can define the UART pins in the init() method, please see below.

#### Custom UART RX/TX:

You can pass the custom pins if it isn't autodected:

```cpp
sensors.init(sensors.Auto,RX,TX); // custom RX, custom TX pines.
```

# TODO

- [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] 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] Added Sensirion SPS30 and Panasonic SN-GCJA5 via i2c
- [x] Enable/Disable UART detection for force only i2c
- [ ] IAQ indicator from BME680 Bosch library

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

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/01ae9e976aa2985bb66856c0d6fae2a03100f552/src/Sensors.hpp#L16-L45).
# Credits

Thanks to all collaborators and [CanAirIO](https://canair.io) community for testing and reports.

---

## Credits

Thanks to all collaborators and [CanAirIO](https://canair.io) community for testing and reports.
3 changes: 2 additions & 1 deletion examples/advanced_sensirion/sensirion.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ void setup() {
sensors.setOnErrorCallBack(&onSensorDataError); // [optional] error callback
sensors.setDebugMode(true); // [optional] debug mode

sensors.init(sensors.Sensirion);
sensors.init(sensors.Sensirion); // forced Sensirion via UART.
// for i2c only leave empty this parameter

if(sensors.isPmSensorConfigured())
Serial.println("-->[SETUP] Sensor configured: " + sensors.getPmDeviceSelected());
Expand Down
10 changes: 7 additions & 3 deletions examples/basic/basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ void setup() {
sensors.setOnErrorCallBack(&onSensorDataError); // [optional] error callback
sensors.setDebugMode(false); // [optional] debug mode

// sensors.init(); // Auto detection of PM sensors (Honeywell, Plantower)
// sensors.init(sensors.Auto); // Auto detection of PM sensors (Honeywell, Plantower)
// 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.init(sensors.Sensirion); // Force detection to Sensirion sensor
sensors.init(); // Force detection to Sensirion sensor

if(sensors.isPmSensorConfigured())
Serial.println("-->[SETUP] Sensor configured: " + sensors.getPmDeviceSelected());
Expand Down
6 changes: 5 additions & 1 deletion examples/basic_esp8266/basic_esp8266.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ void setup() {
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.setDebugMode(true); // [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.init(sensors.Panasonic, 5, 6); // Panasonic sensor with ESP8266 software serial pines

Expand Down
10 changes: 2 additions & 8 deletions examples/co2_cm1106/co2_cm1106.ino
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,8 @@ void setup() {
sensors.setOnErrorCallBack(&onSensorDataError); // [optional] error callback
sensors.setDebugMode(true); // [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.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.setCO2RecalibrationFactor(400); // calibration method (in outdoors)

sensors.init(sensors.CM1106);

if (sensors.isPmSensorConfigured())
Expand Down
8 changes: 2 additions & 6 deletions examples/co2_mhz19/co2_mhz19.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,8 @@ void setup() {
sensors.setOnErrorCallBack(&onSensorDataError); // [optional] error callback
sensors.setDebugMode(true); // [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.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.setCO2RecalibrationFactor(400); // calibration method (in outdoors)

sensors.init(sensors.Mhz19);

if (sensors.isPmSensorConfigured())
Expand Down
23 changes: 8 additions & 15 deletions examples/co2_scd30/co2_scd30.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
#include <Sensors.hpp>

void onSensorDataOk() {
Serial.print("-->[MAIN] PM1: " + sensors.getStringPM1());
Serial.print(" PM2.5: " + sensors.getStringPM25());
Serial.print(" PM10: " + sensors.getStringPM10());

Serial.print(" CO2: " + sensors.getStringCO2());
Serial.print("-->[MAIN] CO2: " + sensors.getStringCO2());
Serial.print(" CO2humi: " + String(sensors.getCO2humi()));
Serial.print(" CO2temp: " + String(sensors.getCO2temp()));

Expand All @@ -49,17 +45,14 @@ void setup() {
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.setDebugMode(false); // [optional] debug mode
sensors.detectI2COnly(true); // force to only i2c sensors

// sensors.setCO2RecalibrationFactor(400); // calibration method (in outdoors)

sensors.scd30.setTemperatureOffset(2.0); // example to set temp offset

// 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.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.init(sensors.Auto);
sensors.init();

if (sensors.isPmSensorConfigured())
Serial.println("-->[SETUP] Sensor configured: " + sensors.getPmDeviceSelected());
Expand Down
22 changes: 12 additions & 10 deletions examples/platformio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ void setup() {
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 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.SDS011); // Force detection to Nova sensor
// sensors.init(sensors.Mhz19); // Force detection to Mhz14 or Mhz19 CO2 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.init(sensors.Auto);
// 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.init();

if(sensors.isPmSensorConfigured())
Serial.println("-->[SETUP] Sensor configured: " + sensors.getPmDeviceSelected());
Expand Down
10 changes: 0 additions & 10 deletions examples/pm_sds011/pm_sds011.ino
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ void setup() {
sensors.setOnErrorCallBack(&onSensorDataError); // [optional] error callback
sensors.setDebugMode(true); // [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.SDS011); // Force detection to Nova sensor
// sensors.init(sensors.Mhz19); // Force detection to Mhz14 or Mhz19 CO2 sensor
// sensors.init(sensors.CM1006); // Force detection to CM1106 CO2 sensor
// sensors.init(sensors.SCD30co2); // Force detection to SCD30 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.init(sensors.SDS011);

if (sensors.isPmSensorConfigured())
Expand Down
2 changes: 0 additions & 2 deletions examples/sps30i2c/sps30i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,5 @@ void setup() {
uint64_t counter = 0;

void loop() {

sensors.loop(); // read sensor data and showed it

}
Loading