From af4fea332723624ec19ba97688d55c5f2ac03383 Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Mon, 16 Nov 2020 21:39:29 +0100 Subject: [PATCH 01/16] fixed some ignore files isssues --- library.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library.json b/library.json index 3c387eb1..016aebe7 100644 --- a/library.json +++ b/library.json @@ -40,7 +40,9 @@ ".travis.yml", ".gitignore", "releases", - "examples/platformio/.vscode" + "examples/platformio/.vscode", + "examples/platformio/platformio.ini.default", + "examples/platformio/platformio.ini.devel" ] }, "authors": From 2c1339942ba6749591e6d7485ed86b8b6f8d4f3c Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Mon, 16 Nov 2020 21:40:18 +0100 Subject: [PATCH 02/16] added PM1 print on main for PM1.0 on Panasonic sensor --- examples/basic/basic.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/basic/basic.ino b/examples/basic/basic.ino index 6e42fa2e..fcd53a23 100644 --- a/examples/basic/basic.ino +++ b/examples/basic/basic.ino @@ -12,6 +12,7 @@ void onSensorDataOk() { Serial.print("-->[MAIN] PM1.0: "+sensors.getStringPM1()); Serial.print (" PM2.5: " + sensors.getStringPM25()); Serial.println(" PM10: " + sensors.getStringPM10()); + Serial.println(" PM1: " + sensors.getStringPM1()); } void onSensorDataError(const char * msg){ From 5dd78b776c608f876830dac88eb1e321ac05dea2 Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Wed, 16 Dec 2020 23:40:24 +0100 Subject: [PATCH 03/16] fixed some issue and library list missing --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ac8c6c61..efba1557 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Particle meter (PM) sensor manager for multiple (PM) sensors: Honeywell, Plantow - [x] Debugging compatible with ESP32 log level - [x] Added bme280, aht10, sht31, am2320 i2c sensors - [x] Exposed public sub-libraries objects, sps30, aht10, etc. -- [ ] Added old DHT sensors +- [x] Added old DHT sensors - [ ] BME680 support (from TTGO-T7 CanAirIO version) ## Usage @@ -77,7 +77,7 @@ void loop() { ```javascript void setup() { - sensors.init(0,RX,TX); // generic sensor(default), custom RX, custom TX pines. + sensors.init(sensors.Auto,RX,TX); // generic sensor(default), custom RX, custom TX pines. } ``` @@ -119,10 +119,15 @@ pio run --target upload You first need to run the examples, install **arduino-cli** or the **Arduino IDE** with the following libraries: -Adafruit Unified Sensor -Adafruit AM2320 sensor library -[Sensirion library sps30](https://github.com/paulvha/sps30) -`CanAirIO Air Quality Sensors Library` (this library). +adafruit/Adafruit Unified Sensor @ 1.1.4 +adafruit/Adafruit AM2320 sensor library @ 1.1.4 +adafruit/Adafruit BME280 Library @ 2.1.2 +adafruit/Adafruit BusIO @ 1.6.0 +adafruit/Adafruit SHT31 Library @ 2.0.0 +enjoyneering/AHT10 @ ^1.1.0 +[DTH_nonblocking](https://github.com/hpsaturn/DHT_nonblocking.git) +[Sensirion library sps30](https://github.com/paulvha/sps30) @ 1.4.9 +`CanAirIO Air Quality Sensors Library` (this library). Also you need to add the **alternative links** for supporting the ESP32 boards: From 0e9d26b89709fec8f685b93844a8daea34f2bb86 Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Wed, 16 Dec 2020 23:51:04 +0100 Subject: [PATCH 04/16] v0.1.6 support for DHT, am2320, sht31, aht10, bme280 sensors --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index 601f4bc3..5422596f 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "CanAirIO Air Quality Sensors Library", - "version": "0.1.5", + "version": "0.1.6", "homepage":"https://canair.io", "keywords": [ From 1d2699b2a4461628ad18abd53e83d980d226979a Mon Sep 17 00:00:00 2001 From: Antonio Vanegas Date: Tue, 29 Dec 2020 15:26:45 +0100 Subject: [PATCH 05/16] Added basic init for Mhz19 sensor --- platformio.ini | 1 + src/Sensors.cpp | 38 ++++++++++++++++++++++++++++++++++++-- src/Sensors.hpp | 13 +++++++++++-- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/platformio.ini b/platformio.ini index 0bd6918b..87383bda 100644 --- a/platformio.ini +++ b/platformio.ini @@ -24,6 +24,7 @@ lib_deps = enjoyneering/AHT10 @ ^1.1.0 https://github.com/hpsaturn/DHT_nonblocking.git paulvha/sps30 @ 1.4.9 + wifwaf/MH-Z19 @ ^1.5.3 ; hpsaturn/CanAirIO Air Quality Sensors Library [esp32_common] diff --git a/src/Sensors.cpp b/src/Sensors.cpp index ee8e062d..d762760f 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -52,7 +52,7 @@ void Sensors::init(int pms_type, int pms_rx, int pms_tx) { DEBUG("-->[SENSORS] sample time set to: ",String(sample_time).c_str()); - if(!pmSensorInit(pms_type, pms_rx, pms_tx)){ + if(!sensorSerialInit(pms_type, pms_rx, pms_tx)){ DEBUG("-->[E][PMSENSOR] init failed!"); } @@ -269,6 +269,16 @@ bool Sensors::pmSensirionRead() { return true; } +bool Sensors:: pmMhz19Read() { + CO2 = myMHZ19.getCO2(); // Request CO2 (as ppm) + CO2temp = myMHZ19.getTemperature(); // Request Temperature (as Celsius) + if(CO2>0){ + DEBUG("-->[AM2320] read > done!"); + return true; + } + return false; +} + /** * @brief read sensor data. Sensor selected. * @return true if data is loaded from sensor @@ -287,6 +297,12 @@ bool Sensors::pmSensorRead() { return pmSensirionRead(); break; + case Mhz19: + return pmMhz19Read(); + break; + + + default: return false; break; @@ -385,7 +401,7 @@ void Sensors::pmSensirionErrorloop(char *mess, uint8_t r) { * @param pms_rx PMS RX pin. * @param pms_tx PMS TX pin. **/ -bool Sensors::pmSensorInit(int pms_type, int pms_rx, int pms_tx) { +bool Sensors::sensorSerialInit(int pms_type, int pms_rx, int pms_tx) { // set UART for autodetection sensors (Honeywell, Plantower, Panasonic) if (pms_type == Auto) { DEBUG("-->[PMSENSOR] detecting Generic PM sensor.."); @@ -400,6 +416,10 @@ bool Sensors::pmSensorInit(int pms_type, int pms_rx, int pms_tx) { DEBUG("-->[PMSENSOR] detecting Sensirion PM sensor.."); if(!serialInit(pms_type, 115200, pms_rx, pms_tx))return false; } + else if (pms_type == Mhz19) { + DEBUG("-->[PMSENSOR] detecting Mhz19 sensor.."); + if(!serialInit(pms_type, 9600, pms_rx, pms_tx))return false; + } // starting auto detection loop int try_sensor_init = 0; @@ -432,6 +452,14 @@ bool Sensors::pmSensorAutoDetect(int pms_type) { return true; } } + + if (pms_type == Mhz19) { + if (pmMhz19Init()) { + device_selected = "MHZ19"; + device_type = Mhz19; + return true; + } + } if (pms_type <= Panasonic) { if (pmGenericRead()) { @@ -451,6 +479,12 @@ bool Sensors::pmSensorAutoDetect(int pms_type) { return false; } +bool Sensors:: pmMhz19Init() { + myMHZ19.begin(*_serial); // *Serial(Stream) refence must be passed to library begin(). + myMHZ19.autoCalibration(); // Turn auto calibration ON (OFF autoCalibration(false)) + return true; +} + bool Sensors::pmSensirionInit() { // Begin communication channel DEBUG("-->[SPS30] starting SPS30 sensor.."); diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 04f9bea9..14684cd5 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include using namespace std; #include @@ -50,7 +51,7 @@ class Sensors { public: /// Supported devices. Auto is for Honeywell and Plantower sensors and similars - enum SENSOR_TYPE { Auto, Panasonic, Sensirion }; + enum SENSOR_TYPE { Auto, Panasonic, Sensirion, Mhz19 }; /// SPS30 values. Only for Sensirion SPS30 sensor. struct sps_values val; @@ -73,6 +74,8 @@ class Sensors { Adafruit_SHT31 sht31; // DHT sensor float dhthumi, dhttemp; + // Mhz19 sensor + MHZ19 myMHZ19; void init(int pms_type = 0, int pms_rx = PMS_RX, int pms_tx = PMS_TX); void loop(); @@ -135,6 +138,9 @@ class Sensors { float pres = 0.0; // Pressure float alt = 0.0; float gas = 0.0; + + int CO2; + float CO2temp; void restart(); void am2320Init(); @@ -145,19 +151,22 @@ class Sensors { void aht10Read(); void sht31Init(); void sht31Read(); + void dhtInit(); void dhtRead(); bool dhtIsReady(float *temperature, float *humidity); - bool pmSensorInit(int pms_type, int rx, int tx); + bool sensorSerialInit(int pms_type, int rx, int tx); bool pmSensorAutoDetect(int pms_type); bool pmSensorRead(); bool pmGenericRead(); bool pmPanasonicRead(); bool pmSensirionRead(); + bool pmMhz19Read(); void onPmSensorError(const char *msg); void printValues(); bool pmSensirionInit(); + bool pmMhz19Init(); void pmSensirionErrtoMess(char *mess, uint8_t r); void pmSensirionErrorloop(char *mess, uint8_t r); void getSensirionDeviceInfo(); From af2bcde2203eb7b89510f5c71c9c40abad90fd9d Mon Sep 17 00:00:00 2001 From: danielbernalb Date: Tue, 29 Dec 2020 13:17:56 -0500 Subject: [PATCH 06/16] Some minor changes, CO2humi added for other sensor --- examples/platformio/src/main.cpp | 11 ++++++++--- src/Sensors.cpp | 24 +++++++++++++++++++++--- src/Sensors.hpp | 13 ++++++++++--- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/examples/platformio/src/main.cpp b/examples/platformio/src/main.cpp index 3ff605eb..8c831d68 100644 --- a/examples/platformio/src/main.cpp +++ b/examples/platformio/src/main.cpp @@ -19,10 +19,15 @@ #include void onSensorDataOk() { - Serial.print ("-->[MAIN] PM1.0: "+sensors.getStringPM1()); + Serial.print ("-->[MAIN] PM1: "+sensors.getStringPM1()); Serial.print (" PM2.5: " + sensors.getStringPM25()); Serial.print (" PM10: " + sensors.getStringPM10()); - Serial.print (" PM1: " + sensors.getStringPM1()); +// Serial.print (" PM1: " + sensors.getStringPM1()); + Serial.print (" CO2: " + sensors.getStringCO2()); + + Serial.print (" CO2humi: " + String(sensors.getCO2humi())); + Serial.print (" CO2temp: " + String(sensors.getCO2temp())); + Serial.print (" T: " + String(sensors.getTemperature())); Serial.println(" H: "+ String(sensors.getHumidity())); } @@ -53,7 +58,7 @@ void setup() { // 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.init(sensors.Auto); + sensors.init(sensors.Mhz19); if(sensors.isPmSensorConfigured()) Serial.println("-->[SETUP] Sensor configured: " + sensors.getPmDeviceSelected()); diff --git a/src/Sensors.cpp b/src/Sensors.cpp index d762760f..0348cda7 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -131,6 +131,24 @@ String Sensors::getStringPM10() { return String(output); } +uint16_t Sensors::getCO2() { + return CO2; +} + +String Sensors::getStringCO2() { + char output[5]; + sprintf(output, "%04d", getCO2()); + return String(output); +} + +float Sensors::getCO2humi() { + return CO2humi; +} + +float Sensors::getCO2temp() { + return CO2temp; +} + float Sensors::getHumidity() { return humi; } @@ -273,7 +291,7 @@ bool Sensors:: pmMhz19Read() { CO2 = myMHZ19.getCO2(); // Request CO2 (as ppm) CO2temp = myMHZ19.getTemperature(); // Request Temperature (as Celsius) if(CO2>0){ - DEBUG("-->[AM2320] read > done!"); + DEBUG("-->[MHZ14-9] read > done!"); return true; } return false; @@ -591,8 +609,8 @@ void Sensors::dhtInit() { /// Print some sensors values void Sensors::printValues() { - char output[100]; - sprintf(output, "PM1:%03d PM25:%03d PM10:%03d H:%03f%% T:%03f°C", pm1, pm25, pm10, humi, temp); + char output[200]; + sprintf(output, "PM1:%03d PM25:%03d PM10:%03d CO2:%04d CO2humi:%03f%% CO2temp:%03f°C H:%03f%% T:%03f°C", pm1, pm25, pm10, CO2, CO2humi, CO2temp, humi, temp); DEBUG("-->[SENSORS]", output); } diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 14684cd5..7afd53b8 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -93,7 +93,11 @@ class Sensors { uint16_t getPM25(); uint16_t getPM4(); uint16_t getPM10(); - + uint16_t getCO2(); + + float getCO2humi(); + float getCO2temp(); + float getTemperature(); float getHumidity(); float getPressure(); @@ -110,6 +114,8 @@ class Sensors { String getStringPM25(); String getStringPM4(); String getStringPM10(); + String getStringCO2(); + String getStringCO2temp(); private: @@ -139,8 +145,9 @@ class Sensors { float alt = 0.0; float gas = 0.0; - int CO2; - float CO2temp; + uint16_t CO2; // CO2 in ppm + float CO2humi = 0.0; // temperature of the CO2 sensor + float CO2temp = 0.0; // temperature of the CO2 sensor void restart(); void am2320Init(); From 0534d239108f5d738abe397e2b65330d0599256d Mon Sep 17 00:00:00 2001 From: Daniel <42117424+danielbernalb@users.noreply.github.com> Date: Tue, 29 Dec 2020 20:50:00 -0500 Subject: [PATCH 07/16] Create Test --- examples/Platformio_CO2_MHZ19/Test | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/Platformio_CO2_MHZ19/Test diff --git a/examples/Platformio_CO2_MHZ19/Test b/examples/Platformio_CO2_MHZ19/Test new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/examples/Platformio_CO2_MHZ19/Test @@ -0,0 +1 @@ + From 8d644fd6f58bc807789226f6b8eac748ead23483 Mon Sep 17 00:00:00 2001 From: Daniel <42117424+danielbernalb@users.noreply.github.com> Date: Tue, 29 Dec 2020 20:50:48 -0500 Subject: [PATCH 08/16] Add files via upload --- examples/Platformio_CO2_MHZ19/README.md | 82 ++++++++++++++++++++ examples/Platformio_CO2_MHZ19/platformio.ini | 34 ++++++++ examples/Platformio_CO2_MHZ19/src/main.cpp | 66 ++++++++++++++++ 3 files changed, 182 insertions(+) create mode 100644 examples/Platformio_CO2_MHZ19/README.md create mode 100644 examples/Platformio_CO2_MHZ19/platformio.ini create mode 100644 examples/Platformio_CO2_MHZ19/src/main.cpp diff --git a/examples/Platformio_CO2_MHZ19/README.md b/examples/Platformio_CO2_MHZ19/README.md new file mode 100644 index 00000000..e73363c8 --- /dev/null +++ b/examples/Platformio_CO2_MHZ19/README.md @@ -0,0 +1,82 @@ +[![PlatformIO](https://github.com/kike-canaries/canairio_sensorlib/workflows/PlatformIO/badge.svg)](https://github.com/kike-canaries/canairio_sensorlib/actions/) + +# PlatformIO sample + +Example for **CanAirIO sensors library**, it is a particle meter (**PM**) sensor manager for multiple (PM) sensors: **Honeywell, Plantower, Panasonic, Sensirion**, etc, also it handling others like **AM2320** sensor. + +You can review a **full implementation** on [CanAirIO project firmware](https://github.com/kike-canaries/canairio_firmware/blob/master/src/main.cpp), but a little brief is the next: + +## Implementation + +```Java + +#include +#include + +void onSensorDataOk() { + Serial.print (" PM1.0: " + sensors.getStringPM1()); + Serial.print (" PM2.5: " + sensors.getStringPM25()); + Serial.println(" PM10 : " + sensors.getStringPM10()); +} + +void onSensorDataError(const char * msg){ + Serial.println(msg); +} + +void setup() { + Serial.begin(115200); + delay(200); + Serial.println("\n== Sensor test setup ==\n"); + Serial.println("-->[SETUP] Detecting sensors.."); + + sensors.setSampleTime(5); // config sensors sample time interval + sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback + sensors.setOnErrorCallBack(&onSensorDataError); // [optional] error callback + sensors.setDebugMode(false); // [optional] debug mode + sensors.init(); // start all sensors and + // force to try autodetection, + // you can try to select one: + // sensors.init(sensors.Sensirion); + + if(sensors.isPmSensorConfigured()) + Serial.println("-->[SETUP] Sensor configured: " + sensors.getPmDeviceSelected()); + + delay(500); +} + +void loop() { + sensors.loop(); // read sensor data and showed it +} +``` + +### Custom RX/TX pines + +```javascript +void setup() { + sensors.init(0,RX,TX); // generic sensor(default), custom RX, custom TX pines. +} +``` + +## Compiling and Installing + +Please install first [PlatformIO](http://platformio.org/) open source ecosystem for IoT development compatible with **Arduino** IDE and its command line tools (Windows, MacOs and Linux), then connect your compatible board to the USB and run the next command: + +```python +pio run --target upload +``` + +### Output + +On your serial monitor you should have something like that: + +```bash +-->[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 +``` + +## Credits + +Thanks to all collaborators and [CanAirIO](https://canair.io) community for testing and reports. diff --git a/examples/Platformio_CO2_MHZ19/platformio.ini b/examples/Platformio_CO2_MHZ19/platformio.ini new file mode 100644 index 00000000..df34b985 --- /dev/null +++ b/examples/Platformio_CO2_MHZ19/platformio.ini @@ -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} diff --git a/examples/Platformio_CO2_MHZ19/src/main.cpp b/examples/Platformio_CO2_MHZ19/src/main.cpp new file mode 100644 index 00000000..3ff605eb --- /dev/null +++ b/examples/Platformio_CO2_MHZ19/src/main.cpp @@ -0,0 +1,66 @@ +/** + * @file main.cpp + * @author Antonio Vanegas @hpsaturn + * @date June 2018 - 2020 + * @brief Particle meter sensor 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: + * https://canair.io + */ + +#include +#include + +void onSensorDataOk() { + Serial.print ("-->[MAIN] PM1.0: "+sensors.getStringPM1()); + Serial.print (" PM2.5: " + sensors.getStringPM25()); + Serial.print (" PM10: " + sensors.getStringPM10()); + Serial.print (" PM1: " + sensors.getStringPM1()); + Serial.print (" T: " + String(sensors.getTemperature())); + Serial.println(" H: "+ String(sensors.getHumidity())); +} + +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.."); + + 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.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.init(sensors.Auto); + + if(sensors.isPmSensorConfigured()) + Serial.println("-->[SETUP] Sensor configured: " + sensors.getPmDeviceSelected()); + + delay(500); +} + +void loop() { + sensors.loop(); // read sensor data and showed it +} \ No newline at end of file From 00887a5b670cf2760a9fadd2cd67740129cc00b2 Mon Sep 17 00:00:00 2001 From: danielbernalb Date: Tue, 29 Dec 2020 20:55:00 -0500 Subject: [PATCH 09/16] Added MHZ19 example --- .../.gitignore | 0 examples/Platformio_CO2_MHZ19/src/main.cpp | 14 ++++++++++---- examples/{Platformio_CO2_MHZ19 => platformio}/Test | 0 examples/platformio/src/main.cpp | 11 +++-------- 4 files changed, 13 insertions(+), 12 deletions(-) rename examples/{platformio => Platformio_CO2_MHZ19}/.gitignore (100%) rename examples/{Platformio_CO2_MHZ19 => platformio}/Test (100%) diff --git a/examples/platformio/.gitignore b/examples/Platformio_CO2_MHZ19/.gitignore similarity index 100% rename from examples/platformio/.gitignore rename to examples/Platformio_CO2_MHZ19/.gitignore diff --git a/examples/Platformio_CO2_MHZ19/src/main.cpp b/examples/Platformio_CO2_MHZ19/src/main.cpp index 3ff605eb..94054390 100644 --- a/examples/Platformio_CO2_MHZ19/src/main.cpp +++ b/examples/Platformio_CO2_MHZ19/src/main.cpp @@ -19,10 +19,15 @@ #include void onSensorDataOk() { - Serial.print ("-->[MAIN] PM1.0: "+sensors.getStringPM1()); + Serial.print ("-->[MAIN] PM1: "+sensors.getStringPM1()); Serial.print (" PM2.5: " + sensors.getStringPM25()); Serial.print (" PM10: " + sensors.getStringPM10()); - Serial.print (" PM1: " + sensors.getStringPM1()); +// Serial.print (" PM1: " + sensors.getStringPM1()); + Serial.print (" CO2: " + sensors.getStringCO2()); + + Serial.print (" CO2humi: " + String(sensors.getCO2humi())); + Serial.print (" CO2temp: " + String(sensors.getCO2temp())); + Serial.print (" T: " + String(sensors.getTemperature())); Serial.println(" H: "+ String(sensors.getHumidity())); } @@ -52,8 +57,9 @@ void setup() { // 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.init(sensors.Auto); + // sensors.init(sensors.Auto,PMS_RX,PMS_TX); // Auto detection, custom RX,TX and custom DHT config + // sensors.init(sensors.Mhz19); // Selected Sensor CO2 Mhz19 + sensors.init(sensors.Mhz19); if(sensors.isPmSensorConfigured()) Serial.println("-->[SETUP] Sensor configured: " + sensors.getPmDeviceSelected()); diff --git a/examples/Platformio_CO2_MHZ19/Test b/examples/platformio/Test similarity index 100% rename from examples/Platformio_CO2_MHZ19/Test rename to examples/platformio/Test diff --git a/examples/platformio/src/main.cpp b/examples/platformio/src/main.cpp index 8c831d68..3ff605eb 100644 --- a/examples/platformio/src/main.cpp +++ b/examples/platformio/src/main.cpp @@ -19,15 +19,10 @@ #include void onSensorDataOk() { - Serial.print ("-->[MAIN] PM1: "+sensors.getStringPM1()); + Serial.print ("-->[MAIN] PM1.0: "+sensors.getStringPM1()); Serial.print (" PM2.5: " + sensors.getStringPM25()); Serial.print (" PM10: " + sensors.getStringPM10()); -// Serial.print (" PM1: " + sensors.getStringPM1()); - Serial.print (" CO2: " + sensors.getStringCO2()); - - Serial.print (" CO2humi: " + String(sensors.getCO2humi())); - Serial.print (" CO2temp: " + String(sensors.getCO2temp())); - + Serial.print (" PM1: " + sensors.getStringPM1()); Serial.print (" T: " + String(sensors.getTemperature())); Serial.println(" H: "+ String(sensors.getHumidity())); } @@ -58,7 +53,7 @@ void setup() { // 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.init(sensors.Mhz19); + sensors.init(sensors.Auto); if(sensors.isPmSensorConfigured()) Serial.println("-->[SETUP] Sensor configured: " + sensors.getPmDeviceSelected()); From cdbc33a2c1489d55628ee02f0b6448ad3492eabe Mon Sep 17 00:00:00 2001 From: danielbernalb Date: Tue, 29 Dec 2020 20:55:51 -0500 Subject: [PATCH 10/16] Delete commented line --- examples/Platformio_CO2_MHZ19/src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/Platformio_CO2_MHZ19/src/main.cpp b/examples/Platformio_CO2_MHZ19/src/main.cpp index 94054390..8f4b5d0e 100644 --- a/examples/Platformio_CO2_MHZ19/src/main.cpp +++ b/examples/Platformio_CO2_MHZ19/src/main.cpp @@ -22,7 +22,6 @@ void onSensorDataOk() { Serial.print ("-->[MAIN] PM1: "+sensors.getStringPM1()); Serial.print (" PM2.5: " + sensors.getStringPM25()); Serial.print (" PM10: " + sensors.getStringPM10()); -// Serial.print (" PM1: " + sensors.getStringPM1()); Serial.print (" CO2: " + sensors.getStringCO2()); Serial.print (" CO2humi: " + String(sensors.getCO2humi())); From ed581eb7f838cef5d27299afd96003e0d1d0f074 Mon Sep 17 00:00:00 2001 From: danielbernalb Date: Wed, 30 Dec 2020 17:05:48 -0500 Subject: [PATCH 11/16] New CO2 mhz19 example --- .../.gitignore | 0 .../README.md | 0 .../platformio.ini | 0 .../src/main.cpp | 10 +-- examples/platformio/.gitignore | 62 +++++++++++++++++++ examples/platformio/Test | 1 - 6 files changed, 67 insertions(+), 6 deletions(-) rename examples/{Platformio_CO2_MHZ19 => CO2_mhz19_14}/.gitignore (100%) rename examples/{Platformio_CO2_MHZ19 => CO2_mhz19_14}/README.md (100%) rename examples/{Platformio_CO2_MHZ19 => CO2_mhz19_14}/platformio.ini (100%) rename examples/{Platformio_CO2_MHZ19 => CO2_mhz19_14}/src/main.cpp (86%) create mode 100644 examples/platformio/.gitignore delete mode 100644 examples/platformio/Test diff --git a/examples/Platformio_CO2_MHZ19/.gitignore b/examples/CO2_mhz19_14/.gitignore similarity index 100% rename from examples/Platformio_CO2_MHZ19/.gitignore rename to examples/CO2_mhz19_14/.gitignore diff --git a/examples/Platformio_CO2_MHZ19/README.md b/examples/CO2_mhz19_14/README.md similarity index 100% rename from examples/Platformio_CO2_MHZ19/README.md rename to examples/CO2_mhz19_14/README.md diff --git a/examples/Platformio_CO2_MHZ19/platformio.ini b/examples/CO2_mhz19_14/platformio.ini similarity index 100% rename from examples/Platformio_CO2_MHZ19/platformio.ini rename to examples/CO2_mhz19_14/platformio.ini diff --git a/examples/Platformio_CO2_MHZ19/src/main.cpp b/examples/CO2_mhz19_14/src/main.cpp similarity index 86% rename from examples/Platformio_CO2_MHZ19/src/main.cpp rename to examples/CO2_mhz19_14/src/main.cpp index 8f4b5d0e..2041d5c8 100644 --- a/examples/Platformio_CO2_MHZ19/src/main.cpp +++ b/examples/CO2_mhz19_14/src/main.cpp @@ -19,16 +19,17 @@ #include void onSensorDataOk() { - Serial.print ("-->[MAIN] PM1: "+sensors.getStringPM1()); + Serial.print ("-->[MAIN] PM1: " + sensors.getStringPM1()); Serial.print (" PM2.5: " + sensors.getStringPM25()); Serial.print (" PM10: " + sensors.getStringPM10()); +// Serial.print (" PM1: " + sensors.getStringPM1()); Serial.print (" CO2: " + sensors.getStringCO2()); Serial.print (" CO2humi: " + String(sensors.getCO2humi())); Serial.print (" CO2temp: " + String(sensors.getCO2temp())); - Serial.print (" T: " + String(sensors.getTemperature())); - Serial.println(" H: "+ String(sensors.getHumidity())); + Serial.print(" H: "+ String(sensors.getHumidity())); + Serial.println (" T: " + String(sensors.getTemperature())); } void onSensorDataError(const char * msg){ @@ -56,8 +57,7 @@ void setup() { // 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.init(sensors.Mhz19); // Selected Sensor CO2 Mhz19 + // sensors.init(sensors.Auto,PMS_RX,PMS_TX); // Auto detection, custom RX,TX and custom DHT config sensors.init(sensors.Mhz19); if(sensors.isPmSensorConfigured()) diff --git a/examples/platformio/.gitignore b/examples/platformio/.gitignore new file mode 100644 index 00000000..a0380a51 --- /dev/null +++ b/examples/platformio/.gitignore @@ -0,0 +1,62 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# Vim backups +*.swp + +# PlatformIO work files +.pio +.pioenvs +.piolibdeps +*tags* + +# Library +*.bin +*.zip + +# IDE +extensions.json +settings.json +*tags* +.clang_complete +.gcc-flags.json +.vscode +.vscode/.browse.c_cpp.db* +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +build + +# Project + +releases diff --git a/examples/platformio/Test b/examples/platformio/Test deleted file mode 100644 index 8b137891..00000000 --- a/examples/platformio/Test +++ /dev/null @@ -1 +0,0 @@ - From 56f8bea9c35786193472fbc9192d2d732ec33bbd Mon Sep 17 00:00:00 2001 From: danielbernalb Date: Wed, 30 Dec 2020 17:12:56 -0500 Subject: [PATCH 12/16] Minor change --- examples/CO2_mhz19_14/src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/CO2_mhz19_14/src/main.cpp b/examples/CO2_mhz19_14/src/main.cpp index 2041d5c8..15eb4e87 100644 --- a/examples/CO2_mhz19_14/src/main.cpp +++ b/examples/CO2_mhz19_14/src/main.cpp @@ -22,7 +22,6 @@ void onSensorDataOk() { Serial.print ("-->[MAIN] PM1: " + sensors.getStringPM1()); Serial.print (" PM2.5: " + sensors.getStringPM25()); Serial.print (" PM10: " + sensors.getStringPM10()); -// Serial.print (" PM1: " + sensors.getStringPM1()); Serial.print (" CO2: " + sensors.getStringCO2()); Serial.print (" CO2humi: " + String(sensors.getCO2humi())); From eba521c92c36d9c3aea0239b9d7fa348fe71086b Mon Sep 17 00:00:00 2001 From: danielbernalb Date: Wed, 30 Dec 2020 17:51:10 -0500 Subject: [PATCH 13/16] Minor changes --- examples/platformio/src/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/platformio/src/main.cpp b/examples/platformio/src/main.cpp index 8c831d68..29598078 100644 --- a/examples/platformio/src/main.cpp +++ b/examples/platformio/src/main.cpp @@ -22,14 +22,14 @@ void onSensorDataOk() { Serial.print ("-->[MAIN] PM1: "+sensors.getStringPM1()); Serial.print (" PM2.5: " + sensors.getStringPM25()); Serial.print (" PM10: " + sensors.getStringPM10()); -// Serial.print (" PM1: " + sensors.getStringPM1()); - Serial.print (" CO2: " + sensors.getStringCO2()); + Serial.print (" CO2: " + sensors.getStringCO2()); Serial.print (" CO2humi: " + String(sensors.getCO2humi())); Serial.print (" CO2temp: " + String(sensors.getCO2temp())); - Serial.print (" T: " + String(sensors.getTemperature())); - Serial.println(" H: "+ String(sensors.getHumidity())); + Serial.print (" H: "+ String(sensors.getHumidity())); + Serial.println (" T: " + String(sensors.getTemperature())); + } void onSensorDataError(const char * msg){ From 2d424645a8102932246b6654542a689ddc0fd965 Mon Sep 17 00:00:00 2001 From: danielbernalb Date: Wed, 30 Dec 2020 17:54:34 -0500 Subject: [PATCH 14/16] New directory co2 mhz19 example --- examples/co2_mhz19/.gitignore | 62 +++++++++++++++++++++++ examples/co2_mhz19/README.md | 82 +++++++++++++++++++++++++++++++ examples/co2_mhz19/platformio.ini | 34 +++++++++++++ examples/co2_mhz19/src/main.cpp | 71 ++++++++++++++++++++++++++ 4 files changed, 249 insertions(+) create mode 100644 examples/co2_mhz19/.gitignore create mode 100644 examples/co2_mhz19/README.md create mode 100644 examples/co2_mhz19/platformio.ini create mode 100644 examples/co2_mhz19/src/main.cpp diff --git a/examples/co2_mhz19/.gitignore b/examples/co2_mhz19/.gitignore new file mode 100644 index 00000000..a0380a51 --- /dev/null +++ b/examples/co2_mhz19/.gitignore @@ -0,0 +1,62 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# Vim backups +*.swp + +# PlatformIO work files +.pio +.pioenvs +.piolibdeps +*tags* + +# Library +*.bin +*.zip + +# IDE +extensions.json +settings.json +*tags* +.clang_complete +.gcc-flags.json +.vscode +.vscode/.browse.c_cpp.db* +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +build + +# Project + +releases diff --git a/examples/co2_mhz19/README.md b/examples/co2_mhz19/README.md new file mode 100644 index 00000000..e73363c8 --- /dev/null +++ b/examples/co2_mhz19/README.md @@ -0,0 +1,82 @@ +[![PlatformIO](https://github.com/kike-canaries/canairio_sensorlib/workflows/PlatformIO/badge.svg)](https://github.com/kike-canaries/canairio_sensorlib/actions/) + +# PlatformIO sample + +Example for **CanAirIO sensors library**, it is a particle meter (**PM**) sensor manager for multiple (PM) sensors: **Honeywell, Plantower, Panasonic, Sensirion**, etc, also it handling others like **AM2320** sensor. + +You can review a **full implementation** on [CanAirIO project firmware](https://github.com/kike-canaries/canairio_firmware/blob/master/src/main.cpp), but a little brief is the next: + +## Implementation + +```Java + +#include +#include + +void onSensorDataOk() { + Serial.print (" PM1.0: " + sensors.getStringPM1()); + Serial.print (" PM2.5: " + sensors.getStringPM25()); + Serial.println(" PM10 : " + sensors.getStringPM10()); +} + +void onSensorDataError(const char * msg){ + Serial.println(msg); +} + +void setup() { + Serial.begin(115200); + delay(200); + Serial.println("\n== Sensor test setup ==\n"); + Serial.println("-->[SETUP] Detecting sensors.."); + + sensors.setSampleTime(5); // config sensors sample time interval + sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback + sensors.setOnErrorCallBack(&onSensorDataError); // [optional] error callback + sensors.setDebugMode(false); // [optional] debug mode + sensors.init(); // start all sensors and + // force to try autodetection, + // you can try to select one: + // sensors.init(sensors.Sensirion); + + if(sensors.isPmSensorConfigured()) + Serial.println("-->[SETUP] Sensor configured: " + sensors.getPmDeviceSelected()); + + delay(500); +} + +void loop() { + sensors.loop(); // read sensor data and showed it +} +``` + +### Custom RX/TX pines + +```javascript +void setup() { + sensors.init(0,RX,TX); // generic sensor(default), custom RX, custom TX pines. +} +``` + +## Compiling and Installing + +Please install first [PlatformIO](http://platformio.org/) open source ecosystem for IoT development compatible with **Arduino** IDE and its command line tools (Windows, MacOs and Linux), then connect your compatible board to the USB and run the next command: + +```python +pio run --target upload +``` + +### Output + +On your serial monitor you should have something like that: + +```bash +-->[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 +``` + +## Credits + +Thanks to all collaborators and [CanAirIO](https://canair.io) community for testing and reports. diff --git a/examples/co2_mhz19/platformio.ini b/examples/co2_mhz19/platformio.ini new file mode 100644 index 00000000..df34b985 --- /dev/null +++ b/examples/co2_mhz19/platformio.ini @@ -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} diff --git a/examples/co2_mhz19/src/main.cpp b/examples/co2_mhz19/src/main.cpp new file mode 100644 index 00000000..29598078 --- /dev/null +++ b/examples/co2_mhz19/src/main.cpp @@ -0,0 +1,71 @@ +/** + * @file main.cpp + * @author Antonio Vanegas @hpsaturn + * @date June 2018 - 2020 + * @brief Particle meter sensor 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: + * https://canair.io + */ + +#include +#include + +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 (" CO2humi: " + String(sensors.getCO2humi())); + Serial.print (" CO2temp: " + String(sensors.getCO2temp())); + + Serial.print (" H: "+ String(sensors.getHumidity())); + Serial.println (" T: " + String(sensors.getTemperature())); + +} + +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.."); + + 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.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.init(sensors.Mhz19); + + if(sensors.isPmSensorConfigured()) + Serial.println("-->[SETUP] Sensor configured: " + sensors.getPmDeviceSelected()); + + delay(500); +} + +void loop() { + sensors.loop(); // read sensor data and showed it +} \ No newline at end of file From 13a57ed1f5d1b81a5c2acfec2c4732c035514783 Mon Sep 17 00:00:00 2001 From: danielbernalb Date: Wed, 30 Dec 2020 18:12:26 -0500 Subject: [PATCH 15/16] Example for arduino --- examples/co2_mhz19/.gitignore | 62 -------------- examples/co2_mhz19/README.md | 82 ------------------- .../co2_mhz19/{src/main.cpp => co2_mhz19.ino} | 0 3 files changed, 144 deletions(-) delete mode 100644 examples/co2_mhz19/.gitignore delete mode 100644 examples/co2_mhz19/README.md rename examples/co2_mhz19/{src/main.cpp => co2_mhz19.ino} (100%) diff --git a/examples/co2_mhz19/.gitignore b/examples/co2_mhz19/.gitignore deleted file mode 100644 index a0380a51..00000000 --- a/examples/co2_mhz19/.gitignore +++ /dev/null @@ -1,62 +0,0 @@ -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app - -# Vim backups -*.swp - -# PlatformIO work files -.pio -.pioenvs -.piolibdeps -*tags* - -# Library -*.bin -*.zip - -# IDE -extensions.json -settings.json -*tags* -.clang_complete -.gcc-flags.json -.vscode -.vscode/.browse.c_cpp.db* -.vscode/.browse.c_cpp.db* -.vscode/c_cpp_properties.json -.vscode/launch.json -build - -# Project - -releases diff --git a/examples/co2_mhz19/README.md b/examples/co2_mhz19/README.md deleted file mode 100644 index e73363c8..00000000 --- a/examples/co2_mhz19/README.md +++ /dev/null @@ -1,82 +0,0 @@ -[![PlatformIO](https://github.com/kike-canaries/canairio_sensorlib/workflows/PlatformIO/badge.svg)](https://github.com/kike-canaries/canairio_sensorlib/actions/) - -# PlatformIO sample - -Example for **CanAirIO sensors library**, it is a particle meter (**PM**) sensor manager for multiple (PM) sensors: **Honeywell, Plantower, Panasonic, Sensirion**, etc, also it handling others like **AM2320** sensor. - -You can review a **full implementation** on [CanAirIO project firmware](https://github.com/kike-canaries/canairio_firmware/blob/master/src/main.cpp), but a little brief is the next: - -## Implementation - -```Java - -#include -#include - -void onSensorDataOk() { - Serial.print (" PM1.0: " + sensors.getStringPM1()); - Serial.print (" PM2.5: " + sensors.getStringPM25()); - Serial.println(" PM10 : " + sensors.getStringPM10()); -} - -void onSensorDataError(const char * msg){ - Serial.println(msg); -} - -void setup() { - Serial.begin(115200); - delay(200); - Serial.println("\n== Sensor test setup ==\n"); - Serial.println("-->[SETUP] Detecting sensors.."); - - sensors.setSampleTime(5); // config sensors sample time interval - sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback - sensors.setOnErrorCallBack(&onSensorDataError); // [optional] error callback - sensors.setDebugMode(false); // [optional] debug mode - sensors.init(); // start all sensors and - // force to try autodetection, - // you can try to select one: - // sensors.init(sensors.Sensirion); - - if(sensors.isPmSensorConfigured()) - Serial.println("-->[SETUP] Sensor configured: " + sensors.getPmDeviceSelected()); - - delay(500); -} - -void loop() { - sensors.loop(); // read sensor data and showed it -} -``` - -### Custom RX/TX pines - -```javascript -void setup() { - sensors.init(0,RX,TX); // generic sensor(default), custom RX, custom TX pines. -} -``` - -## Compiling and Installing - -Please install first [PlatformIO](http://platformio.org/) open source ecosystem for IoT development compatible with **Arduino** IDE and its command line tools (Windows, MacOs and Linux), then connect your compatible board to the USB and run the next command: - -```python -pio run --target upload -``` - -### Output - -On your serial monitor you should have something like that: - -```bash --->[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 -``` - -## Credits - -Thanks to all collaborators and [CanAirIO](https://canair.io) community for testing and reports. diff --git a/examples/co2_mhz19/src/main.cpp b/examples/co2_mhz19/co2_mhz19.ino similarity index 100% rename from examples/co2_mhz19/src/main.cpp rename to examples/co2_mhz19/co2_mhz19.ino From 189cf014a016a940df4c14bb783cb38016c36aab Mon Sep 17 00:00:00 2001 From: danielbernalb Date: Wed, 30 Dec 2020 18:23:44 -0500 Subject: [PATCH 16/16] Minor change example platformio --- examples/platformio/src/main.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/examples/platformio/src/main.cpp b/examples/platformio/src/main.cpp index 3a4e6240..1eda42eb 100644 --- a/examples/platformio/src/main.cpp +++ b/examples/platformio/src/main.cpp @@ -22,11 +22,6 @@ void onSensorDataOk() { Serial.print ("-->[MAIN] PM1.0: "+sensors.getStringPM1()); Serial.print (" PM2.5: " + sensors.getStringPM25()); Serial.print (" PM10: " + sensors.getStringPM10()); - - Serial.print (" CO2: " + sensors.getStringCO2()); - Serial.print (" CO2humi: " + String(sensors.getCO2humi())); - Serial.print (" CO2temp: " + String(sensors.getCO2temp())); - Serial.print (" H: "+ String(sensors.getHumidity())); Serial.println (" T: " + String(sensors.getTemperature()));