shariltumin / esp32-cam-micropython-2022

MicroPython esp32-cam firmware with camera support compiled with esp-idf-4.4.0. Python script files for live streaming
MIT License
174 stars 33 forks source link

GPIO 16 invalid pin #31

Closed robtinkers closed 11 months ago

robtinkers commented 11 months ago

I'm using an AI Thinker ESP32-CAM from Aliexpress (are there clones of this board? if so, possibly a clone).

I read a comment from Sara Santos on randomnerdtutorials that "I’ve used GPIO 16 with a pushbutton in a project that takes photos when the button is pressed. The button worked when I connected it with a 10kOhm pull up resistor." so I added a similar button to mine.

This works as expected with the latest micropython.org firmware:

MicroPython v1.20.0 on 2023-04-26; ESP32 module with ESP32

Type "help()" for more information.

>>> from machine import Pin
>>> Pin(16, Pin.IN).value()
1
>>> Pin(16, Pin.IN).value()
0

but with your builds, I just get "invalid pin":

MicroPython v1.20.0-162-gd080d427e-kaki5 on 2023-06-07; ESP32-CAM OV2640 w/SSL (KAKI5) with ESP32
>>> from machine import Pin
>>> Pin(16, Pin.IN).value()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid pin

I also tested with the 20221121 firmware and got the same result.

shariltumin commented 11 months ago

The firmware was compiled with SPIRAM enabled, which requires this flag CONFIG_ESP32_SPIRAM_SUPPORT=y in the sdkconfig.board

The "machine_pin.c" file defines which pins are available, and we have this

...
    {{&machine_pin_type}, GPIO_NUM_14},
    {{&machine_pin_type}, GPIO_NUM_15},
    #if CONFIG_ESP32_SPIRAM_SUPPORT
    {{NULL}, -1},
    {{NULL}, -1},
    #else
    {{&machine_pin_type}, GPIO_NUM_16},
    {{&machine_pin_type}, GPIO_NUM_17},
    #endif
    {{&machine_pin_type}, GPIO_NUM_18},
    {{&machine_pin_type}, GPIO_NUM_19},
...

which means that GPIO16 and GPIO17 are not defined because they are used by SPIRAM.

I have no idea how the other firmware was satup, especially if the PSRAM was enabled.

All other pins except GPIO16 seem to be OK.

>>> from machine import Pin
>>> b = Pin(16, Pin.IN)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid pin
>>> b = Pin(0, Pin.IN)
>>> b.value()
1
>>> del b
>>> b = Pin(4, Pin.IN)
>>> b.value()
0
>>> del b
>>> b = Pin(2, Pin.IN)
>>> b.value()
0
>>> del b
>>> b = Pin(14, Pin.IN)
>>> b.value()
1
>>> del b
>>> b = Pin(15, Pin.IN)
>>> b.value()
1
>>> del b
>>> b = Pin(13, Pin.IN)
>>> b.value()
1
>>> del b
>>> b = Pin(12, Pin.IN)
>>> b.value()
0

Try using any of them in your project.

robtinkers commented 11 months ago

The other firmware was generic "for ESP32-based boards without external SPIRAM" so it makes sense that it worked there.

Pins are obviously a bit in short supply on this board if you want to use the sd card and have a display, so I'll rejigger things and see what I can come up with.

Thanks for your time and the firmware!