From b2bc1ab7e36c33c2bb4a595ba50fd7c6ebba812c Mon Sep 17 00:00:00 2001 From: roberbike Date: Sat, 5 Aug 2023 21:11:03 +0200 Subject: [PATCH 01/21] Ikea Sensirion I2C SEN5X implementation --- src/Sensors.cpp | 125 +++++++++++++++++++++++++++++++++++++++++++ src/Sensors.hpp | 21 ++++++-- unified-lib-deps.ini | 1 + 3 files changed, 142 insertions(+), 5 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 28ac6ce1..88e9a16e 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -69,6 +69,7 @@ bool Sensors::readAllSensors() { GCJA5Read(); sps30Read(); CO2scd4xRead(); + sen5xRead(); am2320Read(); sht31Read(); bme280Read(); @@ -123,6 +124,7 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { sps30I2CInit(); GCJA5Init(); CO2scd4xInit(); + sen5xInit(); bmp280Init(); bme280Init(); bme680Init(); @@ -309,6 +311,7 @@ void Sensors::setTempOffset(float offset){ toffset = offset; setSCD30TempOffset(toffset); setSCD4xTempOffset(toffset); + // setSEN5xTempOffset(toffset); } /// get Gas resistance value of BMP680 sensor @@ -975,6 +978,47 @@ void Sensors::CO2scd4xRead() { unitRegister(UNIT::CO2HUM); } + +void Sensors::sen5xRead() { + uint16_t error; + char errorMessage[256]; + float massConcentrationPm1p0; + float massConcentrationPm2p5; + float massConcentrationPm4p0; + float massConcentrationPm10p0; + float ambientHumidity; + float ambientTemperature; + float vocIndex; + float noxIndex; + + error = sen5x.readMeasuredValues( + massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0, + massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex, + noxIndex); + + if (error) { + Serial.print("Error trying to execute readMeasuredValues(): "); + errorToString(error, errorMessage, 256); + Serial.println(errorMessage); + } + + // if (massConcentrationPm1p0 > 1000 || massConcentrationPm2p5 > 1000 || massConcentrationPm4p0 > 1000 || massConcentrationPm10p0 > 1000) return; + pm1 = massConcentrationPm1p0; + pm25 = massConcentrationPm2p5; + pm4 = massConcentrationPm4p0; + pm10 = massConcentrationPm4p0; + temp = ambientTemperature; + humi = ambientHumidity; + dataReady = true; + DEBUG("-->[SLIB] SEN5x read\t\t: done!"); + unitRegister(UNIT::PM1); + unitRegister(UNIT::PM25); + unitRegister(UNIT::PM4); + unitRegister(UNIT::PM10); + unitRegister(UNIT::TEMP); + unitRegister(UNIT::HUM); +} + void Sensors::GCJA5Read() { if (dev_uart_type == SENSORS::SGCJA5) return; if (!pmGCJA5.isConnected()) return; @@ -1572,6 +1616,87 @@ void Sensors::setSCD4xAltitudeOffset(float offset) { } } + +void Sensors::sen5xInit() { + sensorAnnounce(SENSORS::SSEN5X); + Wire.begin(); + sen5x.begin(Wire); + uint16_t error; + char errorMessage[256]; + error = sen5x.deviceReset(); + if (error) { + Serial.print("Error trying to execute deviceReset(): "); + errorToString(error, errorMessage, 256); + Serial.println(errorMessage); + } + unsigned char productName[32]; + uint8_t productNameSize = 32; + error = sen5x.getProductName(productName, productNameSize); + + if (error) { + Serial.print("Error trying to execute getProductName(): "); + errorToString(error, errorMessage, 256); + Serial.println(errorMessage); + } else { + Serial.print("ProductName: "); + Serial.println((char*)productName); + + } + uint8_t firmwareMajor; + uint8_t firmwareMinor; + bool firmwareDebug; + uint8_t hardwareMajor; + uint8_t hardwareMinor; + uint8_t protocolMajor; + uint8_t protocolMinor; + error = sen5x.getVersion(firmwareMajor, firmwareMinor, firmwareDebug, + hardwareMajor, hardwareMinor, protocolMajor, + protocolMinor); + if (error) { + Serial.print("Error trying to execute getVersion(): "); + errorToString(error, errorMessage, 256); + Serial.println(errorMessage); + } else { + Serial.print("Firmware: "); + Serial.print(firmwareMajor); + Serial.print("."); + Serial.print(firmwareMinor); + Serial.print(", "); + + Serial.print("Hardware: "); + Serial.print(hardwareMajor); + Serial.print("."); + Serial.println(hardwareMinor); + } + + unsigned char serialNumber[32]; + uint8_t serialNumberSize = 32; + + error = sen5x.getSerialNumber(serialNumber, serialNumberSize); + if (error) { + Serial.print("Error trying to execute getSerialNumber(): "); + errorToString(error, errorMessage, 256); + Serial.println(errorMessage); + } else { + Serial.print("SerialNumber:"); + Serial.println((char*)serialNumber); + } + + sensorRegister(SENSORS::SSEN5X); + +} + +/* +void Sensors::setsen5xTempOffset(float offset) { + if (isSensorRegistered(SENSORS::SSEN5X)) { + Serial.println("-->[SLIB] SEN5x new temperature offset\t: " + String(offset)); + sen5x.stoptMeasurement(); + sen5x.setTemperatureOffsetSimple(tempOffset); + delay(510); + sen5x.startMeasurement(); + } +} +*/ void Sensors::GCJA5Init() { sensorAnnounce(SENSORS::SGCJA5); #ifndef Wire1 diff --git a/src/Sensors.hpp b/src/Sensors.hpp index f57500d9..c6107a14 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -10,11 +10,12 @@ #include #include #include -#include #include #include #include +#include #include +#include #include #include #include @@ -23,8 +24,8 @@ #include #endif -#define CSL_VERSION "0.6.9" -#define CSL_REVISION 376 +#define CSL_VERSION "0.6.9.1" +#define CSL_REVISION 376.1 /*************************************************************** * S E T U P E S P 3 2 B O A R D S A N D F I E L D S @@ -120,6 +121,7 @@ typedef enum UNIT : size_t { SENSOR_UNITS } UNIT; X(IKEAVK, "IKEAVK",1) \ X(SSCD30, "SCD30", 2) \ X(SSCD4X, "SCD4X", 2) \ + X(SSEN5X, "SEN5X", 1) \ X(SSHT31, "SHT31", 3) \ X(SBME280, "BME280", 3) \ X(SBMP280, "BMP280", 3) \ @@ -127,9 +129,9 @@ typedef enum UNIT : size_t { SENSOR_UNITS } UNIT; X(SAHTXX, "AHTXX", 3) \ X(SAM232X, "AM232X", 3) \ X(SDHTX, "DHTX", 3) \ - X(SDFRCO, "DFRCO", 3) \ + X(SDFRCO, "DFRCO", 3) \ X(SDFRNH3, "DFRNH3", 3) \ - X(SCAJOE, "CAJOE", 3) \ + X(SCAJOE, "CAJOE", 3) \ X(SCOUNT, "SCOUNT", 3) #define X(utype, uname, umaintype) utype, @@ -216,6 +218,9 @@ class Sensors { // SCD4x sensor SensirionI2CScd4x scd4x; + // SEN5x sensor PM + SensirionI2CSen5x sen5x; + // IKEA Vindriktn sensor PM1006 *pm1006; @@ -228,6 +233,8 @@ class Sensors { // Geiger CAJOE sensor GEIGER *rad; + + void init(u_int pms_type = 0, int pms_rx = PMS_RX, int pms_tx = PMS_TX); void loop(); @@ -403,6 +410,10 @@ class Sensors { void setSCD4xTempOffset(float offset); void setSCD4xAltitudeOffset(float offset); + void sen5xInit(); + void sen5xRead(); + // void setSEN5xTempOffset(float offset); + void GCJA5Init(); void GCJA5Read(); diff --git a/unified-lib-deps.ini b/unified-lib-deps.ini index e7028ccd..5dcada24 100644 --- a/unified-lib-deps.ini +++ b/unified-lib-deps.ini @@ -13,6 +13,7 @@ lib_deps = jcomas/S8_UART@1.0.1 sensirion/Sensirion Core@0.6.0 sensirion/Sensirion I2C SCD4x@0.4.0 + sensirion/Sensirion I2C SEN5X @ 0.3.0 phzi/DFRobot_MultiGasSensor@2.0.0 https://github.com/enjoyneering/AHTxx.git#eb21571 https://github.com/hpsaturn/DHT_nonblocking.git#ec6e5b9 From aed877e4897c0b7f4f746bf823adfc100511c33f Mon Sep 17 00:00:00 2001 From: roberbike Date: Wed, 18 Oct 2023 22:20:24 +0200 Subject: [PATCH 02/21] added NO2 sensor --- src/Sensors.cpp | 31 +++++++++++++++++++++++++++++-- src/Sensors.hpp | 9 +++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 897c4c6b..f493c358 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -77,6 +77,7 @@ bool Sensors::readAllSensors() { aht10Read(); DFRobotCORead(); DFRobotNH3Read(); + DFRobotNO2Read(); geigerRead(); #ifdef DHT11_ENABLED @@ -131,6 +132,7 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { aht10Init(); DFRobotCOInit(); DFRobotNH3Init(); + DFRobotNO2Init(); #ifdef DHT11_ENABLED dhtInit(); @@ -404,6 +406,11 @@ float Sensors::getCO() { return co; } +/// get NO2 value in ppm +float Sensors::getNO2() { + return no2; +} + /** * @brief UART only: check if the UART sensor is registered * @return bool true if the UART sensor is registered, false otherwise. @@ -636,6 +643,8 @@ float Sensors::getUnitValue(UNIT unit) { return nh3; case CO: return co; + case NO2: + return no2; default: return 0.0; } @@ -1082,6 +1091,12 @@ void Sensors::DFRobotCORead() { } +void Sensors::DFRobotNO2Read() { + if (!dfrNO2.begin()) return; + no2 = dfrNO2.readGasConcentrationPPM(); + unitRegister(UNIT::NO2); +} + #ifdef DHT11_ENABLED DHT_nonblocking dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE); /** @@ -1667,7 +1682,7 @@ void Sensors::GCJA5Init() { /// DFRobot GAS (CO) sensors init void Sensors::DFRobotCOInit() { sensorAnnounce(SENSORS::SDFRCO); - dfrCO = DFRobot_GAS_I2C(&Wire, 0x78); // Be sure that your group of i2c address is 7 + dfrCO = DFRobot_GAS_I2C(&Wire, 0x78); // Be sure that your group of i2c address is 7, and A0=0 A1=0 if (!dfrCO.begin()) return; //Mode of obtaining data: the main controller needs to request the sensor for data dfrCO.changeAcquireMode(dfrCO.PASSIVITY); @@ -1679,7 +1694,7 @@ void Sensors::DFRobotCOInit() { /// DFRobot GAS (NH3) sensors init void Sensors::DFRobotNH3Init() { sensorAnnounce(SENSORS::SDFRNH3); - dfrNH3 = DFRobot_GAS_I2C(&Wire, 0x7A); // 0x77 y 0x75 used by bme680. Be sure that your group of i2c address is 7 + dfrNH3 = DFRobot_GAS_I2C(&Wire, 0x7A); // 0x77 y 0x75 used by bme680. Be sure that your group of i2c address is 7, and A0=1 A1=0 if (!dfrNH3.begin()) return; //Mode of obtaining data: the main controller needs to request the sensor for data dfrNH3.changeAcquireMode(dfrNH3.PASSIVITY); @@ -1688,6 +1703,18 @@ void Sensors::DFRobotNH3Init() { sensorRegister(SENSORS::SDFRNH3); } +/// DFRobot GAS (NO2) sensors init +void Sensors::DFRobotNO2Init() { + sensorAnnounce(SENSORS::SDFRNO2); + dfrNO2 = DFRobot_GAS_I2C(&Wire, 0x7B); // Be sure that your group of i2c address is 7, and A0=1 A1=1 + if (!dfrNO2.begin()) return; + //Mode of obtaining data: the main controller needs to request the sensor for data + dfrNO2.changeAcquireMode(dfrNO2.PASSIVITY); + //Turn on temperature compensation: gas.ON : turn on + dfrNO2.setTempCompensation(dfrNO2.ON); + sensorRegister(SENSORS::SDFRNO2); +} + // Altitude compensation for CO2 sensors without Pressure atm or Altitude compensation void Sensors::CO2correctionAlt() { DEBUG("-->[SLIB] CO2 altitud original\t:", String(CO2Val).c_str()); diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 4a5216f7..109813a1 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -107,6 +107,7 @@ X(RAD, "uSv/h", "RAD") \ X(NH3, "ppm", "NH3") \ X(CO, "ppm", "CO") \ + X(NO2, "ppm", "NO2") \ X(UCOUNT, "COUNT", "UCOUNT") @@ -135,6 +136,7 @@ typedef enum UNIT : size_t { SENSOR_UNITS } UNIT; X(SDHTX, "DHTX", 3) \ X(SDFRCO, "DFRCO", 3) \ X(SDFRNH3, "DFRNH3", 3) \ + X(SDFRNO2, "DFRNO2", 3) \ X(SCAJOE, "CAJOE", 3) \ X(SCOUNT, "SCOUNT", 3) @@ -237,6 +239,8 @@ class Sensors { DFRobot_GAS_I2C dfrCO; /// DFRobot gravity NH3 object sensor addr 0x77 DFRobot_GAS_I2C dfrNH3; + /// DFRobot gravity NO2 object sensor add 0x7B + DFRobot_GAS_I2C dfrNO2; /// Geiger CAJOE object sensor GEIGER *rad; @@ -289,6 +293,8 @@ class Sensors { float getNH3(); float getCO(); + + float getNO2(); void enableGeigerSensor(int gpio); @@ -389,6 +395,7 @@ class Sensors { float nh3; // Amonium in ppm float co; // Carbon monoxide + float no2; // Nitrogen dioxide void am2320Init(); void am2320Read(); @@ -433,6 +440,8 @@ class Sensors { void DFRobotNH3Read(); void DFRobotCOInit(); void DFRobotCORead(); + void DFRobotNO2Init(); + void DFRobotNO2Read(); // UART sensors methods: From 82c7995036d00cf02854f1d124fbaf434313ad4e Mon Sep 17 00:00:00 2001 From: roberbike Date: Wed, 18 Oct 2023 22:30:27 +0200 Subject: [PATCH 03/21] version --- src/Sensors.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 109813a1..2083bf73 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -23,7 +23,7 @@ #include #endif -#define CSL_VERSION "0.7.2" +#define CSL_VERSION "0.7.3" #define CSL_REVISION 379 /*************************************************************** From 646363af0f0b1272787a164dc590779c0dff3678 Mon Sep 17 00:00:00 2001 From: roberbike Date: Wed, 18 Oct 2023 22:46:36 +0200 Subject: [PATCH 04/21] version 380 --- src/Sensors.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 2083bf73..deda7e9d 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -24,7 +24,7 @@ #endif #define CSL_VERSION "0.7.3" -#define CSL_REVISION 379 +#define CSL_REVISION 380 /*************************************************************** * S E T U P E S P 3 2 B O A R D S A N D F I E L D S From ab97de014292e91f950c5ec93eeb1c28d59cfc5e Mon Sep 17 00:00:00 2001 From: roberbike Date: Wed, 18 Oct 2023 23:39:56 +0200 Subject: [PATCH 05/21] i2c change to group 7 --- examples/DfRobot_Multigas/dfr_multigas.ino | 2 + examples/DfRobot_Multigas/i2c_change/main.cpp | 147 ++++++++++++++++++ .../i2c_change/platformio.ini | 18 +++ 3 files changed, 167 insertions(+) create mode 100644 examples/DfRobot_Multigas/i2c_change/main.cpp create mode 100644 examples/DfRobot_Multigas/i2c_change/platformio.ini diff --git a/examples/DfRobot_Multigas/dfr_multigas.ino b/examples/DfRobot_Multigas/dfr_multigas.ino index f114af85..d45669b7 100644 --- a/examples/DfRobot_Multigas/dfr_multigas.ino +++ b/examples/DfRobot_Multigas/dfr_multigas.ino @@ -21,6 +21,7 @@ void onSensorDataOk() { Serial.println("-->[MAIN] NH3: " + String(sensors.getNH3())); Serial.println("-->[MAIN] CO: " + String(sensors.getCO())); + Serial.println("-->[MAIN] NO2: " + String(sensors.getNO2()));) } void onSensorDataError(const char* msg) { @@ -46,6 +47,7 @@ void setup() { sensors.init(SENSORS::SDFRCO); // detect CO sensor sensors.init(SENSORS::SDFRNH3); // detect NH3 sensor + sensors.init(SENSORS::SDFRNO2); // detect NO2 sensor delay(500); } diff --git a/examples/DfRobot_Multigas/i2c_change/main.cpp b/examples/DfRobot_Multigas/i2c_change/main.cpp new file mode 100644 index 00000000..26ab2555 --- /dev/null +++ b/examples/DfRobot_Multigas/i2c_change/main.cpp @@ -0,0 +1,147 @@ +/*! + * @file readGasConcentration.ino + * @brief Obtain gas concentration corresponding to the current environment, output as concentration value + * @n Experimental mode: connect sensor communication pin to the main controller and burn + * @n Communication mode select, DIP switch SEL: 0: I2C, 1: UART + * @n Group serial number Address in the group + * @n A0 A1 DIP level 00 01 10 11 + * @n 1 0x60 0x61 0x62 0x63 + * @n 2 0x64 0x65 0x66 0x67 + * @n 3 0x68 0x69 0x6A 0x6B + * @n 4 0x6C 0x6D 0x6E 0x6F + * @n 5 0x70 0x71 0x72 0x73 + * @n 6 (Default address group) 0x74 0x75 0x76 0x77 (Default address) + * @n 7 0x78 0x79 0x7A 0x7B + * @n 8 0x7C 0x7D 0x7E 0x7F + * @n i2c address select, default to 0x77, A1 and A0 are grouped into 4 I2C addresses. + * @n | A0 | A1 | + * @n | 0 | 0 | 0x74 + * @n | 0 | 1 | 0x75 + * @n | 1 | 0 | 0x76 + * @n | 1 | 1 | 0x77 default i2c address + * @n Experimental phenomenon: view the gas concentration corresponding to the current environment through serial port printing + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + * @license The MIT License (MIT) + * @author PengKaixing(kaixing.peng@dfrobot.com) + * @version V1.0 + * @date 2021-03-28 + * @url https://github.com/DFRobot/DFRobot_MultiGasSensor + */ +#include "DFRobot_MultiGasSensor.h" +#include + +//Turn on by default, using I2C communication at the time, switch to serial port communication after turning off +//#define I2C_COMMUNICATION + +//#ifdef I2C_COMMUNICATION +//#define I2C_ADDRESS 0x77 + DFRobot_GAS_I2C nh3(&Wire,0x7A); + DFRobot_GAS_I2C co(&Wire,0x78); + DFRobot_GAS_I2C no(&Wire,0x7B); + +void setup() { + //Serial port init for viewing printing output + Serial.begin(115200); + + //Change i2c address group + while(gas.changeI2cAddrGroup(7)==0) + { + Serial.println("IIC addr change fail!"); + delay(1000); + } + Serial.println("IIC addr change success!"); +} + + //Sensor init, used to init serial port or I2C, depending on the communication mode currently used + while(!nh3.begin()) + { + Serial.println("No Devices NH3 !"); + delay(1000); + } + //Mode of obtaining data: the main controller needs to request the sensor for data + nh3.changeAcquireMode(nh3.PASSIVITY); + delay(1000); + + nh3.setTempCompensation(nh3.ON); + + Serial.println("The device nh3 0x7A is connected successfully!"); + + while(!co.begin()) + { + Serial.println("No Devices CO !"); + delay(1000); + } + + co.changeAcquireMode(co.PASSIVITY); + delay(1000); + + co.setTempCompensation(co.ON); + + Serial.println("The device CO 0x78 is connected successfully!"); + + while(!no2.begin()) + { + Serial.println("No Devices NO2 !"); + delay(1000); + } + + no2.changeAcquireMode(no2.PASSIVITY); + delay(1000); + + no2.setTempCompensation(no2.ON); + + Serial.println("The device CO 0x7B is connected successfully!"); +} + +void loop() { + String gastypeNH3 = nh3.queryGasType(); + /** + *Fill in the parameter readGasConcentration() with the type of gas to be obtained and print + *The current gas concentration + *Print with 1s delay each time + */ + Serial.print("Ambient "); + Serial.print(gastypeNH3); + Serial.print(" concentration is: "); + Serial.print(nh3.readGasConcentrationPPM()); + if (gastypeNH3 == "O2") + Serial.println(" %vol"); + else + Serial.println(" PPM"); + Serial.println(); + delay(1000); + + String gastypeCO = co.queryGasType(); + /** + *Fill in the parameter readGasConcentration() with the type of gas to be obtained and print + *The current gas concentration + *Print with 1s delay each time + */ + Serial.print("Ambient "); + Serial.print(gastypeCO); + Serial.print(" concentration is: "); + Serial.print(co.readGasConcentrationPPM()); + if (gastypeCO == "O2") + Serial.println(" %vol"); + else + Serial.println(" PPM"); + Serial.println(); + delay(1000); + + String gastypeNO2 = no2.queryGasType(); + /** + *Fill in the parameter readGasConcentration() with the type of gas to be obtained and print + *The current gas concentration + *Print with 1s delay each time + */ + Serial.print("Ambient "); + Serial.print(gastypeNO2); + Serial.print(" concentration is: "); + Serial.print(no2.readGasConcentrationPPM()); + if (gastypeNO2 == "O2") + Serial.println(" %vol"); + else + Serial.println(" PPM"); + Serial.println(); + delay(1000); +} diff --git a/examples/DfRobot_Multigas/i2c_change/platformio.ini b/examples/DfRobot_Multigas/i2c_change/platformio.ini new file mode 100644 index 00000000..468c3596 --- /dev/null +++ b/examples/DfRobot_Multigas/i2c_change/platformio.ini @@ -0,0 +1,18 @@ +; 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 + +[env:esp32doit-devkit-v1] +platform = espressif32 +board = esp32doit-devkit-v1 +monitor_speed = 115200 +monitor_filters = time +framework = arduino +lib_deps = + https://github.com/DFRobot/DFRobot_MultiGasSensor.git \ No newline at end of file From 03d349f5e4eec3c6e0f6086302d5f65728dd22e7 Mon Sep 17 00:00:00 2001 From: roberbike Date: Thu, 19 Oct 2023 12:29:34 +0200 Subject: [PATCH 06/21] add NO2 to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bd3fe4e1..4b3c55bf 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ Panasonic via UART in ESP8266 maybe needs select in detection. | BME680 | i2c | Auto | STABLE | | DfRobot SEN0469 NH3 | i2c | Auto | TESTING | | DFRobot SEN0466 CO | i2c | Auto | TESTING | +| DFRobot SEN0471 NO2 | i2c | Auto | TESTING | | Geiger CAJOE | GPIO | Select | TESTING | | DHTxx | TwoWire | Select | DISABLED | From a9e4230aa1e42d234ebe20aa943dae529e5a905c Mon Sep 17 00:00:00 2001 From: roberbike Date: Thu, 19 Oct 2023 12:44:21 +0200 Subject: [PATCH 07/21] actualizado readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b3c55bf..e5dbd31c 100644 --- a/README.md +++ b/README.md @@ -365,7 +365,7 @@ Also you can make a donation, be a patreon or buy a device: - [x] SenseAir S8 via UART support - [x] Multivariable selection (getNextUnit(),getUnitName(),etc) - [x] Two I2C channel supported for M5Stack Devices (M5StickC tested) -- [x] Added CO and NH3 sensors +- [x] Added CO, NO2 and NH3 sensors - [x] Added Geiger sensor support - [ ] New IKEA VINDSTYRKA device support - [ ] Sea level setting for Pressure sensors and others From 98e1143075f61608a2df8b1089e58ab6e2b049b9 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sun, 22 Oct 2023 13:03:44 +0200 Subject: [PATCH 08/21] fixed missing dependency issue. Sensirion I2C SEN5X --- library.json | 1 + 1 file changed, 1 insertion(+) diff --git a/library.json b/library.json index 7449a5cb..e6bd5d45 100644 --- a/library.json +++ b/library.json @@ -90,6 +90,7 @@ {"name":"Sensirion Core","owner":"sensirion","version":"0.6.0"}, {"name":"Sensirion I2C SCD4x","owner":"sensirion","version":"0.4.0"}, {"name":"DFRobot_MultiGasSensor","owner":"phzi","version":"2.0.0"}, + {"name":"Sensirion I2C SEN5X","owner":"sensirion","version":"0.3.0"}, {"name":"AHTxx", "version":"https://github.com/enjoyneering/AHTxx.git#eb21571"}, {"name":"DHT_nonblocking", "version":"https://github.com/hpsaturn/DHT_nonblocking.git#ec6e5b9"}, From 4e626fbe492b70588c5441d7e972641a1c4d4f10 Mon Sep 17 00:00:00 2001 From: roberbike Date: Sun, 22 Oct 2023 18:56:48 +0200 Subject: [PATCH 09/21] fix definitions and CO Temp compensation --- src/Sensors.cpp | 3 ++- src/Sensors.hpp | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index a18f332d..81d84481 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -1812,7 +1812,7 @@ void Sensors::DFRobotCOInit() { //Mode of obtaining data: the main controller needs to request the sensor for data dfrCO.changeAcquireMode(dfrCO.PASSIVITY); //Turn on temperature compensation: gas.ON : turn on - dfrNH3.setTempCompensation(dfrCO.ON); + dfrCO.setTempCompensation(dfrCO.ON); sensorRegister(SENSORS::SDFRCO); } @@ -1902,6 +1902,7 @@ void Sensors::resetAllVariables() { pres = 0.0; nh3 = 0; co = 0; + no2 = 0; if (rad !=nullptr) rad->clear(); } diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 212ef39d..3cb22ed8 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -239,9 +239,9 @@ class Sensors { SensirionI2CSen5x sen5x; /// IKEA Vindriktn object sensor PM1006 *pm1006; - /// DFRobot gravity NH3 object sensor addr 0x74 + /// DFRobot gravity CO object sensor addr 0x78 DFRobot_GAS_I2C dfrCO; - /// DFRobot gravity NH3 object sensor addr 0x77 + /// DFRobot gravity NH3 object sensor addr 0x7A DFRobot_GAS_I2C dfrNH3; /// DFRobot gravity NO2 object sensor add 0x7B DFRobot_GAS_I2C dfrNO2; @@ -400,8 +400,8 @@ class Sensors { float CO2temp = 0.0; // temperature of CO2 sensor float nh3; // Amonium in ppm - float co; // Carbon monoxide - float no2; // Nitrogen dioxide + float co; // Carbon monoxide in ppm + float no2; // Nitrogen dioxide in ppm void am2320Init(); void am2320Read(); From 607f61bd26cc4767df8aa33c3544ff276dd26503 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Tue, 24 Oct 2023 21:00:02 +0200 Subject: [PATCH 10/21] fixed some issues on the SEN5x implementation --- src/Sensors.cpp | 89 ++++++++----------------------------------------- src/Sensors.hpp | 2 +- 2 files changed, 14 insertions(+), 77 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 81d84481..1e3d7c3d 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -381,7 +381,7 @@ void Sensors::setTempOffset(float offset){ toffset = offset; setSCD30TempOffset(toffset); setSCD4xTempOffset(toffset); - // setSEN5xTempOffset(toffset); + setsen5xTempOffset(toffset); } /// get Gas resistance value of BMP680 sensor @@ -1065,8 +1065,6 @@ void Sensors::CO2scd4xRead() { void Sensors::sen5xRead() { - uint16_t error; - char errorMessage[256]; float massConcentrationPm1p0; float massConcentrationPm2p5; float massConcentrationPm4p0; @@ -1076,18 +1074,13 @@ void Sensors::sen5xRead() { float vocIndex; float noxIndex; - error = sen5x.readMeasuredValues( + uint16_t error = sen5x.readMeasuredValues( massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex, noxIndex); - if (error) { - Serial.print("Error trying to execute readMeasuredValues(): "); - errorToString(error, errorMessage, 256); - Serial.println(errorMessage); - } + if (error) return; - // if (massConcentrationPm1p0 > 1000 || massConcentrationPm2p5 > 1000 || massConcentrationPm4p0 > 1000 || massConcentrationPm10p0 > 1000) return; pm1 = massConcentrationPm1p0; pm25 = massConcentrationPm2p5; pm4 = massConcentrationPm4p0; @@ -1712,88 +1705,32 @@ void Sensors::setSCD4xAltitudeOffset(float offset) { } } - +/// Panasonic SEN5X sensor init void Sensors::sen5xInit() { sensorAnnounce(SENSORS::SSEN5X); - Wire.begin(); + #ifndef Wire1 sen5x.begin(Wire); + #else + sen5x.begin(Wire1); + #endif uint16_t error; - char errorMessage[256]; error = sen5x.deviceReset(); - if (error) { - Serial.print("Error trying to execute deviceReset(): "); - errorToString(error, errorMessage, 256); - Serial.println(errorMessage); - } - unsigned char productName[32]; - uint8_t productNameSize = 32; - error = sen5x.getProductName(productName, productNameSize); - - if (error) { - Serial.print("Error trying to execute getProductName(): "); - errorToString(error, errorMessage, 256); - Serial.println(errorMessage); - } else { - Serial.print("ProductName: "); - Serial.println((char*)productName); - - } - uint8_t firmwareMajor; - uint8_t firmwareMinor; - bool firmwareDebug; - uint8_t hardwareMajor; - uint8_t hardwareMinor; - uint8_t protocolMajor; - uint8_t protocolMinor; - error = sen5x.getVersion(firmwareMajor, firmwareMinor, firmwareDebug, - hardwareMajor, hardwareMinor, protocolMajor, - protocolMinor); - if (error) { - Serial.print("Error trying to execute getVersion(): "); - errorToString(error, errorMessage, 256); - Serial.println(errorMessage); - } else { - Serial.print("Firmware: "); - Serial.print(firmwareMajor); - Serial.print("."); - Serial.print(firmwareMinor); - Serial.print(", "); - - Serial.print("Hardware: "); - Serial.print(hardwareMajor); - Serial.print("."); - Serial.println(hardwareMinor); - } - - unsigned char serialNumber[32]; - uint8_t serialNumberSize = 32; - - error = sen5x.getSerialNumber(serialNumber, serialNumberSize); - if (error) { - Serial.print("Error trying to execute getSerialNumber(): "); - errorToString(error, errorMessage, 256); - Serial.println(errorMessage); - } else { - Serial.print("SerialNumber:"); - Serial.println((char*)serialNumber); - } - + if (error) return; sensorRegister(SENSORS::SSEN5X); - } -/* +/// set SEN5X temperature compensation void Sensors::setsen5xTempOffset(float offset) { if (isSensorRegistered(SENSORS::SSEN5X)) { Serial.println("-->[SLIB] SEN5x new temperature offset\t: " + String(offset)); - sen5x.stoptMeasurement(); - sen5x.setTemperatureOffsetSimple(tempOffset); + sen5x.stopMeasurement(); + sen5x.setTemperatureOffsetSimple(offset); delay(510); sen5x.startMeasurement(); } } -*/ +/// Panasonic GCJA5 sensor init void Sensors::GCJA5Init() { sensorAnnounce(SENSORS::SGCJA5); #ifndef Wire1 diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 3cb22ed8..68c0d182 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -435,7 +435,7 @@ class Sensors { void sen5xInit(); void sen5xRead(); - // void setSEN5xTempOffset(float offset); + void setsen5xTempOffset(float offset); void GCJA5Init(); void GCJA5Read(); From 26fe508432882958fc8dc73a39732a4f9b5766eb Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Tue, 24 Oct 2023 21:04:32 +0200 Subject: [PATCH 11/21] v0.7.3rev381 fixed issues on Sensirion5X --- library.json | 2 +- library.properties | 2 +- src/Sensors.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library.json b/library.json index e6bd5d45..f1867829 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "CanAirIO Air Quality Sensors Library", - "version": "0.7.2", + "version": "0.7.3", "homepage":"https://canair.io", "keywords": [ diff --git a/library.properties b/library.properties index 64e97bcc..2a1a9072 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=CanAirIO Air Quality Sensors Library -version=0.7.2 +version=0.7.3 author=@hpsaturn, CanAirIO project maintainer=Antonio Vanegas url=https://github.com/kike-canaries/canairio_sensorlib diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 68c0d182..9014c113 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -25,7 +25,7 @@ #endif #define CSL_VERSION "0.7.3" -#define CSL_REVISION 380 +#define CSL_REVISION 381 /*************************************************************** * S E T U P E S P 3 2 B O A R D S A N D F I E L D S From cd542a047bba9225211866f83fe97e17ae191061 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Wed, 25 Oct 2023 17:54:28 +0200 Subject: [PATCH 12/21] added set sen5x tempcompensation like others sensirion sensors --- src/Sensors.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 1e3d7c3d..4e3f3f53 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -1662,10 +1662,7 @@ void Sensors::CO2scd4xInit() { uint16_t error; scd4x.begin(Wire); error = scd4x.stopPeriodicMeasurement(); - if (error) { - DEBUG("[W][SLIB] SCD4x stopping error \t:", String(error).c_str()); - return; - } + if (error) return; scd4x.getTemperatureOffset(tTemperatureOffset); scd4x.getSensorAltitude(tSensorAltitude); DEBUG("-->[SLIB] SCD4x Temp offset\t:", String(tTemperatureOffset).c_str()); @@ -1716,6 +1713,12 @@ void Sensors::sen5xInit() { uint16_t error; error = sen5x.deviceReset(); if (error) return; + float tempOffset = 0.0; + DEBUG("-->[SLIB] SEN5X Temp offset\t:",String(sen5x.getTemperatureOffsetSimple(tempOffset)).c_str()); + if(uint16_t((tempOffset*100)) != (uint16_t(toffset*100))) { + sen5x.setTemperatureOffsetSimple(toffset); + delay(10); + } sensorRegister(SENSORS::SSEN5X); } From 181574026370165afbb3f9b47407bee9ace15e24 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Wed, 25 Oct 2023 18:02:40 +0200 Subject: [PATCH 13/21] v0.7.3rev382 fixed issues on Sensirion5X and updated dependencies --- library.json | 8 ++++---- src/Sensors.hpp | 2 +- unified-lib-deps.ini | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/library.json b/library.json index f1867829..5b1ab87d 100644 --- a/library.json +++ b/library.json @@ -82,15 +82,15 @@ {"name":"Adafruit BME680 Library","owner":"adafruit","version":"2.0.2"}, {"name":"Adafruit SHT31 Library", "owner":"adafruit","version":"2.2.2"}, {"name":"Adafruit SCD30", "owner":"adafruit","version":"1.0.9"}, - {"name":"Adafruit BusIO", "owner":"adafruit","version":"1.14.4"}, - {"name":"AM232X", "owner":"robtillaart", "version":"0.4.5"}, - {"name":"sps30", "owner":"paulvha","version":"1.4.16"}, + {"name":"Adafruit BusIO", "owner":"adafruit","version":"1.14.5"}, + {"name":"AM232X", "owner":"robtillaart", "version":"0.5.0"}, + {"name":"sps30", "owner":"paulvha","version":"1.4.17"}, {"name":"MH-Z19", "owner":"wifwaf", "version":"1.5.4"}, {"name":"S8_UART", "owner":"jcomas", "version":"1.0.1"}, {"name":"Sensirion Core","owner":"sensirion","version":"0.6.0"}, {"name":"Sensirion I2C SCD4x","owner":"sensirion","version":"0.4.0"}, - {"name":"DFRobot_MultiGasSensor","owner":"phzi","version":"2.0.0"}, {"name":"Sensirion I2C SEN5X","owner":"sensirion","version":"0.3.0"}, + {"name":"DFRobot_MultiGasSensor","owner":"phzi","version":"2.0.0"}, {"name":"AHTxx", "version":"https://github.com/enjoyneering/AHTxx.git#eb21571"}, {"name":"DHT_nonblocking", "version":"https://github.com/hpsaturn/DHT_nonblocking.git#ec6e5b9"}, diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 9014c113..80f398b4 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -25,7 +25,7 @@ #endif #define CSL_VERSION "0.7.3" -#define CSL_REVISION 381 +#define CSL_REVISION 382 /*************************************************************** * S E T U P E S P 3 2 B O A R D S A N D F I E L D S diff --git a/unified-lib-deps.ini b/unified-lib-deps.ini index 37248c77..6fd4d49a 100644 --- a/unified-lib-deps.ini +++ b/unified-lib-deps.ini @@ -6,15 +6,15 @@ lib_deps = adafruit/Adafruit BME680 Library@2.0.2 adafruit/Adafruit SHT31 Library@2.2.2 adafruit/Adafruit SCD30@1.0.9 - adafruit/Adafruit BusIO@1.14.4 - robtillaart/AM232X@0.4.5 - paulvha/sps30@1.4.16 + adafruit/Adafruit BusIO@1.14.5 + robtillaart/AM232X@0.5.0 + paulvha/sps30@1.4.17 wifwaf/MH-Z19@1.5.4 jcomas/S8_UART@1.0.1 sensirion/Sensirion Core@0.6.0 sensirion/Sensirion I2C SCD4x@0.4.0 - phzi/DFRobot_MultiGasSensor@2.0.0 sensirion/Sensirion I2C SEN5X @ 0.3.0 + phzi/DFRobot_MultiGasSensor@2.0.0 https://github.com/enjoyneering/AHTxx.git#eb21571 https://github.com/hpsaturn/DHT_nonblocking.git#ec6e5b9 https://github.com/paulvha/SN-GCJA5.git#f261968 From a318c03c6d27bd6a80adce7d56cf9917259be96f Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Wed, 25 Oct 2023 23:55:49 +0200 Subject: [PATCH 14/21] rev382 added possible workaround to SEN5x address conflict --- doxygen.conf | 2 +- src/Sensors.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doxygen.conf b/doxygen.conf index 402b4f21..bdaf4350 100644 --- a/doxygen.conf +++ b/doxygen.conf @@ -38,7 +38,7 @@ PROJECT_NAME = "CanAirIO Sensors Library" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 0.7.1 +PROJECT_NUMBER = 0.7.3 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 4e3f3f53..155ff33d 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -65,11 +65,12 @@ bool Sensors::readAllSensors() { DEBUG("-->[SLIB] UART data ready \t:", dataReady ? "true" : "false"); } enableWire1(); + + sen5xRead(); CO2scd30Read(); GCJA5Read(); sps30Read(); CO2scd4xRead(); - sen5xRead(); am2320Read(); sht31Read(); bme280Read(); @@ -1065,6 +1066,7 @@ void Sensors::CO2scd4xRead() { void Sensors::sen5xRead() { + if (!isSensorRegistered(SENSORS::SSEN5X)) return; float massConcentrationPm1p0; float massConcentrationPm2p5; float massConcentrationPm4p0; From ffde6e1044f79060522a49268c4740c4cfafeeb4 Mon Sep 17 00:00:00 2001 From: roberbike Date: Sat, 4 Nov 2023 20:13:01 +0100 Subject: [PATCH 15/21] temporal fix for detection sen5x sensor --- examples/DfRobot_Multigas/i2c_change/main.cpp | 2 +- src/Sensors.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/DfRobot_Multigas/i2c_change/main.cpp b/examples/DfRobot_Multigas/i2c_change/main.cpp index 26ab2555..117a114b 100644 --- a/examples/DfRobot_Multigas/i2c_change/main.cpp +++ b/examples/DfRobot_Multigas/i2c_change/main.cpp @@ -37,7 +37,7 @@ //#define I2C_ADDRESS 0x77 DFRobot_GAS_I2C nh3(&Wire,0x7A); DFRobot_GAS_I2C co(&Wire,0x78); - DFRobot_GAS_I2C no(&Wire,0x7B); + DFRobot_GAS_I2C no2(&Wire,0x7B); void setup() { //Serial port init for viewing printing output diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 1e3d7c3d..1c66f83b 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -125,7 +125,10 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { sps30I2CInit(); GCJA5Init(); CO2scd4xInit(); + if (!sps30I2CInit()) { sen5xInit(); + } + bmp280Init(); bme280Init(); bme680Init(); From 27abd6446b7c1d6a53608389bd6bc5f6d776d050 Mon Sep 17 00:00:00 2001 From: roberbike Date: Sat, 4 Nov 2023 21:02:14 +0100 Subject: [PATCH 16/21] fix sen5x reboot --- src/Sensors.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 1c66f83b..c1e684d8 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -69,6 +69,9 @@ bool Sensors::readAllSensors() { GCJA5Read(); sps30Read(); CO2scd4xRead(); + if (!sps30Read()) { + sen5xRead(); + } sen5xRead(); am2320Read(); sht31Read(); @@ -128,7 +131,6 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { if (!sps30I2CInit()) { sen5xInit(); } - bmp280Init(); bme280Init(); bme680Init(); From 6a0ab8ed991baad9ea94627305e79ed1c4b28a1d Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sun, 19 Nov 2023 13:49:50 +0100 Subject: [PATCH 17/21] updated Adafruit and Sensirion libraries --- unified-lib-deps.ini | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/unified-lib-deps.ini b/unified-lib-deps.ini index 6fd4d49a..c649e8ae 100644 --- a/unified-lib-deps.ini +++ b/unified-lib-deps.ini @@ -1,11 +1,11 @@ [commonlibs] lib_deps = - adafruit/Adafruit Unified Sensor@1.1.13 - adafruit/Adafruit BME280 Library@2.2.2 + adafruit/Adafruit Unified Sensor@1.1.14 + adafruit/Adafruit BME280 Library@2.2.4 adafruit/Adafruit BMP280 Library@2.6.8 - adafruit/Adafruit BME680 Library@2.0.2 + adafruit/Adafruit BME680 Library@2.0.4 adafruit/Adafruit SHT31 Library@2.2.2 - adafruit/Adafruit SCD30@1.0.9 + adafruit/Adafruit SCD30@1.0.11 adafruit/Adafruit BusIO@1.14.5 robtillaart/AM232X@0.5.0 paulvha/sps30@1.4.17 From bd5e28bb1754fd825bddf9c3c513121fb763e54f Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sun, 19 Nov 2023 13:56:29 +0100 Subject: [PATCH 18/21] alternative method enable external hardware like a CanAirIO Bike setup --- examples/advanced_multivariable/src/main.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/advanced_multivariable/src/main.cpp b/examples/advanced_multivariable/src/main.cpp index 27ad8bd8..d3b37046 100644 --- a/examples/advanced_multivariable/src/main.cpp +++ b/examples/advanced_multivariable/src/main.cpp @@ -18,6 +18,8 @@ #include #include +#define MAIN_HW_EN_PIN 27 // Only for setup with booster board with enable pin + void printSensorsDetected() { uint16_t sensors_count = sensors.getSensorsRegisteredCount(); uint16_t units_count = sensors.getUnitsRegisteredCount(); @@ -56,9 +58,18 @@ void onSensorDataError(const char * msg){ * M A I N ******************************************************************************/ +void powerEnableSensors() { + // init all sensors (step-up to 5V with enable pin) + Serial.println("-->[POWR] == enable sensors =="); + pinMode(MAIN_HW_EN_PIN, OUTPUT); + digitalWrite(MAIN_HW_EN_PIN, HIGH); // step-up on +} + void setup() { Serial.begin(115200); delay(200); + // powerEnableSensors(); // Only for special setup hardware with enable + delay(100); Serial.println("\n== Sensor test setup ==\n"); Serial.println("-->[SETUP] Detecting sensors.."); @@ -73,4 +84,4 @@ void setup() { void loop() { sensors.loop(); // read sensor data and showed it -} \ No newline at end of file +} From 2ed621d60567a3ff06418031205cc51ebf5b9df9 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sun, 19 Nov 2023 13:57:17 +0100 Subject: [PATCH 19/21] fixed issue on BME280 init (issue #184) --- src/Sensors.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 8a8a5b26..d1e4293b 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -1561,13 +1561,16 @@ void Sensors::sht31Init() { } void Sensors::bme280Init() { - sensorAnnounce(SENSORS::SBME280); - #ifndef Wire1 - if (!bme280.begin()) return; - #else - if (!bme280.begin() && !bme280.begin(BME280_ADDRESS,&Wire1)) return; - #endif - sensorRegister(SENSORS::SBME280); + sensorAnnounce(SENSORS::SBME280); + #ifndef Wire1 + if (!bme280.begin() && !bme280.begin(BME280_ADDRESS_ALTERNATE)) return; + #else + if (!bme280.begin() && + !bme280.begin(BME280_ADDRESS_ALTERNATE) && + !bme280.begin(BME280_ADDRESS, &Wire1) && + !bme280.begin(BME280_ADDRESS_ALTERNATE, &Wire1)) return; + #endif + sensorRegister(SENSORS::SBME280); } /// Environment BMP280 sensor init From a4afbbb3f8568b24d4781723d44125f7710bd844 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sun, 19 Nov 2023 22:47:49 +0100 Subject: [PATCH 20/21] added example for custom UART pins --- examples/advanced_multivariable/src/main.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/advanced_multivariable/src/main.cpp b/examples/advanced_multivariable/src/main.cpp index d3b37046..ceaa8241 100644 --- a/examples/advanced_multivariable/src/main.cpp +++ b/examples/advanced_multivariable/src/main.cpp @@ -1,7 +1,7 @@ /** * @file main.cpp * @author Antonio Vanegas @hpsaturn - * @date June 2018 - 2022 + * @date June 2018 - 2023 * @brief CanAirIO Sensorslib tests * @license GPL3 * @@ -67,7 +67,7 @@ void powerEnableSensors() { void setup() { Serial.begin(115200); - delay(200); + delay(500); // Only for debugging // powerEnableSensors(); // Only for special setup hardware with enable delay(100); Serial.println("\n== Sensor test setup ==\n"); @@ -75,10 +75,11 @@ void setup() { sensors.setSampleTime(10); // config sensors sample time interval sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback - sensors.setDebugMode(true); // [optional] debug mode - sensors.detectI2COnly(true); // force to only i2c sensors + sensors.setDebugMode(false); // [optional] debug mode + sensors.detectI2COnly(false); // not force to only i2c sensors sensors.setTemperatureUnit(TEMPUNIT::KELVIN); // comment for Celsius or set Fahrenheit - sensors.init(); // Auto detection to UART and i2c sensors + // sensors.init(SENSORS::Auto, 13, 12); // Auto detection (Custom UART sensor pins example) + sensors.init(); // Auto detection (UART and i2c sensors) delay(1000); } From d5a42e614b531a7e593fcf09f927780c275f0748 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sun, 19 Nov 2023 22:48:17 +0100 Subject: [PATCH 21/21] fixed issue whit GENERIC UART sensores detected --- src/Sensors.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index d1e4293b..97fbef30 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -680,11 +680,14 @@ void Sensors::printUnitsRegistered(bool debug) { */ void Sensors::printSensorsRegistered(bool debug) { if (!debug) return; - Serial.printf("-->[SLIB] sensors count \t: %i (", sensors_registered_count); int i = 0; + Serial.printf("-->[SLIB] sensors count \t: %i (", sensors_registered_count); + if (sensors_registered_count > 0 && sensors_registered[0] == SENSORS::Auto) { + Serial.printf("%s,", sensors_device_names[sensors_registered[0]]); + i = 1; + } while (sensors_registered[i++] != 0) { - Serial.print(sensors_device_names[sensors_registered[i-1]]); - Serial.print(","); + Serial.printf("%s,", sensors_device_names[sensors_registered[i-1]]); } Serial.println(")"); } @@ -1210,7 +1213,7 @@ void Sensors::sps30Errorloop(char *mess, uint8_t r) { **/ bool Sensors::sensorSerialInit(u_int pms_type, int pms_rx, int pms_tx) { // set UART for autodetection sensors (Honeywell, Plantower) - if (pms_type == Auto) { + if (pms_type == SENSORS::Auto) { DEBUG("-->[SLIB] UART detecting type\t: Auto"); if (!serialInit(pms_type, 9600, pms_rx, pms_tx)) return false; } @@ -1819,7 +1822,9 @@ void Sensors::sensorAnnounce(SENSORS sensor) { * dynamic calls of the sensors and its units on the GUI or implementation. */ void Sensors::sensorRegister(SENSORS sensor) { - if (isSensorRegistered(sensor)) return; + if (isSensorRegistered(sensor) && sensor != SENSORS::Auto) { + return; + } Serial.printf("-->[SLIB] sensor registered\t: %s \t:D\r\n", getSensorName(sensor).c_str()); sensors_registered[sensors_registered_count++] = sensor; }