56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
/*
|
|
* 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());
|
|
}
|
|
}
|