Skip to content

A MicroPython / CircuitPython board in the device picker - #122

Merged
david-firia merged 2 commits into
mainfrom
generic-micropython
Nov 23, 2026
Merged

david-firia merged 2 commits into
mainfrom
generic-micropython

Conversation

@david-firia

@david-firia david-firia commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What

One new entry in the device picker, MicroPython / CircuitPython board, for any board with a Python prompt over USB (a Raspberry Pi Pico, an ESP32, an Adafruit board). It makes "CodeBot, CodeX, CodeAIR, and more!" true.

  • Connect lists every serial port while it is picked; the board is the generic target.
  • Flavor follows the board: its banner (asked for with Ctrl-B at the first prompt, or just before the first Run if the board was busy with its own program) says MicroPython or CircuitPython, and the Pins blocks and the chip's name follow, with a toast. Before a board is connected it is MicroPython, or what was set in the device menu's small switch.
  • Run goes through the raw REPL, as mpremote run does: nothing is written to main.py or code.py (the board's own program stays; a read-only CircuitPython drive is no obstacle). Stop is Ctrl-C. Stop during sending stops the sending first. The terminal shows the program's output without the raw REPL's markers; the Firia debug filter is off for it. The program's other .py files are not copied to the board (its files are the student's own, such as a driver or config.py, and a CircuitPython drive is read-only to code); a toast says so once.
  • Palette: the general sections plus Pins, four blocks. Each pin is claimed once after the imports: a pin set anywhere is an output (reading it reads back its value, so a toggle works); a pin only read is a pulled-up input.
    Block MicroPython CircuitPython
    set pin to on/off pin_LED.value(True) (setup pin_LED = Pin('LED', Pin.OUT)) pin_LED.value = True (setup DigitalInOut(board.LED), switch_to_output())
    pin is on pin_GP14.value() pin_GP14.value
    analog pin adc_GP26.read_u16() (setup ADC(Pin('GP26'))) adc_A0.value (setup AnalogIn(board.A0))
    milliseconds since start time.ticks_ms() int(time.monotonic() * 1000)
  • On MicroPython, seconds since start writes time.ticks_ms() / 1000 and Title Case is written out: MicroPython has neither time.monotonic nor str.title.
  • My blocks need no change: they carry no device, and a grey block runs as typed (tested).
  • Blink and button examples; Simulate says there is no simulator for this board. The Learn rail is unchanged (opening a Firia pack switches the device, as today).

Also

Repl.writeFile now reports a file that will not open (OSError: [Errno 30]) instead of the NameError that followed it, and error text drops the raw REPL's markers. This touches the Firia boards' companion copy path too.

Independent review

A reviewer subagent read the diff. Fixed from it: Stop during sending (the rest of the program reached the friendly prompt and the final Ctrl-D soft-reset the board; the new test fails on the parent commit), a pin set and read claimed twice, companion copies overwriting a student's own board files, the first Run on a busy board written in the wrong flavor, a character cut between pieces, and a setup line naming a different pin misread. Left: one pin used both digitally and as analog is claimed twice (CircuitPython refuses); noted in the README.

Tests

  • tests/generic-board.mjs: the DeviceManager against a scripted REPL in both flavors: banner sets the flavor, Run uses the raw REPL and writes no file, output without markers, an error's line, Stop on a forever program, a long program arrives whole, read-only drive message.
  • tests/generic-ui.mjs: loopback as a generic board: picker, switch, Pins in both palettes, the Python per flavor and back, flavor following a CircuitPython banner, Run, a student's own block, the wrong-board check, examples, no simulator.
  • tests/round-trip.mjs covers the generic palette in both flavors (80 block and choice pairs each).

Not tested on hardware

No MicroPython board is on a bench, and bench1 has no CodeX or CodeAIR attached, so neither flavor has run on a real board yet. In particular: the raw REPL run and Stop on a real MicroPython (Pico) and CircuitPython board, and the writeFile change on a Firia board's companion copy.

🤖 Generated with Claude Code

david-firia and others added 2 commits November 23, 2026 13:20
…ith a Python prompt

Picked, Connect lists every serial port and the board is the `generic`
target. Its banner says which Python it speaks (src/device/flavor.js), and
the blocks write that one; before a board is connected it is MicroPython, or
what the student set in the device menu's switch.

- Run sends the program through the raw REPL and runs it there: nothing is
  written to main.py or code.py, so the board's own program stays and a
  read-only CircuitPython drive is no obstacle. Stop is Ctrl-C. The terminal
  shows the program's output without the raw REPL's markers, and the Firia
  debug filter is off for it.
- A Pins palette section of four blocks: set a pin, read a pin (pulled up),
  read an analog pin, milliseconds since start. MicroPython writes
  machine.Pin / ADC / time.ticks_ms; CircuitPython board / digitalio /
  analogio / time.monotonic, each pin claimed once after the imports. Python
  back to blocks reads those setup lines as the blocks' own.
- On MicroPython, seconds since start is time.ticks_ms() / 1000 and Title
  Case is written out (it has neither time.monotonic nor str.title).
- Blink and button examples; the simulator says it has no such board.
- writeFile now reports a file that will not open (OSError 30 on a read-only
  drive) instead of the NameError after it, and error text drops the raw
  REPL's markers.

Tests: generic-board.mjs (the DeviceManager against a scripted MicroPython
and CircuitPython REPL), generic-ui.mjs (loopback as a generic board), and
round-trip.mjs now covers the generic palette in both flavors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…o copies to the board, flavor before the first Run

- Stop while a program is still being sent to the raw REPL stops the
  sending first; before, the rest arrived at the prompt Stop left and the
  final Ctrl-D soft-reset the board (tests/generic-board.mjs fails on the
  parent).
- Each pin is claimed once, after the imports, in both flavors: a pin set
  anywhere is an output and reading it reads back its value (a toggle works);
  a pin only read is a pulled-up input. Before, a pin set and read was
  claimed twice ("in use" on CircuitPython) or turned into an input
  (MicroPython). Numbered MicroPython pins now come back from Python as
  blocks too.
- Run copies none of the program's other .py files to a generic board: its
  files are the student's own, and a CircuitPython drive is read-only to code.
  A toast says so, once.
- A board busy with its own program when connected is stopped and asked
  which Python it speaks before the first Run writes its program.
- The program is sent in byte pieces, so no character is cut in two.
- A setup line whose object and pin differ is the student's own, kept as
  Python.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit eb95421):

https://firialabs-open-editor--pr122-generic-micropython-rcgjjg8v.web.app

(expires Mon, 30 Nov 2026 19:52:26 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 81259a1fec315ca1af3747d225d9c7424890be3e

@david-firia
david-firia merged commit a1c42b0 into main Nov 23, 2026
6 of 7 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.

1 participant