EasyManuals Logo

Adafruit Feather M4 Express User Manual

Adafruit Feather M4 Express
178 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #161 background imageLoading...
Page #161 background image
CircuitPython Storage
CircuitPython boards show up as as USB drive, allowing you to edit code directly on the board. You've been doing this
for a while. By now, maybe you've wondered, "Can I write data
from
CircuitPython
to the storage drive to act as a
datalogger?" The answer is yes!
However, it is a little tricky. You need to add some special code to boot.py, not just code.py. That's because you have
to set the filesystem to be read-only when you need to edit code to the disk from your computer, and set it to writeable
when you want the CircuitPython core to be able to write.
The following is your new boot.py. Copy and paste the code into boot.py using your favorite editor. You may need to
create a new file.
For Gemma M0, Trinket M0, Metro M0 Express, Metro M4 Express, ItsyBitsy M0 Express and ItsyBitsy M4 Express,
no changes to the initial code are needed.
For Feather M0 Express and Feather M4 Express, comment out switch = digitalio.DigitalInOut(board.D2) , and
uncomment switch = digitalio.DigitalInOut(board.D5) .
For Circuit Playground Express, comment out switch = digitalio.DigitalInOut(board.D2) , and uncomment switch =
digitalio.DigitalInOut(board.D7) .
The following is your new code.py. Copy and paste the code into code.py using your favorite editor.
You can only have either your computer edit the CIRCUITPY drive files, or CircuitPython. You cannot have
both write to the drive at the same time. (Bad Things Will Happen so we do not allow you to do it!)
import board
import digitalio
import storage
# For Gemma M0, Trinket M0, Metro M0/M4 Express, ItsyBitsy M0/M4 Express
switch = digitalio.DigitalInOut(board.D2)
# switch = digitalio.DigitalInOut(board.D5) # For Feather M0/M4 Express
# switch = digitalio.DigitalInOut(board.D7) # For Circuit Playground Express
switch.direction = digitalio.Direction.INPUT
switch.pull = digitalio.Pull.UP
# If the switch pin is connected to ground CircuitPython can write to the drive
storage.remount("/", switch.value)
Remember: To "comment out" a line, put a # and a space before it. To "uncomment" a line, remove the # +
space from the beginning of the line.
© Adafruit Industries https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51 Page 166 of 183

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Adafruit Feather M4 Express and is the answer not in the manual?

Adafruit Feather M4 Express Specifications

General IconGeneral
BrandAdafruit
ModelFeather M4 Express
CategoryMicrocontrollers
LanguageEnglish

Related product manuals