All Projects → kike-canaries → canairio_sensorlib

kike-canaries / canairio_sensorlib

Licence: GPL-3.0 license
Particle sensor manager for multiple sensors: Honeywell, Plantower, Panasonic, Sensirion, etc. This is sensors layer of CanAirIO project too.

Programming Languages

C++
36643 projects - #6 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to canairio sensorlib

ESPHome-Air-Quality-Monitor
ESPHome configuration for a DIY indoor air quality monitor for CO₂ concentration, PM2.5 and PM10 concentrations, and temperature, humidity and pressure
Stars: ✭ 42 (+75%)
Mutual labels:  esp32, pm25, co2
PMserial
Arduino library for PM sensors with serial interface
Stars: ✭ 41 (+70.83%)
Mutual labels:  esp32, pm25
homebridge-tion
Homebridge plugin to control Tion breezers
Stars: ✭ 32 (+33.33%)
Mutual labels:  sensor, co2
codos
Un sistema de detección del CO2 para el aula
Stars: ✭ 41 (+70.83%)
Mutual labels:  esp32, co2
MH-Z-CO2-Sensors
Arduino imeplementation for CO2 sensors of the MH-Z series (Intelligent Infrared CO2 Module)
Stars: ✭ 59 (+145.83%)
Mutual labels:  sensor, co2
EnviroMonitorStation
Arduino compatible software for ESP8266 based environmental monitoring station. Includes temperature, humidity, barometric pressure and PM2.5, PM10 dust monitoring
Stars: ✭ 71 (+195.83%)
Mutual labels:  sensor, pm25
embedded-ccs811-rs
Platform agnostic Rust driver for the CCS811 ultra-low power digital gas sensor for monitoring indoor air quality
Stars: ✭ 12 (-50%)
Mutual labels:  sensor, co2
Pysmartnode
Micropython Smarthome framework
Stars: ✭ 58 (+141.67%)
Mutual labels:  esp32, sensor
M5Stack-Air-Quality-ESPHome
ESPHome configuration for M5Stack's PM2.5 Air Quality Kit with the PMSA003 particulate matter sensor and the SHT20 temperature and humidity sensor
Stars: ✭ 19 (-20.83%)
Mutual labels:  esp32, pm25
coro2sens
Build a simple device that warns if CO₂ concentration in a room becomes a risk for COVID-19 aerosol infections.
Stars: ✭ 32 (+33.33%)
Mutual labels:  esp32, co2
SDS011
Non blocking SDS011 sensor library for ESP8266
Stars: ✭ 15 (-37.5%)
Mutual labels:  sensor, pm25
CO2-Ampel
CO2-Ampel / CO2-Traffic-Light to measure and show the carbon dioxide concentration in a room, based on Sensirion SCD30/SCD4x sensor and Microchip SAMD21 microcontroller
Stars: ✭ 20 (-16.67%)
Mutual labels:  sensor, co2
sps30
Sensirion SPS30 driver for ESP32, SODAQ, MEGA2560, UNO, ESP8266, Particle-photon on UART OR I2C coummunication
Stars: ✭ 57 (+137.5%)
Mutual labels:  esp32, sensor
Esp32 Mpu Driver
ESP32 full library for all MPU6000 MPU6050 MPU6500 MPU9150 MPU9250 with SPI and I2C support and more.
Stars: ✭ 111 (+362.5%)
Mutual labels:  esp32, sensor
Adafruit CCS811
Arduino driver for CCS811 digital gas sensor
Stars: ✭ 60 (+150%)
Mutual labels:  sensor, co2
SHT31
Arduino library for the SHT31 temperature and humidity sensor
Stars: ✭ 26 (+8.33%)
Mutual labels:  sensor
ESP-Alerts-for-Android
Send Android Notifications to an ESP32 with OLED display
Stars: ✭ 42 (+75%)
Mutual labels:  esp32
ESP32 Thing
Development platform for the Espressif ESP32 WiFi/Microcontroller SoC
Stars: ✭ 66 (+175%)
Mutual labels:  esp32
micronova controller
Allows you to easily control via MQTT any Micronova equiped pellet stove. (MCZ, Extraflame, Laminox, and many others brands!)
Stars: ✭ 30 (+25%)
Mutual labels:  esp32
redcanary-ebpf-sensor
Red Canary's eBPF Sensor
Stars: ✭ 52 (+116.67%)
Mutual labels:  sensor

PlatformIO Build Status ViewCount

Air Quality Sensors Library

Generic sensor manager, abstractions and bindings of multiple sensors libraries: Honeywell, Plantower, Panasonic, Sensirion, etc. and CO2 sensors. Also it's handling others environment sensors. This library is for general purpose, but also is the sensors library base of CanAirIO project.

