Skip to content

Commit

Permalink
Merge pull request #28 from m5stack/develop
Browse files Browse the repository at this point in the history
Fixes compile errors in PlatformIO for existing examples, Prepare for Unit-CO2L, Add ENVIV and refactor QMP6988
  • Loading branch information
imliubo authored Dec 10, 2024
2 parents 06df399 + f9a79c7 commit d576302
Show file tree
Hide file tree
Showing 30 changed files with 4,282 additions and 1,448 deletions.
1 change: 1 addition & 0 deletions .github/workflows/arduino-esp-v2-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
unit:
- UnitCO2
- UnitENVIII
- UnitENVIV
- UnitTVOC
- UnitENVPro

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/arduino-esp-v3-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
unit:
- UnitCO2
- UnitENVIII
- UnitENVIV
- UnitTVOC
- UnitENVPro

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/arduino-m5-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
unit:
- UnitCO2
- UnitENVIII
- UnitENVIV
- UnitTVOC
- UnitENVPro

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/platformio-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
unit:
- UnitCO2
- UnitENVIII
- UnitENVIV
- UnitTVOC
- UnitENVPro

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// #define USING_SINGLE_SHOT

// Using combined unit if defined
// #define USING_ENV3
#define USING_ENV3

namespace {
auto& lcd = M5.Display;
Expand Down Expand Up @@ -61,15 +61,6 @@ void setup()
}
#endif

{
auto cfg = qmp6988.config();
cfg.oversampling_temperature = m5::unit::qmp6988::Oversampling::X1;
cfg.oversampling_pressure = m5::unit::qmp6988::Oversampling::X1;
cfg.filter = m5::unit::qmp6988::Filter::Coeff16;
cfg.standby_time = m5::unit::qmp6988::Standby::Time1ms;
qmp6988.config(cfg);
}

#if defined(USING_ENV3)
#if defined(USING_M5HAL)
#pragma message "Using M5HAL"
Expand Down
11 changes: 11 additions & 0 deletions examples/UnitUnified/UnitENVIV/PlotToSerial/PlotToSerial.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
/*
Example using M5UnitUnified for UnitENVIV
Required
- M5Unified: https://github.com/m5stack/M5Unified
*/
#include "main/PlotToSerial.cpp"
107 changes: 107 additions & 0 deletions examples/UnitUnified/UnitENVIV/PlotToSerial/main/PlotToSerial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
/*
Example using M5UnitUnified for UnitENVIV
*/
#include <M5Unified.h>
#include <M5UnitUnified.h>
#include <M5UnitUnifiedENV.h>
#include <cmath>

#define USING_ENV4

namespace {
auto& lcd = M5.Display;
m5::unit::UnitUnified Units;

#if defined(USING_ENV4)
#pragma message "Using combined unit(ENV4)"
m5::unit::UnitENV4 unitENV4;
#else
#pragma message "Using each unit"
m5::unit::UnitSHT40 unitSHT40;
m5::unit::UnitBMP280 unitBMP280;
#endif

#if defined(USING_ENV4)
auto& sht40 = unitENV4.sht40;
auto& bmp280 = unitENV4.bmp280;
#else
auto& sht40 = unitSHT40;
auto& bmp280 = unitBMP280;
#endif

float calculate_altitude(const float pressure, const float seaLvhPa = 1013.25f)
{
return 44330.f * (1.0f - pow((pressure / 100.f) / seaLvhPa, 0.1903f));
}

} // namespace

void setup()
{
M5.begin();

auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda);
auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl);
M5_LOGI("getPin: SDA:%u SCL:%u", pin_num_sda, pin_num_scl);

{
using namespace m5::unit::bmp280;
auto cfg = bmp280.config();
cfg.osrs_pressure = Oversampling::X16;
cfg.osrs_temperature = Oversampling::X2;
cfg.filter = Filter::Coeff16;
cfg.standby = Standby::Time500ms;
bmp280.config(cfg);
}

#if defined(USING_ENV4)
Wire.begin(pin_num_sda, pin_num_scl, 400000U);

if (!Units.add(unitENV4, Wire) || !Units.begin()) {
M5_LOGE("Failed to begin");
lcd.clear(TFT_RED);
while (true) {
m5::utility::delay(10000);
}
}
#else
Wire.begin(pin_num_sda, pin_num_scl, 400000U);
if (!Units.add(unitSHT40, Wire) || !Units.add(unitBMP280, Wire) || !Units.begin()) {
M5_LOGE("Failed to begin");
lcd.clear(TFT_RED);
while (true) {
m5::utility::delay(10000);
}
}
#endif

M5_LOGI("M5UnitUnified has been begun");
M5_LOGI("%s", Units.debugInfo().c_str());
lcd.clear(TFT_DARKGREEN);
}

void loop()
{
M5.update();
Units.update();

if (sht40.updated()) {
M5_LOGI(
"\n>SHT40Temp:%.4f\n"
">Humidity:%.4f",
sht40.temperature(), sht40.humidity());
}
if (bmp280.updated()) {
auto p = bmp280.pressure();
M5_LOGI(
"\n>BMP280Temp:%.4f\n"
">Pressure:%.4f\n"
">Altitude:%.4f",
bmp280.temperature(), p * 0.01f /* To hPa */, calculate_altitude(p));
}
}
5 changes: 3 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
},
"dependencies": {
"M5UnitUnified": "https://github.com/m5stack/M5UnitUnified.git",
"BME68x Sensor library": "https://github.com/boschsensortec/Bosch-BME68x-Library.git#v1.2.40408"
"BME68x Sensor library": "https://github.com/boschsensortec/Bosch-BME68x-Library.git",
"bsec2": "https://github.com/boschsensortec/Bosch-BSEC2-Library"
},
"version": "1.1.1",
"version": "1.2.0",
"frameworks": [
"arduino"
],
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=M5Unit-ENV
version=1.1.1
version=1.2.0
author=M5Stack
maintainer=M5Stack
sentence=Library for M5Stack UNIT ENV
Expand Down
Loading

0 comments on commit d576302

Please sign in to comment.