Pi Pico SD card?

Hello i know the pi pico is still new to the arduino community world. But from a programming side is it possible to program a SD card the same way that i can do with a arduino board? I have a upcoming project that requires me read file names from the SD card and I do not have any arduino boards available. I do have pi pico board and I don't know python well enough to program this.

Joseph

Hello, I'm still not finding nothing on Setting up the pi pico with An SD card within the arduino IDE environment. I'm going to try it. But I was curious if anyone else has tried it and if they ran into any problems with it?

Joseph

Normal sitution is that if someone knows the answer to your question, they will reply.

I'm sorry srnet. Got a little excite I got my pico board finally and wanted to use it. Every place was out and i found a place that had 2 left and i grab one.

Joseph

I've not hear of the Pi Pico before this, however from what I just read it uses a Arm Cortex M0+ core.

You could try the Cortex M0+ board currently available in the IDE. If that doesn't work you will have to wait for someone to write a board driver.

Thank you JohnRob. I'm trying it using the current pi pico in the board manger that there.

Joseph

Please install / have a look to this package:
https://github.com/esrlephilhower/arduino-pico
In the library area is some information about SD / SDfat.
And you need the courage to do a few experiments.

Hello RudolfAtRTC, Thank you I'm looking into it now. And i will do a update.

Joseph

Hello RudolfAtRTC, I have already installed the pico board manger i can program the pico but i have no clue on the SD card. This is the Sd card module i have. But sense they are using GP/GPIO pins i can not tell which pins are for spi? I'm looking online but only one i found i have tried and and sense they use some GP/GPIO pin mapping when i try to do GP13 or a GPIO13 i get this pin is not in the scope. So I'm unsure what pins goes to where and how to put it what sc pin goes to where.

Joseph

If you have an SPI card, you can take the pin assignment from the attached sketch. It works for me. It is an adapted example from the SD library.

/*===============================================================
  Listfiles: This example prints out the files in a directory on a SD card

  The circuit for card at RPi Pico:
   SD card attached to SPI bus as follows:
   ** MISO - GP16 (pin 21)
   ** MOSI - GP19 (pin 25)
   ** CS   - GP17 (pin 22)
   ** SCK  - GP18 (pin 24)

  created  Nov 2010 by David A. Mellis
  modified 9 Apr 2012 by Tom Igoe
  modified 2 Feb 2014 by Scott Fitzgerald

  This example code is in the public domain.
	---------------------------------------------------------------
	Datei: listfiles.ino
	Autor: Rudolf Schenke
	Stand: 19.06.2021
	===============================================================*/

#include <FileProperties.h>
FileProperties Sketch(__FILE__,__DATE__);	// Constructor mit Dateinamen

#include <SPI.h>
#include <SD.h>

File root;
char stDate[20];	// Buffer für aufbereitetes Datum

void setup() {

  Serial.begin(38400);
  while(not Serial) delay(10);
  delay(2000);
	Sketch.printProps();      // Ausgabe "Sketch = ..."

	Serial.print("Pin SS = ");	// Identify SPI pin group
	Serial.println(SS);
  Serial.print("Initializing SD card...");
  if (not SD.begin(SS)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  root = SD.open("/");

  printDirectory(root, 0);

  Serial.println("done!");
}

void loop() {

}

void printDirectory(File dir, int numTabs) {

  while (true) 
	{
    File entry =  dir.openNextFile();
    if (not entry) 
		{
      break;	// no more files
    }

    for (uint8_t i = 0; i < numTabs; i++) 
    {
      Serial.print("  ");
    }
    Serial.print(entry.name());
    int iLength = strlen(entry.name());
    if (entry.isDirectory()) 
		{
      Serial.println("/");
      printDirectory(entry, numTabs + 1);
    } 
		else 
		{
      // files have sizes, directories do not
      int iLen = 23 - iLength - 2 * numTabs;
      char stForm[8];
      sprintf(stForm,"%%%dd ",iLen);  
      Serial.printf(stForm,entry.size());
      time_t cr = entry.getCreationTime();
      time_t lw = entry.getLastWrite();
      Serial.printf(" Created: %s ", formatDate(cr));
      Serial.printf("  Last write: %s\n", formatDate(lw));
    }
    entry.close();
  }
}

char* formatDate(time_t tVal) {

	struct tm * tmstruct = localtime(&tVal);
	int iYear = ((tmstruct->tm_year) + 1900) % 1000;
	int iMon = tmstruct->tm_mon;
	int iDay = tmstruct->tm_mday;
	int iHour = tmstruct->tm_hour;
	int iMin = tmstruct->tm_min;
	sprintf(stDate,"%02d.%02d.%02d %02d:%02d",iDay,iMon,iYear,iHour,iMin);
	return ((char*)&stDate);
}
2 Likes

hello RudolfAtRTC, Thank you i could not find that pinout anyplace. I saw other pinouts but not for SPI. Is that in one of the examples?

The one i found in the examples of SD(ro2040) in the examples folder was

  The circuit:
   analog sensors on analog ins 0, 1, and 2
   SD card attached to SPI bus as follows (Raspberry Pi Pico):
   ** MISO - pin 0
   ** MOSI - pin 3
   ** CS   - pin 1
   ** SCK  - pin 2

Joseph

You can use my new RP2040_SD library which supports both RP2040 Arduino-mbed or arduino-pico core.

Check RP2040 libraries post #39

Hello khoih-prog. Thank you I'm trying it out now. I hope the SD card module works. I haven't used it in 2 or 3 years. LOL

Joseph

Hello khoih-prog, I have tired the SD card library and for some strange reason it said it failed and can not see the address card. I’m going to try again later today when I get back.

Joseph

Be sure to connect SD card to RPI-pico as follows:

SD card attached to SPI bus as follows:
   // Arduino-pico core
   ** MISO - pin 16
   ** MOSI - pin 19
   ** CS   - pin 17
   ** SCK  - pin 18
   // Arduino-mbed core
   ** MISO - pin 4
   ** MOSI - pin 3
   ** CS   - pin 5
   ** SCK  - pin 2

If you use the SD-card, with badly-designed MISO, follows the hardware fix as in topic Unable to access 2 SD cards with Arduino Mega 2560 Rev3

image

This is how I have wired it up.

CS to GP17
SCK to GP18
Mosi to GP19
Moso to GP16 << There is no MISO. It's labaled as MOSO. Which I'm guessing it is MISO.

Joseph

That's the wiring for Earle Philhower's arduino-pico core. If you use ArduinoCore-mbed core, the wiring is

// Arduino-mbed core
** MISO - pin 4
** MOSI - pin 3
** CS   - pin 5
** SCK  - pin 2

Also connect SD-card's VCC to 5VDC, not 3.3VDC.

1 Like

I'm using the pi pico which has 3.3v I'm using not a arduino board.

Joseph

Also connect SD-card's VCC to 5VDC, not 3.3VDC.

You have to connect either SD-card's VCC to 5VDC (as the card has AMS1117 5v->3.3V regulator) or connect 3.3V to 3.3V OUT pin of AMS1117 of SD-card to test.

Connect 3.3VDC to SD-cards VCC, expecting 5VDC, won't work.

With HW background, you can measure the OUT pin of AMS1117 to verify how bad the voltage is dropped.

Ohhh i totally forgot. Let me try that. I forgot about the LDO. Thank you let me try that. I'm going to have to remove that ldo later on.

Joseph