For developers also you can check the complete library documentation here

Don't forget to star this repository

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
IKEA Vindriktning Yes --- Select TESTING
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
Sensirion SCD4x --- Yes Auto TESTING
MHZ19 Yes --- Select STABLE
CM1106 Yes --- Select STABLE
SenseAir S8 Yes --- Select STABLE

Environmental sensors

Sensor model Protocol Detection mode Status
AM2320 i2c Auto STABLE
SHT31 i2c Auto STABLE
AHT10 i2c Auto STABLE
BME280 i2c Auto STABLE
BMP280 i2c Auto TESTING
BME680 i2c Auto STABLE
DHTxx TwoWire Auto DEPRECATED

NOTE: DHT22 is supported but is not recommended

Features

  • Unified variables and getters for all sensors
  • Auto UART port selection (Hw, Sw, UART1, UART2, etc)
  • Multiple i2c reads and one UART sensor read support
  • Two I2C channel supported (Wire and Wire1)
  • Real time registry of sensors unit registered (see multivariable)
  • Get vendor names of all devices detected
  • 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 group type: NONE, PM, CO2 and ENV.
  • Basic debug mode support toggle in execution
  • Basic power saving management with sample time > 30s on SPS30

Full list of all sub libraries supported here

Quick implementation

sensors.setOnDataCallBack(&onSensorDataOk);   // all data read callback
sensors.init();                               // start all sensors and

Full implementation

You can review a full implementation on CanAirIO project firmware, but a little brief is the next:

/// sensors data callback
void onSensorDataOk() {
    Serial.print("PM2.5: " + String(sensors.getPM25()));
    Serial.print(" CO2: "  + String(sensors.getCO2()));
    Serial.print(" CO2H: " + String(sensors.getCO2humi()));
    Serial.print(" CO2T: " + String(sensors.getCO2temp()));
    Serial.print(" H: "    + String(sensors.getHumidity()));
    Serial.println(" T: "  + String(sensors.getTemperature()));
}

/// sensors error callback
void onSensorDataError(const char * msg){
    Serial.println("Sensor read error: "+String(msg));
}

void setup() {

    sensors.setOnDataCallBack(&onSensorDataOk);     // all data read callback
    sensors.setOnErrorCallBack(&onSensorDataError); // [optional] error callback
    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

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

    // sensors.init(SENSORS::Auto);                 // Auto detection to UART sensors (Honeywell, Plantower, Panasonic)
    // sensors.init(SENSORS::SGCJA5);               // Force UART detection to Panasonic sensor
    // sensors.init(SENSORS::SSPS30);               // Force UART detection to Sensirion sensor
    // sensors.init(SENSORS::SMHZ19);               // Force UART detection to Mhz14 or Mhz19 CO2 sensor
    // sensors.init(SENSORS::SDS011);               // Force UART detection to SDS011 sensor
    // sensors.init(SENSORS::IKEAVK);               // Force UART detection to IKEA Vindriktning sensor
    // sensors.init(SENSORS::SCM1106);              // Force UART detection to CM1106 CO2 sensor
    // sensors.init(SENSORS::SAIRS8);               // 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:

    // sensors.sps30.sleep()
    // sensors.bme.readPressure();
    // sensors.mhz19.getRange();
    // sensors.scd30.getTemperatureOffset();
    // sensors.aht10.readRawData();
    // sensors.s8.set_ABC_period(period)
    // ...

    delay(500);
}

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

Output

On your serial monitor you should have something like that:

-->[SETUP] Detecting sensors..
-->[SETUP] Sensor configured: SENSIRION
-->[MAIN] PM1.0: 002 PM2.5: 004 PM10: 006
-->[MAIN] PM1.0: 002 PM2.5: 002 PM10: 002
-->[MAIN] PM1.0: 002 PM2.5: 002 PM10: 002

Multivariable demo

In this demo on two different devices with multiple sensors, you can choose the possible sub sensors units or variables:

CanAirIO multivariable demo

In this demo on a simple sketch you could have a dinamyc list of variables of multiple sensors brands:

CanAirIO Sensors Lib DEMO with M5CoreInk

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:

For example:

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

void printSensorsDetected() {
    uint16_t sensors_count =  sensors.getSensorsRegisteredCount();
    uint16_t units_count   =  sensors.getUnitsRegisteredCount();
    Serial.println("-->[MAIN] Sensors detected count\t: " + String(sensors_count));
    Serial.println("-->[MAIN] Sensors units count  \t: "  + String(units_count));
    Serial.print(  "-->[MAIN] Sensors devices names\t: ");
    int i = 0;
    while (sensors.getSensorsRegistered()[i++] != 0) {
        Serial.print(sensors.getSensorName((SENSORS)sensors.getSensorsRegistered()[i - 1]));
        Serial.print(",");
    }
    Serial.println();
}

