Sometimes you need a little extra storage for your microcontroller projects: for files, images, fonts, audio clips, etc. If you need lots of space, like in the gigabytes, we always recommend an SD card because you can easily plug it into a computer to edit files. But sometimes you don't need whole gigabytes, you just need a megabyte or two, with the lower cost and power usage that comes with it. That's when we recommend an Adafruit SPI FLASH Breakout in one of three variants: W25Q16 - 16 Mbit / 2 MByte, W25Q64 - 64 Mbit / 8 MByte or W25Q128 - 128 Mbit / 16 MByte chip.

Compared to our QSPI breakouts, this one is single-channel SPI only...BUT it comes with level shifting so it can be used safely with 3V or 5V power and logic. Since we needed to add level shifting, the chip is pre-wired into single channel "SPI" mode, with a level shifters so you can use it with 3V or 5V logic easily. You also get a 3.3V regulator and a pullup on CS. 

Note that the chips come blank, and do not have a wear-leveling subsystem. You can address them as a flat memory space or, if you like, format them with a filesystem like littleFS or FAT. Great for use with data-logging or storage needs where you are OK with doing the management yourself - or if you are adding external memory to an older chip that would like 5V-compatibility.

In Arduino, we have the Adafruit_SPIFlash library that can be used to interface with this chip. Comes with a bit of header that can be used to solder in and plug into a breadboard if desired.

Power Pins

  • VIN - this is the power pin. Since the flash chip may use 3 VDC, we have included a level shifter on board that will take 3-5VDC and safely convert it down. To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V microcontroller like Arduino, use 5V.
  • 3V3 - this is the 3.3V output from the level shifter, you can grab up to 100mA from this if you like.
  • GND - common ground for power and logic.

SPI Logic Pins

  • SCK - This is the SPI Clock pin / SCK Serial Clock, it's an input to the flash chip.
  • MISO - this is the Serial Out / Microcontroller ISerial Out pin, for data sent from the flash chip to your processor.
  • MOSI - this is the Serial In / Microcontroller Out Serial In pin, for data sent from your processor to the flash chip. It's an input to the chip.
  • CS - this is the Chip Select pin, drop it low to start an SPI transaction. It's an input to the flash chip and has a pullup. 

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. 

If the dependencies are already installed, you must make sure you update them through the Arduino Library Manager before loading the example!

Example Code

// 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.

This guide was first published on Nov 16, 2022. It was last updated on Jul 18, 2024.