ESP32-SD CARD
To read the stored directories in SD card using ESP
32 microcontroller development board.
Description:
Interfacing
SD card module with ESP 32 to list the directories stored in memory card.
Hardware required:
ESP32-Microcontroller
Development board
Pin connection:
Pin Mapping:
SDCARD
|
ESP32
|
CS
|
IO5
|
MOSI
|
IO23
|
SCK
|
IO18
|
MISO
|
IO19
|
Procedure:
1.
The above pin connection shows how to interface SD
Card with ESP32 board.
2.
Do the connections as shown in the pin diagram and
pin mapping.
3.
Insert the SD Card in the slot given below the board.
4.
Connect the USB cable to the board.
5.
Open Arduino IDE .Select DOIT ESP32 DEVKIT V1in
boards and select COM port.
6.
Verify the program and Upload it.
7.
Open the serial monitor to observe the output.
Program :
/*
Listfiles
This example shows how print out the files in
a directory on a SD card The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
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.
*/ #include<SPI.h>
#include<SD.h>
Fileroot;
void setup(void)
{
/* Open serial communications and wait for port to open:
*/
Serial.begin(9600);
/* wait for serial port to connect. Needed for native USB
port only */ while(!Serial){
}
Serial.print("Initializing SD card...");
if(!SD.begin(4))
{
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
root=SD.open("/");
printDirectory(root,0);
Serial.println("done!");
}
/*nothing happens after setup finishes */ void loop(void){
}
void print Directory(Filedir,intnumTabs){ while(true)
{
Fileentry= dir.openNextFile();
/* no more files */ if(!entry)
{
break;
}
for(uint8_ti=0;i<numTabs;i++)
{
Serial.print('\t');
}
Serial.print(entry.name());
if(entry.isDirectory()){ Serial.println("/");
printDirectory(entry,numTabs+1);
}
else
{
Serial.print("\t\t"); Serial.println(entry.size(),DEC);
}
entry.close();
}
}
No comments:
Post a Comment