Storage
CircuitPython-compatible microcontrollers show up as a CIRCUITPY drive when
plugged into your computer, allowing you to edit code directly on the board. Perhaps
you've wondered whether or not you can write data from CircuitPython directly to the
board to act as a data logger. The answer is yes!
The storage module in CircuitPython enables you to write code that allows
CircuitPython to write data to the CIRCUITPY drive. This process requires you to
include a boot.py file on your CIRCUITPY drive, along side your code.py file.
The boot.py file is special - the code within it is executed when CircuitPython starts
up, either from a hard reset or powering up the board. It is not run on soft reset, for
example, if you reload the board from the serial console or the REPL. This is in
contrast to the code within code.py, which is executed after CircuitPython is already
running.
The CIRCUITPY drive is typically writable by your computer; this is what allows you to
edit your code directly on the board. The reason you need a boot.py file is that you
have to set the filesystem to be read-only by your computer to allow it to be writable
by CircuitPython. This is because CircuitPython cannot write to the filesystem at the
same time as your computer. Doing so can lead to filesystem corruption and loss of all
content on the drive, so CircuitPython is designed to only allow one at at time.
Wiring for MCP9808
You're going to be logging the temperature. For this task, you will need to wire up a
temperature sensor, like the MCP9808. Connect it to your microcontroller as shown
below.
This example only runs once, so if you do not see any output when you connect
to the serial console, try CTRL+D to reload.
You can only have EITHER your computer edit files on the CIRCUITPY drive, OR
have CircuitPython edit files. You cannot have both writing to the CIRCUITPY
drive at the same time. CircuitPython doesn't allow it!
©Adafruit Industries Page 165 of 263