From 04c58675ac8833ecd2626bbb9d539ab5184cbae4 Mon Sep 17 00:00:00 2001 From: Roberbike Date: Thu, 25 May 2023 23:11:52 +0200 Subject: [PATCH 01/32] Primera aproximacion --- examples/gravity/readGasConcentration.cpp | 95 +++++++ platformio.ini | 1 + src/Sensors.cpp | 52 +++- src/Sensors.hpp | 29 +- src/drivers/DFRobot_MultiGasSensor.cpp | 95 +++++++ src/drivers/DFRobot_MultiGasSensor.h | 326 ++++++++++++++++++++++ 6 files changed, 589 insertions(+), 9 deletions(-) create mode 100644 examples/gravity/readGasConcentration.cpp create mode 100644 src/drivers/DFRobot_MultiGasSensor.cpp create mode 100644 src/drivers/DFRobot_MultiGasSensor.h diff --git a/examples/gravity/readGasConcentration.cpp b/examples/gravity/readGasConcentration.cpp new file mode 100644 index 00000000..e0e42570 --- /dev/null +++ b/examples/gravity/readGasConcentration.cpp @@ -0,0 +1,95 @@ +/*! + * @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" + +//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 gas(&Wire ,I2C_ADDRESS); +#else +#if (!defined ARDUINO_ESP32_DEV) && (!defined __SAMD21G18A__) +/** + UNO:pin_2-----RX + pin_3-----TX +*/ + SoftwareSerial mySerial(2,3); + DFRobot_GAS_SoftWareUart gas(&mySerial); +#else +/** + ESP32:IO16-----RX + IO17-----TX +*/ + DFRobot_GAS_HardWareUart gas(&Serial2); //ESP32HardwareSerial +#endif +#endif + +void setup() { + //Serial port init for viewing printing output + Serial.begin(115200); + + //Sensor init, used to init serial port or I2C, depending on the communication mode currently used + while(!gas.begin()) + { + Serial.println("NO Deivces !"); + delay(1000); + } + Serial.println("The device is connected successfully!"); + + //Mode of obtaining data: the main controller needs to request the sensor for data + gas.changeAcquireMode(gas.PASSIVITY); + delay(1000); + + /** + *Turn on temperature compensation: gas.ON : turn on + * gas.OFF:turn off + */ + gas.setTempCompensation(gas.ON); +} + +void loop() { + String gastype = gas.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(gastype); + Serial.print(" concentration is: "); + Serial.print(gas.readGasConcentrationPPM()); + if (gastype == "O2") + Serial.println(" %vol"); + else + Serial.println(" PPM"); + Serial.println(); + delay(1000); +} \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index df4044c2..83cd886d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -32,6 +32,7 @@ lib_deps = https://github.com/paulvha/SN-GCJA5.git https://github.com/jcomas/S8_UART.git https://github.com/jcomas/CM1106_UART.git + https://github.com/DFRobot/DFRobot_MultiGasSensor.git [common] framework = ${env.framework} diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 622e6c4e..d8d877af 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -71,6 +71,7 @@ bool Sensors::readAllSensors() { bmp280Read(); bme680Read(); dhtRead(); + DFRobotGravityRead(); disableWire1(); printValues(); @@ -117,6 +118,7 @@ void Sensors::init(int pms_type, int pms_rx, int pms_tx) { sht31Init(); aht10Init(); dhtInit(); + DFRobotgravityInit(); printSensorsRegistered(true); } @@ -557,8 +559,12 @@ float Sensors::getUnitValue(UNIT unit) { return pres; case ALT: return alt; - case GAS: - return gas; + // case GAS: + // return gas; + case DFRobot_GAS::NH3: + return NH3; + case DFRobot_GAS::CO: + return CO; default: return 0.0; } @@ -994,6 +1000,24 @@ void Sensors::GCJA5Read() { unitRegister(UNIT::PM10); } +void Sensors::DFRobotGravityRead() { + String gastype = gas.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(gastype); + Serial.print(" concentration is: "); + Serial.print(gas.readGasConcentrationPPM()); + if (gastype == "O2") + Serial.println(" %vol"); + else + Serial.println(" PPM"); + Serial.println(); +} + bool Sensors::dhtIsReady(float *temperature, float *humidity) { static unsigned long measurement_timestamp = millis(); if (millis() - measurement_timestamp > sample_time * (uint32_t)1000) { @@ -1558,6 +1582,28 @@ void Sensors::dhtInit() { dhtRead(); } +void Sensors::DFRobotgravityInit() { + sensorAnnounce(SENSORS::MULTIGAS); + DFRobot_GAS_I2C gas(&Wire ,0x77); + while(!gas.begin()) + { + Serial.println("NO Deivces !"); + delay(1000); + } + Serial.println("The device is connected successfully!"); + + //Mode of obtaining data: the main controller needs to request the sensor for data + gas.changeAcquireMode(gas.PASSIVITY); + delay(1000); + + /** + *Turn on temperature compensation: gas.ON : turn on + * gas.OFF:turn off + */ + gas.setTempCompensation(gas.ON); + sensorRegister(SENSORS::MULTIGAS); +} + // Altitude compensation for CO2 sensors without Pressure atm or Altitude compensation void Sensors::CO2correctionAlt() { @@ -1602,6 +1648,8 @@ void Sensors::resetAllVariables() { alt = 0.0; gas = 0.0; pres = 0.0; + NH3 = 0.0; + CO = 0.0; } void Sensors::DEBUG(const char *text, const char *textb) { diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 04370e9e..ade825a8 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -17,9 +17,10 @@ #include #include #include +#include -#define CSL_VERSION "0.5.9" -#define CSL_REVISION 366 +#define CSL_VERSION "0.5.9.1" +#define CSL_REVISION 366.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 @@ -98,9 +99,12 @@ X(CO2HUM, "%", "CO2H") \ X(PRESS, "hPa", "P") \ X(ALT, "m", "Alt") \ - X(GAS, "Ohm", "Gas") \ + X(NH3, "ppm", "NH3") \ + X(CO, "ppm", "CO") \ X(UCOUNT, "COUNT", "UCOUNT") + // X(GAS, "Ohm", "Gas") \ // COlisiona con DFRobot Multigas + #define X(unit, symbol, name) unit, typedef enum UNIT : size_t { SENSOR_UNITS } UNIT; #undef X @@ -123,6 +127,7 @@ typedef enum UNIT : size_t { SENSOR_UNITS } UNIT; X(SAHT10, "AHT10", 3) \ X(SAM232X, "AM232X", 3) \ X(SDHTX, "DHTX", 3) \ + X(SMULTIGAS, "MULTIGAS", 2) \ X(SCOUNT, "SCOUNT", 3) #define X(utype, uname, umaintype) utype, @@ -204,9 +209,12 @@ class Sensors { // SCD4x sensor SensirionI2CScd4x scd4x; - // IKA Vindriktn sensor + // IKEA Vindriktn sensor PM1006 *pm1006; + // DFRobot gravity Gas sensor + DFRobot_GAS_I2C gas; + void init(int pms_type = 0, int pms_rx = PMS_RX, int pms_tx = PMS_TX); void loop(); @@ -251,13 +259,14 @@ class Sensors { float getAltitude(); - float getGas(); + // float getGas(); // Posible colision con DFRobot Multigas void setTempOffset(float offset); void setCO2AltitudeOffset(float altitude); void setSeaLevelPressure(float hpa); + String getFormatTemp(); @@ -265,7 +274,7 @@ class Sensors { String getFormatHum(); - String getFormatGas(); + // String getFormatGas(); // Posible colision con DFRobot Multigas String getFormatAlt(); @@ -354,12 +363,15 @@ class Sensors { float temp = 0.0; // Temperature (°C) float pres = 0.0; // Pressure float alt = 0.0; - float gas = 0.0; + // float gas = 0.0; // Colisiona con DFRobot Multigas uint16_t CO2Val; // CO2 in ppm float CO2humi = 0.0; // humidity of CO2 sensor float CO2temp = 0.0; // temperature of CO2 sensor + uint16_t NH3; // Amonium in ppm + uint16_t CO; // Carbon monoxide + void am2320Init(); void am2320Read(); @@ -397,6 +409,9 @@ class Sensors { void dhtRead(); bool dhtIsReady(float *temperature, float *humidity); + void DFRobotgravityInit(); + void DFRobotGravityRead(); + // UART sensors methods: bool sensorSerialInit(int pms_type, int rx, int tx); diff --git a/src/drivers/DFRobot_MultiGasSensor.cpp b/src/drivers/DFRobot_MultiGasSensor.cpp new file mode 100644 index 00000000..e0e42570 --- /dev/null +++ b/src/drivers/DFRobot_MultiGasSensor.cpp @@ -0,0 +1,95 @@ +/*! + * @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" + +//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 gas(&Wire ,I2C_ADDRESS); +#else +#if (!defined ARDUINO_ESP32_DEV) && (!defined __SAMD21G18A__) +/** + UNO:pin_2-----RX + pin_3-----TX +*/ + SoftwareSerial mySerial(2,3); + DFRobot_GAS_SoftWareUart gas(&mySerial); +#else +/** + ESP32:IO16-----RX + IO17-----TX +*/ + DFRobot_GAS_HardWareUart gas(&Serial2); //ESP32HardwareSerial +#endif +#endif + +void setup() { + //Serial port init for viewing printing output + Serial.begin(115200); + + //Sensor init, used to init serial port or I2C, depending on the communication mode currently used + while(!gas.begin()) + { + Serial.println("NO Deivces !"); + delay(1000); + } + Serial.println("The device is connected successfully!"); + + //Mode of obtaining data: the main controller needs to request the sensor for data + gas.changeAcquireMode(gas.PASSIVITY); + delay(1000); + + /** + *Turn on temperature compensation: gas.ON : turn on + * gas.OFF:turn off + */ + gas.setTempCompensation(gas.ON); +} + +void loop() { + String gastype = gas.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(gastype); + Serial.print(" concentration is: "); + Serial.print(gas.readGasConcentrationPPM()); + if (gastype == "O2") + Serial.println(" %vol"); + else + Serial.println(" PPM"); + Serial.println(); + delay(1000); +} \ No newline at end of file diff --git a/src/drivers/DFRobot_MultiGasSensor.h b/src/drivers/DFRobot_MultiGasSensor.h new file mode 100644 index 00000000..8c64447f --- /dev/null +++ b/src/drivers/DFRobot_MultiGasSensor.h @@ -0,0 +1,326 @@ +/*! + * @file DFRobot_MultiGasSensor.h + * @brief This is a header file of the library for the sensor that can detect gas concentration in the air. + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + * @license The MIT License (MIT) + * @author PengKaixing(kaixing.peng@dfrobot.com) + * @version V2.0.0 + * @date 2021-09-26 + * @url https://github.com/DFRobot/DFRobot_MultiGasSensor +*/ +#ifndef __DFRobot_GAS_H__ +#define __DFRobot_GAS_H__ + +#include "Arduino.h" +#include + +#if (!defined ARDUINO_ESP32_DEV) && (!defined __SAMD21G18A__) +#include "SoftwareSerial.h" +#else +#include "HardwareSerial.h" +#endif + +#define CMD_CHANGE_GET_METHOD 0X78 +#define CMD_GET_GAS_CONCENTRATION 0X86 +#define CMD_GET_TEMP 0X87 +#define CMD_GET_ALL_DTTA 0X88 +#define CMD_SET_THRESHOLD_ALARMS 0X89 +#define CMD_IIC_AVAILABLE 0X90 +#define CMD_SENSOR_VOLTAGE 0X91 +#define CMD_CHANGE_IIC_ADDR 0X92 + +// Open this macro to see the program running in detail +#define ENABLE_DBG + +#ifdef ENABLE_DBG +#define DBG(...) {Serial.print("[");Serial.print(__FUNCTION__); Serial.print("(): "); Serial.print(__LINE__); Serial.print(" ] 0x"); Serial.println(__VA_ARGS__,HEX);} +#else +#define DBG(...) +#endif + +/** + * @struct sProtocol_t + * @brief Data protocol package for communication + */ +typedef struct +{ + uint8_t head; + uint8_t addr; + uint8_t data[6]; + uint8_t check; +} sProtocol_t; + +/** + * @struct sAllData_t + * @brief The struct used when getting all the data + * @note + * @n ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + * @n | byte0 | byte1 | byte2 | byte3 | byte4 | byte5 | byte6 | byte7 | byte8 + * @n ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + * @n | Protocol Head | Command | Gas Concentrate High 8-bit | Gas Concentration Low 8-bit | Gas Type | Decimal Digits | Temperature High 8-bit | Temperature Low 8-bit | CRC + * @n ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + */ +typedef struct +{ + uint8_t head; + uint8_t cmd; + uint8_t gasconcentration_h; + uint8_t gasconcentration_l; + uint8_t gastype; + uint8_t gasconcentration_decimals; + uint8_t temp_h; + uint8_t temp_l; + uint8_t check; +} sAllData_t; +extern sAllData_t AllData; + +/** + * @struct sAllDataAnalysis_t + * @brief All the parsed data + */ +typedef struct +{ + float gasconcentration; + String gastype; + float temp; +} sAllDataAnalysis_t; +extern sAllDataAnalysis_t AllDataAnalysis; + +class DFRobot_GAS +{ +public: + /** + * @enum eMethod_t + * @brief Type of the data the sensor uploads + */ + typedef enum + { + INITIATIVE = 0x03, + PASSIVITY = 0x04 + } eMethod_t; + + /** + * @enum eType_t + * @brief Gas Type + */ + typedef enum + { + O2 = 0x05, + CO = 0x04, + H2S = 0x03, + NO2 = 0x2C, + O3 = 0x2A, + CL2 = 0x31, + NH3 = 0x02, + H2 = 0x06, + HCL = 0X2E, + SO2 = 0X2B, + HF = 0x33, + _PH3 = 0x45 + } eType_t; + + /** + * @enum eSwitch_t + * @brief Whether to enable ALA alarm function + */ + typedef enum + { + ON = 0x01, + OFF = 0x00 + } eSwitch_t; + + /** + * @enum eSwitch_t + * @brief High and low ALA alarm function + */ + typedef enum + { + LOW_THRESHOLD_ALA = 0x00, + HIGH_THRESHOLD_ALA = 0x01 + } eALA_t; + + DFRobot_GAS(void){}; + ~DFRobot_GAS(void){}; + + /** + * @fn begin + * @brief Parent class init, I2C or UART init is performed in subclass function + * @return bool type, indicating whether init succeed + * @retval True succeed + * @retval False failed + */ + virtual bool begin(void) = 0; + + /** + * @fn changeAcquireMode + * @brief Change the mode of acquiring sensor data + * @param mode Mode select + * @n INITIATIVE The sensor proactively reports data + * @n PASSIVITY The main controller needs to request data from sensor + * @return bool type, indicating whether the setting is successful + * @retval True succeed + * @retval False failed + */ + bool changeAcquireMode(eMethod_t mode); + + /** + * @fn readGasConcentrationPPM + * @brief Get gas concentration from sensor, unit PPM + * @return float type, indicating return gas concentration, if data is transmitted normally, return gas concentration, otherwise, return 0.0 + */ + float readGasConcentrationPPM(void); + + /** + * @fn queryGasType + * @brief Query gas type + * @return String type, indicating return gas type string + */ + String queryGasType(void); + + /** + * @fn setThresholdAlarm + * @brief Set sensor alarm threshold + * @param switchof Whether to turn on threshold alarm switch + * @n ON turn on + * @n OFF turn off + * @param threshold The threshold for starting alarm + * @param alamethod Set sensor high or low threshold alarm + * @param gasType Gas Type + * @return bool type, indicating whether the setting is successful + * @retval True succeed + * @retval False failed + */ + bool setThresholdAlarm(eSwitch_t switchof, uint16_t threshold, eALA_t alamethod, String gasType); + + /** + * @fn readTempC + * @brief Get sensor onboard temperature + * @return float type, indicating return the current onboard temperature + */ + float readTempC(void); + + /** + * @fn setTempCompensation + * @brief Set whether to turn on temperature compensation, values output by sensor under different temperatures are various. + * @n To get more accurate gas concentration, temperature compensation is necessary when calculating gas concentration. + * @param tempswitch Whether to turn on temperature compensation + * @n ON Turn on temperature compensation + * @n OFF Turn off temperature compensation + */ + void setTempCompensation(eSwitch_t tempswitch); + + /** + * @fn readVolatageData + * @brief Get sensor gas concentration output by original voltage, which is different from reading sensor register directly. + * @n The function is mainly for detecting whether the read gas concentration is right. + * @param vopin Pin for receiving the original voltage output from sensor probe + * @return Float type, indicating return the original voltage output of sensor gas concentration + */ + float readVolatageData(uint8_t vopin); + + /** + * @fn pack + * @brief Pack the protocol data for easy transmission + * @param pBuf Data to be packed + * @param len Length of data package + * @return sProtocol_t type, indicating return the packed data + */ + sProtocol_t pack(uint8_t *pBuf, uint8_t len); + + /** + * @fn getSensorVoltage + * @brief Get voltage output by sensor probe (for calculating the current gas concentration) + * @return float type, indicating return voltage value + */ + float getSensorVoltage(void); + + /** + * @fn dataIsAvailable + * @brief Call this function in active mode to determine the presence of data on data line + * @return bool type, indicating whether there is data coming from the sensor + * @retval True Has uploaded data + * @retval False No data uploaded + */ + virtual bool dataIsAvailable(void) = 0; + + /** + * @fn changeI2cAddrGroup + * @brief Change I2C address group + * @param group Address group select + * @return int type, indicating return init status + * @retval bool type + * @retval True Change succeed + * @retval False Change failed + */ + bool changeI2cAddrGroup(uint8_t group); + +protected: + /** + * @fn writeData + * @brief Write data to the specified register of the sensor + * @param Reg Register address to be written + * @param Data Data to be written to register + * @param len Length of data to be written + */ + virtual void writeData(uint8_t Reg, void *Data, uint8_t len) = 0; + + /** + * @fn readData + * @brief Get the data with specified length from the specified sensor + * @param Reg Register address to be read + * @param Data Position of the data stored in the register to be read + * @param len Length of the data to be written + */ + virtual int16_t readData(uint8_t Reg, uint8_t *Data, uint8_t len) = 0; + +private: + bool _tempswitch; +}; + +class DFRobot_GAS_I2C : public DFRobot_GAS +{ + public: + DFRobot_GAS_I2C(TwoWire *pWire=&Wire,uint8_t addr=0x74); + ~DFRobot_GAS_I2C(void){}; + bool begin(void); + void setI2cAddr(uint8_t addr); + bool dataIsAvailable(void); + protected: + void writeData(uint8_t Reg ,void *Data ,uint8_t len); + int16_t readData(uint8_t Reg ,uint8_t *Data ,uint8_t len); + private: + TwoWire* _pWire; + uint8_t _I2C_addr; +}; + +#if (!defined ARDUINO_ESP32_DEV) && (!defined __SAMD21G18A__) +class DFRobot_GAS_SoftWareUart : public DFRobot_GAS +{ + public: + DFRobot_GAS_SoftWareUart(SoftwareSerial *psoftUart); + ~DFRobot_GAS_SoftWareUart(void){}; + bool begin(void); + bool dataIsAvailable(void); + protected: + void writeData(uint8_t Reg ,void *Data ,uint8_t len); + int16_t readData(uint8_t Reg ,uint8_t *Data ,uint8_t len); + private: + SoftwareSerial *_psoftUart; +}; +#else +class DFRobot_GAS_HardWareUart : public DFRobot_GAS +{ + public: + DFRobot_GAS_HardWareUart(HardwareSerial *phardUart); + ~DFRobot_GAS_HardWareUart(void){}; + bool begin(void); + protected: + bool dataIsAvailable(void); + void writeData(uint8_t Reg, void *Data, uint8_t len); + int16_t readData(uint8_t Reg, uint8_t *Data, uint8_t len); + private: + HardwareSerial *_pharduart; +}; + +#endif +#endif \ No newline at end of file From cd17b6d1f55c2f16ee8032820db1602810094bfc Mon Sep 17 00:00:00 2001 From: roberbike Date: Sat, 27 May 2023 12:35:09 +0200 Subject: [PATCH 02/32] Delete DFRobot_MultiGasSensor.cpp --- src/drivers/DFRobot_MultiGasSensor.cpp | 95 -------------------------- 1 file changed, 95 deletions(-) delete mode 100644 src/drivers/DFRobot_MultiGasSensor.cpp diff --git a/src/drivers/DFRobot_MultiGasSensor.cpp b/src/drivers/DFRobot_MultiGasSensor.cpp deleted file mode 100644 index e0e42570..00000000 --- a/src/drivers/DFRobot_MultiGasSensor.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/*! - * @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" - -//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 gas(&Wire ,I2C_ADDRESS); -#else -#if (!defined ARDUINO_ESP32_DEV) && (!defined __SAMD21G18A__) -/** - UNO:pin_2-----RX - pin_3-----TX -*/ - SoftwareSerial mySerial(2,3); - DFRobot_GAS_SoftWareUart gas(&mySerial); -#else -/** - ESP32:IO16-----RX - IO17-----TX -*/ - DFRobot_GAS_HardWareUart gas(&Serial2); //ESP32HardwareSerial -#endif -#endif - -void setup() { - //Serial port init for viewing printing output - Serial.begin(115200); - - //Sensor init, used to init serial port or I2C, depending on the communication mode currently used - while(!gas.begin()) - { - Serial.println("NO Deivces !"); - delay(1000); - } - Serial.println("The device is connected successfully!"); - - //Mode of obtaining data: the main controller needs to request the sensor for data - gas.changeAcquireMode(gas.PASSIVITY); - delay(1000); - - /** - *Turn on temperature compensation: gas.ON : turn on - * gas.OFF:turn off - */ - gas.setTempCompensation(gas.ON); -} - -void loop() { - String gastype = gas.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(gastype); - Serial.print(" concentration is: "); - Serial.print(gas.readGasConcentrationPPM()); - if (gastype == "O2") - Serial.println(" %vol"); - else - Serial.println(" PPM"); - Serial.println(); - delay(1000); -} \ No newline at end of file From 3aec6887b2848417567a390e4a59ff2885a8a3d6 Mon Sep 17 00:00:00 2001 From: roberbike Date: Sat, 27 May 2023 12:35:28 +0200 Subject: [PATCH 03/32] Delete DFRobot_MultiGasSensor.h --- src/drivers/DFRobot_MultiGasSensor.h | 326 --------------------------- 1 file changed, 326 deletions(-) delete mode 100644 src/drivers/DFRobot_MultiGasSensor.h diff --git a/src/drivers/DFRobot_MultiGasSensor.h b/src/drivers/DFRobot_MultiGasSensor.h deleted file mode 100644 index 8c64447f..00000000 --- a/src/drivers/DFRobot_MultiGasSensor.h +++ /dev/null @@ -1,326 +0,0 @@ -/*! - * @file DFRobot_MultiGasSensor.h - * @brief This is a header file of the library for the sensor that can detect gas concentration in the air. - * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) - * @license The MIT License (MIT) - * @author PengKaixing(kaixing.peng@dfrobot.com) - * @version V2.0.0 - * @date 2021-09-26 - * @url https://github.com/DFRobot/DFRobot_MultiGasSensor -*/ -#ifndef __DFRobot_GAS_H__ -#define __DFRobot_GAS_H__ - -#include "Arduino.h" -#include - -#if (!defined ARDUINO_ESP32_DEV) && (!defined __SAMD21G18A__) -#include "SoftwareSerial.h" -#else -#include "HardwareSerial.h" -#endif - -#define CMD_CHANGE_GET_METHOD 0X78 -#define CMD_GET_GAS_CONCENTRATION 0X86 -#define CMD_GET_TEMP 0X87 -#define CMD_GET_ALL_DTTA 0X88 -#define CMD_SET_THRESHOLD_ALARMS 0X89 -#define CMD_IIC_AVAILABLE 0X90 -#define CMD_SENSOR_VOLTAGE 0X91 -#define CMD_CHANGE_IIC_ADDR 0X92 - -// Open this macro to see the program running in detail -#define ENABLE_DBG - -#ifdef ENABLE_DBG -#define DBG(...) {Serial.print("[");Serial.print(__FUNCTION__); Serial.print("(): "); Serial.print(__LINE__); Serial.print(" ] 0x"); Serial.println(__VA_ARGS__,HEX);} -#else -#define DBG(...) -#endif - -/** - * @struct sProtocol_t - * @brief Data protocol package for communication - */ -typedef struct -{ - uint8_t head; - uint8_t addr; - uint8_t data[6]; - uint8_t check; -} sProtocol_t; - -/** - * @struct sAllData_t - * @brief The struct used when getting all the data - * @note - * @n ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * @n | byte0 | byte1 | byte2 | byte3 | byte4 | byte5 | byte6 | byte7 | byte8 - * @n ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - * @n | Protocol Head | Command | Gas Concentrate High 8-bit | Gas Concentration Low 8-bit | Gas Type | Decimal Digits | Temperature High 8-bit | Temperature Low 8-bit | CRC - * @n ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - */ -typedef struct -{ - uint8_t head; - uint8_t cmd; - uint8_t gasconcentration_h; - uint8_t gasconcentration_l; - uint8_t gastype; - uint8_t gasconcentration_decimals; - uint8_t temp_h; - uint8_t temp_l; - uint8_t check; -} sAllData_t; -extern sAllData_t AllData; - -/** - * @struct sAllDataAnalysis_t - * @brief All the parsed data - */ -typedef struct -{ - float gasconcentration; - String gastype; - float temp; -} sAllDataAnalysis_t; -extern sAllDataAnalysis_t AllDataAnalysis; - -class DFRobot_GAS -{ -public: - /** - * @enum eMethod_t - * @brief Type of the data the sensor uploads - */ - typedef enum - { - INITIATIVE = 0x03, - PASSIVITY = 0x04 - } eMethod_t; - - /** - * @enum eType_t - * @brief Gas Type - */ - typedef enum - { - O2 = 0x05, - CO = 0x04, - H2S = 0x03, - NO2 = 0x2C, - O3 = 0x2A, - CL2 = 0x31, - NH3 = 0x02, - H2 = 0x06, - HCL = 0X2E, - SO2 = 0X2B, - HF = 0x33, - _PH3 = 0x45 - } eType_t; - - /** - * @enum eSwitch_t - * @brief Whether to enable ALA alarm function - */ - typedef enum - { - ON = 0x01, - OFF = 0x00 - } eSwitch_t; - - /** - * @enum eSwitch_t - * @brief High and low ALA alarm function - */ - typedef enum - { - LOW_THRESHOLD_ALA = 0x00, - HIGH_THRESHOLD_ALA = 0x01 - } eALA_t; - - DFRobot_GAS(void){}; - ~DFRobot_GAS(void){}; - - /** - * @fn begin - * @brief Parent class init, I2C or UART init is performed in subclass function - * @return bool type, indicating whether init succeed - * @retval True succeed - * @retval False failed - */ - virtual bool begin(void) = 0; - - /** - * @fn changeAcquireMode - * @brief Change the mode of acquiring sensor data - * @param mode Mode select - * @n INITIATIVE The sensor proactively reports data - * @n PASSIVITY The main controller needs to request data from sensor - * @return bool type, indicating whether the setting is successful - * @retval True succeed - * @retval False failed - */ - bool changeAcquireMode(eMethod_t mode); - - /** - * @fn readGasConcentrationPPM - * @brief Get gas concentration from sensor, unit PPM - * @return float type, indicating return gas concentration, if data is transmitted normally, return gas concentration, otherwise, return 0.0 - */ - float readGasConcentrationPPM(void); - - /** - * @fn queryGasType - * @brief Query gas type - * @return String type, indicating return gas type string - */ - String queryGasType(void); - - /** - * @fn setThresholdAlarm - * @brief Set sensor alarm threshold - * @param switchof Whether to turn on threshold alarm switch - * @n ON turn on - * @n OFF turn off - * @param threshold The threshold for starting alarm - * @param alamethod Set sensor high or low threshold alarm - * @param gasType Gas Type - * @return bool type, indicating whether the setting is successful - * @retval True succeed - * @retval False failed - */ - bool setThresholdAlarm(eSwitch_t switchof, uint16_t threshold, eALA_t alamethod, String gasType); - - /** - * @fn readTempC - * @brief Get sensor onboard temperature - * @return float type, indicating return the current onboard temperature - */ - float readTempC(void); - - /** - * @fn setTempCompensation - * @brief Set whether to turn on temperature compensation, values output by sensor under different temperatures are various. - * @n To get more accurate gas concentration, temperature compensation is necessary when calculating gas concentration. - * @param tempswitch Whether to turn on temperature compensation - * @n ON Turn on temperature compensation - * @n OFF Turn off temperature compensation - */ - void setTempCompensation(eSwitch_t tempswitch); - - /** - * @fn readVolatageData - * @brief Get sensor gas concentration output by original voltage, which is different from reading sensor register directly. - * @n The function is mainly for detecting whether the read gas concentration is right. - * @param vopin Pin for receiving the original voltage output from sensor probe - * @return Float type, indicating return the original voltage output of sensor gas concentration - */ - float readVolatageData(uint8_t vopin); - - /** - * @fn pack - * @brief Pack the protocol data for easy transmission - * @param pBuf Data to be packed - * @param len Length of data package - * @return sProtocol_t type, indicating return the packed data - */ - sProtocol_t pack(uint8_t *pBuf, uint8_t len); - - /** - * @fn getSensorVoltage - * @brief Get voltage output by sensor probe (for calculating the current gas concentration) - * @return float type, indicating return voltage value - */ - float getSensorVoltage(void); - - /** - * @fn dataIsAvailable - * @brief Call this function in active mode to determine the presence of data on data line - * @return bool type, indicating whether there is data coming from the sensor - * @retval True Has uploaded data - * @retval False No data uploaded - */ - virtual bool dataIsAvailable(void) = 0; - - /** - * @fn changeI2cAddrGroup - * @brief Change I2C address group - * @param group Address group select - * @return int type, indicating return init status - * @retval bool type - * @retval True Change succeed - * @retval False Change failed - */ - bool changeI2cAddrGroup(uint8_t group); - -protected: - /** - * @fn writeData - * @brief Write data to the specified register of the sensor - * @param Reg Register address to be written - * @param Data Data to be written to register - * @param len Length of data to be written - */ - virtual void writeData(uint8_t Reg, void *Data, uint8_t len) = 0; - - /** - * @fn readData - * @brief Get the data with specified length from the specified sensor - * @param Reg Register address to be read - * @param Data Position of the data stored in the register to be read - * @param len Length of the data to be written - */ - virtual int16_t readData(uint8_t Reg, uint8_t *Data, uint8_t len) = 0; - -private: - bool _tempswitch; -}; - -class DFRobot_GAS_I2C : public DFRobot_GAS -{ - public: - DFRobot_GAS_I2C(TwoWire *pWire=&Wire,uint8_t addr=0x74); - ~DFRobot_GAS_I2C(void){}; - bool begin(void); - void setI2cAddr(uint8_t addr); - bool dataIsAvailable(void); - protected: - void writeData(uint8_t Reg ,void *Data ,uint8_t len); - int16_t readData(uint8_t Reg ,uint8_t *Data ,uint8_t len); - private: - TwoWire* _pWire; - uint8_t _I2C_addr; -}; - -#if (!defined ARDUINO_ESP32_DEV) && (!defined __SAMD21G18A__) -class DFRobot_GAS_SoftWareUart : public DFRobot_GAS -{ - public: - DFRobot_GAS_SoftWareUart(SoftwareSerial *psoftUart); - ~DFRobot_GAS_SoftWareUart(void){}; - bool begin(void); - bool dataIsAvailable(void); - protected: - void writeData(uint8_t Reg ,void *Data ,uint8_t len); - int16_t readData(uint8_t Reg ,uint8_t *Data ,uint8_t len); - private: - SoftwareSerial *_psoftUart; -}; -#else -class DFRobot_GAS_HardWareUart : public DFRobot_GAS -{ - public: - DFRobot_GAS_HardWareUart(HardwareSerial *phardUart); - ~DFRobot_GAS_HardWareUart(void){}; - bool begin(void); - protected: - bool dataIsAvailable(void); - void writeData(uint8_t Reg, void *Data, uint8_t len); - int16_t readData(uint8_t Reg, uint8_t *Data, uint8_t len); - private: - HardwareSerial *_pharduart; -}; - -#endif -#endif \ No newline at end of file From 8a975c9757531274e28b04a59af915f73c3e577d Mon Sep 17 00:00:00 2001 From: roberbike Date: Sat, 27 May 2023 12:35:50 +0200 Subject: [PATCH 04/32] Delete readGasConcentration.cpp --- examples/gravity/readGasConcentration.cpp | 95 ----------------------- 1 file changed, 95 deletions(-) delete mode 100644 examples/gravity/readGasConcentration.cpp diff --git a/examples/gravity/readGasConcentration.cpp b/examples/gravity/readGasConcentration.cpp deleted file mode 100644 index e0e42570..00000000 --- a/examples/gravity/readGasConcentration.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/*! - * @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" - -//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 gas(&Wire ,I2C_ADDRESS); -#else -#if (!defined ARDUINO_ESP32_DEV) && (!defined __SAMD21G18A__) -/** - UNO:pin_2-----RX - pin_3-----TX -*/ - SoftwareSerial mySerial(2,3); - DFRobot_GAS_SoftWareUart gas(&mySerial); -#else -/** - ESP32:IO16-----RX - IO17-----TX -*/ - DFRobot_GAS_HardWareUart gas(&Serial2); //ESP32HardwareSerial -#endif -#endif - -void setup() { - //Serial port init for viewing printing output - Serial.begin(115200); - - //Sensor init, used to init serial port or I2C, depending on the communication mode currently used - while(!gas.begin()) - { - Serial.println("NO Deivces !"); - delay(1000); - } - Serial.println("The device is connected successfully!"); - - //Mode of obtaining data: the main controller needs to request the sensor for data - gas.changeAcquireMode(gas.PASSIVITY); - delay(1000); - - /** - *Turn on temperature compensation: gas.ON : turn on - * gas.OFF:turn off - */ - gas.setTempCompensation(gas.ON); -} - -void loop() { - String gastype = gas.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(gastype); - Serial.print(" concentration is: "); - Serial.print(gas.readGasConcentrationPPM()); - if (gastype == "O2") - Serial.println(" %vol"); - else - Serial.println(" PPM"); - Serial.println(); - delay(1000); -} \ No newline at end of file From fcb4937f9c1b5368c06b8a293b48253823dfe5a7 Mon Sep 17 00:00:00 2001 From: roberbike Date: Sat, 27 May 2023 12:42:23 +0200 Subject: [PATCH 05/32] Update Sensors.hpp Add floats --- src/Sensors.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Sensors.hpp b/src/Sensors.hpp index ade825a8..0b67a60c 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -260,6 +260,10 @@ class Sensors { float getAltitude(); // float getGas(); // Posible colision con DFRobot Multigas + + float getNH3(); + + float getCO(); void setTempOffset(float offset); @@ -364,14 +368,16 @@ class Sensors { float pres = 0.0; // Pressure float alt = 0.0; // float gas = 0.0; // Colisiona con DFRobot Multigas - + uint16_t CO2Val; // CO2 in ppm float CO2humi = 0.0; // humidity of CO2 sensor float CO2temp = 0.0; // temperature of CO2 sensor uint16_t NH3; // Amonium in ppm uint16_t CO; // Carbon monoxide - + float NH3 = 0.0; + float CO = 0.0; + void am2320Init(); void am2320Read(); From bf55f10c78d24811978e0ab302b95db9d21273e3 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Mon, 29 May 2023 23:19:41 +0200 Subject: [PATCH 06/32] fixed build and some implementation issues. Unfinished --- platformio.ini | 1 + src/Sensors.cpp | 24 ++++++++++++------------ src/Sensors.hpp | 17 ++++++++--------- unified-lib-deps.ini | 1 + 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/platformio.ini b/platformio.ini index 3a3c775e..5b112df5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -70,6 +70,7 @@ build_src_filter = -<*> + build_flags = ${env.build_flags} -DBOARD_HAS_PSRAM + -DARDUINO_ESP32_DEV=1 ;-DARDUINO_USB_MODE=1 ;-DARDUINO_USB_CDC_ON_BOOT=1 diff --git a/src/Sensors.cpp b/src/Sensors.cpp index d08e88c9..643126b1 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -536,12 +536,12 @@ float Sensors::getUnitValue(UNIT unit) { return pres; case ALT: return alt; - // case GAS: - // return gas; - case DFRobot_GAS::NH3: - return NH3; - case DFRobot_GAS::CO: - return CO; + case GAS: + return gas; + case NH3: + return nh3; + case CO: + return co; default: return 0.0; } @@ -977,7 +977,7 @@ void Sensors::GCJA5Read() { void Sensors::DFRobotGravityRead() { - String gastype = gas.queryGasType(); + String gastype = dfr_gas.queryGasType(); /** *Fill in the parameter readGasConcentration() with the type of gas to be obtained and print *The current gas concentration @@ -986,7 +986,7 @@ void Sensors::DFRobotGravityRead() { Serial.print("Ambient "); Serial.print(gastype); Serial.print(" concentration is: "); - Serial.print(gas.readGasConcentrationPPM()); + Serial.print(dfr_gas.readGasConcentrationPPM()); if (gastype == "O2") Serial.println(" %vol"); else @@ -1574,7 +1574,7 @@ void Sensors::GCJA5Init() { void Sensors::DFRobotgravityInit() { - sensorAnnounce(SENSORS::MULTIGAS); + sensorAnnounce(SENSORS::SMULTIGAS); DFRobot_GAS_I2C gas(&Wire ,0x77); while(!gas.begin()) { @@ -1592,7 +1592,7 @@ void Sensors::DFRobotgravityInit() { * gas.OFF:turn off */ gas.setTempCompensation(gas.ON); - sensorRegister(SENSORS::MULTIGAS); + sensorRegister(SENSORS::SMULTIGAS); } // Altitude compensation for CO2 sensors without Pressure atm or Altitude compensation @@ -1639,8 +1639,8 @@ void Sensors::resetAllVariables() { alt = 0.0; gas = 0.0; pres = 0.0; - NH3 = 0.0; - CO = 0.0; + nh3 = 0.0; + co = 0.0; } void Sensors::DEBUG(const char *text, const char *textb) { diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 7b401939..117ca29f 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #ifdef DHT11_ENABLED #include @@ -96,11 +96,11 @@ X(CO2HUM, "%", "CO2H") \ X(PRESS, "hPa", "P") \ X(ALT, "m", "Alt") \ + X(GAS, "Ohm", "Gas") \ X(NH3, "ppm", "NH3") \ X(CO, "ppm", "CO") \ X(UCOUNT, "COUNT", "UCOUNT") - // X(GAS, "Ohm", "Gas") \ // COlisiona con DFRobot Multigas #define X(unit, symbol, name) unit, typedef enum UNIT : size_t { SENSOR_UNITS } UNIT; @@ -213,7 +213,8 @@ class Sensors { PM1006 *pm1006; // DFRobot gravity Gas sensor - DFRobot_GAS_I2C gas; + DFRobot_GAS_I2C dfr_gas; + void init(u_int pms_type = 0, int pms_rx = PMS_RX, int pms_tx = PMS_TX); @@ -257,7 +258,7 @@ class Sensors { float getAltitude(); - // float getGas(); // Posible colision con DFRobot Multigas + float getGas(); float getNH3(); @@ -345,16 +346,14 @@ class Sensors { float temp = 0.0; // Temperature (°C) float pres = 0.0; // Pressure float alt = 0.0; - // float gas = 0.0; // Colisiona con DFRobot Multigas + float gas = 0.0; // Colisiona con DFRobot Multigas uint16_t CO2Val; // CO2 in ppm float CO2humi = 0.0; // humidity of CO2 sensor float CO2temp = 0.0; // temperature of CO2 sensor - uint16_t NH3; // Amonium in ppm - uint16_t CO; // Carbon monoxide - float NH3 = 0.0; - float CO = 0.0; + float nh3; // Amonium in ppm + float co; // Carbon monoxide void am2320Init(); void am2320Read(); diff --git a/unified-lib-deps.ini b/unified-lib-deps.ini index 22aca273..71202c5f 100644 --- a/unified-lib-deps.ini +++ b/unified-lib-deps.ini @@ -17,4 +17,5 @@ lib_deps = https://github.com/hpsaturn/DHT_nonblocking.git#ec6e5b9 https://github.com/paulvha/SN-GCJA5.git#f261968 https://github.com/jcomas/CM1106_UART.git#da0eb4e + https://github.com/DFRobot/DFRobot_MultiGasSensor.git From a5a7a43e6fd685153921ca7dafaaaffa8344eef0 Mon Sep 17 00:00:00 2001 From: roberbike Date: Sun, 4 Jun 2023 13:26:07 +0200 Subject: [PATCH 07/32] fusion menor --- src/Sensors.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 117ca29f..ad0a74cf 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -352,8 +352,10 @@ class Sensors { float CO2humi = 0.0; // humidity of CO2 sensor float CO2temp = 0.0; // temperature of CO2 sensor - float nh3; // Amonium in ppm - float co; // Carbon monoxide + uint16_t NH3; // Amonium in ppm + uint16_t CO; // Carbon monoxide + //float NH3 = 0.0; + //float CO = 0.0; void am2320Init(); void am2320Read(); From 88eb99ea9e14e42a90223b71070982b4d0c89fae Mon Sep 17 00:00:00 2001 From: roberbike Date: Wed, 7 Jun 2023 20:01:50 +0200 Subject: [PATCH 08/32] version inicial con errores Sensor NH3 y CO --- platformio.ini | 2 +- src/Sensors.cpp | 105 ++++++++++++++++++++++++++++++++++-------------- src/Sensors.hpp | 17 ++++---- 3 files changed, 83 insertions(+), 41 deletions(-) diff --git a/platformio.ini b/platformio.ini index 5b112df5..b88db787 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,7 +14,7 @@ upload_speed = 1500000 monitor_speed = 115200 monitor_filters = time build_flags = - -D CORE_DEBUG_LEVEL=0 + -D CORE_DEBUG_LEVEL=3 lib_deps = ${commonlibs.lib_deps} [common] diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 643126b1..4d65f351 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -64,7 +64,7 @@ bool Sensors::readAllSensors() { dataReady = pmSensorRead(); DEBUG("-->[SLIB] UART data ready \t:", dataReady ? "true" : "false"); } - enableWire1(); + //enableWire1(); CO2scd30Read(); GCJA5Read(); sps30Read(); @@ -74,13 +74,13 @@ bool Sensors::readAllSensors() { bme280Read(); bmp280Read(); bme680Read(); - aht10Read(); + aht10Read(); DFRobotGravityRead(); #ifdef DHT11_ENABLED dhtRead(); #endif - disableWire1(); + // disableWire1(); printValues(); printSensorsRegistered(devmode); @@ -114,7 +114,8 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { if (!i2conly && !sensorSerialInit(pms_type, pms_rx, pms_tx)) { DEBUG("-->[SLIB] UART sensors detected\t:", "0"); } - startI2C(); + + // startI2C(); CO2scd30Init(); sps30I2CInit(); GCJA5Init(); @@ -124,7 +125,7 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { bme680Init(); am2320Init(); sht31Init(); - aht10Init(); + aht10Init(); DFRobotgravityInit(); #ifdef DHT11_ENABLED @@ -321,6 +322,16 @@ float Sensors::getPressure() { return pres; } +float Sensors::getNH3() { + return nh3; +} + +float Sensors::getCO() { + return co; +} + + + /** * @brief UART only: check if the UART sensor is registered * @return bool true if the UART sensor is registered, false otherwise. @@ -977,21 +988,42 @@ void Sensors::GCJA5Read() { void Sensors::DFRobotGravityRead() { - String gastype = dfr_gas.queryGasType(); + // String gastypenh3 = dfr_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 + */ + float NH3 = dfr_nh3.readGasConcentrationPPM(); + dataReady = true; + DEBUG("-->[SLIB] NH3 read\t\t: done!"); + unitRegister(UNIT::NH3); + + Serial.print("Ambient "); + // Serial.print(gastypenh3); + Serial.print(" concentration is: "); + Serial.print(dfr_nh3.readGasConcentrationPPM()); + Serial.println(" PPM"); + Serial.println(); + + // String gastype = dfr_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 */ + float CO = dfr_co.readGasConcentrationPPM(); + dataReady = true; + DEBUG("-->[SLIB] CO read\t\t: done!"); + unitRegister(UNIT::CO); + Serial.print("Ambient "); - Serial.print(gastype); + //Serial.print(gastype); Serial.print(" concentration is: "); - Serial.print(dfr_gas.readGasConcentrationPPM()); - if (gastype == "O2") - Serial.println(" %vol"); - else - Serial.println(" PPM"); + Serial.print(dfr_co.readGasConcentrationPPM()); + Serial.println(" PPM"); Serial.println(); + } @@ -1575,23 +1607,34 @@ void Sensors::GCJA5Init() { void Sensors::DFRobotgravityInit() { sensorAnnounce(SENSORS::SMULTIGAS); - DFRobot_GAS_I2C gas(&Wire ,0x77); - while(!gas.begin()) - { - Serial.println("NO Deivces !"); - delay(1000); - } - Serial.println("The device is connected successfully!"); - - //Mode of obtaining data: the main controller needs to request the sensor for data - gas.changeAcquireMode(gas.PASSIVITY); - delay(1000); - - /** - *Turn on temperature compensation: gas.ON : turn on - * gas.OFF:turn off - */ - gas.setTempCompensation(gas.ON); + DFRobot_GAS_I2C dfr_nh3(&Wire,0x77); + + //dfr_nh3.begin(); + while(!dfr_nh3.begin()) + { + Serial.println("NO Devices NH3 !"); + delay(1000); + } + +//Mode of obtaining data: the main controller needs to request the sensor for data + dfr_nh3.changeAcquireMode(dfr_nh3.PASSIVITY); + delay(1000); + dfr_nh3.setTempCompensation(dfr_nh3.ON); + Serial.println("The device nh3 0x77 is connected successfully!"); + + DFRobot_GAS_I2C dfr_co(&Wire,0x74); + //dfr_co.begin(); + while(!dfr_co.begin()) + { + Serial.println("No Devices CO !"); + delay(1000); + } + + dfr_co.changeAcquireMode(dfr_co.PASSIVITY); + delay(1000); + dfr_co.setTempCompensation(dfr_co.ON); + Serial.println("The device CO 0x74 is connected successfully!"); + sensorRegister(SENSORS::SMULTIGAS); } @@ -1639,8 +1682,8 @@ void Sensors::resetAllVariables() { alt = 0.0; gas = 0.0; pres = 0.0; - nh3 = 0.0; - co = 0.0; + dfr_nh3 = 0; + dfr_co = 0; } void Sensors::DEBUG(const char *text, const char *textb) { diff --git a/src/Sensors.hpp b/src/Sensors.hpp index ad0a74cf..ae70d570 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -149,7 +149,7 @@ class Sensors { bool devmode; // Initial sample time for all sensors - int sample_time = 5; + int sample_time = 10; // temperature offset (for final temp output) float toffset = 0.0; @@ -213,8 +213,9 @@ class Sensors { PM1006 *pm1006; // DFRobot gravity Gas sensor - DFRobot_GAS_I2C dfr_gas; - + //DFRobot_GAS_I2C dfr_gas; + DFRobot_GAS_I2C dfr_nh3; + DFRobot_GAS_I2C dfr_co; void init(u_int pms_type = 0, int pms_rx = PMS_RX, int pms_tx = PMS_TX); @@ -346,17 +347,15 @@ class Sensors { float temp = 0.0; // Temperature (°C) float pres = 0.0; // Pressure float alt = 0.0; - float gas = 0.0; // Colisiona con DFRobot Multigas + float gas = 0.0; // uint16_t CO2Val; // CO2 in ppm float CO2humi = 0.0; // humidity of CO2 sensor float CO2temp = 0.0; // temperature of CO2 sensor - uint16_t NH3; // Amonium in ppm - uint16_t CO; // Carbon monoxide - //float NH3 = 0.0; - //float CO = 0.0; - + float nh3; // Amonium in ppm + float co; // Carbon monoxide + void am2320Init(); void am2320Read(); From 15135e1765e107a1b1a6fc3b32482ff45c60d94c Mon Sep 17 00:00:00 2001 From: roberbike Date: Wed, 7 Jun 2023 22:17:14 +0200 Subject: [PATCH 09/32] ERROR en .ini esp32 definido como esp32c3. --- platformio.ini | 2 +- src/Sensors.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/platformio.ini b/platformio.ini index b88db787..dd3a725b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -52,7 +52,7 @@ extends = esp32_common build_src_filter = -<*> + build_flags = ${env.build_flags} - -D ESP32C3=1 + ;-D ESP32C3=1 [env:esp32c3] extends = esp32_common diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 4d65f351..0f879b62 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -64,7 +64,7 @@ bool Sensors::readAllSensors() { dataReady = pmSensorRead(); DEBUG("-->[SLIB] UART data ready \t:", dataReady ? "true" : "false"); } - //enableWire1(); + enableWire1(); CO2scd30Read(); GCJA5Read(); sps30Read(); @@ -80,7 +80,7 @@ bool Sensors::readAllSensors() { dhtRead(); #endif - // disableWire1(); + disableWire1(); printValues(); printSensorsRegistered(devmode); @@ -115,7 +115,7 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { DEBUG("-->[SLIB] UART sensors detected\t:", "0"); } - // startI2C(); + startI2C(); CO2scd30Init(); sps30I2CInit(); GCJA5Init(); @@ -1007,12 +1007,12 @@ void Sensors::DFRobotGravityRead() { Serial.println(); // String gastype = dfr_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 */ - float CO = dfr_co.readGasConcentrationPPM(); + /* float CO = dfr_co.readGasConcentrationPPM(); dataReady = true; DEBUG("-->[SLIB] CO read\t\t: done!"); unitRegister(UNIT::CO); @@ -1023,7 +1023,7 @@ void Sensors::DFRobotGravityRead() { Serial.print(dfr_co.readGasConcentrationPPM()); Serial.println(" PPM"); Serial.println(); - + */ } @@ -1622,7 +1622,7 @@ void Sensors::DFRobotgravityInit() { dfr_nh3.setTempCompensation(dfr_nh3.ON); Serial.println("The device nh3 0x77 is connected successfully!"); - DFRobot_GAS_I2C dfr_co(&Wire,0x74); + /* DFRobot_GAS_I2C dfr_co(&Wire,0x74); //dfr_co.begin(); while(!dfr_co.begin()) { @@ -1634,7 +1634,7 @@ void Sensors::DFRobotgravityInit() { delay(1000); dfr_co.setTempCompensation(dfr_co.ON); Serial.println("The device CO 0x74 is connected successfully!"); - + */ sensorRegister(SENSORS::SMULTIGAS); } From 0b10f81e8f2576f2d20b396817f376cc2fbc9b0c Mon Sep 17 00:00:00 2001 From: roberbike Date: Wed, 7 Jun 2023 22:34:34 +0200 Subject: [PATCH 10/32] activado co --- src/Sensors.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 0f879b62..3c09aec0 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -1007,12 +1007,12 @@ void Sensors::DFRobotGravityRead() { Serial.println(); // String gastype = dfr_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 */ - /* float CO = dfr_co.readGasConcentrationPPM(); + float CO = dfr_co.readGasConcentrationPPM(); dataReady = true; DEBUG("-->[SLIB] CO read\t\t: done!"); unitRegister(UNIT::CO); @@ -1023,7 +1023,7 @@ void Sensors::DFRobotGravityRead() { Serial.print(dfr_co.readGasConcentrationPPM()); Serial.println(" PPM"); Serial.println(); - */ + } @@ -1622,7 +1622,7 @@ void Sensors::DFRobotgravityInit() { dfr_nh3.setTempCompensation(dfr_nh3.ON); Serial.println("The device nh3 0x77 is connected successfully!"); - /* DFRobot_GAS_I2C dfr_co(&Wire,0x74); + DFRobot_GAS_I2C dfr_co(&Wire,0x74); //dfr_co.begin(); while(!dfr_co.begin()) { @@ -1634,7 +1634,7 @@ void Sensors::DFRobotgravityInit() { delay(1000); dfr_co.setTempCompensation(dfr_co.ON); Serial.println("The device CO 0x74 is connected successfully!"); - */ + sensorRegister(SENSORS::SMULTIGAS); } From 6ae8fe1d674754b64709afaf024345f17107623d Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Mon, 29 May 2023 23:19:41 +0200 Subject: [PATCH 11/32] fixed build and some implementation issues. Unfinished --- platformio.ini | 1 + src/Sensors.cpp | 24 ++++++++++++------------ src/Sensors.hpp | 17 ++++++++--------- unified-lib-deps.ini | 1 + 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/platformio.ini b/platformio.ini index 3a3c775e..5b112df5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -70,6 +70,7 @@ build_src_filter = -<*> + build_flags = ${env.build_flags} -DBOARD_HAS_PSRAM + -DARDUINO_ESP32_DEV=1 ;-DARDUINO_USB_MODE=1 ;-DARDUINO_USB_CDC_ON_BOOT=1 diff --git a/src/Sensors.cpp b/src/Sensors.cpp index d08e88c9..643126b1 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -536,12 +536,12 @@ float Sensors::getUnitValue(UNIT unit) { return pres; case ALT: return alt; - // case GAS: - // return gas; - case DFRobot_GAS::NH3: - return NH3; - case DFRobot_GAS::CO: - return CO; + case GAS: + return gas; + case NH3: + return nh3; + case CO: + return co; default: return 0.0; } @@ -977,7 +977,7 @@ void Sensors::GCJA5Read() { void Sensors::DFRobotGravityRead() { - String gastype = gas.queryGasType(); + String gastype = dfr_gas.queryGasType(); /** *Fill in the parameter readGasConcentration() with the type of gas to be obtained and print *The current gas concentration @@ -986,7 +986,7 @@ void Sensors::DFRobotGravityRead() { Serial.print("Ambient "); Serial.print(gastype); Serial.print(" concentration is: "); - Serial.print(gas.readGasConcentrationPPM()); + Serial.print(dfr_gas.readGasConcentrationPPM()); if (gastype == "O2") Serial.println(" %vol"); else @@ -1574,7 +1574,7 @@ void Sensors::GCJA5Init() { void Sensors::DFRobotgravityInit() { - sensorAnnounce(SENSORS::MULTIGAS); + sensorAnnounce(SENSORS::SMULTIGAS); DFRobot_GAS_I2C gas(&Wire ,0x77); while(!gas.begin()) { @@ -1592,7 +1592,7 @@ void Sensors::DFRobotgravityInit() { * gas.OFF:turn off */ gas.setTempCompensation(gas.ON); - sensorRegister(SENSORS::MULTIGAS); + sensorRegister(SENSORS::SMULTIGAS); } // Altitude compensation for CO2 sensors without Pressure atm or Altitude compensation @@ -1639,8 +1639,8 @@ void Sensors::resetAllVariables() { alt = 0.0; gas = 0.0; pres = 0.0; - NH3 = 0.0; - CO = 0.0; + nh3 = 0.0; + co = 0.0; } void Sensors::DEBUG(const char *text, const char *textb) { diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 7b401939..117ca29f 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #ifdef DHT11_ENABLED #include @@ -96,11 +96,11 @@ X(CO2HUM, "%", "CO2H") \ X(PRESS, "hPa", "P") \ X(ALT, "m", "Alt") \ + X(GAS, "Ohm", "Gas") \ X(NH3, "ppm", "NH3") \ X(CO, "ppm", "CO") \ X(UCOUNT, "COUNT", "UCOUNT") - // X(GAS, "Ohm", "Gas") \ // COlisiona con DFRobot Multigas #define X(unit, symbol, name) unit, typedef enum UNIT : size_t { SENSOR_UNITS } UNIT; @@ -213,7 +213,8 @@ class Sensors { PM1006 *pm1006; // DFRobot gravity Gas sensor - DFRobot_GAS_I2C gas; + DFRobot_GAS_I2C dfr_gas; + void init(u_int pms_type = 0, int pms_rx = PMS_RX, int pms_tx = PMS_TX); @@ -257,7 +258,7 @@ class Sensors { float getAltitude(); - // float getGas(); // Posible colision con DFRobot Multigas + float getGas(); float getNH3(); @@ -345,16 +346,14 @@ class Sensors { float temp = 0.0; // Temperature (°C) float pres = 0.0; // Pressure float alt = 0.0; - // float gas = 0.0; // Colisiona con DFRobot Multigas + float gas = 0.0; // Colisiona con DFRobot Multigas uint16_t CO2Val; // CO2 in ppm float CO2humi = 0.0; // humidity of CO2 sensor float CO2temp = 0.0; // temperature of CO2 sensor - uint16_t NH3; // Amonium in ppm - uint16_t CO; // Carbon monoxide - float NH3 = 0.0; - float CO = 0.0; + float nh3; // Amonium in ppm + float co; // Carbon monoxide void am2320Init(); void am2320Read(); diff --git a/unified-lib-deps.ini b/unified-lib-deps.ini index 22aca273..71202c5f 100644 --- a/unified-lib-deps.ini +++ b/unified-lib-deps.ini @@ -17,4 +17,5 @@ lib_deps = https://github.com/hpsaturn/DHT_nonblocking.git#ec6e5b9 https://github.com/paulvha/SN-GCJA5.git#f261968 https://github.com/jcomas/CM1106_UART.git#da0eb4e + https://github.com/DFRobot/DFRobot_MultiGasSensor.git From 71b90dbe5e3be3d6d077a14877fb21688c27075b Mon Sep 17 00:00:00 2001 From: roberbike Date: Sun, 4 Jun 2023 13:26:07 +0200 Subject: [PATCH 12/32] fusion menor --- src/Sensors.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 117ca29f..ad0a74cf 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -352,8 +352,10 @@ class Sensors { float CO2humi = 0.0; // humidity of CO2 sensor float CO2temp = 0.0; // temperature of CO2 sensor - float nh3; // Amonium in ppm - float co; // Carbon monoxide + uint16_t NH3; // Amonium in ppm + uint16_t CO; // Carbon monoxide + //float NH3 = 0.0; + //float CO = 0.0; void am2320Init(); void am2320Read(); From 0faaa9bb4ca6bcc6798f0f8e3413316dd019ff57 Mon Sep 17 00:00:00 2001 From: roberbike Date: Wed, 7 Jun 2023 20:01:50 +0200 Subject: [PATCH 13/32] version inicial con errores Sensor NH3 y CO --- platformio.ini | 2 +- src/Sensors.cpp | 105 ++++++++++++++++++++++++++++++++++-------------- src/Sensors.hpp | 17 ++++---- 3 files changed, 83 insertions(+), 41 deletions(-) diff --git a/platformio.ini b/platformio.ini index 5b112df5..b88db787 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,7 +14,7 @@ upload_speed = 1500000 monitor_speed = 115200 monitor_filters = time build_flags = - -D CORE_DEBUG_LEVEL=0 + -D CORE_DEBUG_LEVEL=3 lib_deps = ${commonlibs.lib_deps} [common] diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 643126b1..4d65f351 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -64,7 +64,7 @@ bool Sensors::readAllSensors() { dataReady = pmSensorRead(); DEBUG("-->[SLIB] UART data ready \t:", dataReady ? "true" : "false"); } - enableWire1(); + //enableWire1(); CO2scd30Read(); GCJA5Read(); sps30Read(); @@ -74,13 +74,13 @@ bool Sensors::readAllSensors() { bme280Read(); bmp280Read(); bme680Read(); - aht10Read(); + aht10Read(); DFRobotGravityRead(); #ifdef DHT11_ENABLED dhtRead(); #endif - disableWire1(); + // disableWire1(); printValues(); printSensorsRegistered(devmode); @@ -114,7 +114,8 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { if (!i2conly && !sensorSerialInit(pms_type, pms_rx, pms_tx)) { DEBUG("-->[SLIB] UART sensors detected\t:", "0"); } - startI2C(); + + // startI2C(); CO2scd30Init(); sps30I2CInit(); GCJA5Init(); @@ -124,7 +125,7 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { bme680Init(); am2320Init(); sht31Init(); - aht10Init(); + aht10Init(); DFRobotgravityInit(); #ifdef DHT11_ENABLED @@ -321,6 +322,16 @@ float Sensors::getPressure() { return pres; } +float Sensors::getNH3() { + return nh3; +} + +float Sensors::getCO() { + return co; +} + + + /** * @brief UART only: check if the UART sensor is registered * @return bool true if the UART sensor is registered, false otherwise. @@ -977,21 +988,42 @@ void Sensors::GCJA5Read() { void Sensors::DFRobotGravityRead() { - String gastype = dfr_gas.queryGasType(); + // String gastypenh3 = dfr_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 + */ + float NH3 = dfr_nh3.readGasConcentrationPPM(); + dataReady = true; + DEBUG("-->[SLIB] NH3 read\t\t: done!"); + unitRegister(UNIT::NH3); + + Serial.print("Ambient "); + // Serial.print(gastypenh3); + Serial.print(" concentration is: "); + Serial.print(dfr_nh3.readGasConcentrationPPM()); + Serial.println(" PPM"); + Serial.println(); + + // String gastype = dfr_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 */ + float CO = dfr_co.readGasConcentrationPPM(); + dataReady = true; + DEBUG("-->[SLIB] CO read\t\t: done!"); + unitRegister(UNIT::CO); + Serial.print("Ambient "); - Serial.print(gastype); + //Serial.print(gastype); Serial.print(" concentration is: "); - Serial.print(dfr_gas.readGasConcentrationPPM()); - if (gastype == "O2") - Serial.println(" %vol"); - else - Serial.println(" PPM"); + Serial.print(dfr_co.readGasConcentrationPPM()); + Serial.println(" PPM"); Serial.println(); + } @@ -1575,23 +1607,34 @@ void Sensors::GCJA5Init() { void Sensors::DFRobotgravityInit() { sensorAnnounce(SENSORS::SMULTIGAS); - DFRobot_GAS_I2C gas(&Wire ,0x77); - while(!gas.begin()) - { - Serial.println("NO Deivces !"); - delay(1000); - } - Serial.println("The device is connected successfully!"); - - //Mode of obtaining data: the main controller needs to request the sensor for data - gas.changeAcquireMode(gas.PASSIVITY); - delay(1000); - - /** - *Turn on temperature compensation: gas.ON : turn on - * gas.OFF:turn off - */ - gas.setTempCompensation(gas.ON); + DFRobot_GAS_I2C dfr_nh3(&Wire,0x77); + + //dfr_nh3.begin(); + while(!dfr_nh3.begin()) + { + Serial.println("NO Devices NH3 !"); + delay(1000); + } + +//Mode of obtaining data: the main controller needs to request the sensor for data + dfr_nh3.changeAcquireMode(dfr_nh3.PASSIVITY); + delay(1000); + dfr_nh3.setTempCompensation(dfr_nh3.ON); + Serial.println("The device nh3 0x77 is connected successfully!"); + + DFRobot_GAS_I2C dfr_co(&Wire,0x74); + //dfr_co.begin(); + while(!dfr_co.begin()) + { + Serial.println("No Devices CO !"); + delay(1000); + } + + dfr_co.changeAcquireMode(dfr_co.PASSIVITY); + delay(1000); + dfr_co.setTempCompensation(dfr_co.ON); + Serial.println("The device CO 0x74 is connected successfully!"); + sensorRegister(SENSORS::SMULTIGAS); } @@ -1639,8 +1682,8 @@ void Sensors::resetAllVariables() { alt = 0.0; gas = 0.0; pres = 0.0; - nh3 = 0.0; - co = 0.0; + dfr_nh3 = 0; + dfr_co = 0; } void Sensors::DEBUG(const char *text, const char *textb) { diff --git a/src/Sensors.hpp b/src/Sensors.hpp index ad0a74cf..ae70d570 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -149,7 +149,7 @@ class Sensors { bool devmode; // Initial sample time for all sensors - int sample_time = 5; + int sample_time = 10; // temperature offset (for final temp output) float toffset = 0.0; @@ -213,8 +213,9 @@ class Sensors { PM1006 *pm1006; // DFRobot gravity Gas sensor - DFRobot_GAS_I2C dfr_gas; - + //DFRobot_GAS_I2C dfr_gas; + DFRobot_GAS_I2C dfr_nh3; + DFRobot_GAS_I2C dfr_co; void init(u_int pms_type = 0, int pms_rx = PMS_RX, int pms_tx = PMS_TX); @@ -346,17 +347,15 @@ class Sensors { float temp = 0.0; // Temperature (°C) float pres = 0.0; // Pressure float alt = 0.0; - float gas = 0.0; // Colisiona con DFRobot Multigas + float gas = 0.0; // uint16_t CO2Val; // CO2 in ppm float CO2humi = 0.0; // humidity of CO2 sensor float CO2temp = 0.0; // temperature of CO2 sensor - uint16_t NH3; // Amonium in ppm - uint16_t CO; // Carbon monoxide - //float NH3 = 0.0; - //float CO = 0.0; - + float nh3; // Amonium in ppm + float co; // Carbon monoxide + void am2320Init(); void am2320Read(); From c7bc62fde71850a9aaf65cae45920bbce39923cb Mon Sep 17 00:00:00 2001 From: roberbike Date: Wed, 7 Jun 2023 22:17:14 +0200 Subject: [PATCH 14/32] ERROR en .ini esp32 definido como esp32c3. --- platformio.ini | 2 +- src/Sensors.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/platformio.ini b/platformio.ini index b88db787..dd3a725b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -52,7 +52,7 @@ extends = esp32_common build_src_filter = -<*> + build_flags = ${env.build_flags} - -D ESP32C3=1 + ;-D ESP32C3=1 [env:esp32c3] extends = esp32_common diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 4d65f351..0f879b62 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -64,7 +64,7 @@ bool Sensors::readAllSensors() { dataReady = pmSensorRead(); DEBUG("-->[SLIB] UART data ready \t:", dataReady ? "true" : "false"); } - //enableWire1(); + enableWire1(); CO2scd30Read(); GCJA5Read(); sps30Read(); @@ -80,7 +80,7 @@ bool Sensors::readAllSensors() { dhtRead(); #endif - // disableWire1(); + disableWire1(); printValues(); printSensorsRegistered(devmode); @@ -115,7 +115,7 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { DEBUG("-->[SLIB] UART sensors detected\t:", "0"); } - // startI2C(); + startI2C(); CO2scd30Init(); sps30I2CInit(); GCJA5Init(); @@ -1007,12 +1007,12 @@ void Sensors::DFRobotGravityRead() { Serial.println(); // String gastype = dfr_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 */ - float CO = dfr_co.readGasConcentrationPPM(); + /* float CO = dfr_co.readGasConcentrationPPM(); dataReady = true; DEBUG("-->[SLIB] CO read\t\t: done!"); unitRegister(UNIT::CO); @@ -1023,7 +1023,7 @@ void Sensors::DFRobotGravityRead() { Serial.print(dfr_co.readGasConcentrationPPM()); Serial.println(" PPM"); Serial.println(); - + */ } @@ -1622,7 +1622,7 @@ void Sensors::DFRobotgravityInit() { dfr_nh3.setTempCompensation(dfr_nh3.ON); Serial.println("The device nh3 0x77 is connected successfully!"); - DFRobot_GAS_I2C dfr_co(&Wire,0x74); + /* DFRobot_GAS_I2C dfr_co(&Wire,0x74); //dfr_co.begin(); while(!dfr_co.begin()) { @@ -1634,7 +1634,7 @@ void Sensors::DFRobotgravityInit() { delay(1000); dfr_co.setTempCompensation(dfr_co.ON); Serial.println("The device CO 0x74 is connected successfully!"); - + */ sensorRegister(SENSORS::SMULTIGAS); } From cd532060945c4830e7f4e1c54652b4332e615e41 Mon Sep 17 00:00:00 2001 From: roberbike Date: Wed, 7 Jun 2023 22:34:34 +0200 Subject: [PATCH 15/32] activado co --- src/Sensors.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 0f879b62..3c09aec0 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -1007,12 +1007,12 @@ void Sensors::DFRobotGravityRead() { Serial.println(); // String gastype = dfr_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 */ - /* float CO = dfr_co.readGasConcentrationPPM(); + float CO = dfr_co.readGasConcentrationPPM(); dataReady = true; DEBUG("-->[SLIB] CO read\t\t: done!"); unitRegister(UNIT::CO); @@ -1023,7 +1023,7 @@ void Sensors::DFRobotGravityRead() { Serial.print(dfr_co.readGasConcentrationPPM()); Serial.println(" PPM"); Serial.println(); - */ + } @@ -1622,7 +1622,7 @@ void Sensors::DFRobotgravityInit() { dfr_nh3.setTempCompensation(dfr_nh3.ON); Serial.println("The device nh3 0x77 is connected successfully!"); - /* DFRobot_GAS_I2C dfr_co(&Wire,0x74); + DFRobot_GAS_I2C dfr_co(&Wire,0x74); //dfr_co.begin(); while(!dfr_co.begin()) { @@ -1634,7 +1634,7 @@ void Sensors::DFRobotgravityInit() { delay(1000); dfr_co.setTempCompensation(dfr_co.ON); Serial.println("The device CO 0x74 is connected successfully!"); - */ + sensorRegister(SENSORS::SMULTIGAS); } From b05ac3ba9f09f64db30fdcc73f1f2f22e987b2b1 Mon Sep 17 00:00:00 2001 From: roberbike Date: Fri, 9 Jun 2023 00:06:54 +0200 Subject: [PATCH 16/32] almacenamiento variables --- src/Sensors.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 3c09aec0..c70e2dda 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -64,7 +64,7 @@ bool Sensors::readAllSensors() { dataReady = pmSensorRead(); DEBUG("-->[SLIB] UART data ready \t:", dataReady ? "true" : "false"); } - enableWire1(); + /*enableWire1(); CO2scd30Read(); GCJA5Read(); sps30Read(); @@ -74,7 +74,7 @@ bool Sensors::readAllSensors() { bme280Read(); bmp280Read(); bme680Read(); - aht10Read(); + aht10Read(); */ DFRobotGravityRead(); #ifdef DHT11_ENABLED dhtRead(); @@ -115,7 +115,7 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { DEBUG("-->[SLIB] UART sensors detected\t:", "0"); } - startI2C(); + /*startI2C(); CO2scd30Init(); sps30I2CInit(); GCJA5Init(); @@ -125,7 +125,7 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { bme680Init(); am2320Init(); sht31Init(); - aht10Init(); + aht10Init(); */ DFRobotgravityInit(); #ifdef DHT11_ENABLED @@ -994,7 +994,8 @@ void Sensors::DFRobotGravityRead() { *The current gas concentration *Print with 1s delay each time */ - float NH3 = dfr_nh3.readGasConcentrationPPM(); + float _nh3 = dfr_nh3.readGasConcentrationPPM(); + nh3 = _nh3; dataReady = true; DEBUG("-->[SLIB] NH3 read\t\t: done!"); unitRegister(UNIT::NH3); @@ -1012,7 +1013,8 @@ void Sensors::DFRobotGravityRead() { *The current gas concentration *Print with 1s delay each time */ - float CO = dfr_co.readGasConcentrationPPM(); + float _co = dfr_co.readGasConcentrationPPM(); + co = _co; dataReady = true; DEBUG("-->[SLIB] CO read\t\t: done!"); unitRegister(UNIT::CO); @@ -1619,7 +1621,7 @@ void Sensors::DFRobotgravityInit() { //Mode of obtaining data: the main controller needs to request the sensor for data dfr_nh3.changeAcquireMode(dfr_nh3.PASSIVITY); delay(1000); - dfr_nh3.setTempCompensation(dfr_nh3.ON); + dfr_nh3.setTempCompensation(dfr_nh3.ON); Serial.println("The device nh3 0x77 is connected successfully!"); DFRobot_GAS_I2C dfr_co(&Wire,0x74); From 0ad87767ff12fcd2ada44bd812b245af35fd6092 Mon Sep 17 00:00:00 2001 From: roberbike Date: Fri, 9 Jun 2023 22:38:36 +0200 Subject: [PATCH 17/32] se bloquea el i2c. Desconectando el sensor y reconectando mide --- src/Sensors.cpp | 51 +++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index c70e2dda..012910b4 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -64,7 +64,7 @@ bool Sensors::readAllSensors() { dataReady = pmSensorRead(); DEBUG("-->[SLIB] UART data ready \t:", dataReady ? "true" : "false"); } - /*enableWire1(); + enableWire1(); CO2scd30Read(); GCJA5Read(); sps30Read(); @@ -74,7 +74,7 @@ bool Sensors::readAllSensors() { bme280Read(); bmp280Read(); bme680Read(); - aht10Read(); */ + aht10Read(); DFRobotGravityRead(); #ifdef DHT11_ENABLED dhtRead(); @@ -115,7 +115,7 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { DEBUG("-->[SLIB] UART sensors detected\t:", "0"); } - /*startI2C(); + startI2C(); CO2scd30Init(); sps30I2CInit(); GCJA5Init(); @@ -125,7 +125,7 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { bme680Init(); am2320Init(); sht31Init(); - aht10Init(); */ + aht10Init(); DFRobotgravityInit(); #ifdef DHT11_ENABLED @@ -988,44 +988,53 @@ void Sensors::GCJA5Read() { void Sensors::DFRobotGravityRead() { - // String gastypenh3 = dfr_nh3.queryGasType(); + + DFRobot_GAS_I2C dfr_co(&Wire,0x74); { + String gastype = dfr_co.queryGasType(); + dfr_co.begin(); /** *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 */ - float _nh3 = dfr_nh3.readGasConcentrationPPM(); - nh3 = _nh3; - dataReady = true; - DEBUG("-->[SLIB] NH3 read\t\t: done!"); - unitRegister(UNIT::NH3); + + float _co = dfr_co.readGasConcentrationPPM(); + co = _co; + dataReady = true; + DEBUG("-->[SLIB] CO read\t\t: done!"); + unitRegister(UNIT::CO); Serial.print("Ambient "); - // Serial.print(gastypenh3); + Serial.print(gastype); Serial.print(" concentration is: "); - Serial.print(dfr_nh3.readGasConcentrationPPM()); + Serial.print(dfr_co.readGasConcentrationPPM()); Serial.println(" PPM"); Serial.println(); + } - // String gastype = dfr_co.queryGasType(); + DFRobot_GAS_I2C dfr_nh3(&Wire,0x77); + { + dfr_nh3.begin(); + String gastypenh3 = dfr_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 */ - float _co = dfr_co.readGasConcentrationPPM(); - co = _co; - dataReady = true; - DEBUG("-->[SLIB] CO read\t\t: done!"); - unitRegister(UNIT::CO); + float _nh3 = dfr_nh3.readGasConcentrationPPM(); + nh3 = _nh3; + dataReady = true; + + DEBUG("-->[SLIB] NH3 read\t\t: done!"); + unitRegister(UNIT::NH3); Serial.print("Ambient "); - //Serial.print(gastype); + Serial.print(gastypenh3); Serial.print(" concentration is: "); - Serial.print(dfr_co.readGasConcentrationPPM()); + Serial.print(dfr_nh3.readGasConcentrationPPM()); Serial.println(" PPM"); Serial.println(); - + } } From 19cd15bf08c3a9c1bf152c0790a02083efed5267 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sat, 10 Jun 2023 10:14:40 +0200 Subject: [PATCH 18/32] implementation with two address (CO and NH3) from DFR library --- src/Sensors.cpp | 125 +++++++++++++++--------------------------------- src/Sensors.hpp | 18 ++++--- 2 files changed, 50 insertions(+), 93 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 012910b4..3a126059 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -74,8 +74,9 @@ bool Sensors::readAllSensors() { bme280Read(); bmp280Read(); bme680Read(); - aht10Read(); - DFRobotGravityRead(); + aht10Read(); + DFRobotCORead(); + DFRobotNH3Read(); #ifdef DHT11_ENABLED dhtRead(); #endif @@ -125,8 +126,9 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { bme680Init(); am2320Init(); sht31Init(); - aht10Init(); - DFRobotgravityInit(); + aht10Init(); + DFRobotCOInit(); + DFRobotNH3Init(); #ifdef DHT11_ENABLED dhtInit(); @@ -579,7 +581,7 @@ void Sensors::printUnitsRegistered(bool debug) { */ void Sensors::printSensorsRegistered(bool debug) { if (!debug) return; - Serial.printf("-->[SLIB] Sensors i2c count \t: %i (", sensors_registered_count); + Serial.printf("-->[SLIB] Sensors count \t: %i (", sensors_registered_count); int i = 0; while (sensors_registered[i++] != 0) { Serial.print(sensors_device_names[sensors_registered[i-1]]); @@ -986,57 +988,19 @@ void Sensors::GCJA5Read() { unitRegister(UNIT::PM10); } - -void Sensors::DFRobotGravityRead() { - - DFRobot_GAS_I2C dfr_co(&Wire,0x74); { - String gastype = dfr_co.queryGasType(); - dfr_co.begin(); - /** - *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 - */ - - float _co = dfr_co.readGasConcentrationPPM(); - co = _co; - dataReady = true; - DEBUG("-->[SLIB] CO read\t\t: done!"); - unitRegister(UNIT::CO); - - Serial.print("Ambient "); - Serial.print(gastype); - Serial.print(" concentration is: "); - Serial.print(dfr_co.readGasConcentrationPPM()); - Serial.println(" PPM"); - Serial.println(); - } - - DFRobot_GAS_I2C dfr_nh3(&Wire,0x77); - { - dfr_nh3.begin(); - String gastypenh3 = dfr_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 - */ - float _nh3 = dfr_nh3.readGasConcentrationPPM(); - nh3 = _nh3; - dataReady = true; - - DEBUG("-->[SLIB] NH3 read\t\t: done!"); +void Sensors::DFRobotNH3Read() { + if (!dfrNH3.dataIsAvailable()) return; + String gastype = dfrNH3.queryGasType(); + nh3 = dfrNH3.readGasConcentrationPPM(); unitRegister(UNIT::NH3); - - Serial.print("Ambient "); - Serial.print(gastypenh3); - Serial.print(" concentration is: "); - Serial.print(dfr_nh3.readGasConcentrationPPM()); - Serial.println(" PPM"); - Serial.println(); - } } +void Sensors::DFRobotCORead() { + if (!dfrCO.dataIsAvailable()) return; + String gastype = dfrCO.queryGasType(); + co = dfrCO.readGasConcentrationPPM(); + unitRegister(UNIT::CO); +} #ifdef DHT11_ENABLED DHT_nonblocking dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE); @@ -1614,39 +1578,28 @@ void Sensors::GCJA5Init() { sensorRegister(SENSORS::SGCJA5); } +void Sensors::DFRobotCOInit() { + sensorAnnounce(SENSORS::SDFRCO); + dfrCO = DFRobot_GAS_I2C(&Wire, 0x74); + if (!dfrCO.begin()) return; + //Mode of obtaining data: the main controller needs to request the sensor for data + delay(1000); // TODO: we need validate if we need that + //Turn on temperature compensation: gas.ON : turn on + dfrNH3.setTempCompensation(dfrCO.ON); + sensorRegister(SENSORS::SDFRCO); +} +void Sensors::DFRobotNH3Init() { + sensorAnnounce(SENSORS::SDFRNH3); + dfrNH3 = DFRobot_GAS_I2C(&Wire, 0x77); + if (!dfrNH3.begin()) return; + //Mode of obtaining data: the main controller needs to request the sensor for data + dfrNH3.changeAcquireMode(dfrNH3.PASSIVITY); + delay(1000); // TODO: we need validate if we need that -void Sensors::DFRobotgravityInit() { - sensorAnnounce(SENSORS::SMULTIGAS); - DFRobot_GAS_I2C dfr_nh3(&Wire,0x77); - - //dfr_nh3.begin(); - while(!dfr_nh3.begin()) - { - Serial.println("NO Devices NH3 !"); - delay(1000); - } - -//Mode of obtaining data: the main controller needs to request the sensor for data - dfr_nh3.changeAcquireMode(dfr_nh3.PASSIVITY); - delay(1000); - dfr_nh3.setTempCompensation(dfr_nh3.ON); - Serial.println("The device nh3 0x77 is connected successfully!"); - - DFRobot_GAS_I2C dfr_co(&Wire,0x74); - //dfr_co.begin(); - while(!dfr_co.begin()) - { - Serial.println("No Devices CO !"); - delay(1000); - } - - dfr_co.changeAcquireMode(dfr_co.PASSIVITY); - delay(1000); - dfr_co.setTempCompensation(dfr_co.ON); - Serial.println("The device CO 0x74 is connected successfully!"); - - sensorRegister(SENSORS::SMULTIGAS); + //Turn on temperature compensation: gas.ON : turn on + dfrNH3.setTempCompensation(dfrNH3.ON); + sensorRegister(SENSORS::SDFRNH3); } // Altitude compensation for CO2 sensors without Pressure atm or Altitude compensation @@ -1693,8 +1646,8 @@ void Sensors::resetAllVariables() { alt = 0.0; gas = 0.0; pres = 0.0; - dfr_nh3 = 0; - dfr_co = 0; + nh3 = 0; + co = 0; } void Sensors::DEBUG(const char *text, const char *textb) { diff --git a/src/Sensors.hpp b/src/Sensors.hpp index ae70d570..3166347e 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -124,7 +124,8 @@ typedef enum UNIT : size_t { SENSOR_UNITS } UNIT; X(SAHTXX, "AHTXX", 3) \ X(SAM232X, "AM232X", 3) \ X(SDHTX, "DHTX", 3) \ - X(SMULTIGAS, "MULTIGAS", 2) \ + X(SDFRCO, "DFRCO", 2) \ + X(SDFRNH3, "DFRNH3", 2) \ X(SCOUNT, "SCOUNT", 3) #define X(utype, uname, umaintype) utype, @@ -212,10 +213,11 @@ class Sensors { // IKEA Vindriktn sensor PM1006 *pm1006; - // DFRobot gravity Gas sensor - //DFRobot_GAS_I2C dfr_gas; - DFRobot_GAS_I2C dfr_nh3; - DFRobot_GAS_I2C dfr_co; + // DFRobot gravity NH3 sensor addr 0x74 + DFRobot_GAS_I2C dfrCO; + + // DFRobot gravity NH3 sensor addr 0x77 + DFRobot_GAS_I2C dfrNH3; void init(u_int pms_type = 0, int pms_rx = PMS_RX, int pms_tx = PMS_TX); @@ -395,8 +397,10 @@ class Sensors { bool dhtIsReady(float *temperature, float *humidity); #endif - void DFRobotgravityInit(); - void DFRobotGravityRead(); + void DFRobotNH3Init(); + void DFRobotNH3Read(); + void DFRobotCOInit(); + void DFRobotCORead(); // UART sensors methods: From 8c04042fd32f6057f4150f213a229a172715676f Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sat, 10 Jun 2023 10:23:31 +0200 Subject: [PATCH 19/32] fixed C3 build issue --- platformio.ini | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index dd3a725b..f1e79127 100644 --- a/platformio.ini +++ b/platformio.ini @@ -15,6 +15,10 @@ monitor_speed = 115200 monitor_filters = time build_flags = -D CORE_DEBUG_LEVEL=3 + -D ARDUINO_ESP32_DEV=1 + ; -D DHT11_ENABLED=1 // Deprecated, please change this old sensor + ; -D DHT_SENSOR_TYPE=2 + ; -D DHT_SENSOR_PIN=19 lib_deps = ${commonlibs.lib_deps} [common] @@ -70,7 +74,6 @@ build_src_filter = -<*> + build_flags = ${env.build_flags} -DBOARD_HAS_PSRAM - -DARDUINO_ESP32_DEV=1 ;-DARDUINO_USB_MODE=1 ;-DARDUINO_USB_CDC_ON_BOOT=1 From 1f7c9e06952bf4ce9ead7f607e2f2fb7652004cb Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sat, 10 Jun 2023 10:42:13 +0200 Subject: [PATCH 20/32] testing different read validation --- src/Sensors.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 3a126059..47d2c218 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -76,7 +76,7 @@ bool Sensors::readAllSensors() { bme680Read(); aht10Read(); DFRobotCORead(); - DFRobotNH3Read(); + // DFRobotNH3Read(); #ifdef DHT11_ENABLED dhtRead(); #endif @@ -128,7 +128,7 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { sht31Init(); aht10Init(); DFRobotCOInit(); - DFRobotNH3Init(); + // DFRobotNH3Init(); #ifdef DHT11_ENABLED dhtInit(); @@ -996,7 +996,7 @@ void Sensors::DFRobotNH3Read() { } void Sensors::DFRobotCORead() { - if (!dfrCO.dataIsAvailable()) return; + if (!dfrCO.begin()) return; String gastype = dfrCO.queryGasType(); co = dfrCO.readGasConcentrationPPM(); unitRegister(UNIT::CO); From b0c03f4acbd10a9ffc9ecd3590d536daaf044004 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sat, 10 Jun 2023 10:53:05 +0200 Subject: [PATCH 21/32] testing NH3 sensor only --- src/Sensors.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 47d2c218..228f687b 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -75,8 +75,8 @@ bool Sensors::readAllSensors() { bmp280Read(); bme680Read(); aht10Read(); - DFRobotCORead(); - // DFRobotNH3Read(); + // DFRobotCORead(); + DFRobotNH3Read(); #ifdef DHT11_ENABLED dhtRead(); #endif @@ -127,8 +127,8 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { am2320Init(); sht31Init(); aht10Init(); - DFRobotCOInit(); - // DFRobotNH3Init(); + // DFRobotCOInit(); + DFRobotNH3Init(); #ifdef DHT11_ENABLED dhtInit(); @@ -989,7 +989,7 @@ void Sensors::GCJA5Read() { } void Sensors::DFRobotNH3Read() { - if (!dfrNH3.dataIsAvailable()) return; + if (!dfrNH3.begin()) return; String gastype = dfrNH3.queryGasType(); nh3 = dfrNH3.readGasConcentrationPPM(); unitRegister(UNIT::NH3); @@ -1594,7 +1594,7 @@ void Sensors::DFRobotNH3Init() { dfrNH3 = DFRobot_GAS_I2C(&Wire, 0x77); if (!dfrNH3.begin()) return; //Mode of obtaining data: the main controller needs to request the sensor for data - dfrNH3.changeAcquireMode(dfrNH3.PASSIVITY); +// dfrNH3.changeAcquireMode(dfrNH3.PASSIVITY); delay(1000); // TODO: we need validate if we need that //Turn on temperature compensation: gas.ON : turn on From e9bdecc81d96475606b96c3b1e8324dcb8d04aa5 Mon Sep 17 00:00:00 2001 From: roberbike Date: Sat, 10 Jun 2023 19:32:39 +0200 Subject: [PATCH 22/32] desactivado bme680 por conflicto --- src/Sensors.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 228f687b..e54b32d9 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -64,18 +64,18 @@ bool Sensors::readAllSensors() { dataReady = pmSensorRead(); DEBUG("-->[SLIB] UART data ready \t:", dataReady ? "true" : "false"); } - enableWire1(); + enableWire1(); CO2scd30Read(); GCJA5Read(); sps30Read(); CO2scd4xRead(); - am2320Read(); + am2320Read(); sht31Read(); bme280Read(); bmp280Read(); - bme680Read(); - aht10Read(); - // DFRobotCORead(); + //bme680Read(); + aht10Read(); + DFRobotCORead(); DFRobotNH3Read(); #ifdef DHT11_ENABLED dhtRead(); @@ -116,18 +116,18 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { DEBUG("-->[SLIB] UART sensors detected\t:", "0"); } - startI2C(); + startI2C(); CO2scd30Init(); sps30I2CInit(); GCJA5Init(); CO2scd4xInit(); bmp280Init(); bme280Init(); - bme680Init(); - am2320Init(); - sht31Init(); - aht10Init(); - // DFRobotCOInit(); + //bme680Init(); + am2320Init(); + sht31Init(); + aht10Init(); + DFRobotCOInit(); DFRobotNH3Init(); #ifdef DHT11_ENABLED @@ -993,6 +993,7 @@ void Sensors::DFRobotNH3Read() { String gastype = dfrNH3.queryGasType(); nh3 = dfrNH3.readGasConcentrationPPM(); unitRegister(UNIT::NH3); + } void Sensors::DFRobotCORead() { @@ -1000,6 +1001,7 @@ void Sensors::DFRobotCORead() { String gastype = dfrCO.queryGasType(); co = dfrCO.readGasConcentrationPPM(); unitRegister(UNIT::CO); + } #ifdef DHT11_ENABLED @@ -1582,10 +1584,12 @@ void Sensors::DFRobotCOInit() { sensorAnnounce(SENSORS::SDFRCO); dfrCO = DFRobot_GAS_I2C(&Wire, 0x74); if (!dfrCO.begin()) return; + dfrCO.changeAcquireMode(dfrCO.PASSIVITY); //Mode of obtaining data: the main controller needs to request the sensor for data delay(1000); // TODO: we need validate if we need that //Turn on temperature compensation: gas.ON : turn on dfrNH3.setTempCompensation(dfrCO.ON); + delay(1000); sensorRegister(SENSORS::SDFRCO); } @@ -1594,11 +1598,11 @@ void Sensors::DFRobotNH3Init() { dfrNH3 = DFRobot_GAS_I2C(&Wire, 0x77); if (!dfrNH3.begin()) return; //Mode of obtaining data: the main controller needs to request the sensor for data -// dfrNH3.changeAcquireMode(dfrNH3.PASSIVITY); + dfrNH3.changeAcquireMode(dfrNH3.PASSIVITY); delay(1000); // TODO: we need validate if we need that - //Turn on temperature compensation: gas.ON : turn on dfrNH3.setTempCompensation(dfrNH3.ON); + delay(1000); sensorRegister(SENSORS::SDFRNH3); } From 4f8c55177581cbc844e494de5c409bba64aadf8b Mon Sep 17 00:00:00 2001 From: roberbike Date: Sat, 10 Jun 2023 20:10:34 +0200 Subject: [PATCH 23/32] bme680 fixed conflict with dfrobot sensor --- platformio.ini | 2 +- src/Sensors.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/platformio.ini b/platformio.ini index f1e79127..6031d9ae 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,7 +14,7 @@ upload_speed = 1500000 monitor_speed = 115200 monitor_filters = time build_flags = - -D CORE_DEBUG_LEVEL=3 + -D CORE_DEBUG_LEVEL=0 -D ARDUINO_ESP32_DEV=1 ; -D DHT11_ENABLED=1 // Deprecated, please change this old sensor ; -D DHT_SENSOR_TYPE=2 diff --git a/src/Sensors.cpp b/src/Sensors.cpp index e54b32d9..14ad9938 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -73,7 +73,7 @@ bool Sensors::readAllSensors() { sht31Read(); bme280Read(); bmp280Read(); - //bme680Read(); + bme680Read(); aht10Read(); DFRobotCORead(); DFRobotNH3Read(); @@ -123,7 +123,7 @@ void Sensors::init(u_int pms_type, int pms_rx, int pms_tx) { CO2scd4xInit(); bmp280Init(); bme280Init(); - //bme680Init(); + bme680Init(); am2320Init(); sht31Init(); aht10Init(); @@ -1595,7 +1595,7 @@ void Sensors::DFRobotCOInit() { void Sensors::DFRobotNH3Init() { sensorAnnounce(SENSORS::SDFRNH3); - dfrNH3 = DFRobot_GAS_I2C(&Wire, 0x77); + dfrNH3 = DFRobot_GAS_I2C(&Wire, 0x76); // 0x77 y 0x75 used by bme680 if (!dfrNH3.begin()) return; //Mode of obtaining data: the main controller needs to request the sensor for data dfrNH3.changeAcquireMode(dfrNH3.PASSIVITY); From f1005580220728a1938acb8b31d7e7a975c422bb Mon Sep 17 00:00:00 2001 From: roberbike Date: Sat, 10 Jun 2023 22:38:19 +0200 Subject: [PATCH 24/32] clean delays --- src/Sensors.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 14ad9938..f73b8b33 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -990,7 +990,6 @@ void Sensors::GCJA5Read() { void Sensors::DFRobotNH3Read() { if (!dfrNH3.begin()) return; - String gastype = dfrNH3.queryGasType(); nh3 = dfrNH3.readGasConcentrationPPM(); unitRegister(UNIT::NH3); @@ -998,7 +997,6 @@ void Sensors::DFRobotNH3Read() { void Sensors::DFRobotCORead() { if (!dfrCO.begin()) return; - String gastype = dfrCO.queryGasType(); co = dfrCO.readGasConcentrationPPM(); unitRegister(UNIT::CO); @@ -1584,12 +1582,10 @@ void Sensors::DFRobotCOInit() { sensorAnnounce(SENSORS::SDFRCO); dfrCO = DFRobot_GAS_I2C(&Wire, 0x74); if (!dfrCO.begin()) return; - dfrCO.changeAcquireMode(dfrCO.PASSIVITY); //Mode of obtaining data: the main controller needs to request the sensor for data - delay(1000); // TODO: we need validate if we need that - //Turn on temperature compensation: gas.ON : turn on + dfrCO.changeAcquireMode(dfrCO.PASSIVITY); + //Turn on temperature compensation: gas.ON : turn on dfrNH3.setTempCompensation(dfrCO.ON); - delay(1000); sensorRegister(SENSORS::SDFRCO); } @@ -1599,10 +1595,8 @@ void Sensors::DFRobotNH3Init() { if (!dfrNH3.begin()) return; //Mode of obtaining data: the main controller needs to request the sensor for data dfrNH3.changeAcquireMode(dfrNH3.PASSIVITY); - delay(1000); // TODO: we need validate if we need that //Turn on temperature compensation: gas.ON : turn on dfrNH3.setTempCompensation(dfrNH3.ON); - delay(1000); sensorRegister(SENSORS::SDFRNH3); } From afeac6abc99be5913f1cbb6f86f61c0ca4ba4a0e Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sat, 10 Jun 2023 22:55:45 +0200 Subject: [PATCH 25/32] v0.6.8 RC3 support for CO and NH3 sensors. Thanks to @roberbike --- library.json | 3 ++- library.properties | 4 ++-- platformio.ini | 2 -- src/Sensors.hpp | 4 ++-- unified-lib-deps.ini | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/library.json b/library.json index 16040a14..ddd0ec80 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "CanAirIO Air Quality Sensors Library", - "version": "0.6.7", + "version": "0.6.8", "homepage":"https://canair.io", "keywords": [ @@ -88,6 +88,7 @@ {"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":"DHT_nonblocking", "version":"https://github.com/hpsaturn/DHT_nonblocking.git#ec6e5b9"}, {"name":"AHTxx", "version":"https://github.com/enjoyneering/AHTxx.git#eb21571"}, diff --git a/library.properties b/library.properties index e25d9fe7..ae26f78e 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=CanAirIO Air Quality Sensors Library -version=0.6.7 +version=0.6.8 author=@hpsaturn, CanAirIO project maintainer=Antonio Vanegas url=https://github.com/kike-canaries/canairio_sensorlib sentence=Air quality particle meter and CO2 sensors manager for multiple models. paragraph=Generic sensor manager, abstratctions and bindings of multiple air sensors libraries: Honeywell, Plantower, Panasonic, Sensirion, Nova, etc. and CO2 sensors. Also it handling others environment sensors. This library is for general purpose but also is the sensors library base of CanAirIO project. category=sensors -depends=AM232X,Adafruit Unified Sensor,sps30,Adafruit BME280 Library,AHT10,Adafruit BusIO,Adafruit SHT31 Library,DHT_nonblocking,MH-Z19,SparkFun SCD30 Arduino Library,CM1106_UART,SN-GCJA5,Adafruit BME680 Library,S8_UART,Sensirion I2C SCD4x +depends=AM232X,Adafruit Unified Sensor,sps30,Adafruit BME280 Library,AHT10,Adafruit BusIO,Adafruit SHT31 Library,DHT_nonblocking,MH-Z19,SparkFun SCD30 Arduino Library,CM1106_UART,SN-GCJA5,Adafruit BME680 Library,S8_UART,Sensirion I2C SCD4x,DFRobot_MultiGasSensor license=GPL-3.0-only diff --git a/platformio.ini b/platformio.ini index 6031d9ae..ae2152fc 100644 --- a/platformio.ini +++ b/platformio.ini @@ -56,7 +56,6 @@ extends = esp32_common build_src_filter = -<*> + build_flags = ${env.build_flags} - ;-D ESP32C3=1 [env:esp32c3] extends = esp32_common @@ -70,7 +69,6 @@ board = esp32-s3-devkitc-1 board_build.mcu = esp32s3 board_build.f_cpu = 240000000L build_src_filter = -<*> + -;platform_packages = framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#2.0.3 build_flags = ${env.build_flags} -DBOARD_HAS_PSRAM diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 3166347e..b878c4e1 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -22,8 +22,8 @@ #include #endif -#define CSL_VERSION "0.6.7" -#define CSL_REVISION 374 +#define CSL_VERSION "0.6.8" +#define CSL_REVISION 375 /*************************************************************** * 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 71202c5f..e7028ccd 100644 --- a/unified-lib-deps.ini +++ b/unified-lib-deps.ini @@ -13,9 +13,9 @@ lib_deps = 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 https://github.com/enjoyneering/AHTxx.git#eb21571 https://github.com/hpsaturn/DHT_nonblocking.git#ec6e5b9 https://github.com/paulvha/SN-GCJA5.git#f261968 https://github.com/jcomas/CM1106_UART.git#da0eb4e - https://github.com/DFRobot/DFRobot_MultiGasSensor.git From 1f16d97ee34ad487eea7c67d5cb01b5880f027e5 Mon Sep 17 00:00:00 2001 From: roberbike Date: Sat, 10 Jun 2023 23:42:49 +0200 Subject: [PATCH 26/32] example --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b73607b2..7daabeed 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ NOTE: Panasonic via UART in ESP8266 maybe needs select in detection | BMP280 | i2c | Auto | TESTING | | BME680 | i2c | Auto | STABLE | | DHTxx | TwoWire | Auto | DISABLED | +| DfRobot SEN0469 NH3 | --- | Yes | Auto | TESTING | +| DFRobot SEN0466 CO | --- | Yes | Auto | TESTING | NOTE: DHT22 is supported but is not recommended. Please see the documentation. From b02cdbb882e01dbd22e1689169b4a793f241538c Mon Sep 17 00:00:00 2001 From: roberbike Date: Sat, 10 Jun 2023 23:43:13 +0200 Subject: [PATCH 27/32] example --- examples/DfRobot_Multigas/dfr_multigas.ino | 55 ++++++++++++++++++++++ src/Sensors.hpp | 4 +- 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 examples/DfRobot_Multigas/dfr_multigas.ino diff --git a/examples/DfRobot_Multigas/dfr_multigas.ino b/examples/DfRobot_Multigas/dfr_multigas.ino new file mode 100644 index 00000000..f114af85 --- /dev/null +++ b/examples/DfRobot_Multigas/dfr_multigas.ino @@ -0,0 +1,55 @@ +/** + * @file main.cpp + * @date June 2018 - 2021 + * @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.println("-->[MAIN] NH3: " + String(sensors.getNH3())); + Serial.println("-->[MAIN] CO: " + String(sensors.getCO())); +} + +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(false); // [optional] debug mode + sensors.detectI2COnly(true); // force to only i2c sensors + + sensors.init(SENSORS::SDFRCO); // detect CO sensor + sensors.init(SENSORS::SDFRNH3); // detect NH3 sensor + + delay(500); +} + +void loop() { + sensors.loop(); // read sensor data and showed it +} \ No newline at end of file diff --git a/src/Sensors.hpp b/src/Sensors.hpp index b878c4e1..4d37ffe4 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -124,8 +124,8 @@ typedef enum UNIT : size_t { SENSOR_UNITS } UNIT; X(SAHTXX, "AHTXX", 3) \ X(SAM232X, "AM232X", 3) \ X(SDHTX, "DHTX", 3) \ - X(SDFRCO, "DFRCO", 2) \ - X(SDFRNH3, "DFRNH3", 2) \ + X(SDFRCO, "DFRCO", 3) \ + X(SDFRNH3, "DFRNH3", 3) \ X(SCOUNT, "SCOUNT", 3) #define X(utype, uname, umaintype) utype, From 391b2c8a0a1346ad532d81fba7d240d2a358d4f1 Mon Sep 17 00:00:00 2001 From: roberbike Date: Sun, 11 Jun 2023 11:23:23 +0200 Subject: [PATCH 28/32] Readme corregido --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7daabeed..625cbda3 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,8 @@ NOTE: Panasonic via UART in ESP8266 maybe needs select in detection | BMP280 | i2c | Auto | TESTING | | BME680 | i2c | Auto | STABLE | | DHTxx | TwoWire | Auto | DISABLED | -| DfRobot SEN0469 NH3 | --- | Yes | Auto | TESTING | -| DFRobot SEN0466 CO | --- | Yes | Auto | TESTING | +| DfRobot SEN0469 NH3 | i2c | Yes | TESTING | +| DFRobot SEN0466 CO | i2c | Yes | TESTING | NOTE: DHT22 is supported but is not recommended. Please see the documentation. From 0d270e4104631b3b00beff9f939620c4a75258d3 Mon Sep 17 00:00:00 2001 From: roberbike Date: Sun, 11 Jun 2023 11:43:38 +0200 Subject: [PATCH 29/32] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 625cbda3..8828d182 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,8 @@ NOTE: Panasonic via UART in ESP8266 maybe needs select in detection | BMP280 | i2c | Auto | TESTING | | BME680 | i2c | Auto | STABLE | | DHTxx | TwoWire | Auto | DISABLED | -| DfRobot SEN0469 NH3 | i2c | Yes | TESTING | -| DFRobot SEN0466 CO | i2c | Yes | TESTING | +| DfRobot SEN0469 NH3 | i2c | Auto | TESTING | +| DFRobot SEN0466 CO | i2c | Auto | TESTING | NOTE: DHT22 is supported but is not recommended. Please see the documentation. From 57161f38de9997e734ff8589e56ec48925a98cce Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sun, 11 Jun 2023 11:52:49 +0200 Subject: [PATCH 30/32] fixed some issues and improved third party libraries reference --- README.md | 49 +++++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 7daabeed..5750fe60 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # Air Quality Sensors Library -Generic sensor manager, abstractions and bindings of multiple sensors [libraries](https://github.com/kike-canaries/canairio_sensorlib/blob/master/platformio.ini#L18-L34): 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](https://canair.io/docs). +Generic sensor manager, abstractions and bindings of multiple sensors [libraries](https://github.com/kike-canaries/canairio_sensorlib/blob/master/unified-lib-deps.ini): 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](https://canair.io/docs). For developers also you can check the complete library documentation [here](http://hpsaturn.com/canairio_sensorlib_doc/html/index.html) @@ -25,7 +25,7 @@ For developers also you can check the complete library documentation [here](http | Panasonic SN-GCJA5L | Yes | Yes | Auto | STABLE | | Plantower models | Yes | --- | Auto | STABLE | | Nova SDS011 | Yes | --- | Auto | STABLE | -| IKEA Vindriktning | Yes | --- | Select | TESTING| +| IKEA Vindriktning | Yes | --- | Select | STABLE | | Sensirion SPS30 | Yes | Yes | Select / Auto | STABLE | NOTE: Panasonic via UART in ESP8266 maybe needs select in detection @@ -49,11 +49,11 @@ NOTE: Panasonic via UART in ESP8266 maybe needs select in detection | SHT31 | i2c | Auto | STABLE | | AHT10 | i2c | Auto | STABLE | | BME280 | i2c | Auto | STABLE | -| BMP280 | i2c | Auto | TESTING | +| BMP280 | i2c | Auto | STABLE | | BME680 | i2c | Auto | STABLE | +| DfRobot SEN0469 NH3 | i2c | Auto | TESTING | +| DFRobot SEN0466 CO | i2c | Auto | TESTING | | DHTxx | TwoWire | Auto | DISABLED | -| DfRobot SEN0469 NH3 | --- | Yes | Auto | TESTING | -| DFRobot SEN0466 CO | --- | Yes | Auto | TESTING | NOTE: DHT22 is supported but is not recommended. Please see the documentation. @@ -62,8 +62,8 @@ NOTE: DHT22 is supported but is not recommended. Please see the documentation. | Platform | Variants | Notes | Status | |:----------------------- |:-----:|:-------:|:----------:| | ESP32 | WROVER* | ESP32Devkit and similar (recommended) | STABLE | -| ESP32S3 | LilyGo TDisplay | In testing | UNSTABLE | -| ESP32C3 | Devkit v3 | In testing | UNSTABLE | +| ESP32S3 | LilyGo TDisplay | In testing | STABLE | +| ESP32C3 | Devkit v3 | In testing | STABLE | | ESP8266 | 12 | D1MINI tested and similar (old) | STABLE | | Atmelsam | seeed_wio_terminal | Only works via i2c on left port | STABLE | | Arduino | Atmel | Some third party libraries fails | IN PROGRESS | @@ -74,9 +74,9 @@ NOTE: DHT22 is supported but is not recommended. Please see the documentation. - 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 +- Multiple i2c sensors and one UART sensor supported at the same time - Two I2C channel supported (Wire and Wire1) -- Real time registry of sensors unit registered (see multivariable) +- Real time registry of sensor units (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 @@ -87,9 +87,8 @@ NOTE: DHT22 is supported but is not recommended. Please see the documentation. - 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](https://github.com/kike-canaries/canairio_sensorlib/blob/master/library.json#L72-L89) +Full list of all sub libraries supported [here](https://github.com/kike-canaries/canairio_sensorlib/blob/master/unified-lib-deps.ini) # Quick implementation @@ -172,7 +171,6 @@ In this [demo](https://www.youtube.com/watch?v=uxlmP905-FE) on a simple sketch y [![CanAirIO Sensors Lib DEMO with M5CoreInk](https://img.youtube.com/vi/i15iEF47CbY/0.jpg)](https://youtu.be/i15iEF47CbY) - ## 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: @@ -233,16 +231,14 @@ void setup() { void loop() { sensors.loop(); // read sensor data and showed it } -``` - +``` -## UART detection demo +## UART detection demo [![CanAirIO auto configuration demo](https://img.youtube.com/vi/hmukAmG5Eec/0.jpg)](https://www.youtube.com/watch?v=hmukAmG5Eec) CanAirIO sensorlib auto configuration demo on [Youtube](https://www.youtube.com/watch?v=hmukAmG5Eec) - # 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: @@ -253,20 +249,20 @@ The current version of library supports 3 kinds of wiring connection, UART, i2c The library has [pre-defined some UART pin configs](https://github.com/kike-canaries/canairio_sensorlib/blob/master/src/Sensors.hpp#L19-L52), these are selected on compiling time. Maybe you don't need change anything with your board, and maybe the nexts alternatives works for you: -| Board model | TX | RX | Notes +| 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 | | +| 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: +### Custom UART Also you could define a custom UART pins in the init() method and select specific sensors model, like this: @@ -282,27 +278,22 @@ We are using the default pins for each board, some times it's pins are 21,22, pl For now we are using it only for DHT sensors in PIN 23. For more info please review the next lines [here](https://github.com/kike-canaries/canairio_sensorlib/blob/master/src/Sensors.hpp#L19-L52). - # Examples ### PlatformIO (recommended) -#### Compiling and Installing - We recommended PlatformIO because is more easy than Arduino IDE. For this, please install first [PlatformIO](http://platformio.org/) and its command line tools (Windows, MacOs and Linux), **pio** command, then connect your compatible board to the USB and run the next command: ```python -pio run --target upload +pio run -e esp32 --target upload ``` ### Arduino IDE -Only import the `ino` file of the sample and install the libraries listed on `library.json` and this library. +Only import the `ino` file of the sample and install the libraries listed on `library.json` and this library. Complete list of libraries used [here](https://github.com/kike-canaries/canairio_sensorlib/blob/master/unified-lib-deps.ini) ### 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](https://github.com/kike-canaries/canairio_sensorlib/blob/master/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](https://github.com/kike-canaries/canairio_sensorlib/releases) section. Also you need to add the **alternative links** for supporting the ESP32 boards: @@ -318,9 +309,7 @@ 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: @@ -354,7 +343,6 @@ Also you can make a donation, be a patreon or buy a device: - **Buy a device**: [CanAirIO Bike in Tindie](https://www.tindie.com/products/hpsaturn/canairio-bike/) - [Inviting us **a coffee**](https://www.buymeacoffee.com/hpsaturn) - # TODO - [x] Auto detection for UART sensors (Honeywell, Panasonic and Plantower) @@ -372,6 +360,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 - [ ] Sea level setting for Pressure sensors and others - [ ] Support to second UART port From c9a9892f0faf119c5fe13e9379b2b66714b7b0cb Mon Sep 17 00:00:00 2001 From: roberbike Date: Sat, 17 Jun 2023 00:47:16 +0200 Subject: [PATCH 31/32] cambio direccion i2c nh3 y co --- src/Sensors.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index f73b8b33..986b8522 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -1580,7 +1580,7 @@ void Sensors::GCJA5Init() { void Sensors::DFRobotCOInit() { sensorAnnounce(SENSORS::SDFRCO); - dfrCO = DFRobot_GAS_I2C(&Wire, 0x74); + dfrCO = DFRobot_GAS_I2C(&Wire, 0x78); if (!dfrCO.begin()) return; //Mode of obtaining data: the main controller needs to request the sensor for data dfrCO.changeAcquireMode(dfrCO.PASSIVITY); @@ -1591,7 +1591,7 @@ void Sensors::DFRobotCOInit() { void Sensors::DFRobotNH3Init() { sensorAnnounce(SENSORS::SDFRNH3); - dfrNH3 = DFRobot_GAS_I2C(&Wire, 0x76); // 0x77 y 0x75 used by bme680 + dfrNH3 = DFRobot_GAS_I2C(&Wire, 0x7A); // 0x77 y 0x75 used by bme680 if (!dfrNH3.begin()) return; //Mode of obtaining data: the main controller needs to request the sensor for data dfrNH3.changeAcquireMode(dfrNH3.PASSIVITY); From 715892384318fd77e4937b5d00600064aab1dccb Mon Sep 17 00:00:00 2001 From: roberbike Date: Sat, 17 Jun 2023 11:22:06 +0200 Subject: [PATCH 32/32] comentarios --- src/Sensors.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 986b8522..0b4aeedd 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -1580,7 +1580,7 @@ void Sensors::GCJA5Init() { void Sensors::DFRobotCOInit() { sensorAnnounce(SENSORS::SDFRCO); - dfrCO = DFRobot_GAS_I2C(&Wire, 0x78); + dfrCO = DFRobot_GAS_I2C(&Wire, 0x78); // Be sure that your group of i2c address is 7 if (!dfrCO.begin()) return; //Mode of obtaining data: the main controller needs to request the sensor for data dfrCO.changeAcquireMode(dfrCO.PASSIVITY); @@ -1591,7 +1591,7 @@ void Sensors::DFRobotCOInit() { void Sensors::DFRobotNH3Init() { sensorAnnounce(SENSORS::SDFRNH3); - dfrNH3 = DFRobot_GAS_I2C(&Wire, 0x7A); // 0x77 y 0x75 used by bme680 + dfrNH3 = DFRobot_GAS_I2C(&Wire, 0x7A); // 0x77 y 0x75 used by bme680. Be sure that your group of i2c address is 7 if (!dfrNH3.begin()) return; //Mode of obtaining data: the main controller needs to request the sensor for data dfrNH3.changeAcquireMode(dfrNH3.PASSIVITY);