Datasheet

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.
import board
import digitalio
import storage
# For Gemma M0, Trinket M0, Metro M0/M4 Express, ItsyBitsy M0/M4 Express
switch = digitalio.DigitalInOut(board.D2)
# For Feather M0/M4 Express
# switch = digitalio.DigitalInOut(board.D5)
# For Circuit Playground Express, Circuit Playground Bluefruit
# switch = digitalio.DigitalInOut(board.D7)
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)
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 and Circuit Playground Bluefruit, comment out switch =
digitalio.DigitalInOut(board.D2) , and uncomment switch = digitalio.DigitalInOut(board.D7) . Remember, D7 is the
onboard slide switch, so there's no extra wires or alligator clips needed.
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!)
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-itsybitsy-nrf52840-express Page 163 of 179