iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🔌

Connecting to MicroCat.1 (MECHATRAX) using VSCode and MicroPico

に公開

What this is about

I immediately purchased the MicroCat.1 (pre-release version) from MECHATRAX, which went on sale on 2025/12/15, and have been serving as a "human guinea pig."

https://mechatrax.com/2025/12/15/microcat1-pre/

I was able to run MicroPython using Thonny, but I really wanted to run it in VS Code, so this is a record of my attempts. Specifically, I solved the issue where I could not connect when using the VS Code extension "MicroPico" for the MicroCat.1 (RP2350 series) MicroPython environment, even though the serial port was not occupied by tools like screen. I also noted how to deal with some parts that were not stable even after the port was recognized.

Quick Start

  • Connect microcat.1 via USB
    alt text
    alt text

  • Confirm that you can access the REPL using screen /dev/cu.usbmodem1101 115200 or similar.
    alt text

  • Open a new window in VS Code, create a project folder, and open it.
    alt text
    alt text

  • Install the MicroPico extension.
    alt text
    alt text

  • Execute the micropico initialization
    Open the Command Palette with cmd + shift + p and run MicroPico: Initialize micropico project.
    alt text

  • You will have a folder structure like this
    alt text

  • In this state, you cannot connect even if you click the MicroPico icon in the bottom left.
    (The reason will be explained later)
    alt text

  • Download and execute patch_micropico.sh to patch the extension.

https://github.com/takao2704/public-zenn-docs/blob/main/files/patch_micropico.sh

chmod +x patch_micropico.sh
./patch_micropico.sh

Execution example:

takao@TakaonoMacBook-Pro files % ./patch_micropico.sh 
Found extensions:
  /Users/takao/.vscode/extensions/paulober.pico-w-go-4.3.4-darwin-arm64
Patching /Users/takao/.vscode/extensions/paulober.pico-w-go-4.3.4-darwin-arm64/dist/extension.js
Backup will be saved to /Users/takao/.vscode/extensions/paulober.pico-w-go-4.3.4-darwin-arm64/dist/extension.js.bak.20251218233200
Patched successfully.
Done. Backup saved as /Users/takao/.vscode/extensions/paulober.pico-w-go-4.3.4-darwin-arm64/dist/extension.js.bak.20251218233200
  • Reload the workspace.
    Open the Command Palette with shift + cmd + p and run Developer: Reload Window.
    alt text

  • REPL connection to the actual device becomes possible.
    alt text

  • Naturally, the display in the bottom left will also change.
    alt text

  • For example, if you type:

from machine import Pin
pin = Pin("LED", Pin.OUT)
pin.high()

the LED will light up.
alt text
before
alt text
after
alt text

For example, if you save a script like the one introduced on this site:

from machine import Pin
from utime import sleep

pin = Pin("LED", Pin.OUT)

print("LED starts flashing...")
while True:
    try:
        pin.toggle()
        sleep(1) # sleep 1sec
    except KeyboardInterrupt:
        break
pin.off()
print("Finished.")

as blink.py and click the Run button in the bottom left while the file is open, you can execute it.
alt text

  • If you want to write it to microCat.1 as a program that runs automatically
    save the file as main.py, open the Command Palette with Shift + Cmd + P, and execute MicroPico: Upload file to Pico.
    alt text

  • After writing, it will reset, and main.py will run automatically.

Explanation

Environment Used

  • Board: MechaTracks MicroCat.1
  • Firmware: mtx branch of mechatrax/micropython
  • Extension: paulober.pico-w-go-4.3.4 (MicroPico)
  • OS: macOS (installed under ~/.vscode/extensions)

Symptoms and Environment Confirmation

  • Symptom 1:
    /dev/cu.usbmodem1101 is visible, but MicroPico cannot connect because the VID/PID differ from the standard Pico.

    • Remedy:
      Apply a patch to absorb the VID/PID difference.
  • Symptom 2:
    Even after accounting for the VID/PID difference, getSerialPorts fires continuously, causing a RangeError to persist.

    • Remedy:
      Apply a patch to stop enumeration when a specific port is provided.
  • Symptom 3:
    When "Toggle Mpy FS" is enabled, stat/readFile errors occur frequently, making it impossible to retrieve the file list and rendering it impractical.

    • Remedy:
      Give up (For MicroCat.1, do not use "Toggle Mpy FS" and stick to manual connection + upload operation).

