Skip to content

[m5_unit_roller485] Add support for the Unit Roller485 - #6

Merged
parker-int64 merged 3 commits into
m5stack:m5-devfrom
New-Kringster:feat-m5-unit-roller485
Dec 2, 2026
Merged

parker-int64 merged 3 commits into
m5stack:m5-devfrom
New-Kringster:feat-m5-unit-roller485

Conversation

@New-Kringster

Copy link
Copy Markdown

Adds the M5Stack Unit Roller485, a brushless motor with its own driver, over I2C. The motor and stall protection are switches, the mode a select, and the speed, position and current targets numbers. Readbacks are sensors, the status a text sensor, the LED an RGB light, and there is a button to clear a stall. Tested on a CoreS3 in speed, position and current modes.

Roller485 controls and sensors in Home Assistant


Opened by claude-opus-5-5 with Claude Code on behalf of Braven.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
m5agent pushed a commit to m5agent/agent-work-logs that referenced this pull request Dec 1, 2026
@m5agent

m5agent commented Dec 1, 2026 •

Copy link
Copy Markdown

Thanks for the component. I reviewed the implementation against the published
M5Unit-Roller485-Internal-FW V4 source and the M5Unit-Roller Arduino library, and ran it
on a CoreS3 virtual device with a Roller485 on PORT.A.

Conclusion: no blocking defect found in the register map, scaling, or command paths.

Evidence level: virtual-device validation (CoreS3 QEMU + Roller485 Unit model on
PORT.A), plus host-level test and code-level verification. Hardware validation is
NOT RUN.

What was executed:

  • Host tests: script/cpp_unit_test.py m5_unit_roller485 → 22/22 PASS, covering restore
    modes, reconnect, failed writes, LED ordering, status strings and target scaling.
  • Component build: script/test_build_components.py -c m5_unit_roller485 -t esp32-idf →
    1 passed, 0 failed; esphome config on the probe is valid.
  • CoreS3 boot: bus scan finds 0x64, Firmware version: 3,
    setup() finished successfully!, no Communication failed over the run.
  • Commands observed from the guest by reading the unit registers back over the same I2C bus:
    • speed mode: 0x00=1, 0x01=1, 0x40=150000 (1500.00 rpm), 0x50=80000 (800.00 mA);
    • position mode: 0x01=2, 0x80=9025 (90.25°), 0x20=60000 (600.00 mA);
    • LED: 0x10=0x64 (brightness 100), 0x30..0x33 = 00 80 FF 01 (B/G/R = 0/128/255,
      user mode);
    • motor 0x00 1→0 and stall protection 0x0F 1→0; status text Standby, and
      Running after the motor was on and the stall reset was written.

The scaling matches the vendor protocol: 0.01 rpm / 0.01° / 0.01 mA / 0.01 V, raw °C for
temperature, and the 16-byte read of 0x00..0x0F is supported by the firmware
(i2c_protocol.c prepares 0x0F - reg + 1 bytes; the slave buffer is 600 bytes).

Minor, non-blocking observations:

  1. 0x33 is written only on the first LED write per connection (led_mode_set_ is reset
    only in connect_()). The unit's own OLED menu can set rgb_show_mode back to 0, after
    which light.turn_on writes only B/G/R and the user colour will not show until the ESP
    reconnects or reboots. Re-writing the 4-byte block, or reading 0x33 in
    read_settings_(), would close this.
  2. The V4 firmware also has MODE_POS_SPEED = 5 and accepts any mode < 6 on I2C; the
    select exposes 1–4 and read_settings_() ignores > 4. If mode 5 is not meant to be
    user-visible, a short comment would help; otherwise it needs a fifth option.
  3. MULTI_CONF = True with default 0x64: two hubs at the default address still pass
    esphome config but would drive the same unit. The component does not expose the unit's
    0xFF address-change register, so a note that multiple units must be re-addressed first
    (or dropping MULTI_CONF) would avoid that trap.

Uncovered limits:

  • No physical Roller485: motor spin/load, real stall trip and recovery, current/temperature,
    LED optics, OLED menu, and the RS485 frame/electrical layer are NOT RUN.
  • The Unit model does not simulate motor physics; the virtual readback sensors were
    exercised at model defaults (0 rpm / 0° / 0 mA, 12 V, 30 °C), so non-zero scaling is
    covered by the host tests only.
  • The model exposes no RGB QOM property; LED evidence is the guest raw register read-back
    above plus the host tests.
  • fault/system-state are read-only fixtures, so only Standby/Running were observed;
    the other status strings are host-tested. The 0x0B stall-reset write is host-tested; its
    fault-clearing effect could not be observed on the model.

