Go Down

Topic: NodeMCU - Unable to mount SD card (Lua) (Read 241 times) previous topic - next topic

ritesht93

Nov 26, 2017, 11:54 am Last Edit: Dec 11, 2017, 11:49 am by ritesht93
I am using the NodeMCU Amica Board and this sdcard module (it has level shifter and a 3.3v regulator built in) but I am unable to mount the SD card.

The following line

vol = file.mount("/SD0", 8 );

gives me nil in vol.

Wiring is proper.

  • nodemcu 3.3v -> sdcard board Vcc
  • nodemcu GND -> sdcard board GND
  • nodemcu D5 -> sdcard board SCK
  • nodemcu D6 -> sdcard board MISO
  • nodemcu D7 -> sdcard board MOSI
  • nodemcu D8 -> sdcard board CS

I also tried powering up sdcard module with external Arduino Uno +5V volts but the same issue persists. I also tried switching Chip Select (CS) pin from D8 to D2 and issued the command: vol = file.mount("/SD0″, 2); but the same problem is present. vol is still nil and it doesn't mount.

Any help is appreciated. Thanks

ritesht93

can anyone help on this please?

gdsports

Quote
I also tried switching Chip Select (CS) pin from D8 to D2 and issued the command: vol = file.mount("/SD0″, 2); but the same problem is present. vol is still nil and it doesn't mount.
On NodeMCU boards, the labels printed on the board are misleading. For example, D2 is not GPIO2. D2 is actually GPIO4. Google for "nodemcu pin out" for the full details.

ritesht93

#3
Dec 11, 2017, 03:00 am Last Edit: Dec 11, 2017, 11:35 am by ritesht93
On NodeMCU boards, the labels printed on the board are misleading. For example, D2 is not GPIO2. D2 is actually GPIO4. Google for "nodemcu pin out" for the full details.
Hi. I have made the connections using the nodemcu pin outs.

According to this diagram:



D5 to D8 represent HSPI. So I made the connections in the following way:

  • nodemcu D5 -> sdcard board SCK
  • nodemcu D6 -> sdcard board MISO
  • nodemcu D7 -> sdcard board MOSI
  • nodemcu D8 -> sdcard board CS


Also I am able to read/write successfully using Arduino Uno and the same sd card module and same sd card (tried both 128 MB and 4 GB).

I'm stumped. I really dont know what seems to be wrong?
Would really appreciate if anyone knows whats the issue? Do i have to change the flash frequency while flashing the binary? or something else is out of place? Has anyone else used the aforementioned sd card adapter module?

Any help is appreciated Thanks!

gdsports

Are you using the SDCARD library included with the ESP8266? Run the ESP8266 SD library example such as cardinfo.ino. The example defaults to GPIO4 so change it to 15 or move the select wire to GPIO2.

Since you are using D8, GPIO15 is connected to the SPI select. Does your code specify pin number 15 as the select pin?

Post you code using code using code tags.

ritesht93

Hi gdsports. I am not using the SDCARD C library included with ESP. I am using the NodeMCU devkit on the hardware side as well as NodeMCU Lua firmware on the software side.

As per your suggestion, I flashed the both ReadWrite.ino and cardinfo.ino examples onto ESP and both are working fine (using same sd card module and same sd card).

I am not able to do the same using Lua firmware. Here is the Lua code I am using:

Code: [Select]

-- Before mounting the volume(s) on the SD card, you need to
-- initialize the SPI interface from Lua
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
-- NOTE: the card initialization process during `file.mount()` will set spi divider temporarily to 200 (400 kHz)
-- it's reverted back to the current user setting before `file.mount()` finishes
vol = file.mount("/SD0:", 8)   -- 2nd parameter is optional for non-standard SS/CS pin
if not vol then
  print("retry mounting")
  vol = file.mount("/SD0:", 8)
  if not vol then
    error("mount failed")
  end
  else
    print("\nSD Card mounted\n")
end


I tried using both '/SD0:' as well as '/SD0'. Also tried different CS pins  (D8, D2 etc)

gdsports

Sorry, I missed that part about Lua. I have never used Lua. You should probably ask on a NodeMCU Lua forum.

Go Up