first commit
This commit is contained in:
commit
5893b00dd2
1669 changed files with 1982740 additions and 0 deletions
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
Example using M5UnitUnified for UnitCO2
|
||||
Required
|
||||
- M5Unified: https://github.com/m5stack/M5Unified
|
||||
*/
|
||||
#include "main/PlotToSerial.cpp"
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
Example using M5UnitUnified for UnitCO2
|
||||
*/
|
||||
// #define USING_M5HAL // When using M5HAL
|
||||
#include <M5Unified.h>
|
||||
#include <M5UnitUnified.h>
|
||||
#include <M5UnitUnifiedENV.h>
|
||||
|
||||
namespace {
|
||||
auto& lcd = M5.Display;
|
||||
m5::unit::UnitUnified Units;
|
||||
m5::unit::UnitCO2 unit;
|
||||
} // 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);
|
||||
|
||||
#if defined(USING_M5HAL)
|
||||
#pragma message "Using M5HAL"
|
||||
// Using M5HAL
|
||||
m5::hal::bus::I2CBusConfig i2c_cfg;
|
||||
i2c_cfg.pin_sda = m5::hal::gpio::getPin(pin_num_sda);
|
||||
i2c_cfg.pin_scl = m5::hal::gpio::getPin(pin_num_scl);
|
||||
auto i2c_bus = m5::hal::bus::i2c::getBus(i2c_cfg);
|
||||
if (!Units.add(unit, i2c_bus ? i2c_bus.value() : nullptr) || !Units.begin()) {
|
||||
M5_LOGE("Failed to begin");
|
||||
lcd.clear(TFT_RED);
|
||||
while (true) {
|
||||
m5::utility::delay(10000);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#pragma message "Using Wire"
|
||||
// Using TwoWire
|
||||
Wire.end();
|
||||
Wire.begin(pin_num_sda, pin_num_scl, 400000U);
|
||||
if (!Units.add(unit, 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());
|
||||
|
||||
{
|
||||
auto ret = unit.stopPeriodicMeasurement();
|
||||
float offset{};
|
||||
ret &= unit.readTemperatureOffset(offset);
|
||||
uint16_t altitude{};
|
||||
ret &= unit.readSensorAltitude(altitude);
|
||||
uint16_t pressure{};
|
||||
ret &= unit.readAmbientPressure(pressure);
|
||||
bool asc{};
|
||||
ret &= unit.readAutomaticSelfCalibrationEnabled(asc);
|
||||
uint16_t ppm{};
|
||||
ret &= unit.readAutomaticSelfCalibrationTarget(ppm);
|
||||
ret &= unit.startPeriodicMeasurement();
|
||||
|
||||
M5.Log.printf(
|
||||
" temp offset:%f\n"
|
||||
" sensor altitude:%u\n"
|
||||
"ambient pressure:%u\n"
|
||||
" ASC enabled:%u\n"
|
||||
" ASC target:%u\n",
|
||||
offset, altitude, pressure, asc, ppm);
|
||||
|
||||
if (!ret) {
|
||||
lcd.clear(TFT_RED);
|
||||
while (true) {
|
||||
m5::utility::delay(10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
lcd.clear(TFT_DARKGREEN);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
M5.update();
|
||||
Units.update();
|
||||
if (unit.updated()) {
|
||||
// Can be checked e.g. by serial plotters
|
||||
M5.Log.printf(">CO2:%u\n>Temperature:%2.2f\n>Humidity:%2.2f\n", unit.co2(), unit.temperature(),
|
||||
unit.humidity());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
Example using M5UnitUnified for UnitCO2L
|
||||
Required
|
||||
- M5Unified: https://github.com/m5stack/M5Unified
|
||||
*/
|
||||
#include "main/PlotToSerial.cpp"
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
Example using M5UnitUnified for UnitCO2L
|
||||
*/
|
||||
// #define USING_M5HAL // When using M5HAL
|
||||
#include <M5Unified.h>
|
||||
#include <M5UnitUnified.h>
|
||||
#include <M5UnitUnifiedENV.h>
|
||||
|
||||
namespace {
|
||||
auto& lcd = M5.Display;
|
||||
m5::unit::UnitUnified Units;
|
||||
m5::unit::UnitCO2L unit;
|
||||
|
||||
} // namespace
|
||||
|
||||
using namespace m5::unit::scd4x;
|
||||
|
||||
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);
|
||||
|
||||
#if defined(USING_M5HAL)
|
||||
#pragma message "Using M5HAL"
|
||||
// Using M5HAL
|
||||
m5::hal::bus::I2CBusConfig i2c_cfg;
|
||||
i2c_cfg.pin_sda = m5::hal::gpio::getPin(pin_num_sda);
|
||||
i2c_cfg.pin_scl = m5::hal::gpio::getPin(pin_num_scl);
|
||||
auto i2c_bus = m5::hal::bus::i2c::getBus(i2c_cfg);
|
||||
if (!Units.add(unit, i2c_bus ? i2c_bus.value() : nullptr) || !Units.begin()) {
|
||||
M5_LOGE("Failed to begin");
|
||||
lcd.clear(TFT_RED);
|
||||
while (true) {
|
||||
m5::utility::delay(10000);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#pragma message "Using Wire"
|
||||
// Using TwoWire
|
||||
Wire.end();
|
||||
Wire.begin(pin_num_sda, pin_num_scl, 400000U);
|
||||
if (!Units.add(unit, 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());
|
||||
|
||||
{
|
||||
auto ret = unit.stopPeriodicMeasurement();
|
||||
float offset{};
|
||||
ret &= unit.readTemperatureOffset(offset);
|
||||
uint16_t altitude{};
|
||||
ret &= unit.readSensorAltitude(altitude);
|
||||
uint16_t pressure{};
|
||||
ret &= unit.readAmbientPressure(pressure);
|
||||
bool asc{};
|
||||
ret &= unit.readAutomaticSelfCalibrationEnabled(asc);
|
||||
uint16_t ppm{};
|
||||
ret &= unit.readAutomaticSelfCalibrationTarget(ppm);
|
||||
uint16_t initialPeriod{}, standardPeriod{};
|
||||
ret &= unit.readAutomaticSelfCalibrationInitialPeriod(initialPeriod);
|
||||
ret &= unit.readAutomaticSelfCalibrationStandardPeriod(standardPeriod);
|
||||
|
||||
ret &= unit.startPeriodicMeasurement();
|
||||
|
||||
M5.Log.printf(
|
||||
" temp offset:%f\n"
|
||||
" sensor altitude:%u\n"
|
||||
"ambient pressure:%u\n"
|
||||
" ASC enabled:%u\n"
|
||||
" ASC target:%u\n"
|
||||
" initial period:%u\n"
|
||||
" standard period:%u\n",
|
||||
offset, altitude, pressure, asc, ppm, initialPeriod, standardPeriod);
|
||||
|
||||
if (!ret) {
|
||||
lcd.clear(TFT_RED);
|
||||
while (true) {
|
||||
m5::utility::delay(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
lcd.clear(TFT_DARKGREEN);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
M5.update();
|
||||
auto touch = M5.Touch.getDetail();
|
||||
|
||||
// Periodic
|
||||
Units.update();
|
||||
if (unit.updated()) {
|
||||
// Can be checked e.g. by serial plotters
|
||||
M5.Log.printf(">CO2:%u\n>Temperature:%2.2f\n>Humidity:%2.2f\n", unit.co2(), unit.temperature(),
|
||||
unit.humidity());
|
||||
}
|
||||
|
||||
// Single shot
|
||||
if (M5.BtnA.wasClicked() || touch.wasClicked()) {
|
||||
static bool all{}; // false: RHT only
|
||||
all = !all;
|
||||
M5.Log.printf("Try single shot %u, waiting measurement...\n", all);
|
||||
unit.stopPeriodicMeasurement();
|
||||
Data d{};
|
||||
if (all) {
|
||||
if (unit.measureSingleshot(d)) {
|
||||
M5.Log.printf(" SingleAll: %u/%2.2f/%2.2f\n", d.co2(), d.temperature(), d.humidity());
|
||||
}
|
||||
} else {
|
||||
if (unit.measureSingleshotRHT(d)) {
|
||||
M5.Log.printf(" SingleRHT: %2.2f/%2.2f", d.temperature(), d.humidity());
|
||||
}
|
||||
}
|
||||
unit.startPeriodicMeasurement();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
Example using M5UnitUnified for UnitENVIII
|
||||
Required
|
||||
- M5Unified: https://github.com/m5stack/M5Unified
|
||||
*/
|
||||
#include "main/PlotToSerial.cpp"
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
Example using M5UnitUnified for UnitENVIII
|
||||
*/
|
||||
#include <M5Unified.h>
|
||||
#include <M5UnitUnified.h>
|
||||
#include <M5UnitUnifiedENV.h>
|
||||
|
||||
// #define USING_M5HAL // When using M5HAL
|
||||
|
||||
// Using single shot measurement If defined
|
||||
// #define USING_SINGLE_SHOT
|
||||
|
||||
// Using combined unit if defined
|
||||
#define USING_ENV3
|
||||
|
||||
namespace {
|
||||
auto& lcd = M5.Display;
|
||||
m5::unit::UnitUnified Units;
|
||||
|
||||
#if defined(USING_ENV3)
|
||||
#pragma message "Using combined unit(ENV3)"
|
||||
m5::unit::UnitENV3 unitENV3;
|
||||
#else
|
||||
#pragma message "Using each unit"
|
||||
m5::unit::UnitSHT30 unitSHT30;
|
||||
m5::unit::UnitQMP6988 unitQMP6988;
|
||||
#endif
|
||||
|
||||
#if defined(USING_ENV3)
|
||||
auto& sht30 = unitENV3.sht30;
|
||||
auto& qmp6988 = unitENV3.qmp6988;
|
||||
#else
|
||||
auto& sht30 = unitSHT30;
|
||||
auto& qmp6988 = unitQMP6988;
|
||||
#endif
|
||||
} // 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);
|
||||
|
||||
#if defined(USING_SINGLE_SHOT)
|
||||
{
|
||||
auto cfg = sht30.config();
|
||||
cfg.start_periodic = false;
|
||||
sht30.config(cfg);
|
||||
}
|
||||
{
|
||||
auto cfg = qmp6988.config();
|
||||
cfg.start_periodic = false;
|
||||
qmp6988.config(cfg);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USING_ENV3)
|
||||
#if defined(USING_M5HAL)
|
||||
#pragma message "Using M5HAL"
|
||||
m5::hal::bus::I2CBusConfig i2c_cfg;
|
||||
i2c_cfg.pin_sda = m5::hal::gpio::getPin(pin_num_sda);
|
||||
i2c_cfg.pin_scl = m5::hal::gpio::getPin(pin_num_scl);
|
||||
auto i2c_bus = m5::hal::bus::i2c::getBus(i2c_cfg);
|
||||
if (!Units.add(unitENV3, i2c_bus ? i2c_bus.value() : nullptr) || !Units.begin()) {
|
||||
M5_LOGE("Failed to begin");
|
||||
lcd.clear(TFT_RED);
|
||||
while (true) {
|
||||
m5::utility::delay(10000);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#pragma message "Using Wire"
|
||||
Wire.end();
|
||||
Wire.begin(pin_num_sda, pin_num_scl, 400000U);
|
||||
|
||||
if (!Units.add(unitENV3, Wire) || !Units.begin()) {
|
||||
M5_LOGE("Failed to begin");
|
||||
lcd.clear(TFT_RED);
|
||||
while (true) {
|
||||
m5::utility::delay(10000);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#if defined(USING_M5HAL)
|
||||
#pragma message "Using M5HAL"
|
||||
m5::hal::bus::I2CBusConfig i2c_cfg;
|
||||
i2c_cfg.pin_sda = m5::hal::gpio::getPin(pin_num_sda);
|
||||
i2c_cfg.pin_scl = m5::hal::gpio::getPin(pin_num_scl);
|
||||
auto i2c_bus = m5::hal::bus::i2c::getBus(i2c_cfg);
|
||||
if (!Units.add(unitSHT30, i2c_bus ? i2c_bus.value() : nullptr) ||
|
||||
!Units.add(unitQMP6988, i2c_bus ? i2c_bus.value() : nullptr) || !Units.begin()) {
|
||||
M5_LOGE("Failed to begin");
|
||||
lcd.clear(TFT_RED);
|
||||
while (true) {
|
||||
m5::utility::delay(10000);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#pragma message "Using Wire"
|
||||
Wire.begin(pin_num_sda, pin_num_scl, 400000U);
|
||||
if (!Units.add(unitSHT30, Wire) || !Units.add(unitQMP6988, Wire) || !Units.begin()) {
|
||||
M5_LOGE("Failed to begin");
|
||||
lcd.clear(TFT_RED);
|
||||
while (true) {
|
||||
m5::utility::delay(10000);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
M5_LOGI("M5UnitUnified has been begun");
|
||||
M5_LOGI("%s", Units.debugInfo().c_str());
|
||||
#if defined(USING_SINGLE_SHOT)
|
||||
M5_LOGI("\n>>> Click BtnA to single shot measurement");
|
||||
#endif
|
||||
lcd.clear(TFT_DARKGREEN);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
M5.update();
|
||||
Units.update();
|
||||
|
||||
#if defined(USING_SINGLE_SHOT)
|
||||
if (M5.BtnA.wasClicked()) {
|
||||
m5::unit::sht30::Data ds{};
|
||||
if (sht30.measureSingleshot(ds)) {
|
||||
M5.Log.printf(">SHT30Temp:%2.2f\n>Humidity:%2.2f\n", ds.temperature(), ds.humidity());
|
||||
}
|
||||
m5::unit::qmp6988::Data dq{};
|
||||
if (qmp6988.measureSingleshot(dq)) {
|
||||
M5.Log.printf(">QMP6988Temp:%2.2f\n>Pressure:%.2f\n", dq.temperature(), dq.pressure() * 0.01f);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (sht30.updated()) {
|
||||
M5.Log.printf(">SHT30Temp:%2.2f\n>Humidity:%2.2f\n", sht30.temperature(), sht30.humidity());
|
||||
}
|
||||
if (qmp6988.updated()) {
|
||||
M5.Log.printf(">QMP6988Temp:%2.2f\n>Pressure:%.2f\n", qmp6988.temperature(), qmp6988.pressure() * 0.01f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
@ -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"
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* 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.end();
|
||||
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.end();
|
||||
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.Log.printf(
|
||||
">SHT40Temp:%.4f\n"
|
||||
">Humidity:%.4f\n",
|
||||
sht40.temperature(), sht40.humidity());
|
||||
}
|
||||
if (bmp280.updated()) {
|
||||
auto p = bmp280.pressure();
|
||||
M5.Log.printf(
|
||||
">BMP280Temp:%.4f\n"
|
||||
">Pressure:%.4f\n"
|
||||
">Altitude:%.4f\n",
|
||||
bmp280.temperature(), p * 0.01f /* To hPa */, calculate_altitude(p));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
Example using M5UnitUnified for UnitENVPro
|
||||
Required
|
||||
- M5Unified: https://github.com/m5stack/M5Unified
|
||||
*/
|
||||
#include "main/PlotToSerial.cpp"
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
Example using M5UnitUnified for UnitENVPro
|
||||
*/
|
||||
#include <M5Unified.h>
|
||||
#include <M5UnitUnified.h>
|
||||
#include <M5UnitUnifiedENV.h>
|
||||
|
||||
namespace {
|
||||
auto& lcd = M5.Display;
|
||||
m5::unit::UnitUnified Units;
|
||||
m5::unit::UnitENVPro unit;
|
||||
} // 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);
|
||||
Wire.end();
|
||||
Wire.begin(pin_num_sda, pin_num_scl, 400 * 1000U);
|
||||
|
||||
if (!Units.add(unit, Wire) || !Units.begin()) {
|
||||
M5_LOGE("Failed to begin");
|
||||
lcd.clear(TFT_RED);
|
||||
while (true) {
|
||||
m5::utility::delay(10000);
|
||||
}
|
||||
}
|
||||
|
||||
M5_LOGI("M5UnitUnified has been begun");
|
||||
M5_LOGI("%s", Units.debugInfo().c_str());
|
||||
lcd.clear(TFT_DARKGREEN);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
M5.update();
|
||||
Units.update();
|
||||
if (unit.updated()) {
|
||||
#if defined(UNIT_BME688_USING_BSEC2)
|
||||
M5.Log.printf(">IAQ:%.2f\n>Temperature:%.2f\n>Pressure:%.2f\n>Humidity:%.2f\n>GAS:%.2f\n", unit.iaq(),
|
||||
unit.temperature(), unit.pressure(), unit.humidity(), unit.gas());
|
||||
#else
|
||||
M5.Log.printf(">Temperature:%.2f\n>Pressure:%.2f\n>Humidity:%.2f\n>GAS:%.2f\n", unit.temperature(),
|
||||
unit.pressure(), unit.humidity(), unit.gas());
|
||||
m5::utility::delay(1000);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
Example using M5UnitUnified for UnitTVOC
|
||||
*/
|
||||
#include "main/PlotToSerial.cpp"
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
Example using M5UnitUnified for UnitTVOC
|
||||
*/
|
||||
#include <M5Unified.h>
|
||||
#include <M5UnitUnified.h>
|
||||
#include <M5UnitUnifiedENV.h>
|
||||
#include <Wire.h>
|
||||
|
||||
namespace {
|
||||
auto& lcd = M5.Display;
|
||||
|
||||
m5::unit::UnitUnified Units;
|
||||
m5::unit::UnitTVOC unit;
|
||||
} // 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);
|
||||
Wire.end();
|
||||
Wire.begin(pin_num_sda, pin_num_scl, 400 * 1000U);
|
||||
|
||||
if (!Units.add(unit, Wire) || !Units.begin()) {
|
||||
M5_LOGE("Failed to begin");
|
||||
lcd.clear(TFT_RED);
|
||||
while (true) {
|
||||
m5::utility::delay(10000);
|
||||
}
|
||||
}
|
||||
|
||||
M5_LOGI("M5UnitUnified has been begun");
|
||||
M5_LOGI("%s", Units.debugInfo().c_str());
|
||||
M5_LOGW("SGP30 measurement starts 15 seconds after begin");
|
||||
|
||||
lcd.clear(TFT_DARKGREEN);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
M5.update();
|
||||
Units.update();
|
||||
|
||||
// SGP30 measurement starts 15 seconds after begin.
|
||||
if (unit.updated()) {
|
||||
// Can be checked on serial plotters
|
||||
M5.Log.printf("\n>CO2eq:%u\n>TVOC:%u", unit.co2eq(), unit.tvoc());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue