From fdb9fd4796b517e2fd0d4473ea537682793df5e2 Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Sat, 28 Nov 2026 16:40:34 +0100 Subject: [PATCH] mcu-tbeam: T-Beam v1.1 as a geolocation test receiver (NEO-6M on ubx, OLED, AXP192 battery, NAV-SVINFO test aid) --- mcu-tbeam.yaml | 230 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 mcu-tbeam.yaml diff --git a/mcu-tbeam.yaml b/mcu-tbeam.yaml new file mode 100644 index 0000000..f136d95 --- /dev/null +++ b/mcu-tbeam.yaml @@ -0,0 +1,230 @@ +--- +# Hardware: LilyGO T-Beam v1.1 (ESP32, AXP192), geolocation test receiver +# Pinout: +# GPIO12 GNSS RX -> uart_gnss (uart tx_pin) +# GPIO21 -> system_i2c (i2c sda) +# GPIO22 -> system_i2c (i2c scl) +# GPIO34 GNSS TX -> uart_gnss (uart rx_pin) +# GPIO38 User button (middle) -> user_button (binary_sensor gpio) +# I2C: +# 0x34 pmu_axp (axp192), LDO3 powers the GNSS, DCDC3 the ESP32 +# 0x3C oled (display ssd1306_i2c) +# GNSS: u-blox NEO-6M (u-blox 6, fw 7.03), 9600 baud -> gnss (ubx), active antenna +# LoRa (SX1276) not set up yet +substitutions: + device: tbeam + name: T-Beam + area: DEV + comment: geolocation test receiver + +esphome: + name: mcu-${device} + friendly_name: ${name} + area: ${area} + comment: ${comment} + +esp32: + board: ttgo-t-beam + framework: + type: esp-idf + +packages: + common: !include common/common.yaml + ipv6_only: !include common/ipv6_only.yaml + +external_components: + - source: github://m5stack/esphome-yaml + components: [axp192] + refresh: 1h + # geolocation hub + nmea and ubx platforms, esphome/esphome#23301 (stacked on #23293) + - source: github://pr#23301 + components: [geolocation, nmea, ubx] + +i2c: + id: system_i2c + sda: 21 + scl: 22 + +axp192: + id: pmu_axp + address: 0x34 + i2c_id: system_i2c + +output: + - platform: axp192 + id: gnss_power + channel: DLDO3 + voltage: 3300 + +switch: + - platform: output + id: gnss_enable + name: GNSS Power + output: gnss_power + restore_mode: ALWAYS_ON + +uart: + id: uart_gnss + rx_pin: 34 + tx_pin: 12 + baud_rate: 9600 + # Test aid: decode the NAV-SVINFO answers to the poll in interval below + debug: + direction: RX + after: + bytes: 512 + timeout: 50ms + sequence: + - lambda: |- + for (size_t i = 0; i + 8 <= bytes.size(); i++) { + if (bytes[i] != 0xB5 || bytes[i + 1] != 0x62 || bytes[i + 2] != 0x01 || bytes[i + 3] != 0x30) + continue; + const size_t len = bytes[i + 4] | (bytes[i + 5] << 8); + if (i + 6 + len > bytes.size() || len < 8) + break; + const uint8_t *p = bytes.data() + i + 6; + const uint8_t num = p[4]; + int tracked = 0, used = 0; + std::string sats; + for (uint8_t k = 0; k < num && 8 + 12 * (k + 1) <= len; k++) { + const uint8_t *c = p + 8 + 12 * k; + if (c[4] == 0) + continue; + tracked++; + if (c[2] & 0x01) + used++; + char buf[12]; + snprintf(buf, sizeof(buf), " %u:%u", c[1], c[4]); + sats += buf; + } + ESP_LOGI("ubxdbg", "NAV-SVINFO used %d, tracked %d of %u channels, PRN:cno%s", used, tracked, num, + sats.c_str()); + break; + } + +geolocation: + - platform: ubx + id: gnss + update_interval: 10s + +sensor: + - platform: geolocation + type: latitude + id: latitude + name: Latitude + - platform: geolocation + type: longitude + id: longitude + name: Longitude + - platform: geolocation + type: altitude + id: altitude + name: Altitude + - platform: geolocation + type: speed + id: speed + name: Speed + - platform: geolocation + type: course + id: course + name: Course + - platform: geolocation + type: satellites + id: satellites + name: Satellites + - platform: geolocation + type: hdop + id: hdop + name: HDOP + - platform: geolocation + type: horizontal_accuracy + id: horizontal_accuracy + name: Horizontal Accuracy + - platform: geolocation + type: vertical_accuracy + name: Vertical Accuracy + - platform: axp192 + id: pmu_sensors + axp192_id: pmu_axp + update_interval: 60s + battery_voltage: + id: battery_voltage + name: Battery Voltage + battery_level: + id: battery_level + name: Battery Level + battery_charge_current: + name: Battery Charge Current + entity_category: diagnostic + battery_discharge_current: + name: Battery Discharge Current + entity_category: diagnostic + vbus_voltage: + name: VBUS Voltage + entity_category: diagnostic + internal_temperature: + name: PMU Temperature + entity_category: diagnostic + battery_charging: + name: Battery Charging + battery_connected: + id: battery_connected + name: Battery Connected + vbus_present: + id: usb_power + name: USB Power + +binary_sensor: + - platform: gpio + id: user_button + name: Button + pin: + number: 38 + inverted: true + +time: + - platform: geolocation + id: gnss_time + +interval: + # Test aid: poll NAV-SVINFO (u-blox 6 has no NAV-SAT) + - interval: 10s + then: + - uart.write: + id: uart_gnss + data: [0xB5, 0x62, 0x01, 0x30, 0x00, 0x00, 0x31, 0x94] + +font: + # Tiny5 Mono bitmap, 6x9 cell: 21 columns, 7 rows on 128x64 + - file: assets/fonts/Tiny5Mono.bdf + id: font_mono + +display: + - platform: ssd1306_i2c + id: oled + model: "SSD1306 128x64" + address: 0x3C + i2c_id: system_i2c + update_interval: 2s + lambda: |- + it.printf(0, 0, id(font_mono), "Sats %.0f", id(satellites).state); + if (!std::isnan(id(hdop).state)) + it.printf(127, 0, id(font_mono), TextAlign::TOP_RIGHT, "HDOP %.1f", id(hdop).state); + if (std::isnan(id(latitude).state)) { + it.print(0, 9, id(font_mono), "No fix"); + } else { + it.printf(0, 9, id(font_mono), "Lat %11.6f", id(latitude).state); + it.printf(0, 18, id(font_mono), "Lon %11.6f", id(longitude).state); + it.printf(0, 27, id(font_mono), "Alt %.0f m", id(altitude).state); + it.printf(127, 27, id(font_mono), TextAlign::TOP_RIGHT, "+-%.0f m", id(horizontal_accuracy).state); + it.printf(0, 36, id(font_mono), "%.1f km/h", id(speed).state); + if (!std::isnan(id(course).state)) + it.printf(127, 36, id(font_mono), TextAlign::TOP_RIGHT, "%.0f deg", id(course).state); + } + auto now = id(gnss_time).now(); + if (now.is_valid()) + it.strftime(0, 46, id(font_mono), "%H:%M:%S", now); + if (id(battery_connected).state && !std::isnan(id(battery_level).state)) + it.printf(127, 46, id(font_mono), TextAlign::TOP_RIGHT, "Bat %.0f%%", id(battery_level).state); + if (id(usb_power).state) + it.print(127, 55, id(font_mono), TextAlign::TOP_RIGHT, "USB");