diff --git a/.github/workflows/pr-build-check.yml b/.github/workflows/pr-build-check.yml index 0dcb159e..529a1a21 100644 --- a/.github/workflows/pr-build-check.yml +++ b/.github/workflows/pr-build-check.yml @@ -42,6 +42,8 @@ jobs: - wio-e5-mini_repeater - LilyGo_T3_STM32_repeater - LilyGo_T3_STM32_companion_radio_usb + - LilyGo_T3_STM32_repeater_ina219 + - LilyGo_T3_STM32_companion_radio_usb_ina219 # ESP32-C6 - LilyGo_Tlora_C6_repeater_ # LR1110 (nRF52) diff --git a/variants/lilygo_t3_stm32/README.md b/variants/lilygo_t3_stm32/README.md index 2686aa7f..efc12c5c 100644 --- a/variants/lilygo_t3_stm32/README.md +++ b/variants/lilygo_t3_stm32/README.md @@ -15,6 +15,41 @@ The companion supports 100 contacts and eight channels. Radio settings inherit the repository defaults; select settings appropriate to the board's RF band. Existing saved preferences override build defaults. +## Optional INA219 telemetry + +The INA219 builds use MeshCore's existing environment sensor driver to report +voltage, current, and power. Build either role with: + +```sh +pio run -e LilyGo_T3_STM32_repeater_ina219 +pio run -e LilyGo_T3_STM32_companion_radio_usb_ina219 +``` + +Connect the sensor's logic supply to **3.3 V** and use a common ground: + +| INA219 connection | T3 STM32 connection | +| --- | --- | +| VCC / logic supply | 3.3 V | +| GND | GND | +| SDA | PB7 (JP2 pin 9) | +| SCL | PB8 (JP2 pin 10) | + +PB7/PB8 are the alternate I2C1 pins exposed on the board headers. The default +STM32 I2C pins, PA9/PA10, are reserved for USB serial. The OLED uses SPI. +The sensor is detected at startup at address **0x40**; to use another address, +override `TELEM_INA219_ADDRESS` in the build flags. An absent sensor produces no +additional telemetry. The base builds do not initialize I2C or include the driver. + +The measurement terminals (VIN+ and VIN-) go in series with the positive supply +of the circuit being measured; these are separate from the sensor's logic supply. +See the [INA219 wiring guide](https://learn.adafruit.com/adafruit-ina219-current-sensor-breakout/wiring). +USB power can bypass a sensor placed only in the battery lead. + +Readings use environment telemetry permissions. Existing telemetry encodes current +in 1 mA steps and power in whole watts; it does not provide accumulated mAh or +battery percentage. INA219 telemetry has been confirmed on hardware with the +repeater build; the USB companion sensor build has been compile-tested only. + ## Flash and connect Connect the USB serial port. Hold BOOT, press and release RST, then release BOOT: @@ -63,4 +98,4 @@ pings timed out; long-term reliability has not been established. Higher transmit powers are outside the validated MVP setting. The repeater builds successfully; forwarding has not been hardware-tested. -Battery telemetry, SD storage, and low-power optimization are not implemented. +Built-in battery telemetry, SD storage, and low-power optimization are not implemented. diff --git a/variants/lilygo_t3_stm32/platformio.ini b/variants/lilygo_t3_stm32/platformio.ini index ba56cf52..39e059b7 100644 --- a/variants/lilygo_t3_stm32/platformio.ini +++ b/variants/lilygo_t3_stm32/platformio.ini @@ -50,3 +50,32 @@ build_src_filter = ${lilygo_t3_stm32.build_src_filter} +<../examples/companion_radio/ui-orig/*.cpp> lib_deps = ${lilygo_t3_stm32.lib_deps} densaugeo/base64 @ ~1.4.0 + +; Optional INA219 telemetry on I2C1. Keep the base builds sensor-free. +[lilygo_t3_stm32_ina219] +build_flags = + -D ENV_INCLUDE_INA219=1 + -D PIN_WIRE_SDA=PB7 + -D PIN_WIRE_SCL=PB8 +build_src_filter = + + +lib_deps = + adafruit/Adafruit INA219 @ ^1.2.3 + +[env:LilyGo_T3_STM32_repeater_ina219] +extends = env:LilyGo_T3_STM32_repeater +build_flags = ${env:LilyGo_T3_STM32_repeater.build_flags} + ${lilygo_t3_stm32_ina219.build_flags} +build_src_filter = ${env:LilyGo_T3_STM32_repeater.build_src_filter} + ${lilygo_t3_stm32_ina219.build_src_filter} +lib_deps = ${lilygo_t3_stm32.lib_deps} + ${lilygo_t3_stm32_ina219.lib_deps} + +[env:LilyGo_T3_STM32_companion_radio_usb_ina219] +extends = env:LilyGo_T3_STM32_companion_radio_usb +build_flags = ${env:LilyGo_T3_STM32_companion_radio_usb.build_flags} + ${lilygo_t3_stm32_ina219.build_flags} +build_src_filter = ${env:LilyGo_T3_STM32_companion_radio_usb.build_src_filter} + ${lilygo_t3_stm32_ina219.build_src_filter} +lib_deps = ${env:LilyGo_T3_STM32_companion_radio_usb.lib_deps} + ${lilygo_t3_stm32_ina219.lib_deps} diff --git a/variants/lilygo_t3_stm32/target.cpp b/variants/lilygo_t3_stm32/target.cpp index f98783fe..b7a14c48 100644 --- a/variants/lilygo_t3_stm32/target.cpp +++ b/variants/lilygo_t3_stm32/target.cpp @@ -1,12 +1,19 @@ #include #include +#if ENV_INCLUDE_INA219 + #include +#endif #include "target.h" LilyGoT3STM32Board board; RADIO_CLASS radio = new STM32WLx_Module(); WRAPPER_CLASS radio_driver(radio, board); VolatileRTCClock rtc_clock; +#if ENV_INCLUDE_INA219 +EnvironmentSensorManager sensors; +#else SensorManager sensors; +#endif DISPLAY_CLASS display; // PH3 is also BOOT0: the board's button is active high with an external pull-down. MomentaryButton user_btn(PIN_USER_BTN, 1000, false); @@ -24,6 +31,11 @@ static const Module::RfSwitchMode_t rfswitch_table[] = { void LilyGoT3STM32Board::begin() { STM32Board::begin(); +#if ENV_INCLUDE_INA219 + // These builds remap Wire to PB7/PB8; PA9/PA10 are used by USART1. + Wire.begin(); +#endif + // The SD card shares SPI1 with the OLED; keep it deselected. digitalWrite(PA4, HIGH); pinMode(PA4, OUTPUT); diff --git a/variants/lilygo_t3_stm32/target.h b/variants/lilygo_t3_stm32/target.h index 83235cbd..2db3173b 100644 --- a/variants/lilygo_t3_stm32/target.h +++ b/variants/lilygo_t3_stm32/target.h @@ -4,7 +4,11 @@ #include #include #include -#include +#if ENV_INCLUDE_INA219 + #include +#else + #include +#endif #include #include @@ -20,7 +24,11 @@ public: extern LilyGoT3STM32Board board; extern WRAPPER_CLASS radio_driver; extern VolatileRTCClock rtc_clock; +#if ENV_INCLUDE_INA219 +extern EnvironmentSensorManager sensors; +#else extern SensorManager sensors; +#endif extern DISPLAY_CLASS display; extern MomentaryButton user_btn;