arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.18k stars 4.81k forks source link

Counter used for frequency measurement #3053

Closed kajmaj closed 6 years ago

kajmaj commented 6 years ago

Actually, is there any possibility to directly measure frequency - pulses per second - by a sensor connected to any available GPIO of Sonoff ? It might be usefull for RPM, anemometer, speed etc. In my case frequency is within the range between 0 and 80 Hz.

Frogmore42 commented 6 years ago

Not directly, and it's not clear how useful it would be. 80Hz is actually quite fast for the way counters in Tasmota work. You can setup a counter on a GPIO pin and then send that to NodeRED and with simple math get the frequency over the last period.

(Counter - OldCounter)/(NowInSeconds - OldTimeInSeconds) That will give the average number of pulses over the period.

kajmaj commented 6 years ago

Do you mean count it "out" of the sonoff and do math there as well? Well, math itself is not a problem. But if I set up teleperiod let say 10 secs - do I receive number of pulses within this period i.e. 800 at 80Hz or 10 at 1Hz etc.? Next 10 secs it will count from 0, or just continue to another value, accumulating value in buffer(or memory if you wish)? First possibility would be good enough. BTW is there any way how to reset counter after teleperiod is over?

Frogmore42 commented 6 years ago

You can read all about counters in the wiki https://github.com/arendst/Sonoff-Tasmota/wiki/Commands

kajmaj commented 6 years ago

I found "pulse Counter or pulse Timer" there in Counters and do not fully understand what does it mean. I learned sofar that, for my purpose, it is enough to have it working as per-period counter. But I do not know (yet) how to achieve it. :(

Frogmore42 commented 6 years ago

The best way to learn about these things is to try them out and see how they behave. I am not sure exactly how pulse timer works. It is the inverse of what you requested (frequency) but I have never tried using it. I did look at the code months ago and did not find it particularly useful for my needs. The counter is exactly what it says it is. It keeps a running total of the pulses it has received. If there is a power failure, it can go backwards, since it does not continually update the flash (which would wear it out much faster).

You can pick a gpio pin and set it to counter 1 That will cause it to start counting pulses.

kajmaj commented 6 years ago

I' m going to start experimenting. I think that it should be possible to reset counter at the end of each telemetry period by a rule. Rules are another unknown (to me) area.

ascillato commented 6 years ago

Hi,

The rule to reset a counter every teleperiod is:

rule 1
rule on tele-counter#c1>0 do counter1 0 endon

For more information see https://github.com/arendst/Sonoff-Tasmota/wiki/Rules

Thanks.

kajmaj commented 6 years ago

Thank you. edit: extended your rule to: rule on tele-counter#c1>0 do publish cmnd/wind/counter1 %value% endon on tele-counter#c1>0 do counter1 0 endon Now it does exactly what I need. Rest is math and proper debouncing.

ascillato2 commented 6 years ago

Great!

Thanks a lot for sharing. :+1:

Closing this issue.

riddik14 commented 5 years ago

Is possible read rpm from 5v 3 wired fan with tasmota? And is possible use pwm to control fan power directly?