Is there any way to get the current pinmode of a gpio pin in ESP8266 using Arduino IDE?
Your help will be appreciated. Thanks.
Explore... Chat... Share...
Moderator: igrr
btidey wrote:The short answer is no.
The longer one is that it depends on what you are trying to achieve.
pinMode manipulates several hardware registers to achieve what is specified in the mode. These include registers that control the pin muxing, function, direction and items like pull up/down, open drain etc.
code is in core_esp8266_wiring_digital.cpp
So when you issue a pinMode call then these registers are set appropriately but there is nothing directly remembering the mode associated with that pin.
In addition GPIO16 is special and has a more limited set of possible modes.
In principle one could write a routine that interpreted all the registers associated with a pin and figure out what mode that pin had been set to but it would be quite complex.
So there are a couple of suggestions depending on what you are trying to achieve.
If it is something simple like figuring out whether a pin is input or output then that can be achieved fairly simply by looking at the GPE (enable register).
If you really want to retrieve the full mode then the simplest way is to write a shell function (e.g. pinModeEx) that stores the mode for a pin in an array and calls the standard pinMode function.
Another thing to take from this is that if you are manipulating pinMode to say switch a pin from input to output repeatedly then there can be some benefit in setting it once via pinMode and then doing further switches by using the GPE register directly. This is much faster than going through the complex logic in pinMode. This is particularly beneficial if muxing a pin from input to output in an interrupt service routine.
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]