From 97c0d11783e42298b8460a0a92a66154f50d8877 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Thu, 7 Mar 2024 12:46:39 -0500 Subject: [PATCH 1/9] added basic and initial support for M5AirQ SCD40 sensor --- examples/m5airq/platformio.ini | 31 ++++++++++++ examples/m5airq/src/main.cpp | 86 ++++++++++++++++++++++++++++++++++ src/Sensors.cpp | 9 +++- src/Sensors.hpp | 8 ++++ 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 examples/m5airq/platformio.ini create mode 100644 examples/m5airq/src/main.cpp diff --git a/examples/m5airq/platformio.ini b/examples/m5airq/platformio.ini new file mode 100644 index 00000000..9024a223 --- /dev/null +++ b/examples/m5airq/platformio.ini @@ -0,0 +1,31 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[platformio] +src_dir = . +lib_dir = ../.. +extra_configs = ../../unified-lib-deps.ini + +[env] +framework = arduino +upload_speed = 1500000 +monitor_speed = 115200 +build_flags = + -D CORE_DEBUG_LEVEL=0 + -D ARDUINO_USB_CDC_ON_BOOT=1 + -D ARDUINO_ESP32_DEV=1 + -D M5AIRQ=1 +lib_deps = ${commonlibs.lib_deps} + +[env:m5airq] +extends = env +platform = espressif32 +board = esp32-s3-devkitc-1 +board_build.filesystem = littlefs diff --git a/examples/m5airq/src/main.cpp b/examples/m5airq/src/main.cpp new file mode 100644 index 00000000..0dc8e70a --- /dev/null +++ b/examples/m5airq/src/main.cpp @@ -0,0 +1,86 @@ +/** + * @file main.cpp + * @author Antonio Vanegas @hpsaturn + * @date June 2018 - 2024 + * @brief CanAirIO M5AirQ test + * @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 documentation: + * https://canair.io/docs + */ + +#include +#include + +#define MAIN_HW_EN_PIN 10 // M5AirQ sensor hardware enable + +void printSensorsDetected() { + uint16_t sensors_count = sensors.getSensorsRegisteredCount(); + uint16_t units_count = sensors.getUnitsRegisteredCount(); + Serial.println("-->[MAIN] Sensors detected count\t: " + String(sensors_count)); + Serial.println("-->[MAIN] Sensors units count \t: " + String(units_count)); + Serial.print( "-->[MAIN] Sensors devices names\t: "); + int i = 0; + while (sensors.getSensorsRegistered()[i++] != 0) { + Serial.print(sensors.getSensorName((SENSORS)sensors.getSensorsRegistered()[i - 1])); + Serial.print(","); + } + Serial.println(); +} + +void printSensorsValues() { + Serial.println("-->[MAIN] Preview sensor values:"); + UNIT unit = sensors.getNextUnit(); + while(unit != UNIT::NUNIT) { + String uName = sensors.getUnitName(unit); + float uValue = sensors.getUnitValue(unit); + String uSymb = sensors.getUnitSymbol(unit); + Serial.printf("-->[MAIN] %s:\t%02.1f\t%s\n", uName.c_str(), uValue, uSymb.c_str()); + unit = sensors.getNextUnit(); + } +} + +void onSensorDataOk() { + Serial.println("======= E X A M P L E T E S T ========="); + printSensorsDetected(); + printSensorsValues(); +} + +void onSensorDataError(const char * msg){ +} +/****************************************************************************** +* M A I N +******************************************************************************/ + +void powerEnableSensors() { + Serial.println("-->[POWR] == enable sensors =="); + pinMode(MAIN_HW_EN_PIN, OUTPUT); + digitalWrite(MAIN_HW_EN_PIN, HIGH); // step-up on +} + +void setup() { + Serial.begin(115200); + delay(2000); // Only for debugging + powerEnableSensors(); // M5AirQ enable sensors + delay(100); + Serial.println("\n== Sensor test setup ==\n"); + Serial.println("-->[SETUP] Detecting sensors.."); + + sensors.setSampleTime(10); // config sensors sample time interval + sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback + sensors.setDebugMode(false); // [optional] debug mode + sensors.detectI2COnly(false); // not force to only i2c sensors + sensors.setTemperatureUnit(TEMPUNIT::CELSIUS); // comment for Celsius or set Fahrenheit + sensors.init(); // Auto detection (UART and i2c sensors) + delay(1000); +} + +void loop() { + sensors.loop(); // read sensor data and showed it +} diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 5bed7daf..7e2d65b9 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -1956,8 +1956,15 @@ void Sensors::startI2C() { #ifdef M5ATOM enableWire1(); #endif +#ifdef M5AIRQ + Serial.println("-->[SLIB] M5AIRQ I2C enable"); + pinMode(GROVE_SDA, OUTPUT); + pinMode(GROVE_SCL, OUTPUT); + Wire.begin(I2C1_SDA_PIN, I2C1_SCL_PIN); + // enableWire1(); +#endif #if not defined(M5STICKCPLUS) && not defined(M5COREINK) && not defined(M5ATOM) && \ - not defined(ESP32C3) + not defined(ESP32C3) && not defined(M5AIRQ) Wire.begin(); #endif #ifdef ESP32C3 diff --git a/src/Sensors.hpp b/src/Sensors.hpp index be2ce711..30b3a5a5 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -81,6 +81,14 @@ #define EXT_I2C_SDA 32 #define EXT_I2C_SCL 33 +#ifdef M5AIRQ +#define GROVE_SDA 13 +#define GROVE_SCL 15 + +#define I2C1_SDA_PIN 11 +#define I2C1_SCL_PIN 12 +#endif + // Read UART sensor retry. #define SENSOR_RETRY 1000 // Max Serial characters From e0fa841c8d118b8cb981c4036368c7030a6f8423 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Thu, 7 Mar 2024 13:27:32 -0500 Subject: [PATCH 2/9] removed Wire initialization. The user should do that. Please check! --- src/Sensors.cpp | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 7e2d65b9..5a4e60af 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -1738,11 +1738,7 @@ void Sensors::setSCD4xAltitudeOffset(float offset) { /// Panasonic SEN5X sensor init void Sensors::sen5xInit() { sensorAnnounce(SENSORS::SSEN5X); -#ifndef Wire1 sen5x.begin(Wire); -#else - sen5x.begin(Wire1); -#endif uint16_t error; error = sen5x.deviceReset(); if (error) return; @@ -1956,17 +1952,6 @@ void Sensors::startI2C() { #ifdef M5ATOM enableWire1(); #endif -#ifdef M5AIRQ - Serial.println("-->[SLIB] M5AIRQ I2C enable"); - pinMode(GROVE_SDA, OUTPUT); - pinMode(GROVE_SCL, OUTPUT); - Wire.begin(I2C1_SDA_PIN, I2C1_SCL_PIN); - // enableWire1(); -#endif -#if not defined(M5STICKCPLUS) && not defined(M5COREINK) && not defined(M5ATOM) && \ - not defined(ESP32C3) && not defined(M5AIRQ) - Wire.begin(); -#endif #ifdef ESP32C3 Wire.begin(19, 18); #endif From ba50613994ed69aa710d4c46088fcdd8bfb8ed43 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Thu, 7 Mar 2024 13:28:00 -0500 Subject: [PATCH 3/9] fixed SEN5X init issue (bad pin level choosed) --- examples/m5airq/platformio.ini | 8 +++++--- examples/m5airq/src/main.cpp | 25 +++++++++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/examples/m5airq/platformio.ini b/examples/m5airq/platformio.ini index 9024a223..5a7a8512 100644 --- a/examples/m5airq/platformio.ini +++ b/examples/m5airq/platformio.ini @@ -21,11 +21,13 @@ build_flags = -D CORE_DEBUG_LEVEL=0 -D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_ESP32_DEV=1 - -D M5AIRQ=1 -lib_deps = ${commonlibs.lib_deps} + -D M5AIRQ=1 ; in your implementation you NEED it (it will improved in the future) +lib_deps = + ${commonlibs.lib_deps} + tanakamasayuki/I2C BM8563 RTC@^1.0.4 [env:m5airq] extends = env platform = espressif32 board = esp32-s3-devkitc-1 -board_build.filesystem = littlefs +board_build.filesystem = littlefs ; compatibility with original demo firmware diff --git a/examples/m5airq/src/main.cpp b/examples/m5airq/src/main.cpp index 0dc8e70a..cabea9d4 100644 --- a/examples/m5airq/src/main.cpp +++ b/examples/m5airq/src/main.cpp @@ -17,8 +17,19 @@ #include #include +#include -#define MAIN_HW_EN_PIN 10 // M5AirQ sensor hardware enable +#define POWER_HOLD 46 // M5AirQ main board +#define SEN55_POWER_EN 10 + +#define GROVE_SDA 13 +#define GROVE_SCL 15 + +#define I2C1_SDA_PIN 11 +#define I2C1_SCL_PIN 12 + + +I2C_BM8563 bm8563(I2C_BM8563_DEFAULT_ADDRESS, Wire); void printSensorsDetected() { uint16_t sensors_count = sensors.getSensorsRegisteredCount(); @@ -60,21 +71,27 @@ void onSensorDataError(const char * msg){ void powerEnableSensors() { Serial.println("-->[POWR] == enable sensors =="); - pinMode(MAIN_HW_EN_PIN, OUTPUT); - digitalWrite(MAIN_HW_EN_PIN, HIGH); // step-up on + pinMode(POWER_HOLD, OUTPUT); + digitalWrite(POWER_HOLD, HIGH); + pinMode(SEN55_POWER_EN, OUTPUT); + digitalWrite(SEN55_POWER_EN, LOW); } void setup() { Serial.begin(115200); delay(2000); // Only for debugging powerEnableSensors(); // M5AirQ enable sensors + Wire.begin(I2C1_SDA_PIN, I2C1_SCL_PIN); + Serial.println("-->[SETUP] RTC(BM8563) init"); + bm8563.begin(); + bm8563.clearIRQ(); delay(100); Serial.println("\n== Sensor test setup ==\n"); Serial.println("-->[SETUP] Detecting sensors.."); sensors.setSampleTime(10); // config sensors sample time interval sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback - sensors.setDebugMode(false); // [optional] debug mode + sensors.setDebugMode(true); // [optional] debug mode sensors.detectI2COnly(false); // not force to only i2c sensors sensors.setTemperatureUnit(TEMPUNIT::CELSIUS); // comment for Celsius or set Fahrenheit sensors.init(); // Auto detection (UART and i2c sensors) From 9b38f52f152df15aaad32932574e8a5549138d08 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Thu, 7 Mar 2024 14:36:44 -0500 Subject: [PATCH 4/9] fixed issue on sen5x read. Added startMeasure call --- examples/m5airq/src/main.cpp | 4 ++-- src/Sensors.cpp | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/examples/m5airq/src/main.cpp b/examples/m5airq/src/main.cpp index cabea9d4..9ecaeab5 100644 --- a/examples/m5airq/src/main.cpp +++ b/examples/m5airq/src/main.cpp @@ -34,7 +34,7 @@ I2C_BM8563 bm8563(I2C_BM8563_DEFAULT_ADDRESS, Wire); void printSensorsDetected() { uint16_t sensors_count = sensors.getSensorsRegisteredCount(); uint16_t units_count = sensors.getUnitsRegisteredCount(); - Serial.println("-->[MAIN] Sensors detected count\t: " + String(sensors_count)); + Serial.println("-->[MAIN] Sensors detected \t: " + String(sensors_count)); Serial.println("-->[MAIN] Sensors units count \t: " + String(units_count)); Serial.print( "-->[MAIN] Sensors devices names\t: "); int i = 0; @@ -52,7 +52,7 @@ void printSensorsValues() { String uName = sensors.getUnitName(unit); float uValue = sensors.getUnitValue(unit); String uSymb = sensors.getUnitSymbol(unit); - Serial.printf("-->[MAIN] %s:\t%02.1f\t%s\n", uName.c_str(), uValue, uSymb.c_str()); + Serial.printf("-->[MAIN] %6s:\t%02.1f\t%s\n", uName.c_str(), uValue, uSymb.c_str()); unit = sensors.getNextUnit(); } } diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 5a4e60af..b4068253 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -66,7 +66,6 @@ bool Sensors::readAllSensors() { } enableWire1(); - sen5xRead(); CO2scd30Read(); GCJA5Read(); sps30Read(); @@ -1068,12 +1067,15 @@ void Sensors::sen5xRead() { massConcentrationPm1p0, massConcentrationPm2p5, massConcentrationPm4p0, massConcentrationPm10p0, ambientHumidity, ambientTemperature, vocIndex, noxIndex); - if (error) return; + if (error) { + DEBUG("[E][SLIB] SEN5x read error!"); + return; + } - pm1 = massConcentrationPm1p0; - pm25 = massConcentrationPm2p5; - pm4 = massConcentrationPm4p0; - pm10 = massConcentrationPm4p0; + pm1 = (u_int16_t) massConcentrationPm1p0; + pm25 = (u_int16_t) massConcentrationPm2p5; + pm4 = (u_int16_t) massConcentrationPm4p0; + pm10 = (u_int16_t) massConcentrationPm4p0; temp = ambientTemperature; humi = ambientHumidity; dataReady = true; @@ -1749,6 +1751,12 @@ void Sensors::sen5xInit() { sen5x.setTemperatureOffsetSimple(toffset); delay(10); } + /** Start Measurement */ + error = sen5x.startMeasurement(); + if (error) { + DEBUG("[E][SLIB] Error trying to execute startMeasurement():"); + return; + } sensorRegister(SENSORS::SSEN5X); } From d19b2dd74fee72d00b4a4d3506185cf726bb213a Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Thu, 7 Mar 2024 14:56:32 -0500 Subject: [PATCH 5/9] clang format and minors refators --- examples/m5airq/src/main.cpp | 113 +++++++++++++++++------------------ src/Sensors.cpp | 5 +- 2 files changed, 56 insertions(+), 62 deletions(-) diff --git a/examples/m5airq/src/main.cpp b/examples/m5airq/src/main.cpp index 9ecaeab5..2f58242d 100644 --- a/examples/m5airq/src/main.cpp +++ b/examples/m5airq/src/main.cpp @@ -4,22 +4,22 @@ * @date June 2018 - 2024 * @brief CanAirIO M5AirQ test * @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 documentation: * https://canair.io/docs */ #include + #include -#include -#define POWER_HOLD 46 // M5AirQ main board +#define POWER_HOLD 46 // M5AirQ main board #define SEN55_POWER_EN 10 #define GROVE_SDA 13 @@ -28,76 +28,71 @@ #define I2C1_SDA_PIN 11 #define I2C1_SCL_PIN 12 - -I2C_BM8563 bm8563(I2C_BM8563_DEFAULT_ADDRESS, Wire); - void printSensorsDetected() { - uint16_t sensors_count = sensors.getSensorsRegisteredCount(); - uint16_t units_count = sensors.getUnitsRegisteredCount(); - Serial.println("-->[MAIN] Sensors detected \t: " + String(sensors_count)); - Serial.println("-->[MAIN] Sensors units count \t: " + String(units_count)); - Serial.print( "-->[MAIN] Sensors devices names\t: "); - int i = 0; - while (sensors.getSensorsRegistered()[i++] != 0) { - Serial.print(sensors.getSensorName((SENSORS)sensors.getSensorsRegistered()[i - 1])); - Serial.print(","); - } - Serial.println(); + uint16_t sensors_count = sensors.getSensorsRegisteredCount(); + uint16_t units_count = sensors.getUnitsRegisteredCount(); + Serial.println("-->[MAIN] Sensors detected \t: " + String(sensors_count)); + Serial.println("-->[MAIN] Sensors units count \t: " + String(units_count)); + Serial.print("-->[MAIN] Sensors devices names\t: "); + int i = 0; + while (sensors.getSensorsRegistered()[i++] != 0) { + Serial.print(sensors.getSensorName((SENSORS)sensors.getSensorsRegistered()[i - 1])); + Serial.print(","); + } + Serial.println(); } void printSensorsValues() { - Serial.println("-->[MAIN] Preview sensor values:"); - UNIT unit = sensors.getNextUnit(); - while(unit != UNIT::NUNIT) { - String uName = sensors.getUnitName(unit); - float uValue = sensors.getUnitValue(unit); - String uSymb = sensors.getUnitSymbol(unit); - Serial.printf("-->[MAIN] %6s:\t%02.1f\t%s\n", uName.c_str(), uValue, uSymb.c_str()); - unit = sensors.getNextUnit(); - } + Serial.println("-->[MAIN] Preview sensor values:"); + UNIT unit = sensors.getNextUnit(); + while (unit != UNIT::NUNIT) { + String uName = sensors.getUnitName(unit); + float uValue = sensors.getUnitValue(unit); + String uSymb = sensors.getUnitSymbol(unit); + Serial.printf("-->[MAIN] %6s:\t%02.1f\t%s\n", uName.c_str(), uValue, uSymb.c_str()); + unit = sensors.getNextUnit(); + } } void onSensorDataOk() { - Serial.println("======= E X A M P L E T E S T ========="); - printSensorsDetected(); - printSensorsValues(); + Serial.println("======= E X A M P L E T E S T ========="); + printSensorsDetected(); + printSensorsValues(); } -void onSensorDataError(const char * msg){ -} +void onSensorDataError(const char* msg) {} /****************************************************************************** -* M A I N -******************************************************************************/ + * M A I N + ******************************************************************************/ void powerEnableSensors() { - Serial.println("-->[POWR] == enable sensors =="); - pinMode(POWER_HOLD, OUTPUT); - digitalWrite(POWER_HOLD, HIGH); - pinMode(SEN55_POWER_EN, OUTPUT); - digitalWrite(SEN55_POWER_EN, LOW); + Serial.println("-->[POWR] == enable sensors =="); + pinMode(POWER_HOLD, OUTPUT); + digitalWrite(POWER_HOLD, HIGH); + pinMode(SEN55_POWER_EN, OUTPUT); + digitalWrite(SEN55_POWER_EN, LOW); } void setup() { - Serial.begin(115200); - delay(2000); // Only for debugging - powerEnableSensors(); // M5AirQ enable sensors - Wire.begin(I2C1_SDA_PIN, I2C1_SCL_PIN); - Serial.println("-->[SETUP] RTC(BM8563) init"); - bm8563.begin(); - bm8563.clearIRQ(); - delay(100); - Serial.println("\n== Sensor test setup ==\n"); - Serial.println("-->[SETUP] Detecting sensors.."); - - sensors.setSampleTime(10); // config sensors sample time interval - sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback - sensors.setDebugMode(true); // [optional] debug mode - sensors.detectI2COnly(false); // not force to only i2c sensors - sensors.setTemperatureUnit(TEMPUNIT::CELSIUS); // comment for Celsius or set Fahrenheit - sensors.init(); // Auto detection (UART and i2c sensors) - delay(1000); + Serial.begin(115200); + delay(2000); // Only for debugging + powerEnableSensors(); // M5AirQ enable sensors + + Wire.begin(I2C1_SDA_PIN, I2C1_SCL_PIN); + + delay(100); + Serial.println("\n== Sensor test setup ==\n"); + Serial.println("-->[SETUP] Detecting sensors.."); + + sensors.setSampleTime(10); // config sensors sample time interval + sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback + sensors.setDebugMode(true); // [optional] debug mode + sensors.detectI2COnly(false); // not force to only i2c sensors + sensors.setTemperatureUnit(TEMPUNIT::CELSIUS); // comment for Celsius or set Fahrenheit + sensors.init(); // Auto detection (UART and i2c sensors) + delay(1000); } void loop() { - sensors.loop(); // read sensor data and showed it + sensors.loop(); // read sensor data and showed it } diff --git a/src/Sensors.cpp b/src/Sensors.cpp index b4068253..69132360 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -1745,13 +1745,12 @@ void Sensors::sen5xInit() { error = sen5x.deviceReset(); if (error) return; float tempOffset = 0.0; - DEBUG("-->[SLIB] SEN5X Temp offset\t:", - String(sen5x.getTemperatureOffsetSimple(tempOffset)).c_str()); + sen5x.getTemperatureOffsetSimple(tempOffset); + DEBUG("-->[SLIB] SEN5X Temp offset\t:", String(tempOffset).c_str()); if (uint16_t((tempOffset * 100)) != (uint16_t(toffset * 100))) { sen5x.setTemperatureOffsetSimple(toffset); delay(10); } - /** Start Measurement */ error = sen5x.startMeasurement(); if (error) { DEBUG("[E][SLIB] Error trying to execute startMeasurement():"); From 130b12671ba5fd82f2bdb95746692728d71d9445 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Thu, 7 Mar 2024 14:57:43 -0500 Subject: [PATCH 6/9] removed unnecesary libraries --- examples/m5airq/platformio.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/m5airq/platformio.ini b/examples/m5airq/platformio.ini index 5a7a8512..2e6a89a5 100644 --- a/examples/m5airq/platformio.ini +++ b/examples/m5airq/platformio.ini @@ -24,7 +24,6 @@ build_flags = -D M5AIRQ=1 ; in your implementation you NEED it (it will improved in the future) lib_deps = ${commonlibs.lib_deps} - tanakamasayuki/I2C BM8563 RTC@^1.0.4 [env:m5airq] extends = env From 540ed6f4b51e308e22380728b714916a0462e020 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Thu, 7 Mar 2024 16:05:17 -0500 Subject: [PATCH 7/9] added missing variables from sen5x sensor. New units: voci and noxi --- src/Sensors.cpp | 14 +++++++++----- src/Sensors.hpp | 6 +++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 69132360..60ee645a 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -1070,12 +1070,14 @@ void Sensors::sen5xRead() { if (error) { DEBUG("[E][SLIB] SEN5x read error!"); return; - } + } - pm1 = (u_int16_t) massConcentrationPm1p0; - pm25 = (u_int16_t) massConcentrationPm2p5; - pm4 = (u_int16_t) massConcentrationPm4p0; - pm10 = (u_int16_t) massConcentrationPm4p0; + pm1 = (u_int16_t)massConcentrationPm1p0; + pm25 = (u_int16_t)massConcentrationPm2p5; + pm4 = (u_int16_t)massConcentrationPm4p0; + pm10 = (u_int16_t)massConcentrationPm4p0; + voci = vocIndex; + noxi = noxIndex; temp = ambientTemperature; humi = ambientHumidity; dataReady = true; @@ -1086,6 +1088,8 @@ void Sensors::sen5xRead() { unitRegister(UNIT::PM10); unitRegister(UNIT::TEMP); unitRegister(UNIT::HUM); + unitRegister(UNIT::VOCI); + unitRegister(UNIT::NOXI); } void Sensors::GCJA5Read() { diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 30b3a5a5..069ff234 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -119,6 +119,8 @@ X(NH3, "ppm", "NH3") \ X(CO, "ppm", "CO") \ X(NO2, "ppm", "NO2") \ + X(NOXI, "noxi", "NOXI") \ + X(VOCI, "voci", "VOCI") \ X(UCOUNT, "COUNT", "UCOUNT") #define X(unit, symbol, name) unit, @@ -399,7 +401,9 @@ 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; + float voci = 0.0; + float noxi = 0.0; // temperature unit (C,K,F) TEMPUNIT temp_unit = TEMPUNIT::CELSIUS; From 375a48a8ba3d2b8f1ffb9b58eb3f50addef71044 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Thu, 7 Mar 2024 16:07:49 -0500 Subject: [PATCH 8/9] fixed some clang issues --- src/Sensors.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sensors.hpp b/src/Sensors.hpp index 069ff234..b0181307 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -119,8 +119,8 @@ X(NH3, "ppm", "NH3") \ X(CO, "ppm", "CO") \ X(NO2, "ppm", "NO2") \ - X(NOXI, "noxi", "NOXI") \ - X(VOCI, "voci", "VOCI") \ + X(NOXI, "noxi", "NOXI") \ + X(VOCI, "voci", "VOCI") \ X(UCOUNT, "COUNT", "UCOUNT") #define X(unit, symbol, name) unit, From 689712bfd16ceb1b2806465843329c22ca59bd7c Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Thu, 7 Mar 2024 20:19:37 -0500 Subject: [PATCH 9/9] improved i2c init for M5AIRQ variant --- examples/m5airq/platformio.ini | 2 +- examples/m5airq/src/main.cpp | 12 +++++------- src/Sensors.cpp | 8 ++++++++ src/Sensors.hpp | 1 - 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/examples/m5airq/platformio.ini b/examples/m5airq/platformio.ini index 2e6a89a5..e7785bd0 100644 --- a/examples/m5airq/platformio.ini +++ b/examples/m5airq/platformio.ini @@ -18,7 +18,7 @@ framework = arduino upload_speed = 1500000 monitor_speed = 115200 build_flags = - -D CORE_DEBUG_LEVEL=0 + -D CORE_DEBUG_LEVEL=0 -D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_ESP32_DEV=1 -D M5AIRQ=1 ; in your implementation you NEED it (it will improved in the future) diff --git a/examples/m5airq/src/main.cpp b/examples/m5airq/src/main.cpp index 2f58242d..91be28f3 100644 --- a/examples/m5airq/src/main.cpp +++ b/examples/m5airq/src/main.cpp @@ -31,8 +31,8 @@ void printSensorsDetected() { uint16_t sensors_count = sensors.getSensorsRegisteredCount(); uint16_t units_count = sensors.getUnitsRegisteredCount(); - Serial.println("-->[MAIN] Sensors detected \t: " + String(sensors_count)); - Serial.println("-->[MAIN] Sensors units count \t: " + String(units_count)); + Serial.println("-->[MAIN] Sensors detected \t: " + String(sensors_count)); + Serial.println("-->[MAIN] Sensors units count\t: " + String(units_count)); Serial.print("-->[MAIN] Sensors devices names\t: "); int i = 0; while (sensors.getSensorsRegistered()[i++] != 0) { @@ -43,7 +43,7 @@ void printSensorsDetected() { } void printSensorsValues() { - Serial.println("-->[MAIN] Preview sensor values:"); + Serial.println("-->[MAIN] Preview sensor values :"); UNIT unit = sensors.getNextUnit(); while (unit != UNIT::NUNIT) { String uName = sensors.getUnitName(unit); @@ -78,16 +78,14 @@ void setup() { delay(2000); // Only for debugging powerEnableSensors(); // M5AirQ enable sensors - Wire.begin(I2C1_SDA_PIN, I2C1_SCL_PIN); - delay(100); Serial.println("\n== Sensor test setup ==\n"); Serial.println("-->[SETUP] Detecting sensors.."); sensors.setSampleTime(10); // config sensors sample time interval sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback - sensors.setDebugMode(true); // [optional] debug mode - sensors.detectI2COnly(false); // not force to only i2c sensors + sensors.setDebugMode(false); // [optional] debug mode + sensors.detectI2COnly(true); // not force to only i2c sensors sensors.setTemperatureUnit(TEMPUNIT::CELSIUS); // comment for Celsius or set Fahrenheit sensors.init(); // Auto detection (UART and i2c sensors) delay(1000); diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 60ee645a..d156d88b 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -1966,6 +1966,10 @@ void Sensors::startI2C() { #ifdef ESP32C3 Wire.begin(19, 18); #endif +#ifdef M5AIRQ + Wire.begin(I2C1_SDA_PIN, I2C1_SCL_PIN); + enableWire1(); +#endif } void Sensors::enableWire1() { @@ -1981,6 +1985,10 @@ void Sensors::enableWire1() { Wire1.flush(); Wire1.begin(26, 32); // M5CoreInk Ext port (default for all sensors) #endif +#ifdef M5AIRQ + Wire1.flush(); + Wire1.begin(GROVE_SDA, GROVE_SCL); +#endif } void Sensors::disableWire1() { diff --git a/src/Sensors.hpp b/src/Sensors.hpp index b0181307..e55937df 100644 --- a/src/Sensors.hpp +++ b/src/Sensors.hpp @@ -84,7 +84,6 @@ #ifdef M5AIRQ #define GROVE_SDA 13 #define GROVE_SCL 15 - #define I2C1_SDA_PIN 11 #define I2C1_SCL_PIN 12 #endif