1
0
Fork
You've already forked esphome-components
0

fix(mlx90640): drive the Melexis sensor over ESPHome's I2C bus, not Wire #1

Merged
stackdrift merged 1 commit from fix/mlx90640-esphome-i2c-bus into main 2026年05月30日 04:21:12 +02:00

Summary

  • Ports the MLX90640 thermal driver off Arduino Wire onto the component's
    ESPHome i2c::I2CBus, fixing the thermal camera on ESPHome 2026.x. The IDF
    i2c backend never initialises Wire, so every MLX read failed (parameter
    extraction returned -4) while the rest of the bus worked.
  • Reads use write_readv() (atomic address-then-read). ESPHome's legacy
    write(stop=false)+read() ignores stop and issues two STOP-terminated
    transactions, losing the MLX address pointer.
  • Reads are chunked (16 words / 32 bytes) — a single large EEPROM/frame
    transfer stalls the IDF driver and trips the task watchdog (boot loop).
  • Drops the <Wire.h> dependency entirely.

Test plan

  • ./docker/esphome compile configs/test-atoms3u-sensors.yaml — green.
  • Flashed an AtomS3U: EEPROM extraction OK, frames read (768 valid pixels,
    ~24 °C avg), no -4, no watchdog resets; SCD4x + QMP6988 unaffected.
## Summary - Ports the MLX90640 thermal driver off Arduino `Wire` onto the component's ESPHome `i2c::I2CBus`, fixing the thermal camera on ESPHome 2026.x. The IDF i2c backend never initialises `Wire`, so every MLX read failed (parameter extraction returned `-4`) while the rest of the bus worked. - Reads use `write_readv()` (atomic address-then-read). ESPHome's legacy `write(stop=false)+read()` ignores `stop` and issues two STOP-terminated transactions, losing the MLX address pointer. - Reads are chunked (16 words / 32 bytes) — a single large EEPROM/frame transfer stalls the IDF driver and trips the task watchdog (boot loop). - Drops the `<Wire.h>` dependency entirely. ## Test plan - `./docker/esphome compile configs/test-atoms3u-sensors.yaml` — green. - Flashed an AtomS3U: EEPROM extraction OK, frames read (768 valid pixels, ~24 °C avg), no `-4`, no watchdog resets; SCD4x + QMP6988 unaffected.
The bundled Melexis driver did raw Arduino Wire I2C and MLX90640_I2CInit()
was empty, relying on ESPHome's old Arduino-Wire backend to have started the
bus. ESPHome 2026.x drives I2C through the IDF driver, so Wire was never
initialised and every MLX read failed (parameter extraction returned -4)
while the rest of the bus worked.
Route the four MLX90640_I2C* functions through the component's i2c::I2CBus
(handed over via MLX90640_SetI2CBus() from setup, since the component is
already an i2c::I2CDevice) and drop the Wire dependency entirely.
Two IDF-specific details, learned on hardware:
- Reads use write_readv() for the address-then-data transfer. ESPHome's
 legacy write(stop=false)+read() ignores `stop` and issues two separate
 STOP-terminated transactions, so the MLX loses its address pointer and
 returns garbage. write_readv() keeps the connection open across the
 repeated start.
- Reads are chunked (16 words / 32 bytes per transaction). A single large
 combined transfer (the 832-word EEPROM dump / 834-word frame) stalls the
 IDF driver long enough to trip the task watchdog and boot-loop the device.
Verified on an AtomS3U: EEPROM extraction succeeds, frames read (768 valid
pixels, plausible temperatures), no watchdog resets.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
stackdrift deleted branch fix/mlx90640-esphome-i2c-bus 2026年05月30日 04:21:12 +02:00
Sign in to join this conversation.
No reviewers
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
stackdrift/esphome-components!1
Reference in a new issue
stackdrift/esphome-components
No description provided.
Delete branch "fix/mlx90640-esphome-i2c-bus"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?