Wireless SD Card Reader on ESP8266

ESP8266 ESP-12E

Neutrino

Just plug the device with an SD card inside into any USB port. It creates an FTP server where we can send and receive data to the SD card.

USB was supposed to be universal, and the main goal was to make a hot-swappable, super easy to interface with other devices but over the years the idea went haywire. There are so many different variants of these USB ports which is so frustrating at times and the way these works totally contradict their name [USB - Universal Serial Bus] because Every USB receiver should be compatible with any USB device! You can't plug in your USB stick or a keyboard inside a charger and expect it to work.

But the concept sounds too good! That's why to initiate this "Universal-Port" concept I started with a simple project "Wireless Card reader"

This fulfilled all my wishes, all I have to do is to just plug it inside any USB receiver, it doesn't matter which one!

As soon as you plug it in, it creates an access point where we can connect and then connect to the access point and just open up any FTP client application in any compatible device. With this setup, we can copy as well as save files to the SD card wirelessly (Figure 1)!

Wireless SD Card Reader on ESP8266.
Figure 1. Wireless SD Card Reader on ESP8266.

Supplies:

These are the list of products which can help you do this project with ease

  • Esp12E
  • SD card
  • Micro SD Adapter
  • HeaderPins
  • Angled Header Pins
  • Wires
  • FTDI
  • Male USB
  • PCB
  • Soldering Gun
  • Soldering Lead

SD(Secure Digital) Card

SD stands for Secure Digital, it’s similar to your Pendrive but with a smaller footprint and much cheaper price.

When we have to use this with any of the microcontrollers there are 2 options, one is SDIO and SPI. Almost all the SD cards share many standard features and have the same physical and electrical specifications. The actual differences between the SPI and SDIO are mainly on the software level. You can read more about it in Specification.

For now, let’s just say SDIO is faster but harder to implement and SPI is slower but easier to implement. Since most of the microcontrollers support SPI by default we'll just stick on to it.

SD card pinout for SPI is shown in Figure 2.

Figure 2. SD, miniSD, microSD card pinout for SPI.

 

SD, miniSD, microSD Card pin description you can see in Table 1.

Table 1. SD, miniSD, microSD card pins description.
Card Pin Description
1 CS (Chip Select)
2 DI (MOSI)
3 GND
4 GND
5 SCLK
6 GND
7 DO (MISO)
8 Not used
9 Not used

SD Card Adapter Modification

You can use any SD card modules which support Arduino and esp8266 but for the purpose of this project, we'll use the microSD card adapter and will modify in such a way that we can use that instead of the module.

First, clean the contacts of the SD card adapter. Then use angled header pins and solder the pins directly to the adapter contacts. Once the soldering is done, check the contacts between the header pins to check for any short circuit. Remove the black separator one by one, so when we place it back, it would flush with the PCB (Figure 3).

SD Card Adapter Modification for Wireless SD Card Reader on ESP8266.
SD Card Adapter Modification for Wireless SD Card Reader on ESP8266.
SD Card Adapter Modification for Wireless SD Card Reader on ESP8266.
SD Card Adapter Modification for Wireless SD Card Reader on ESP8266.
Figure 3. SD Card Adapter Modification for Wireless SD Card
Reader on ESP8266.

Cut the PCB in such a way that it fits perfectly with the SD card adapter and has some extra space, to add the male USB port.

You can also do the same process with the SD card instead of the adapter, but it's quite risky if you damage it.

USB Connection

We need to power the SD card, For that, we'll be using the USB receiving port itself. So we'll use a male USB port. This usually has 4 pins, where 2 middle pins are used for data transfer and 2 extreme pins are used for power and ground. Since we just need power, I will cut data pins and just keep the GND and VCC (Figure 4).

Wireless SD Card Reader on ESP8266 Schematic Diagram.
Рисунок 4. Wireless SD Card Reader on ESP8266 Schematic Diagram.

Then placed the male USB port in front of the SD card where we made some space earlier, then solder it in place. This did not solve any power issue yet! Because the SD card requires 3.3v but the USB supply is standard 5V if you just plug this in the supply, you will probably fry out the SD card (But no damages will be taken by the microSD adapter).

To solve this we'll use a 3.3V regulator and connect the input of the USB supply to 3.3V regulator i.e connect GND of the USB to pin 1 of the regulator and connect pin 3 of the regulator to +5V of the regulator. Finally, solder the pin 3 (output pin) and ground of the regulator to the SD card (Figure 5).

Connecting male USB port and 3.3 V regulator.
Connecting male USB port and 3.3 V regulator.
Figure 5. Connecting male USB port and 3.3 V regulator.

This will setup the power for the SD card. You can check the circuit diagram for a more detailed connection.

Putting Everything Together With ESP-12E

Now to read and write the data from the SD card we'll use the Esp12E wifi module, even though it's slower than esp32. But it really doesn’t matter which one you choose, I will tell reason in the latter steps.

