Skip to content

Adding a card reader to a ESP32 NodeMCU

fredlcore edited this page Jun 22, 2024 · 8 revisions

The ESP32-NodeMCU microcontrollers do not come with a card reader, however there exist small and inexpensive external card readers that can be connected to the ESP32. There are several types of card readers available and generally two ways on how to connect them. One is via SPI and one is via SD_MMC. While SD_MMC is about twice as fast as SPI, SPI is nevertheless recommended because it does not cause problems when performing a firmware update.
Some cards or readers support both ways, some just one, so you must either have a close look at the specs or simlpy try it out.

SPI mode

On card readers that have pins labeled MOSI, MISO or CS, you can safely assume that this reader supports SPI.
Standard-sized SD card reader connected via SPI: 310550886-3ba473da-ff15-4d72-84b9-a64d78c09af2 Micro-SD card reader connected via SPI: 309470660-d3ff9f3c-56b4-4d16-94fe-65fe1c2e784c

The connections to the microcontroller need to be done this way:

SPI SD Card Adapter Joy-It ESP32 NodeMCU
VCC VIN*
CS GPIO5
MOSI GPIO23
CLK GPIO18
MISO GPIO19
GND GND

The pin numbers can be configured through these definements in BSB_LAN_config.h:

#define SD_SCK 18
#define SD_MISO 19
#define SD_MOSI 23
#define SD_CS 5

However, the default settings should usually work.

SD_MMC

Some card readers also support connecting them to the microcontroller using the SD_MMC protocol which is about double as fast compared to SPI. Card readers that support this connection mode usually have several pull-up resistors of 10k between the data lines. If that is the case, then you could try if this setting also works for you:

SD Card Adapter ESP32 MCU
3.3V 3.3V
CS* --
MOSI GPIO15
CLK GPIO14
MISO GPIO2
GND GND

To tell BSB-LAN that you want to use SD_MMC instead of SPI, you have to remove the leading // from #define FORCE_SD_MMC_ON_NODEMCU.
Attention: Since GPIO2 is connected also during a firmware-update, this prevents the ESP from performing it properly. So for any kind of firmware update, you have to remove the device from GPIO2.

Thanks to GitHub user @sebi5361 for coming up with this solution in this discussion!

Clone this wiki locally