Blog


Connect Serial Flash to Arduino

How to Connect Serial Flash to Arduino to Save Power

I chose a SPI Flash or Serial Flash module for 2 reasons. Firstly, it uses a lot less power than an SD card and secondly it has a much smaller form factor. An SPI Flash module will use <10mA for writing whereas an SD card will use up to 150mA.

So my thought was ‘I can drive the Serial Flash module from one of the Arduino digital IO pins’.

I bought one of these https://www.ebay.co.uk/itm/W25Q-Winbond-Serial-Flash-Memory-Module-SPI-W25Q128B-BIOS-25Q64BVSIG-EEPROM-/181873964697. This contains a winbond 128Mbit Serial Flash chip.

The board includes pull up resistors (more about these later) and labelled pins. The board is 3.3v volts. I did all my testing for this post using a Arduino Mini Pro at 3.3v so I didn’t have to do any logic level conversion.

Why 128Mbits?

One of my previous posts included code to write a serial buffer to EEPROM. This allowed chunks of data up to 255bytes to be written sequentially to the EEPROM. On startup the code determined the next ‘free page’ to write to and only overwrote one 4K block once the log started to loop.

So 128Mbits = 16777216 bytes

So 16777216 bytes = 65536 lots of 255byte records

So if I write a single log record every minute that is 45 days of logging

Wiring the Winbond W25Q128B module to the Arduino

Wiring the SPI Flash Module
Arduino Pin SPIFlash Pin
Pin 6 (your choice) VCC
GND GND
VCC WP/IO2
VCC HOLD/IO3
MISO DO/IO1
MOSI DI/IO0
SCK CLK
Pin 10 (SS) CS

Enable and Disable

I firstly tried to the SPIMemory library for sleeping. There are functions for powerUp() and powerDown(). I rejected these. A powerDown and Arduino reset causes the SPI Flash module to lock up and the Arduino wouldn’t restart.

This took a bit of trial and error but I eventually came up with the following function. I’ve attached VCC of the Serial Flash to Pin 6 of

void flashToggle(bool yes) {
  if (yes) {
      pinMode(6, OUTPUT); 
      digitalWrite(6, HIGH); 
      flash.begin();
  }
  else {
      pinMode(6, INPUT); 
     digitalWrite(6, LOW); 
  }
}

Switching the pin to INPUT and setting low seemed to stop all power from the pin. I tried all other options.

Power  Use

These were measured on the VCC line with a cheap multimeter.

Continuous write ~ 5mA
after flashToggle(false) – 0uA (err, yes really. Nothing)

Conclusion

For me, a result. The module uses a tiny about of power and I can switch it off by simply toggling the DIO pin. I need to see if the same is true when it is attached to a 5v Arduino through a logic level converted.