Using a SPI flash breakout board with Arduino involves wiring up the flash chip to your Arduino-compatible microcontroller, installing the Adafruit_SPIFlash library and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the flash breakout VIN.
Here is an Adafruit Metro wired up to the flash breakout using a solderless breadboard.
- Board 5V to breakout VIN (red wire)
- Board GND to breakout GND (black wire)
- Board pin 10 to breakout CS (orange wire)
- Board pin 11 to breakout MOSI (blue wire)
- Board pin 12 to breakout MISO (green wire)
- Board pin 13 to breakout SCK (yellow wire)
Library Installation
You can install the Adafruit SPIFlash library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit SPIFlash, and select the Adafruit SPIFlash library:
If asked about dependencies, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
// SPDX-FileCopyrightText: 2019 Ha Thach for Adafruit Industries // // SPDX-License-Identifier: MIT // The MIT License (MIT) // Copyright (c) 2019 Ha Thach for Adafruit Industries #include <SPI.h> #include <SdFat.h> #include <Adafruit_SPIFlash.h> #define CS_PIN 10 Adafruit_FlashTransport_SPI flashTransport(CS_PIN, SPI); Adafruit_SPIFlash flash(&flashTransport); // the setup function runs once when you press reset or power the board void setup() { Serial.begin(115200); while (!Serial) { delay(100); // wait for native usb } Serial.println("Adafruit Serial Flash Info example"); flash.begin(); Serial.print("JEDEC ID: 0x"); Serial.println(flash.getJEDECID(), HEX); Serial.print("Flash size: "); Serial.print(flash.size() / 1024); Serial.println(" KB"); } void loop() { // nothing to do }
Upload the read/write sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You'll see the flash ID and size printed to the Serial Monitor.
Text editor powered by tinymce.