Storage Writable Mode
If you want to be able to create new files, or save changes to existing ones, then you need the storage in your CircuitPython device to be mounted as writable. This can be achieved with a little bit of code inside of the boot.py file. For this project, I've hooked up a button that the user can press during boot up to configure the device as writable vs. read only. This technique and more general information about the storage module can be found on this CircuitPython Essentials guide page. If you're unfamiliar with that process, I recommend you look over that Essentials guide page first and then return here. The devices and specific pins mentioned on the Essentials page are different from the ones this project uses, but the technique is the exact same.
Loading boot.py
If you do not already have a boot.py file on your CIRCUITPY drive, you can simply copy the one from the project files onto your device. If you do have a pre-existing boot.py with some code that you want to keep you can copy/paste the code from the project boot.py file into your own existing file.
# SPDX-FileCopyrightText: 2024 Tim Cocks
#
# SPDX-License-Identifier: MIT
import usb_cdc
import board
import digitalio
import storage
usb_cdc.enable(console=True, data=True) # Enable console and data
write_mode_btn = digitalio.DigitalInOut(board.D9)
write_mode_btn.direction = digitalio.Direction.INPUT
write_mode_btn.pull = digitalio.Pull.UP
storage.remount("/", readonly=write_mode_btn.value)
Load the Code
Click the Download Project Bundle button in the window below. It will download all the code for this project to your computer as a zipped folder.
After downloading the Project Bundle, plug your Feather into the computer's USB port with a known good USB data+power cable. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called CIRCUITPY. Unzip the folder and copy the following items to the Feather CIRCUITPY drive.
- lib folder
- adafruit_editor folder
- code.py
# SPDX-FileCopyrightText: 2024 Tim Cocks
#
# SPDX-License-Identifier: MIT
import traceback
from adafruit_editor import editor, picker
# 3.5" FeatherWing (original)
from adafruit_featherwing import tft_featherwing_35
# 2.4" FeatherWing V2
# from adafruit_featherwing import tft_featherwing_24
import terminalio
import displayio
from adafruit_display_text.bitmap_label import Label
import usb_cdc
#pylint: disable=redefined-builtin,broad-except
def print(message):
usb_cdc.data.write(f"{message}\r\n".encode("utf-8"))
# 3.5" FeatherWing (original)
tft_featherwing = tft_featherwing_35.TFTFeatherWing35V2()
# 2.4" FeatherWing V2
# tft_featherwing = tft_featherwing_24.TFTFeatherWing24V2()
display = tft_featherwing.display
display.rotation = 180
customized_console_group = displayio.Group()
display.root_group = customized_console_group
customized_console_group.append(displayio.CIRCUITPYTHON_TERMINAL)
visible_cursor = Label(terminalio.FONT, text="",
color=0x000000, background_color=0xeeeeee, padding_left=1)
visible_cursor.hidden = True
visible_cursor.anchor_point = (0, 0)
customized_console_group.append(visible_cursor)
try:
while True:
try:
visible_cursor.hidden = True
filename = picker.pick_file()
except KeyboardInterrupt:
customized_console_group.remove(displayio.CIRCUITPYTHON_TERMINAL)
break
try:
visible_cursor.hidden = False
editor.edit(filename, visible_cursor)
except KeyboardInterrupt:
visible_cursor.hidden = True
# Any Exception, including Keyboard Interrupt
except Exception as e:
print("\n".join(traceback.format_exception(e)))
customized_console_group.remove(displayio.CIRCUITPYTHON_TERMINAL)
Drive Structure
After copying the files, your drive should look like the listing below. It can contain other files as well, but must contain these at a minimum:
Page last edited January 22, 2025
Text editor powered by tinymce.