ADC values of the ESP32 as a button

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Zidanoff
Normal user
Posts: 19
Joined: 09 Apr 2023, 13:52
Location: Ukraine

ADC values of the ESP32 as a button

#1 Post by Zidanoff » 30 Jun 2023, 09:42

Please tell me if it is possible to set the ADC values of the ESP32 as a button by setting the status trigger levels on or off and a kind of trashhold for the response time. This should work fast enough, at the level of the speed of a conventional button, from 50ms.

The fact is that there is an optocoupler output pulled to the ground, and this will help determine the input signal level, and not just on / off.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ADC values of the ESP32 as a button

#2 Post by TD-er » 30 Jun 2023, 10:01

So you want to use an ADC port as a switch input?
A bit like how the Touch plugin is working?

Right now there isn't an option to trigger an event when an ADC value crosses some threshold.
So you could act on it via rules, but I guess that will be quite unusable as you either need to use very frequent loop timers evaluating the ADC value, or it will be quite slow to act on an input change.

I guess it would be a nice feature to have, to set some threshold + hysteresis for ADC pins, but right now we don't have such a plugin or feature in existing plugins.

Zidanoff
Normal user
Posts: 19
Joined: 09 Apr 2023, 13:52
Location: Ukraine

Re: ADC values of the ESP32 as a button

#3 Post by Zidanoff » 30 Jun 2023, 10:20

Yes, that's right, like Touch. Too bad it's not available right now.

User avatar
Andrew Mamohin
Normal user
Posts: 95
Joined: 12 Jun 2020, 08:30
Location: Belarus, Gomel
Contact:

Re: ADC values of the ESP32 as a button

#4 Post by Andrew Mamohin » 30 Jun 2023, 16:35

TD-er wrote: 30 Jun 2023, 10:01 So you could act on it via rules, but I guess that will be quite unusable as you either need to use very frequent loop timers evaluating the ADC value, or it will be quite slow to act on an input change.
And if you use a divisor in the formula, wouldn't it make things easier? For example: %value%/10 or %value%/100.
Andy.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ADC values of the ESP32 as a button

#5 Post by TD-er » 30 Jun 2023, 19:35

Problem is that the ADC input can't be set to give an event when it changes beyond some threshold.
So you need to wait for the minimal interval period (1 sec) of the task to evaluate the task values.


Only way to make something like this without adding code to ESPEasy, is to add some extra hardware.
For example some comparators, so you can trigger a different GPIO pin when the voltage gets above some level.
Maybe you can even use some of those Lithium Ion battery monitoring LEDs to turn on the next GPIO pin at the next analog voltage level.

Zidanoff
Normal user
Posts: 19
Joined: 09 Apr 2023, 13:52
Location: Ukraine

Re: ADC values of the ESP32 as a button

#6 Post by Zidanoff » 05 Aug 2023, 23:05

I return to the task again. In addition to the proposed options, it is possible to add another tricky option with a comparator and ESP32 DAC. Through the DAC, we set the level of the reference voltage to the comparator and so we adjust the response threshold, right?
However, how will the ESP behave if there are problems with MQTT server connection at the time of active pressing? - for example, the web interface at such moments is very slow.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 28 guests