Page 1 of 1

Adding new GPIO20 define for Arduino framework

Posted: Tue Jan 12, 2021 12:11 pm
by marius
I'm testing the new ESP32-Pico-Mini-02 module which features GPIO20 that was previously unavailable. The current version of the Arduino framework doesn't contain definitions for GPIO20 and I'm getting errors like:

Code: Select all

"GPIO_NUM_20" is undefined
Is there an easy way I could define GPIO20 in my current project main.h header file? What is the correct syntax for doing that? This way it would keep existing libraries and code working with the new pin.

Thanks!

Re: Adding new GPIO20 define for Arduino framework

Posted: Wed Jan 13, 2021 6:08 am
by boarchuz
You might still run into problems if any drivers check the validity of the pin (eg. pinMode(20, OUTPUT) -> error?).

Something like this will make the compiler stop complaining but don't expect correct functionality:
#define GPIO_NUM_20 ((gpio_num_t)(20))

Using a different pin for now would be best.

Re: Adding new GPIO20 define for Arduino framework

Posted: Wed Jan 13, 2021 6:33 am
by marius
Defining it that way does allow the code to compile fine but as expected I don't get correct functionality, not even a simple blinky with digitalWrite() function.

I have also tried experimenting with modifying ..\tools\sdk\include\driver\driver\gpio.h specifically:
line 59 adding "#define GPIO_SEL_20 (BIT(20))"
line 156 adding "GPIO_NUM_20 = 20,"

But with no luck, I still don't get functionality for writing to that pin.

Re: Adding new GPIO20 define for Arduino framework

Posted: Wed Jan 13, 2021 8:18 am
by boarchuz
Yeah there's a lot more to it. A lot of the Arduino stuff is precompiled so making changes there won't achieve much.

If you're really motivated and you only need simple IO, you might look at ESP-IDF to learn how to initialise and read/write using the registers directly.

I would pick a different pin!

Re: Adding new GPIO20 define for Arduino framework

Posted: Wed Jan 13, 2021 9:48 am
by marius
Okay, thanks for the info.