# Pico demo sd-card

**URL:** <https://forums.pimoroni.com/t/pico-demo-sd-card/21076>\
**Category:** Support\
**Created:** [January 1, 2023, 11:03am UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076 "2023-01-01T11:03:11Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![tonypigram](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonypigram/32/9334_2.png) [@tonypigram](https://forums.pimoroni.com/u/tonypigram)\
**Post date:** [January 1, 2023, 11:03am UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/1 "2023-01-01T11:03:11Z")

</div>

Can anyone tell me what the correct values for using the sd-card on the pico demo board are?  
I have a FAT32 formatted sd-card, that has been tested and works in 2 other LCD screen sd-cards (using different GPIO values) and I can read/write and list the files/folders.

Using the same code with the pico demo board, all I get now is ‘bad SCK pin’.  
I’m looking for something that maps:  
SD\_CLK : (GPIO 5)  
SD\_DAT3 : (GPIO 22)  
DAT2 : (GPIO 21)  
DAT1 : (GPIO 20)  
DAT0 : (GPIO 19)  
CMD : (GPIO 18)

to the required values for CS, SCK, MOSI and MISO. The Hardware PDF does give me values - but they do not seem to work - did I mis-interpret them? [https://datasheets.raspberrypi.com/rp2040/hardware-design-with-rp2040.pdf](https://datasheets.raspberrypi.com/rp2040/hardware-design-with-rp2040.pdf) PAGE 21

This does not work as I expected it to in MicroPython code:

cs = machine.Pin(18, machine.Pin.OUT, value=1)  
spi = machine.SPI(0,  
baudrate=1000000,  
polarity=0,  
phase=0,  
bits=8,  
firstbit=machine.SPI.MSB,  
sck=machine.Pin(5),  
mosi=machine.Pin(19),  
miso=machine.Pin(20))

sd = sdcard.SDCard(spi, cs)

any assistance / guidance really appreciated!

---

<div class="post-metadata">

**Author:** ![bablokb](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@bablokb](https://forums.pimoroni.com/u/bablokb)\
**Post date:** [January 2, 2023, 3:54pm UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/2 "2023-01-02T15:54:37Z")

</div>

‘bad SCK pin’ is the key to your problem: GPIO5 is not a valid SPI-SCK pin. See [https://pico.pinout.xyz/](https://pico.pinout.xyz/)

---

<div class="post-metadata">

**Author:** ![tonypigram](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonypigram/32/9334_2.png) [@tonypigram](https://forums.pimoroni.com/u/tonypigram)\
**Post date:** [January 2, 2023, 4:20pm UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/3 "2023-01-02T16:20:24Z")

</div>

Hi, yes, I did a bit more logical deduction last night using that layout and determined that it should be:  
CS = GPIO5 or GPIO22 - get same response  
SCK = GPIO18  
(If I set the following two to any other value the MicroPython library quite nicely tells me I am wrong)  
MOSI = GPIO19  
MISO =GPIO20

and now I get an error: OSError: no SD card

I even set this up: [GitHub - carlk3/no-OS-FatFS-SD-SPI-RPi-Pico: A FAT filesystem with SPI driver for SD card on Raspberry Pi Pico](https://github.com/carlk3/no-OS-FatFS-SD-SPI-RPi-Pico)  
and built my own uf2 so I could test doing the “mount 0:” and debugging the errors from there.  
As I say, I can make this work repeatedly on other breadboard setups, just not on the pico demo and I cannot figure out why?

I really don’t want to have wasted £20 on a pico demo just so I can have VGA - pretty pointless if I cannot get the sd-card working with it. There must be something “simple” I am missing here?

---

<div class="post-metadata">

**Author:** ![bablokb](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@bablokb](https://forums.pimoroni.com/u/bablokb)\
**Post date:** [January 2, 2023, 5:59pm UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/4 "2023-01-02T17:59:30Z")

</div>

I checked the wiring and I’m sure now that the SD-card is wired not for the SPI interface, but the SDIO interface. I have no experience with that, until now I only used SPI (including carlk3’s implementation). I found this link [Pico w/4-bit SDIO interface example? - Raspberry Pi Forums](https://forums.raspberrypi.com/viewtopic.php?t=337143), but I’m not sure if this helps.

---

<div class="post-metadata">

**Author:** ![tonypigram](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonypigram/32/9334_2.png) [@tonypigram](https://forums.pimoroni.com/u/tonypigram)\
**Post date:** [January 4, 2023, 3:33pm UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/5 "2023-01-04T15:33:20Z")

</div>

Just a small update:  
I was doing some random digging & I can confirm that the actual values are:  
SCK: GPIO18  
CS: GPIO22  
MOSI: GPIO19

However, I still get the “SD Card not found” error… I was doing this as a “quick test” using MicroPython - just to make sure that I could read the sdcard from the device.

I found the above values within some C/C++ code here: [https://github.com/fhoedemakers/pico-infonesPlus/blob/main/drivers/sdcard/sdcard.h](https://github.com/fhoedemakers/pico-infonesPlus/blob/main/drivers/sdcard/sdcard.h)

…and that is when the realisation dawned on me…what if this doesn’t work from MicroPython!

I then checked on the main product page…and, there it is at the top:

**Please note that VGA Demo Base only currently works with the C/C++ Pico SDK!**

Maybe it needs to be in a BIGGER font - I hang my head in shame…

unfortunately, I still cannot get it to access the SDCard from C-code. Following the simple instructions from here: [Pico supports SD cards and FatFS - Hackster.io](https://www.hackster.io/kamaluddinkhan/pico-supports-sd-cards-and-fatfs-5b4fb5)

I still get

> mount 0:  
> sd\_spi\_go\_low\_frequency: Actual frequency: 398089  
> sd\_wait\_ready failed  
> /home/tony/dev/pico/c-code/v2/no-OS-FatFS/FatFs\_SPI/sd\_driver/sd\_card.c:462: Card not ready yet  
> sd\_wait\_ready failed  
> /home/tony/dev/pico/c-code/v2/no-OS-FatFS/FatFs\_SPI/sd\_driver/sd\_card.c:462: Card not ready yet  
> sd\_wait\_ready failed

I have tried several different sdcards, proven to work on other devices. am a bit stumped now.

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [January 4, 2023, 8:14pm UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/6 "2023-01-04T20:14:02Z")

</div>

How are the SD Cards formatted? I think they need to be Fat formatted.

---

<div class="post-metadata">

**Author:** ![tonypigram](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonypigram/32/9334_2.png) [@tonypigram](https://forums.pimoroni.com/u/tonypigram)\
**Post date:** [January 4, 2023, 8:20pm UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/7 "2023-01-04T20:20:06Z")

</div>

yep, all FAT formatted. I have a 2Gb, 16GB and 32GB for variance

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [January 4, 2023, 9:53pm UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/8 "2023-01-04T21:53:03Z")

</div>

Ok, was just a stab in the dark.

---

<div class="post-metadata">

**Author:** ![tonypigram](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonypigram/32/9334_2.png) [@tonypigram](https://forums.pimoroni.com/u/tonypigram)\
**Post date:** [January 4, 2023, 10:15pm UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/9 "2023-01-04T22:15:31Z")

</div>

no worries! I’ve been doing a lot of that recently with this. Am open to all / any suggestions.

I’ve just hacked up some waveshare C code that accesses the sdcard on their 2.8" touchscreen - am basically removing all references to the LCD display… am nearly there. I have that code successfully accessing the sdcard on that device (_the previous mentioned code ‘no-OS-FatFS’ was failing to access this sdcard too_).  
However, I now have a list of files being output and I can navigate into sub-folders and list them too, so some success on the waveshield device!  
I’ll look to clean this code up and then see if I can move it over to then try it on the pico demo board… just have to change the config PINS… in theory…

---

<div class="post-metadata">

**Author:** ![bablokb](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@bablokb](https://forums.pimoroni.com/u/bablokb)\
**Post date:** [January 5, 2023, 7:15am UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/10 "2023-01-05T07:15:00Z")

</div>

I still don’t think that you will be able to access the SD-card on the pico-demo with SPI. According to the pinout on the product page, SD-CLK is wired to pin7, i.e. GP5, which is not a SPI clock-pin on the pico.

You are claiming that GPIO18 is SPI-SCK, but that pin is wired to SD-CMD (where you expect MOSI in SPI-mode).

---

<div class="post-metadata">

**Author:** ![tonypigram](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonypigram/32/9334_2.png) [@tonypigram](https://forums.pimoroni.com/u/tonypigram)\
**Post date:** [January 5, 2023, 9:51am UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/11 "2023-01-05T09:51:32Z")

</div>

I dug a bit deeper and whilst doing cmake I pass it the board type:  
cmake -D"PICO\_BOARD=vgaboard" …  
_(not sure why that shows as 3 dots - should be 2)_

which led me to find this file:  
/opt/pico-sdk/src/boards/include/boards/vgaboard.h

that defined these values:  
// Note DAT1/2 are shared with UART TX/RX (pull jumpers off header to access  
// UART pins and disconnect SD DAT1/2)  
#define VGABOARD\_SD\_CLK\_PIN 5  
#define VGABOARD\_SD\_CMD\_PIN 18  
#define VGABOARD\_SD\_DAT0\_PIN 19

and I was using SD\_CS PIN 22 in my C code and spi1.

Using these values I still cannot get it to initialise from C/C++,

> _SD card mount file system failed ,error code :(3)_

so maybe you are right… it might not be SPI?

In which case, are there any c/c++ examples out there that access the sd-card on the pico demo board? I cannot seem to find anything.  
I did find an example of someone [using the pico dvi board (hdmi version) and their code](https://github.com/fhoedemakers/pico-infonesPlus) doesn’t seem to do anything smart with the sdcard, so I’m a bit baffled - did I just get a broken board and I’ve been chasing my tail all along?

---

<div class="post-metadata">

**Author:** ![bablokb](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@bablokb](https://forums.pimoroni.com/u/bablokb)\
**Post date:** [January 5, 2023, 10:33am UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/12 "2023-01-05T10:33:56Z")

</div>

I think you found the correct link (I failed). If you look at the source code, they implement SPI using PIO, i.e. they don’t use the hardware-spi function-blocks of the pico, but implement their own PIO-version. That’s why it is not relevant that the SD-CLK is not connected to a pico-spi-clk pin. You will find the code in the drivers/sdcard subdirectory.

So the next step for you would be to try to integrate that code into your project. Would be great if this works.

---

<div class="post-metadata">

**Author:** ![tonypigram](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonypigram/32/9334_2.png) [@tonypigram](https://forums.pimoroni.com/u/tonypigram)\
**Post date:** [January 5, 2023, 3:48pm UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/13 "2023-01-05T15:48:26Z")

</div>

okay… I need bigger brains than I’ve got to figure this one out.

I’ve uploaded the code to here:

> **[pico\_c/picovga at main · pi-gram/pico\_c](https://github.com/pi-gram/pico_c/tree/main/picovga)**
>
> main/picovga

It contains the libraries grafted into a super-simple app that attempts to initialise and mount the sdcard for the Pico demo VGA board.

I’ve pasted my debug output into the sdcard\_test.c file, but will reproduce it here:  
SDCARD\_TEST.C: system init response=0  
SDCARD\_TEST.C: SDCARD\_SPI\_BUS=1073987584  
SDCARD\_TEST.C: SDCARD\_PIN\_SPI0\_CS=22  
SDCARD\_TEST.C: SDCARD\_PIN\_SPI0\_SCK=18  
SDCARD\_TEST.C: SDCARD\_PIN\_SPI0\_MOSI=19  
SDCARD\_TEST.C: SDCARD\_PIN\_SPI0\_MISO=20  
SDCARD\_TEST.C: SDCARD\_PIO=1344274432  
SDCARD\_TEST.C: SDCARD\_PIO\_SM=0  
SDCARD\_TEST.C: Let’s try to mount the SDcard  
FF.C: inside f\_mount about to call mount\_volume  
FF.C: about to call disk\_initialize from within mount\_volume  
SDCARD.C: about to call init\_spi() here, I think I was called by FF.C: mount\_volume  
SDCARD.C: we should be executing the PIO code here  
SDCARD\_TEST.C: SD card mount error: 3  
SDCARD\_TEST.C: sdcard\_success=0  
SDCARD\_TEST.C: Bugger an error happened…again…

I put the filename on the front of the printf’s so I could trace through the logic of the code and make sure it was working as I thought it was. From what I can tell, it is indeed going through the correct steps… but still failing anyway.

I’ve tried with:  
cmake …  
make  
and with the board specified:  
cmake -D"PICO\_BOARD=vgaboard" …  
make  
that doesn’t seem to make a difference.  
I’ve tried changing from sp1 to sp0, just incase it is on the first device, done the same with pio1 and pio0 - same result.  
Maybe I have a typo / assumption somewhere that is blazing obvious to someone else? but I think I’ve now tried everything I can to read an SDCard using the Pico demo VGA board, without success :-(

The good news is… I don’t think the GPIO PIN settings is the problem :-D That appears to be okay.

---

<div class="post-metadata">

**Author:** ![bablokb](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@bablokb](https://forums.pimoroni.com/u/bablokb)\
**Post date:** [January 6, 2023, 12:55pm UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/14 "2023-01-06T12:55:28Z")

</div>

I think your pins don’t match the wiring of the board:  
[https://cdn.shopify.com/s/files/1/0174/1800/files/vgademobase\_480x480.png?v=1617010535](https://cdn.shopify.com/s/files/1/0174/1800/files/vgademobase_480x480.png?v=1617010535)

e.g.

SD-CLK = Pin7 = GP5 = SDCARD\_PIN\_SPI0\_SCK  
SD-CMD = Pin24 = GP18 = SDCARD\_PIN\_SPI0\_MOSI

I still have to figure out the other pins, they are labeled SD\_DAT0-SD\_DAT3 in the shop. But I somewhere have a SD-pinout which labels all the pins in both ways, so give me some time.

---

<div class="post-metadata">

**Author:** ![tonypigram](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonypigram/32/9334_2.png) [@tonypigram](https://forums.pimoroni.com/u/tonypigram)\
**Post date:** [January 6, 2023, 1:08pm UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/15 "2023-01-06T13:08:02Z")

</div>

You genius!

SDCARD\_TEST.C: system init response=0  
SDCARD\_TEST.C: SDCARD\_SPI\_BUS=1074003968  
SDCARD\_TEST.C: SDCARD\_PIN\_SPI0\_CS=22  
SDCARD\_TEST.C: SDCARD\_PIN\_SPI0\_SCK=5  
SDCARD\_TEST.C: SDCARD\_PIN\_SPI0\_MOSI=18  
SDCARD\_TEST.C: SDCARD\_PIN\_SPI0\_MISO=19  
SDCARD\_TEST.C: SDCARD\_PIO=1345323008  
SDCARD\_TEST.C: SDCARD\_PIO\_SM=0  
SDCARD\_TEST.C: Let’s try to mount the SDcard  
FF.C: inside f\_mount about to call mount\_volume  
FF.C: about to call disk\_initialize from within mount\_volume  
SDCARD.C: about to call init\_spi() here, I think I was called by FF.C: mount\_volume  
SDCARD.C: we should be executing the PIO code here  
SDCARD.C: pio\_spi\_init executed  
SDCARD\_TEST.C: Mounted OKAY!  
SDCARD\_TEST.C: Current directory is: /  
SDCARD\_TEST.C: sdcard\_success=1  
SDCARD\_TEST.C: Woo!hoo! party time

---

<div class="post-metadata">

**Author:** ![bablokb](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@bablokb](https://forums.pimoroni.com/u/bablokb)\
**Post date:** [January 6, 2023, 2:36pm UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/16 "2023-01-06T14:36:18Z")

</div>

Glad it works! The real genius are the people that implemented that SPI-PIO stuff. I really have to spend some time with that technology one day.

---

<div class="post-metadata">

**Author:** ![dkts2021](https://avatars.discourse-cdn.com/v4/letter/d/f08c70/32.png) [@dkts2021](https://forums.pimoroni.com/u/dkts2021)\
**Post date:** [May 21, 2024, 12:32pm UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/17 "2024-05-21T12:32:28Z")

</div>

Hi  
I have this lcd display with onboard sd card from waveshare [https://www.waveshare.com/pico-restouch-lcd-2.8.htm](https://www.waveshare.com/pico-restouch-lcd-2.8.htm)

i can only access the sd card successfully using the library that waveshare provides. I think the two boards have similar pinout, but i get a  
…  
SDCARD\_TEST.C: SDCARD\_PIN\_SPI0\_CS=22  
SDCARD\_TEST.C: SDCARD\_PIN\_SPI0\_SCK=5  
SDCARD\_TEST.C: SDCARD\_PIN\_SPI0\_MOSI=18  
SDCARD\_TEST.C: SDCARD\_PIN\_SPI0\_MISO=19  
…  
SDCARD\_TEST.C: SD card mount error: 3

with the code from picovga repo  
I tried the [no-OS-FatFS-SD-SDIO-SPI-RPi-Pico](https://github.com/carlk3/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico) library with no success.

I can’t figure out what is wrong. Any idea?

---

<div class="post-metadata">

**Author:** ![bablokb](https://avatars.discourse-cdn.com/v4/letter/b/ee59a6/32.png) [@bablokb](https://forums.pimoroni.com/u/bablokb)\
**Post date:** [May 21, 2024, 1:10pm UTC](https://forums.pimoroni.com/t/pico-demo-sd-card/21076/18 "2024-05-21T13:10:38Z")

</div>

The thread above is about a board that uses bitbang SPI over PIO. The Waveshare SD-card uses plain and simple hardware SPI.
