CircuitPython
Belay also supports CircuitPython.
Unlike MicroPython, CircuitPython automatically mounts the device's filesystem as a USB drive.
This is usually convenient, but it makes the filesystem read-only to the python interpreter.
To get around this, we need to manually add the following lines to boot.py
on-device.
import storage
storage.remount("/")
Afterwards, reset the device and it's prepared for Belay.
Reverting
To revert this configuration, there are multiple options:
Edit
boot.py
using Thonny, then reboot. Thonny (like Belay), operates via the REPL, so it has write-access since it's operating through circuitpython.Through circuitpython's REPL via an interactive shell, such as
rshell
orpython -m serial.tools.miniterm
:
import os
os.remove("boot.py")
Using Belay in an interactive python prompt on host:
from belay import Device
device = Device("/dev/ttyUSB0") # replace with appropriate port
device("os.remove('boot.py')")
# Then reboot.
Physical Configuration
Storage mounting can be configured based on a physical pin state.
Adding the following contents to /boot.py
will configure the system to:
Be in "normal" circuitpython mode if pin 14 is floating/high (due to configured pullup) on boot.
Be in Belay-compatible mode if pin 14 is connected to ground on boot. This could be done, for example, by a push-button or a toggle switch.
import board
import storage
from digitalio import DigitalInOut, Pull
op_mode = DigitalInOut(board.GP14) # Choose whichever pin you would like
op_mode.switch_to_input(Pull.UP)
if not op_mode.value:
# Mount system in host-readonly, circuitpython-writeable mode (Belay compatible).
storage.remount("/")