Isolation and Observation

1. Physical/Firmware Confirmation

  • Change cables and ports, reconnect, and confirm whether you can enter the REPL with screen /dev/cu.usbmodem1101 115200.
  • Confirm that picotool info -d is visible in BOOTSEL mode (the board is responding).

2. Confirming VID/PID Mismatch

  • ports/rp2/boards/MTX_MICROCAT1/mpconfigboard.h has the following definitions:
    • MICROPY_HW_USB_VID (0x388B)
    • MICROPY_HW_USB_PID (0xCA71)
  • Since it differs from the standard Pico (0x2E8A series), it is excluded from the extension's automatic enumeration.

3. Confirming MicroPico Behavior

  • Even after absorbing the VID/PID difference, getSerialPorts runs every 1.5 seconds, causing continuous RangeError issues, and connection is not established.
  • With "Toggle Mpy FS," stat/readFile errors occur frequently, and the virtual FS is essentially unusable.

Log Sample (Excerpt)

RangeError: offset is out of bounds              # When getSerialPorts hits repeatedly
Error: Failed to read file: stat/readFile error  # When Toggle Mpy FS is on

Policy for Response and Resolution

  1. Do not change the VID/PID on the firmware side; handle it on the extension side.
  2. When a port is manually specified, stop port enumeration and the automatic connection timer.
  3. Since "Toggle Mpy FS" is unstable, do not use it and stick to manual connection + upload operation.

Provisional Remedy (Configuration only, unresolved)

  • Even if micropico.manualComDevice was specified and autoConnect was set to false, the enumeration timer remained, and the RangeError did not stop.
  • Just grasping the VID/PID difference did not resolve the issue, as it could not suppress the repeatedly firing getSerialPorts.

Root Cause Fix (Extension Patch)

  • Modified setupAutoConnect() to directly openSerialPort() without calling getSerialPorts() or starting a timer when a port is manually specified.
  • This stopped the RangeError, allowing stable operation by sticking to manual connection + upload.

Patch Overview

  • Target file: ~/.vscode/extensions/paulober.pico-w-go-4.3.4-darwin-arm64/dist/extension.js
  • Changes:
    • Changed the behavior of processing equivalent to setupAutoConnect().
      • If micropico.manualComDevice is set, do not call getSerialPorts(), directly openSerialPort() with the specified port, and exit. Do not start the automatic connection timer.
      • Only perform port enumeration as before if the manual specification is empty and micropico.autoConnect is true.
    • This prevents RangeError even in custom VID/PID environments, ensuring stable manual connections.

Patch Application Procedure

  1. Confirm that the MicroPico extension is installed.
  2. Execute the patch script at the repository root.
cd /Users/takao/Project/MicroPico-1
./scripts/patch_micropico.sh
# Specify the path if you have multiple extensions installed
# ./scripts/patch_micropico.sh ~/.vscode/extensions/paulober.pico-w-go-4.3.4-darwin-arm64
  • Upon execution, dist/extension.js.bak.<timestamp> will be created, and the target extension will be patched directly. Since this will revert if you reinstall the extension, reapply it as necessary.

VS Code Settings Example (Stable Operation)

An example of settings.json. It connects only via the manually specified port and does not use the automatic connection timer.

{
  "micropico.manualComDevice": "/dev/cu.usbmodem1101",
  "micropico.autoConnect": false,
  "micropico.openOnStart": false
}

Validation Results

  • After patching, RangeError did not reoccur with the manually specified port, and connection/upload became stable.
  • Resetting after upload started main.py, confirming operations like LED blinking.

Recurrence Prevention and Notes for Updates

  • If extension.js is overwritten by an extension update, it will revert, so execute patch_micropico.sh again after updates.
  • Treat "Toggle Mpy FS" as unsupported (unstable) and operate under the premise of not using it.
  • If the path differs for other OSs or versions, specify the extension directory explicitly to patch_micropico.sh.

Summary

  • I can now use it without much stress.
  • The problem where MicroPico's automatic enumeration fails due to the MicroCat.1's custom VID/PID can be solved by simply making the extension "not enumerate if a manual port is specified."
  • It can be easily applied with scripts/patch_micropico.sh, and it became stable with manual connection + upload operation.
  • Reapply after confirming the backup when updating the extension.
GitHubで編集を提案

Discussion