First solder the EN(enable pin) to the VCC of the esp12E, this will turn on the IC. If this is not connected to the HIGH signal, the IC won't turn on. Then place the esp12E on the back of the PCB board and solder the SPI pins of the esp12E to the SPI pins on the SD card. For the detail, connection checks the circuit diagram (Figure 6).

Solder ESP-12E on the PCB and connecting SPI pins.
Solder ESP-12E on the PCB and connecting SPI pins.
Solder ESP-12E on the PCB and connecting SPI pins.
Figure 6. Solder ESP-12E on the PCB and connecting SPI pins.

HTTP VS FTP

Before programming, I did some research on how downloads and uploads work, that’s when I stumbled across the word FTP. Basically FTP stands for file transfer protocol, this protocol is used to transfer files between servers and client and it’s totally different from the regular HTTP where the client and server send and receive requests/response which is very small in size.

FTP is faster than the HTTP in transferring files because it was specifically made for it. So, I wanted to implement this in this project. Where an FTP server runs on the esp-12E and we can push and fetch data through this FTP to the SD card.

Figuring Out the FTP Library

I couldn’t find any FTP library that’s very actively developed or specifically made for esp8266. But with some digging I came across David Paiva who ported an Arduino version of the FTP server to esp8266 but with the SPIFFS support and not the SD card.

But with little more effort, I found someone who did some work on David Paiva library to convert the SPIFFS to the SD card. But when I tried to use this, I faced 2 issues. First, the page where I found this out was in Korean, So I had to literally sit and translate everything to know what was going on before I could do anything with it. Then the second problem was, I had to modify the existing SD library to support the changes he made but that felt very clumsy.

So, I compared both this library, one from David Paiva and the other one from the Korean website, Then made some minor changes and made the whole thing into a single project so there is no need to install any library of any sort.

Programming the ESP-12E

ESP-12E doesn't come with an inbuilt programmer, so we need to use an external programmer like the FDTI module. So I made an adapter with a few wires and female header pins, With this, we can temporarily solder the esp12E and program it using the FTDI module.

Connect the GND[esp12E] to GND, Rx[esp12E] to Tx, Tx[esp12E] to Rx, GPIO15[esp12E] to GND, GPIO0 [esp12E] to GND, VCC[esp12E] to VCC of FDTI module (Table 2).

 

Table 2. Connecting FTDI module to ESP-12E for programming.
ESP-12E pins FTDI USB-UART
TTL module
GND GND
Rx Tx
Tx Rx
GPIO15 GND
GPIO0 GND
VCC VCC

Then upload the code from download section using the Arduino IDE.

Once the program is uploaded you can desolder the wires which were connected to program the esp12E.

Finishing the Project!

Just Put in any microSD[32 GB max] card inside the adapter and plug the whole device into any USB compatible device, That should power things up! But there are few things to consider, make sure the USB port output current is greater than 1amp, just to be on a safer side. Because the Esp12E module consumes more current when it's transferring files.

As soon as the device is powered the device creates an access point called SD Reader. Connect to this access point using the password which is on the code. Then Depending on which device you are using to connect to the 12E download the respective FTP client software if you're using PC download WinSCP or Filzella and if you're using an Android device download AndFTP.

Once the installation is done, open the AndFTP and fill in the credentials to set up the FTP client. In my case, I left the user name and the password to default "esp8266" in the code. So, use that for the user information and for the host use 192.168.12.7. Finally, connect to the FTP server (Figure 7).

Connecting to ESP-12E FTP server from Android device.
Connecting to ESP-12E FTP server from Android device.
Connecting to ESP-12E FTP server from Android device.
Figure 7. Connecting to ESP-12E FTP server from Android
device.

Once That’s done, you can download any files from the SD card as well as you can upload files from your phone to the SD card.

You can see the video to know how it works!

Final Thoughts

But before jumping into the conclusion that it's a very handy device to have, let’s take a step back.

Even though it does what I want, it is utterly slow! For just 4 files(each ~100Kb) it takes roughly 30secs, and if you try with a larger file like 10MB it will take around 3-4mins to complete. There are ways to optimize this, and from the page where I referred he was able to get roughly 450kbs read speed. (With Esp32 and SD_MMC library transfer speed may be around 1MB/sec)

The reason why I stopped the project here and didn't try optimizing it was because of 2 reasons. First reason, I really wish, along with the FTP server I could still use the USB data line to transfer data, but it’s not supported in esp8266 or esp32. And the second reason is that I couldn’t get enough speed to transfer the files over FTP. These are also the same reason as to why I didn’t bother to use the esp32 instead of the esp12E.

But I think some of these problems can be solved if we can use the esp32 S2 boards which supports full speed on the go USB. Maybe I can do that for another tutorial.

Downloads

  1. Source code for project - download

hackster.io

JLCPCP: 2USD 2Layer 5PCBs, 5USD 4Layer 5PCBs

You may have to register before you can post comments and get full access to forum.
User Name
Free Shipping for All PCB Assembly Order