Compare commits

...
3 Commits
Author SHA1 Message Date
randy 93f622f430 mcu-m5core2: M5GFX SH1107 init on boot for the Unit OLED
CI / ESPHome config validation (push) Successful in 1m5s
CI / YAML lint (push) Successful in 18s
2026-11-05 13:32:04 +01:00
randy 9c20f605d2 nrf: packet_interface link with reliability and session, add Tacx Neo 2
The DK <-> ANT UART link now runs packet_transport over packet_interface:
HDLC retransmits lost frames and the session layer reports in HA whether
mcu-nrf-ant is reachable (ANT Link). Tacx Neo 2 (FE-C, ANT ID 13888)
publishes power, cadence and in use.
2026-11-05 13:31:29 +01:00
randy 0383ea9871 m5core2: MLX90640 thermal camera, backlight voltage
MLX90640 on Port C through the randybb fork without a web server, a
camera entity and sensors in HA and a thermal page on the LCD (32x24
upscaled bilinear with the iron palette). DC3 is set to 3.3 V on boot:
the AXP192 forgets it when the Faces battery runs flat and the LCD stays
dark.
2026-11-05 11:46:47 +01:00
3 changed files with 245 additions and 5 deletions

No files matched your search

+183 -2
View File
@@ -29,7 +29,8 @@
# I2C Port C: # I2C Port C:
# 0x3C oled (display ssd1306_i2c), Unit OLED SH1107 # 0x3C oled (display ssd1306_i2c), Unit OLED SH1107
# 0x3E unit_lcd (display m5stack_st7789v2), Unit LCD, firmware 0.3 # 0x3E unit_lcd (display m5stack_st7789v2), Unit LCD, firmware 0.3
# 0x5F cardkb (m5stack_keyboard), CardKB # 0x33 thermal (mlx90640), MLX90640 32x24 thermal camera
# 0x5F cardkb (m5stack_keyboard), CardKB (unplugged for now, its warning at boot is expected)
substitutions: substitutions:
device: m5core2 device: m5core2
name: M5Core2 name: M5Core2
@@ -48,6 +49,7 @@ esphome:
then: then:
- lambda: |- - lambda: |-
auto *axp = id(pmu_axp); auto *axp = id(pmu_axp);
axp->writeRegister(0x27, (3300 - 700) / 25); // DC3 (LCD backlight) 3.3 V
axp->writeRegister(0x28, (axp->readRegister(0x28) & 0x0F) | 0xF0); // LDO2 3.3 V axp->writeRegister(0x28, (axp->readRegister(0x28) & 0x0F) | 0xF0); // LDO2 3.3 V
axp->writeRegister(0x12, axp->readRegister(0x12) | 0x46); // EXTEN, LDO2, DC3 axp->writeRegister(0x12, axp->readRegister(0x12) | 0x46); // EXTEN, LDO2, DC3
axp->writeRegister(0x95, (axp->readRegister(0x95) & 0x72) | 0x84); // GPIO4 output axp->writeRegister(0x95, (axp->readRegister(0x95) & 0x72) | 0x84); // GPIO4 output
@@ -59,6 +61,12 @@ esphome:
then: then:
# the m5stack component sets these in the AXP2101 layout: 4.1 V, 360 mA, end at 10 % # the m5stack component sets these in the AXP2101 layout: 4.1 V, 360 mA, end at 10 %
- lambda: id(pmu_axp)->writeRegister(0x33, 0x83); - lambda: id(pmu_axp)->writeRegister(0x33, 0x83);
# The SH1107 once stuck showing noise (even after a power cycle) with ESPHome's init alone;
# M5GFX's settings that ESPHome lacks or sets otherwise brought it back, kept as insurance:
# end read-modify-write, POR clock, SH1107 precharge, VCOMH, DC-DC, RAM content, on
- lambda: |-
for (uint8_t c : {0xEE, 0xD5, 0x50, 0xD9, 0x20, 0xDB, 0x35, 0xAD, 0x8B, 0xA4, 0xAF})
id(oled).write_byte(0x00, c);
- bm8563.read_time: - bm8563.read_time:
- lvgl.page.show: {id: status_page, lvgl_id: lvgl_main} - lvgl.page.show: {id: status_page, lvgl_id: lvgl_main}
@@ -91,6 +99,33 @@ external_components:
- source: github://randybb/esphome-components - source: github://randybb/esphome-components
components: [m5stack_keyboard, m5stack_st7789v2, meshtastic] components: [m5stack_keyboard, m5stack_st7789v2, meshtastic]
refresh: 0s refresh: 0s
# MLX90640, camera entity in HA (its heatmap page at /thermal needs web_server_base only)
- source: github://randybb/esphome-mlx-90640@optional-web-server
components: [mlx90640]
# MLX90640 on Port C; settings changed at runtime are saved on the device
mlx90640:
id: thermal
i2c_id: i2c_port_c
refresh_rate: 4Hz
update_interval: 10s
min_temperature:
name: Thermal Min
max_temperature:
name: Thermal Max
mean_temperature:
name: Thermal Mean
center_temperature:
name: Thermal Center
ambient_temperature:
name: Thermal Sensor Die
frame_rate:
name: Thermal Frame Rate
i2c_errors:
name: Thermal I2C Errors
camera:
name: Thermal Camera
resolution: 320x240
api: api:
# status page until Home Assistant connects (log viewers don't subscribe to states) # status page until Home Assistant connects (log viewers don't subscribe to states)
@@ -383,7 +418,28 @@ key_collector:
on_progress: *line_progress on_progress: *line_progress
on_result: *line_result on_result: *line_result
select:
- platform: mlx90640
refresh_rate:
name: Thermal Refresh Rate
palette:
name: Thermal Palette
number:
- platform: mlx90640
emissivity:
name: Thermal Emissivity
range_min:
name: Thermal Range Min
range_max:
name: Thermal Range Max
switch: switch:
- platform: mlx90640
auto_range:
name: Thermal Auto Range
mirror:
name: Thermal Mirror
- platform: template - platform: template
name: Unit LCD Invert name: Unit LCD Invert
icon: mdi:invert-colors icon: mdi:invert-colors
@@ -493,6 +549,77 @@ interval:
id(aps_voltage).publish_state(adc12(0x7E) * 1.4f / 1000); id(aps_voltage).publish_state(adc12(0x7E) * 1.4f / 1000);
id(pmu_temperature).publish_state(adc12(0x5E) * 0.1f - 144.7f); id(pmu_temperature).publish_state(adc12(0x5E) * 0.1f - 144.7f);
id(battery_charging).publish_state(r(0x01) & 0x40); id(battery_charging).publish_state(r(0x01) & 0x40);
# thermal page: the newest MLX90640 frame, 32x24 upscaled bilinear x8 with the iron palette
- interval: 125ms
then:
- if:
condition:
lvgl.page.is_showing: thermal_page
then:
- lambda: |-
static float px[32 * 24];
static uint32_t shown = 0;
static uint16_t palette[256];
static bool palette_ready = false;
if (!id(thermal).has_frame() || id(thermal).get_frame_count() == shown)
return;
shown = id(thermal).get_frame_count();
id(thermal).copy_display_frame(px);
if (!palette_ready) {
// iron: black, navy, magenta, orange, yellow, white
const float stop[][4] = {{0, 0, 0, 0}, {0.2f, 32, 0, 140}, {0.45f, 204, 0, 119},
{0.7f, 255, 140, 0}, {0.85f, 255, 215, 0}, {1, 255, 255, 255}};
for (int i = 0; i < 256; i++) {
const float t = i / 255.0f;
int k = 0;
while (k < 4 && t > stop[k + 1][0])
k++;
const float f = (t - stop[k][0]) / (stop[k + 1][0] - stop[k][0]);
auto mix = [&](int c) { return uint8_t(stop[k][c] + f * (stop[k + 1][c] - stop[k][c])); };
palette[i] = lv_color_to_u16(lv_color_make(mix(1), mix(2), mix(3)));
}
palette_ready = true;
}
float lo = px[0], hi = px[0];
for (float v : px) {
lo = std::min(lo, v);
hi = std::max(hi, v);
}
const float center = (px[11 * 32 + 15] + px[11 * 32 + 16] + px[12 * 32 + 15] + px[12 * 32 + 16]) / 4;
float a = lo, b = hi;
if (b - a < 2) { // flat scenes would show noise
a = (lo + hi) / 2 - 1;
b = a + 2;
}
const float k = 255 / (b - a);
lv_obj_t *canvas = id(thermal_canvas);
lv_draw_buf_t *buf = lv_canvas_get_draw_buf(canvas);
for (int y = 0; y < 192; y++) {
const float sy = std::clamp((y + 0.5f) / 8 - 0.5f, 0.0f, 23.0f);
const int y0 = int(sy), y1 = std::min(y0 + 1, 23);
const float fy = sy - y0;
auto *row = reinterpret_cast<uint16_t *>(buf->data + y * buf->header.stride);
for (int x = 0; x < 256; x++) {
const float sx = std::clamp((x + 0.5f) / 8 - 0.5f, 0.0f, 31.0f);
const int x0 = int(sx), x1 = std::min(x0 + 1, 31);
const float fx = sx - x0;
const float top = px[y0 * 32 + x0] + fx * (px[y0 * 32 + x1] - px[y0 * 32 + x0]);
const float bottom = px[y1 * 32 + x0] + fx * (px[y1 * 32 + x1] - px[y1 * 32 + x0]);
row[x] = palette[std::clamp(int((top + fy * (bottom - top) - a) * k), 0, 255)];
}
}
// crosshair on the center spot
const uint16_t white = lv_color_to_u16(lv_color_white());
for (int d = -6; d <= 6; d++) {
if (d > -2 && d < 2)
continue;
reinterpret_cast<uint16_t *>(buf->data + 96 * buf->header.stride)[128 + d] = white;
reinterpret_cast<uint16_t *>(buf->data + (96 + d) * buf->header.stride)[128] = white;
}
lv_obj_invalidate(canvas);
lv_label_set_text(id(thermal_max), str_sprintf("%.1f°", hi).c_str());
lv_label_set_text(id(thermal_center), str_sprintf("%.1f°", center).c_str());
lv_label_set_text(id(thermal_min), str_sprintf("%.1f°", lo).c_str());
- interval: 1s - interval: 1s
then: then:
- lvgl.label.update: - lvgl.label.update:
@@ -654,7 +781,61 @@ lvgl:
text_font: font_status text_font: font_status
text: "-" text: "-"
# 4: status (shown until Home Assistant connects) # 4: MLX90640 thermal image, drawn by the 125 ms interval
- id: thermal_page
widgets:
- canvas:
id: thermal_canvas
x: 0
y: 24
width: 256
height: 192
- label:
x: 262
y: 24
text_font: font_status
text_color: 0x8C8C8C
text: Max
- label:
id: thermal_max
x: 262
y: 44
text_font: font_status
text_color: 0xFF6040
text: "-"
- label:
x: 262
y: 98
text_font: font_status
text_color: 0x8C8C8C
text: "Center"
- label:
id: thermal_center
x: 262
y: 118
text_font: font_status
text: "-"
- label:
x: 262
y: 172
text_font: font_status
text_color: 0x8C8C8C
text: Min
- label:
id: thermal_min
x: 262
y: 192
text_font: font_status
text_color: 0x40A0FF
text: "-"
- label:
align: TOP_MID
x: -32
y: 2
text_font: font_status
text: MLX90640
# 5: status (shown until Home Assistant connects)
- id: status_page - id: status_page
on_load: on_load:
- script.execute: update_status - script.execute: update_status
+24 -1
View File
@@ -20,6 +20,7 @@
# 886796 Garmin Rally RS200 power + cadence # 886796 Garmin Rally RS200 power + cadence
# 343922 Garmin Speed Sensor 2 speed # 343922 Garmin Speed Sensor 2 speed
# 42898 SRAM Force AXS shifting (Cube Litening C:68X), battery only # 42898 SRAM Force AXS shifting (Cube Litening C:68X), battery only
# 13888 Tacx Neo 2 fitness equipment (FE-C), basement trainer
esphome: esphome:
name: mcu-nrf-ant name: mcu-nrf-ant
friendly_name: nRF ANT+ friendly_name: nRF ANT+
@@ -141,6 +142,17 @@ ant_plus:
battery_low: battery_low:
id: speed2_battery_low id: speed2_battery_low
name: Garmin Speed Sensor 2 Battery Low name: Garmin Speed Sensor 2 Battery Low
- type: fitness_equipment # Tacx Neo 2
device_number: 13888
power:
id: neo_power
name: Tacx Neo 2 Power
cadence:
id: neo_cadence
name: Tacx Neo 2 Cadence
in_use:
id: neo_in_use
name: Tacx Neo 2 In Use
- type: shifting # SRAM Force AXS (Cube Litening C:68X) - type: shifting # SRAM Force AXS (Cube Litening C:68X)
device_number: 42898 device_number: 42898
battery_low: battery_low:
@@ -155,9 +167,17 @@ uart:
rx_pin: P1.01 rx_pin: P1.01
baud_rate: 115200 baud_rate: 115200
packet_transport: # same layers as mcu-nrf-dk, both ends must match
packet_interface:
- platform: uart - platform: uart
id: link_packets
uart_id: link uart_id: link
reliability:
session:
packet_transport:
- platform: packet_interface
packet_interface: link_packets
update_interval: 1s update_interval: 1s
sensors: sensors:
- hrm_pro_heart_rate - hrm_pro_heart_rate
@@ -177,6 +197,8 @@ packet_transport:
- rally_cadence - rally_cadence
- speed2_speed - speed2_speed
- speed2_battery - speed2_battery
- neo_power
- neo_cadence
binary_sensors: binary_sensors:
- ant_connected - ant_connected
- ant_unknown_device - ant_unknown_device
@@ -186,3 +208,4 @@ packet_transport:
- rally_battery_low - rally_battery_low
- speed2_battery_low - speed2_battery_low
- sram_battery_low - sram_battery_low
- neo_in_use
+38 -2
View File
@@ -13,7 +13,7 @@
# P0.25 Button 4 (active low) -> Button 4 (binary_sensor gpio) # P0.25 Button 4 (active low) -> Button 4 (binary_sensor gpio)
# P1.01 UART1 RX <- mcu-nrf-ant UART1 TX (P1.02), packet_transport; plus GND # P1.01 UART1 RX <- mcu-nrf-ant UART1 TX (P1.02), packet_transport; plus GND
# P1.02 UART1 TX -> mcu-nrf-ant UART1 RX (P1.01), packet_transport # P1.02 UART1 TX -> mcu-nrf-ant UART1 RX (P1.01), packet_transport
# ANT+ values (Garmin HRM-Pro, Concept2 PM5, Garmin Tempe, Garmin Varia RTL515) come from mcu-nrf-ant # ANT+ values (Garmin HRM-Pro, Concept2 PM5, Garmin Tempe, Garmin Varia RTL515, Tacx Neo 2, ...) come from mcu-nrf-ant
esphome: esphome:
name: mcu-nrf-dk name: mcu-nrf-dk
friendly_name: nRF DK friendly_name: nRF DK
@@ -49,9 +49,21 @@ uart:
tx_pin: P1.02 tx_pin: P1.02
baud_rate: 115200 baud_rate: 115200
packet_transport: # retransmits lost frames; the session's keep-alives show whether mcu-nrf-ant is reachable
packet_interface:
- platform: uart - platform: uart
id: ant_link_packets
uart_id: ant_link uart_id: ant_link
reliability:
session:
binary_sensor:
name: ANT Link
device_class: connectivity
entity_category: diagnostic
packet_transport:
- platform: packet_interface
packet_interface: ant_link_packets
providers: providers:
- name: mcu-nrf-ant - name: mcu-nrf-ant
@@ -204,6 +216,24 @@ sensor:
device_class: voltage device_class: voltage
accuracy_decimals: 2 accuracy_decimals: 2
entity_category: diagnostic entity_category: diagnostic
- platform: packet_transport
provider: mcu-nrf-ant
remote_id: neo_power
name: Tacx Neo 2 Power
internal: false
unit_of_measurement: W
device_class: power
filters:
- throttle: 1s
- platform: packet_transport
provider: mcu-nrf-ant
remote_id: neo_cadence
name: Tacx Neo 2 Cadence
internal: false
unit_of_measurement: rpm
icon: mdi:rotate-right
filters:
- throttle: 1s
output: output:
- platform: gpio - platform: gpio
@@ -280,6 +310,12 @@ binary_sensor:
internal: false internal: false
device_class: battery device_class: battery
entity_category: diagnostic entity_category: diagnostic
- platform: packet_transport
provider: mcu-nrf-ant
remote_id: neo_in_use
name: Tacx Neo 2 In Use
internal: false
device_class: running
- platform: gpio - platform: gpio
name: Button 1 name: Button 1
pin: {number: P0.11, inverted: true, mode: {input: true, pullup: true}} pin: {number: P0.11, inverted: true, mode: {input: true, pullup: true}}