{
  "id": "mattytrentini/micropython-rollercan",
  "name": "micropython-rollercan",
  "prettyName": "micropython-rollercan",
  "description": "MicroPython machine.CAN driver for the M5Stack RollerCAN Lite motor",
  "version": "",
  "author": "mattytrentini",
  "license": "MIT",
  "tags": [],
  "status": "VALID",
  "official": false,
  "source": "https://github.com/mattytrentini/micropython-rollercan",
  "updatedAt": "2026-11-22T07:43:17.144Z",
  "page": "https://checkmim.com/packages/mattytrentini+micropython-rollercan",
  "createdAt": "2026-11-22T07:43:14.865Z",
  "submittedBy": "Matt",
  "install": {
    "mpremote": "mpremote mip install github:mattytrentini/micropython-rollercan",
    "mip": "import mip; mip.install(\"github:mattytrentini/micropython-rollercan\")"
  },
  "readme": "# RollerCAN Lite for MicroPython\n\nA dependency-free, MIT-licensed driver for the [M5Stack RollerCAN Lite](https://docs.m5stack.com/en/unit/Unit_RollerCAN-Lite) using [`machine.CAN`](https://docs.micropython.org/en/latest/library/machine.CAN.html). Supports speed, position, current and encoder (dial) modes, plus feedback and telemetry. It does not use `pyb.CAN`, SocketCAN, or UIFlow.\n\n## Install\n\n```sh\nmpremote mip install github:mattytrentini/micropython-rollercan\n```\n\nOn a network-connected board:\n\n```python\nimport mip\nmip.install(\"github:mattytrentini/micropython-rollercan\")\n```\n\n## Connect and check status\n\nUse a MicroPython build exposing `machine.CAN` and a CAN transceiver. The\nmotor uses Classic CAN with 29-bit extended IDs. The factory defaults are\n1 Mbit/s and motor ID `0xA8`. Provide the motor a suitable 6–16 V supply via\nthe PwrCAN connector. Connect CAN-H, CAN-L and a common ground, and terminate\nthe two physical ends of the bus. Do not connect the motor supply to MCU I/O.\n\n```python\nfrom machine import CAN\nfrom rollercan import RollerCAN\n\ncan = CAN(1, 1_000_000)  # The controller ID is board-specific.\ncan.set_filters(None)    # Accept all on an isolated bench bus.\nmotor = RollerCAN(can)\nprint(hex(motor.ping()))\nprint(motor.status())\n```\n\n`RollerCAN(can, node_id=0xA8, host_id=0, timeout_ms=250)` does not transmit,\nchange filters, or enable the motor during construction. Use a free host ID\nthat is distinct from every motor ID on the bus. The driver consumes the CAN\nreceive queue, discarding stale or unrelated frames. You can share the physical\nbus and use multiple motor instances on one controller, but run transactions\nsequentially and do not use the same controller concurrently for other I/O.\nOn a busy bus, configure hardware filters for the reply IDs before use.\n\n## Run at a low speed\n\nFixture the motor securely and keep the shaft and attachments clear. Verify\nthat you have a physical way to cut motor power before commanding motion.\nThe manufacturer rates the Lite for 500 mA continuous without forced cooling\nand up to 1 A for short periods. The driver rejects current targets or limits\nabove 1 A in magnitude; it does not enforce a continuous-duty thermal limit.\n\n```python\nfrom time import sleep_ms\n\nmotor.stop()\nmotor.set_mode(RollerCAN.SPEED)\nmotor.set_current_limit(RollerCAN.SPEED, 100)  # mA\nmotor.set_speed(30)                            # rpm\ntry:\n    motor.start()\n    sleep_ms(500)\n    print(motor.speed())\nfinally:\n    motor.stop()\n```\n\n`stop()` disables drive output; it does not actively brake or hold position.\nA timeout raises `OSError` with `ETIMEDOUT`. It does not prove that a command\nwas never executed or that the motor has stopped. The driver asks the CAN\ncontroller to cancel any pending transmission on failure. If communication\nis lost, cut motor power rather than relying on software stop.\n\n## API\n\n| Operation | Methods and units |\n| --- | --- |\n| Device and output | `ping()` returns the node ID; `status()`, `start()`, `stop()` return `Feedback` |\n| Mode | `set_mode(RollerCAN.SPEED / POSITION / CURRENT / ENCODER)` |\n| Targets | `set_speed(rpm)`, `set_position(degrees)`, `set_current(milliamps)`, `set_encoder_count(count)` |\n| Current limit | `set_current_limit(mode, milliamps)` applies to `SPEED` or `POSITION` |\n| Telemetry | `speed()` in rpm, `position()` in degrees, `current()` in mA, `voltage()` in V, `temperature()` in °C, `encoder_count()` in raw dial counts |\n\nSetters return `Feedback` and do not enable output or silently switch modes.\nChanging a target or mode while already running can take effect immediately.\n`Feedback` contains `state`, `mode`, `faults`, `speed_rpm`, `position_deg`,\n`current_ma` and `voltage_v`. Fault bits are `OVER_VOLTAGE`, `STALL` and\n`OUT_OF_RANGE`. Feedback uses whole-unit values; the dedicated speed,\nposition, current and voltage reads have 0.01-unit resolution on the wire.\nThe motor acknowledges writes with feedback, not a register echo; state and\nfaults should be checked rather than treating a reply as proof of movement.\nThis driver does not save parameters to flash or disable motor protection.\n\n## Test and reference\n\nRun `MICROPYPATH=. micropython tests/test_rollercan.py` from the repository root for\nprotocol tests against a simulated CAN controller. Physical hardware has not\nbeen tested.\n\nProtocol sources: [M5Stack's CAN control manual](https://m5stack-doc.oss-cn-shenzhen.aliyuncs.com/779/Unit-RollerCAN-CAN-Protocol-EN.pdf)\nand [RollerCAN firmware](https://github.com/m5stack/M5Unit-RollerCAN-Internal-FW/blob/5410e37b6910eb3a80c7446bdfbdd3ce93893389/code/Unit-RollerCAN/Core/User/can/can_protocol.c).\n"
}