Datasheet

Type OK and press enter in the serial monitor input to confirm that you'd like to format the flash memory. You need to
enter OK in all capital letters!
Once confirmed the sketch will format the flash memory. The format process takes about a minute so be patient as the
data is erased and formatted. You should see a message printed once the format process is complete. At this point
the flash chip will be ready to use with a brand new empty filesystem.
Datalogging Example
One handy use of the SPI flash is to store data, like datalogging sensor readings. The fatfs_datalogging example
shows basic file writing/datalogging. Open the example in the Arduino IDE and upload it to your Feather M0 board.
Then open the serial monitor at 115200 baud. You should see a message printed every minute as the sketch writes a
new line of data to a file on the flash filesystem.
To understand how to write to a file look in the loop function of the sketch:
Just like using the Arduino SD card library you create a File object by calling an open function and pointing it at the
name of the file and how you'd like to open it (FILE_WRITE mode, i.e. writing new data to the end of the file). Notice
// Open the datalogging file for writing. The FILE_WRITE mode will open
// the file for appending, i.e. it will add new data to the end of the file.
File dataFile = fatfs.open(FILE_NAME, FILE_WRITE);
// Check that the file opened successfully and write a line to it.
if (dataFile) {
// Take a new data reading from a sensor, etc. For this example just
// make up a random number.
int reading = random(0,100);
// Write a line to the file. You can use all the same print functions
// as if you're writing to the serial monitor. For example to write
// two CSV (commas separated) values:
dataFile.print("Sensor #1");
dataFile.print(",");
dataFile.print(reading, DEC);
dataFile.println();
// Finally close the file when done writing. This is smart to do to make
// sure all the data is written to the file.
dataFile.close();
Serial.println("Wrote new measurement to data file!");
}
© Adafruit Industries
https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-
circuitpython
Page 47 of 199