Could you add the YAML and a UART log from your CoreS3 hardware run, and state the unit
firmware version you tested (V3 or V4)? Mode 5 only appears in the V4 source.

One CI note: script/build_codeowners.py --check fails on the current m5-dev baseline
for many unrelated components already missing from CODEOWNERS; the new
m5_unit_roller485 entry itself matches the generator output.

Detailed log, decode and probe: https://github.com/m5agent/agent-work-logs/blob/0a587be992a539d695a64fcda0b6ff728bbfb072/records/m5stack-esphome/2026-12-01-pr6-m5-unit-roller485/README.md

The menu on the unit can switch the LED back to its own colours, so the
mode byte now goes with every colour instead of once per connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@New-Kringster

Copy link
Copy Markdown
Author

Thanks for the review.

  1. Fixed in f22d7f3: the mode byte at 0x33 now goes with every colour, so a colour from the light shows again after the unit's menu turns it off. Brightness is still written once per connection.
  2. The unit here reports firmware version 1, and the M5Unit-Roller library lists modes 1 to 4 only, so I left mode 5 out. A comment now says that the select keeps its state when the unit is in another mode.
  3. This works like other I2C components that allow more than one instance: each unit needs its own address:, and the address has to be changed on the unit first. Changing it from ESPHome is left out on purpose.

The brightness register is 0x12 (I2C_RGB_BRIGHTNESS_REG in the library). 0x10 is the RS485 ID.

Hardware: a CoreS3 with the Roller485 on Port A and power from the Grove port only (Vin reads about 4.7 V). I tested speed mode (300 rpm target, 297 rpm read back), position mode (90°, held at 89–92°) and current mode (300 mA). The motor switch, mode select and targets worked from Home Assistant. Encoder mode and a real stall were not tested.

Log at boot, when the AW9523 has just switched Port A on and the unit is still starting:

[13:58:17][I][power:030]: Port A 5V switched on
[13:58:18][W][component:290]: m5_unit_roller485 set Warning flag: Communication failed
[13:58:19][D][m5_unit_roller485:106]: Status Standby (system status 0, error code 0)
[13:58:19][W][component:325]: m5_unit_roller485 cleared Warning flag
[13:45:54][C][m5_unit_roller485:236]: M5Stack Unit Roller485:
[13:45:54]  Firmware version: 1
[13:45:54][C][m5_unit_roller485:240]:   Address: 0x64
YAML
esp32:
  variant: esp32s3
  flash_size: 16MB
  framework:
    type: esp-idf

logger:
  hardware_uart: USB_SERIAL_JTAG
  level: DEBUG
  logs:
    sensor: INFO
    i2c.idf: DEBUG

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

api:
  encryption:
    key: !secret api_key

ota:
  - platform: esphome
    password: !secret ota_password

i2c:
  - id: internal_bus
    sda: GPIO12
    scl: GPIO11
    frequency: 400kHz
  - id: port_a
    sda: GPIO2
    scl: GPIO1
    scan: true
    frequency: 100kHz

m5_unit_roller485:
  id: roller
  i2c_id: port_a

sensor:
  - platform: m5_unit_roller485
    speed:
      name: Speed
    position:
      name: Position
    current:
      name: Current
    voltage:
      name: Voltage
    temperature:
      name: Temperature
    encoder:
      name: Encoder
  - platform: wifi_signal
    name: Wi-Fi signal
    update_interval: 60s

text_sensor:
  - platform: m5_unit_roller485
    status:
      name: Status

switch:
  - platform: m5_unit_roller485
    motor:
      name: Motor
    stall_protection:
      name: Stall protection

select:
  - platform: m5_unit_roller485
    mode:
      name: Mode

number:
  - platform: m5_unit_roller485
    speed:
      name: Target speed
      mode: box
    speed_max_current:
      name: Speed max current
      mode: box
    position:
      name: Target position
      mode: box
    position_max_current:
      name: Position max current
      mode: box
    current:
      name: Target current
      mode: box

button:
  - platform: m5_unit_roller485
    reset_stall:
      name: Reset stall

light:
  - platform: m5_unit_roller485
    name: LED

The on_boot lambda that switches Port A's 5 V on through the AW9523 is left out here.

@m5agent

m5agent commented Dec 2, 2026

Copy link
Copy Markdown

Thanks for the follow-up and the hardware numbers.

Conclusion: the 0x33 change is correct and I re-verified it; no blocking issue remains. The 0x12 item below is the only new observation.

Evidence level: virtual-device validation (CoreS3 QEMU + Roller485 register model on PORT.A) plus host tests and source cross-check. Your CoreS3 results are hardware validation as reported; I have not reproduced them.

What I re-ran at f22d7f3b3:

  • script/cpp_unit_test.py m5_unit_roller485 → 22/22 PASS, including the new LaterColoursSetTheModeAgain.
  • Full esphome compile for m5stack-cores3 (esp32-idf) passed.
  • Probe: wrote 0x33=0 to mimic the unit menu, then light.turn_on; readback 0x33=1. The 4-byte write at 0x30..0x33 is also what i2c_protocol.c expects (the fourth byte sets rgb_show_mode), so the extra byte is correct.

On the points:

  1. 0x33: fixed. Residual of the same class: the unit's <RGB%> menu writes brightness_index (0x12) and saves it to flash. With 0x12 written only once per connection, a menu brightness change persists; my probe set 0x12=20 and the next colour write left it at 20. If the unit brightness is meant to be a user cap, a line saying so would help; if not, read 0x12 in read_settings_() and re-write 100 when it differs (or send it with each colour). Non-blocking.
  2. Mode 5: fine with the comment. V4 has MODE_POS_SPEED=5 and accepts mode < 6; V3 documents 1–4. The V3 protocol fixes 0xFE at 3 and the V4 source sets 4, so the 1 you see is likely an earlier build; it does not change the decision.
  3. MULTI_CONF: fine as a deliberate choice, same as other I2C components. A one-line note in the component docs that each unit must be re-addressed before adding a second instance would be enough.

On the register label: you're right — 0x12 is RGB brightness and 0x10 is the RS485 motor ID. My earlier comment's 0x10=0x64 was a labelling error; the readback behind it was the 0x10..0x12 = 00 00 64 triple, i.e. 0x12=100. The component already writes 0x12 (REG_RGB_BRIGHTNESS).

The boot Communication failed is the first poll racing the AW9523 port power; it cleared on the next update, so I would leave it rather than add a fixed delay.

Not covered: encoder mode, real stall trip/recovery, LED optics and the RS485 frame/electrical layer remain NOT RUN here; the model does not simulate motor physics, and I have no Roller485 hardware. Thanks for the 300→297 rpm, 90°→89–92° and 300 mA data — that covers the hardware gap I had flagged, with the limits you noted.

Record: https://github.com/m5agent/agent-work-logs/blob/e8cb508c24c5bf2434933e64369e6da0bee02cd2/records/m5stack-esphome/2026-12-02-pr6-followup/README.md

The menu on the unit can change the brightness as well as the LED mode,
so both now go with every colour. Rename to_byte_ to to_byte, which
clang-tidy requires for a static method.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@New-Kringster

Copy link
Copy Markdown
Author

Done in 5f3dbe2: the brightness at 0x12 now goes with every colour as well, so a change from the unit menu lasts only until the next colour. The same commit fixes a clang-tidy naming error in the light header.

@m5agent

m5agent commented Dec 2, 2026

Copy link
Copy Markdown

Conclusion: both changes are correct, and the 0x12 residual is closed. No blocking issue from my side.

Evidence level: virtual-device validation (CoreS3 QEMU + Roller485 register model on PORT.A) plus host tests and a source-diff review. Your hardware run remains the only physical evidence; I have not reproduced it.

At 5f3dbe2eb:

  • script/cpp_unit_test.py m5_unit_roller485 → 22/22 PASS. The renamed LaterColoursSetTheModeAndBrightnessAgain now expects 0x12=100.
  • Full esphome compile for m5stack-cores3 (esp32-idf) passed.
  • Probe: wrote 0x12=20 to mimic the unit menu, then light.turn_on; readback was 0x12=100 and 0x33=1. The earlier run left 0x12=20, so this commit closes that residual.
  • to_byte_ → to_byte is correct at the definition and both call sites. I did not run clang-tidy itself, so that part is code-level only.

Needed steps: none for the behavioural points. Merge timing is the maintainers' call.

Not covered: physical LED brightness/optics, motor/stall/encoder behaviour and the RS485 layer remain NOT RUN here; the brightness restore is proven at register level only. Nothing else from my earlier review needs reopening.

Record: https://github.com/m5agent/agent-work-logs/blob/78762cc53c5a3456f85dd0bb2ddb9be514a9e3fa/records/m5stack-esphome/2026-12-02-pr6-brightness-fix/README.md

@parker-int64
parker-int64 merged commit 2e4626b into m5stack:m5-dev Dec 2, 2026
30 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants