Skip to content

[User Interface and DOC] - Pulldown/pullup in Plugin "Switch input - Switch" #4800

@iz8mbw

Description

@iz8mbw

Hello.
Recently I have done some test and experience using the Plugin "Switch input - Switch" on ESP32 board.
My work was to use a push button switch connected to a pin of the GPIO in order to generate actions/commands.

What I discovered is that just adding a 10 centimeter copper cable to the GPIO (so leave it free on the air) generate a State flapping (floating) between 0 and 1, so it looks like some residual current (or may be better to call "energy") is received (sensed) by the GPIO pin.
I noticed this behavior also depend on the quality of Power Supply, connecting a Power Bank seems that this behavior disappear or is reduced.

This is what I see in the log:

296072: SW : GPIO=18 State=0 Output value=0
296080: EVENT: sw#State=0
296372: SW : GPIO=18 State=0 Output value=1
296380: EVENT: sw#State=1
297072: SW : GPIO=18 State=0 Output value=0
297079: EVENT: sw#State=0
298172: SW : GPIO=18 State=0 Output value=1
298183: EVENT: sw#State=1
299900: SW : GPIO=18 State=0 Output value=0
299912: EVENT: sw#State=0
302972: SW : GPIO=18 State=0 Output value=1
302984: EVENT: sw#State=1
303272: SW : GPIO=18 State=0 Output value=0
303283: EVENT: sw#State=0
304072: SW : GPIO=18 State=0 Output value=1
304083: EVENT: sw#State=1
304272: SW : GPIO=18 State=0 Output value=0
304282: EVENT: sw#State=0
304572: SW : GPIO=18 State=0 Output value=1
304582: EVENT: sw#State=1
304807: SW : GPIO=18 State=0 Output value=0
304819: EVENT: sw#State=0
305172: SW : GPIO=18 State=0 Output value=1
305183: EVENT: sw#State=1
305572: SW : GPIO=18 State=0 Output value=0
305583: EVENT: sw#State=0
305772: SW : GPIO=18 State=0 Output value=1
305782: EVENT: sw#State=1
306145: SW : GPIO=18 State=0 Output value=0
306156: EVENT: sw#State=0
306572: SW : GPIO=18 State=0 Output value=1
306583: EVENT: sw#State=1
306772: SW : GPIO=18 State=0 Output value=0
306784: EVENT: sw#State=0
307304: SW : GPIO=18 State=0 Output value=1
307340: EVENT: sw#State=1
307572: SW : GPIO=18 State=0 Output value=0
307584: EVENT: sw#State=0
308072: SW : GPIO=18 State=0 Output value=1
308083: EVENT: sw#State=1

So also if the push button is not pressed anyway I have a State flapping between 0 and 1.
Well, so in order to fix it I thought to enable the internal pull-down resistor of the ESP32 board, so I went in the Hardware page and I set the GPIO from "Default" to "Input pulldown", then to be sure I also rebooted the board.
I went again in the log and I see the GPIO is still flapping between 0 and 1:

70222: SW : GPIO=18 State=0 Output value=1
70228: EVENT: sw#State=1
70723: SW : GPIO=18 State=0 Output value=0
70729: EVENT: sw#State=0
71223: SW : GPIO=18 State=0 Output value=1
71229: EVENT: sw#State=1
71723: SW : GPIO=18 State=0 Output value=0
71729: EVENT: sw#State=0
72222: SW : GPIO=18 State=0 Output value=1
72233: EVENT: sw#State=1
72722: SW : GPIO=18 State=0 Output value=0
72733: EVENT: sw#State=0
73722: SW : GPIO=18 State=0 Output value=1
73733: EVENT: sw#State=1
74016: SW : GPIO=18 State=0 Output value=0
74032: EVENT: sw#State=0

So only to set the GPIO mode to "Input pulldown" didn't solve.

Then I went in the "Device" page and editing the "Switch input - Switch" and I see there is the option "Internal PullUp:", so I was confused because I need to enable the "PullDown" and not the "PullUp"...
But anyway I tried and I enabled "PullUp" and well, I SOLVED.

So I understood the option to enable or disable the "Internal PullUp:" in fact is related to the GPIO pin settings of the Hardware page.
So if the GPIO pin is configured as "Input pulldown" (in the Hardware page) then when I enable "Internal PullUp:" (in the Device page of the "Switch input - Switch ") it works as PullDown.

So, for what I have discovered, this means the check box to enable or disable "Internal PullUp:" in the Plugin "Switch input - Switch" should be renamed to "Internal PullDown / PullUp:" and add a Note that this setting will follow the GPIO Mode configured in the Hardware page for that GPIO pin.
Currently there is a note for "Inversed Logic:" that say "Note: Will go into effect on next input change.", well we need a new Note for the PullDwon / PullUp that this setting will follow the Mode (PullDwon or PullUp) configured in the Hardware page for that GPIO pin.

Also che be useful to update the DOC (https://espeasy.readthedocs.io/en/latest/Plugin/P001.html) by specify the concept about PullDown and PullUp when this Plugin is used for Switch or Push Button.

More, also here https://espeasy.readthedocs.io/en/latest/Plugin/P001_Switch.html is spcefied "Internal pull-up: Check if you want to use the internal pull-up of the ESP (not all GPIO pins have this internal pull-up.)" so it only specify there is the PullUp and not also the PullDown.

Thanks!

PS: Just a funny note, before I discovered this, in order to solve this flapping of the State, I physically added a 10 kohm resistor between GND and the GPIO pin, so I created the PullDown and I fixed the State flapping. But since it can be used the Internal PullDown resistor of the board and have the same goal, I prefer to use the Internal PullDown.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: DocumentationType: EnhancementImprove something already presentType: Feature RequestAdd a completely new feature (e.g. controller/plugin)Type: QuestionQuestion about how something works with concrete answers

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions