Datasheet
Using SPI Flash
One of the best features of the M0 express board is a small SPI flash memory chip built into the board. This memory
can be used for almost any purpose like storing data files, Python code, and more. Think of it like a little SD card that is
always connected to the board, and in fact with Arduino you can access the memory using a library that is very similar
to the Arduino SD card library (https://adafru.it/ucu). You can even read and write files that CircuitPython stores on the
flash chip!
To use the flash memory with Arduino you'll need to install the Adafruit SPI Flash Memory library (https://adafru.it/wbt)
in the Arduino IDE. Click the button below to download the source for this library, open the zip file, and then copy it
into an Adafruit_SPIFlash folder (remove the -master GitHub adds to the downloaded zip and folder) in the Arduino
library folder on your computer (https://adafru.it/dNR):
https://adafru.it/wbu
https://adafru.it/wbu
Once the library is installed open the Arduino IDE and look for the following examples in the library:
fatfs_circuitpython
fatfs_datalogging
fatfs_format
fatfs_full_usage
fatfs_print_file
flash_erase
These examples allow you to format the flash memory with a FAT filesystem (the same kind of filesystem used on SD
cards) and read and write files to it just like a SD card.
Read & Write CircuitPython Files
The fatfs_circuitpython example shows how to read and write files on the flash chip so that they're accessible from
CircuitPython. This means you can run a CircuitPython program on your board and have it store data, then run an
Arduino sketch that uses this library to interact with the same data.
Note that before you use the fatfs_circuitpython example you must have loaded CircuitPython on your board. Load
the latest version of CircuitPython as explained in this guide (https://adafru.it/BeN) first to ensure a CircuitPython
filesystem is initialized and written to the flash chip. Once you've loaded CircuitPython then you can run the
fatfs_circuitpython example sketch.
To run the sketch load it in the Arduino IDE and upload it to the Feather/Metro/ItsyBitsy M0 board. Then open the
serial monitor at 115200 baud. You should see the serial monitor display messages as it attempts to read files and write
to a file on the flash chip. Specifically the example will look for a boot.py and main.py file (like what CircuitPython runs
when it starts) and print out their contents. Then it will add a line to the end of a data.txt file on the board (creating it if
it doesn't exist already). After running the sketch you can reload CircuitPython on the board and open the data.txt file
to read it from CircuitPython!
To understand how to read & write files that are compatible with CircuitPython let's examine the sketch code. First
notice an instance of the Adafruit_M0_Express_CircuitPython class is created and passed an instance of the flash
chip class in the last line below:
© Adafruit Industries
https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-
circuitpython
Page 44 of 199