ESP32-Cam and SD Card

MadScientist
Posts: 9
Joined: Tue Jul 09, 2019 12:50 am

ESP32-Cam and SD Card

Postby MadScientist » Tue Jul 16, 2019 4:30 pm

I posted recently about some issues with an ESP32-cam module and servos and you guys were a great help. They're working great and I'm making progress with my project, but now I'm running into an issue with the built on SD card slot.

My first issue is that it looks like the SD card uses most of the remaining GPIO pins, which would mean I couldn't use the servos. That may end up precluding me from using the SD card (which isn't horrible, but the card would make life so much easier). Regardless, without the servos attached/enabled I still can't get the SD card to even function. I've tried all of the examples for ESP32(SD) and SD_MMC and even one from the web (https://randomnerdtutorials.com/esp32-c ... rosd-card/) and they all fail with error 0x108 and say they cannot mount the card.

I've tried several cards and verified they were formatted FAT32 but the result is always the same. Does anyone have any ideas of what I could check to figure this out?

Thanks in advance!

MadScientist
Posts: 9
Joined: Tue Jul 09, 2019 12:50 am

Re: ESP32-Cam and SD Card

Postby MadScientist » Tue Jul 16, 2019 7:25 pm

So after some tedious testing and investigation it looks like with the camera AND SD card enabled there is only really ONE gpio that's left usable with no side effects, IO0 (which is also used to put the board into flash mode but once it's running then you can use it as a standard GPIO).

I could also use IO4, but that's tied to the LED so I'd get weird flashing/strobing if I tried to control the servo from that pin, even though the servo works.

So unless you guys know of any magic tricks I'm missing it looks like I can't use the SD card for this project... That's not ideal but it's manageable.

Thanks :)

User avatar
HermannSW
Posts: 90
Joined: Fri Oct 27, 2017 6:58 am
Location: Eberbach, Germany
Contact:

Re: ESP32-Cam and SD Card

Postby HermannSW » Tue Jul 16, 2019 9:40 pm

I don't know where to find official ESP32-CAM SD card pinout.
I found this:
https://raw.githubusercontent.com/v1234 ... /README.md

Code: Select all

   ESP32-CAM board uses  the SD card to the following pins:
   SD Card | ESP32    |esp32-cam
      D2       -          -
      D3       SS         gpio13
      CMD      MOSI       gpio15
      VSS      GND        gnd
      VDD      3.3V       3.3v
      CLK      SCK        gpio14
      VSS      GND        gnd
      D0       MISO       gpio2
      D1       -          gpio4 + LED flash also  :(
  FLASHLED                gpio4
  led1                    gpio33 (mini smd ledje below ESP32-controler)
      SD card socket : pin 9 is SD ( = CARD DETECTION , is a card inserted ? )
This should leave GPIO0, GPIO1, GPIO3, GPIO12 and GPIO16 for you (they are not used by camera, see camera_pins.h).
GPIO1+GPIO3 are used for serial, so you can use only if you do not need serial.
Image

MadScientist
Posts: 9
Joined: Tue Jul 09, 2019 12:50 am

Re: ESP32-Cam and SD Card

Postby MadScientist » Wed Jul 17, 2019 7:36 pm

I need serial, so 1 and 3 are out. 0 works fine, so that's good for one of the two servo motors. If I have a servo on 16 then camera fails to detect and the unit just reboots in a loop with a Meditation Guru error. If I have a servo on pin 12 then the servo moves randomly whenever the camera takes a picture. I can try with another chip to make sure it's not an issue with the board I have it attached to, but otherwise I don't think I can use the SD and Camera and 2 servos all at the same time. Not a huge deal, just an annoyance.

User avatar
HermannSW
Posts: 90
Joined: Fri Oct 27, 2017 6:58 am
Location: Eberbach, Germany
Contact:

Re: ESP32-Cam and SD Card

Postby HermannSW » Wed Jul 17, 2019 8:40 pm

Interesting, please test with another ESP32-CAM module, according camera_pins.h GPIO12 and GPIO16 are not used:

Code: Select all

$ grep 37 camera_pins.h 
#define Y8_GPIO_NUM      37
$ grep 16 camera_pins.h 
$ grep 12 camera_pins.h 
$ 

MadScientist
Posts: 9
Joined: Tue Jul 09, 2019 12:50 am

Re: ESP32-Cam and SD Card

Postby MadScientist » Thu Jul 18, 2019 12:57 am

Same results... when I have a servo on 16 the board just reboots with the Guru Meditation error. When I have a servo on 12 then I get unwanted servo movement whenever one of the following happens:

- Flashlight LED flashes
- Camera takes a picture
- SD card is accessed/written

All three of those events take place simultaneous with the test program I found so it's hard to tell which one is actually doing it. I'll need to dig a little further.

For the Guru Meditation error with the server on pin 16 the board appears to start ok but when I try to access the camera to take pictures I get the following in the serial console:

[E][camera.c:495] i2s_run(): Timeout waiting for VSYNC
Camera capture failed
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400d2070 PS : 0x00060930 A0 : 0x80122bd4 A1 : 0x3ffe5120
A2 : 0x3ffe2f7c A3 : 0x00000000 A4 : 0x3ffc14a8 A5 : 0xffffffff
A6 : 0x3ffe3ee4 A7 : 0x00000001 A8 : 0x800d206e A9 : 0x3ffe5100
A10 : 0x00000017 A11 : 0x00000015 A12 : 0x0000006d A13 : 0x0000ff00
A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x00000004 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000010 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xfffffffb

Backtrace: 0x400d2070:0x3ffe5120 0x40122bd1:0x3ffe5250 0x40121e25:0x3ffe5280 0x40121f01:0x3ffe5310 0x4012230c:0x3ffe5330 0x40121442:0x3ffe5350 0x40121494:0x3ffe5390 0x4008b221:0x3ffe53b0

Rebooting...

User avatar
HermannSW
Posts: 90
Joined: Fri Oct 27, 2017 6:58 am
Location: Eberbach, Germany
Contact:

Re: ESP32-Cam and SD Card

Postby HermannSW » Thu Jul 18, 2019 5:03 pm

Hi,

in case you really cannot use SD card with your two servos and camera, then you might just write to flash instead (SPIFFS).
See "Install ESP32 Filesystem Uploader in Arduino IDE" on how you can upload files:
https://randomnerdtutorials.com/install ... duino-ide/

But you can read+write files in SPIFFS from a sketch as well.

MadScientist
Posts: 9
Joined: Tue Jul 09, 2019 12:50 am

Re: ESP32-Cam and SD Card

Postby MadScientist » Thu Jul 18, 2019 8:56 pm

I completely forgot about spiffs! Thank you! :)

mozgy-eu
Posts: 1
Joined: Thu Jul 25, 2019 10:53 am

Re: ESP32-Cam and SD Card

Postby mozgy-eu » Thu Jul 25, 2019 11:07 am

Hello,

on AI-Cam start SD with

Code: Select all

void initSDCard( void ) {

//  if( !SD_MMC.begin() ) { // fast 4bit mode
  if( !SD_MMC.begin( "/sdcard", true ) ) { // slow 1bit mode
    DBG_OUTPUT_PORT.println( "SD card init failed" );
    return;
  }
}
now you should have two more IOs free.

--
Mozz

mikronauts
Posts: 12
Joined: Wed Dec 09, 2015 8:11 pm

Re: ESP32-Cam and SD Card

Postby mikronauts » Sun Jul 28, 2019 1:46 am

Any luck with gpio16?

I just got my modules a few days ago.

Who is online

Users browsing this forum: No registered users and 12 guests