Datasheet
By using this Adafruit_M0_Express_CircuitPython class you'll get a filesystem object that is compatible with reading
and writing files on a CircuitPython-formatted flash chip. This is very important for interoperability between
CircuitPython and Arduino as CircuitPython has specialized partitioning and flash memory layout that isn't compatible
with simpler uses of the library (shown in the other examples).
Once an instance of the Adafruit_M0_Express_CircuitPython class is created (called pythonfs in this sketch) you can
go on to interact with it just like if it were the SD card library in Arduino (https://adafru.it/wbw). You can open files for
reading & writing, create directories, delete files and directories and more. Here's how the sketch checks if a boot.py
file exists and prints it out a character at a time:
Notice the exists function is called to check if the boot.py file is found, and then the open function is used to open it in
read mode. Once a file is opened you'll get a reference to a File class object which you can read and write from as if it
were a Serial device (again just like the SD card library, all of the same File class functions are
available (https://adafru.it/wbw)). In this case the available function will return the number of bytes left to read in the
file, and the read function will read a character at a time to print it to the serial monitor.
Writing a file is just as easy, here's how the sketch writes to data.txt:
#define FLASH_SS SS1 // Flash chip SS pin.
#define FLASH_SPI_PORT SPI1 // What SPI port is Flash on?
Adafruit_SPIFlash flash(FLASH_SS, &FLASH_SPI_PORT); // Use hardware SPI
// Alternatively you can define and use non-SPI pins!
//Adafruit_SPIFlash flash(SCK1, MISO1, MOSI1, FLASH_SS);
// Finally create an Adafruit_M0_Express_CircuitPython object which gives
// an SD card-like interface to interacting with files stored in CircuitPython's
// flash filesystem.
Adafruit_M0_Express_CircuitPython pythonfs(flash);
// Check if a boot.py exists and print it out.
if (pythonfs.exists("boot.py")) {
File bootPy = pythonfs.open("boot.py", FILE_READ);
Serial.println("Printing boot.py...");
while (bootPy.available()) {
char c = bootPy.read();
Serial.print(c);
}
Serial.println();
}
else {
Serial.println("No boot.py found...");
}
© Adafruit Industries
https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-
circuitpython
Page 45 of 199