void printSensorsValues() {
    Serial.println("\n-->[MAIN] Preview sensor values:");
    UNIT unit = sensors.getNextUnit();
    while(unit != UNIT::NUNIT) {
        String uName = sensors.getUnitName(unit);
        float uValue = sensors.getUnitValue(unit);
        String uSymb = sensors.getUnitSymbol(unit);
        Serial.print("-->[MAIN] " + uName + ": " + String(uValue) + " " + uSymb);
        unit = sensors.getNextUnit();
    }
}

void onSensorDataOk() {
    Serial.println("======= E X A M P L E   T E S T =========");
    printSensorsDetected();
    printSensorsValues(); 
    Serial.println("=========================================");
}

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

void setup() {
    Serial.begin(115200);
    delay(100);
    sensors.setSampleTime(5);                       // config sensors sample time interval
    sensors.setOnDataCallBack(&onSensorDataOk);     // all data read 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
}

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

UART detection demo

CanAirIO auto configuration demo

CanAirIO sensorlib auto configuration demo on Youtube

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

Predefined UART

The library has pre-defined some UART pin configs, these are selected on compiling time. Maybe you don't need change anything with your board, and maybe the nexts alternatives works for you:

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:

Also you could define a custom UART pins in the init() method and select specific sensors model, like this:

sensors.init(SENSORS::SDS011,yourRX,yourTX); // 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.

Examples

PlatformIO (recommended)

Compiling and Installing

We recommended PlatformIO because is more easy than Arduino IDE. For this, please install first PlatformIO and its command line tools (Windows, MacOs and Linux), pio command, then connect your compatible board to the USB and run the next command:

pio run --target upload

Arduino IDE

Only import the ino file of the sample and install the libraries listed on library.json and this library.

Arduino CLI

Prerequisites

For run the examples, you first need to install arduino-cli or the Arduino IDE with the libraries referenced in lib_deps on the file platformio.ini, becuase Arduino don't install it automatically like PlatformIO. Then put CanAirIO sensor library in your library directory, you can download it from releases section.

Also you need to add the alternative links for supporting the ESP32 boards:

arduino-cli config init

in the .arduino15/arduino-cli.yaml file add:

board_manager:
  additional_urls:
    - https://arduino.esp8266.com/stable/package_esp8266com_index.json
    - https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Compiling and Installing

From arduino-cli you can run the basic example in a ESP32 board following these steps:

arduino-cli core update-index
arduino-cli core install esp32:esp32:lolin32
arduino-cli compile --fqbn esp32:esp32:lolin32 basic
arduino-cli upload --fqbn esp32:esp32:lolin32:UploadSpeed=115200 -p /dev/ttyUSB0 basic

where basic is the basic example on examples directory.

Supporting the project

If you want to contribute to the code or documentation, consider posting a bug report, feature request or a pull request.

When creating a pull request, we recommend that you do the following:

  • Clone the repository
  • Create a new branch for your fix or feature. For example, git checkout -b fix/my-fix or git checkout -b feat/my-feature.
  • Run to any clang formatter if it is a code, for example using the vscode formatter. We are using Google style. More info here
  • Document the PR description or code will be great
  • Target your pull request to be merged with devel branch

Also you can make a donation, be a patreon or buy a device:

TODO

  • Auto detection for UART sensors (Honeywell, Panasonic and Plantower)
  • Added SPS30 library with auto UART detection
  • Disable/enable logs (debug mode flag)
  • Added bme280, bmp280, aht10, sht31, am2320 i2c sensors
  • Exposed public sub-libraries objects, sps30, aht10, etc.
  • Added old DHT sensors
  • Added CO2 sensors: MHZ19, SCD30, CM1106 via UART
  • Added SDS011 particle metter
  • BME680 support
  • Added Sensirion SPS30 and Panasonic SN-GCJA5 via i2c
  • Enable/Disable UART detection for force only i2c
  • Temperature and Altitude compensation
  • SenseAir S8 via UART support
  • Multivariable selection (getNextUnit(),getUnitName(),etc)
  • Two I2C channel supported for M5Stack Devices (M5StickC tested)
  • Sea level setting for Pressure sensors and others
  • Support to second UART port

Projects using this Library

  • CanAirIO Device: ESP32 Air quality device for mobile and fixed stations. (PM2.5 and CO2)
  • Medidor de CO2: Un medidor de CO2 de alta calidad con pantalla en color. (CO2)

Credits

Thanks to all collaborators and CanAirIO community for testing and reports.


Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].