Skip to content

SD Card Support

In this guide, we connect an SD card to the Pico board using pico-jxgLABO.

pico-jxgLABO mounts part of the Pico board's flash memory as the L: drive, allowing you to read and write files. The capacity of this drive is about 2.5 MBytes on the Pico2 board and about 0.5 MBytes (500 KBytes) on the Pico board. This is practical for saving text data, but insufficient for large data such as images or audio.

By connecting an SD card, you can use large-capacity storage in the GByte range, greatly expanding the Pico board's capabilities. SD cards are inexpensive and easy to obtain, and can be used by connecting to the Pico board's SPI interface.

SD Card Reader Modules

SD card reader modules are basically just an SD card slot with some resistors and a voltage regulator, but the supply voltage, signal level, and presence of pull-up resistors vary by module, so be careful.

Below are some SD card reader modules I had on hand (mainly from Amazon), with notes on supply voltage, pull-up resistors, and signal levels.

Appearance Notes
sdcard-adapter Standard SD card module. Both 5V and 3.3V supply pins are available. If using 5V, a voltage regulator steps down to 3.3V for the SD card. All signal lines have 10kΩ pull-up resistors, so no external pull-ups are needed. Signal level is 3.3V.
ILI9341-back Standard SD card slot on the TFT LCD ILI9341. Power is supplied from the TFT LCD connector at 3.3V. External pull-up resistors are required1. Signal level is 3.3V.
u-sdcard-adapter-1 microSD card module. Supply voltage is 5V, stepped down to 3.3V by a voltage regulator. No external pull-ups are needed. Signal lines have a buffer (74HC125), so it can connect to both 3.3V and 5V signal levels.
u-sdcard-adapter-2 microSD card module. Supply voltage is 3.3V. All signal lines have 10kΩ pull-up resistors, so no external pull-ups are needed. Signal level is 3.3V.

To distinguish the supply voltage, if the SD card reader module has a voltage regulator like the one shown below, use 5V supply; if not, use 3.3V supply.

sdcard-adapter-voltage

Device Connection and Operation Check

The SD card reader module is connected via the SPI interface. You can use either SPI0 or SPI1 on the Pico board, and the pin layout can be freely set with commands. Here, we use SPI0 and connect as follows:

SD Card Reader Module Pico Pin No. GPIO Function
VCC 39 or 36 VSYS or 3V3
GND 3 GND
SCK 4 GPIO2 SPI0 SCK
MOSI 5 GPIO3 SPI0 TX (MOSI)
MISO 6 GPIO4 SPI0 RX (MISO)
CS 7 GPIO5 SIO

Warning

Be careful where you connect the VCC of the SD card reader module, depending on the supply voltage: - For 5V supply, connect to VSYS (pin 39) on the Pico board. If you connect to 3V3, the voltage drop across the module's regulator will prevent proper operation. - For 3.3V supply, connect to 3V3 (pin 36) on the Pico board. If you connect to VSYS, the SD card may be damaged.

The wiring diagram is shown below. There are multiple GND pins on the Pico board, so you can connect to any of them.

circuit-sdcard

Run the following command to set the GPIO assignment for SPI0 to GPIO2 (SPI0 SCK), GPIO3 (SPI0 TX), and GPIO4 (SPI0 RX). The appropriate function assignment is done automatically, so the order does not matter.

L:/>spi0 -p 2,3,4

Run the following command to set the SPI interface for the SD card to SPI0, the CS pin to GPIO5, and the drive name to M:

L:/>sdcard setup {spi:0 cs:5 drive:'M'}

This completes the SD card setup.

Use the ls-drive command to display the list of available drives:

L:/>ls-drive
 Drive  Format           Total
*L:     FAT12          2621440
 M:     unmounted            0

Since there is no SD card inserted yet, it shows as unmounted. Insert an SD card and run ls-drive again. Here, a 32 GByte SD card formatted as FAT was inserted:

L:/>ls-drive
 Drive  Format        Total
*L:     FAT12       2621440
 M:     FAT32   30945574912

Try various file operations. See here for a summary of file operation commands provided by pico-jxgLABO2.

L:/>M:
M:/>dir
...

  1. In my tests, the SD card worked without pull-up resistors, but some SD cards may require them. If it doesn't work, check for pull-up resistors. 

  2. pico-jxgLABO features are based on the pico-jxglib library.