Read and Write to the flash memory

arduino m0 samd21 robotdyn flash

Pre-requisites

Read and write a single number to the flash memory of a SAMD21 board (E.g. Arduino M0 or RobotDyn SAMD21 M0-Mini).

Code

Download code
#include <FlashStorage.h>

FlashStorage(my_flash_store, int);
String readString = "54";  // Change this number to store in flash

void setup() {
  SerialUSB.begin(9600);
  while (!SerialUSB) { }
  delay(100);

  int number;

  SerialUSB.print("Number read from flash before storing: ");
  number = my_flash_store.read();
  SerialUSB.println(number);

  SerialUSB.print("Number from user: ");
  SerialUSB.println(readString);

  SerialUSB.println("Number has been stored in flash!");
  my_flash_store.write(readString.toInt());

  SerialUSB.print("Number read from flash: ");
  number = my_flash_store.read();
  SerialUSB.println(number);
}

void loop() {}

Serial console

Serial output from the firmware.

Read and Write to the flash memory serial console

References