Use %syssec% to increment PWM Output

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Dorfrog
New user
Posts: 9
Joined: 25 Feb 2019, 00:53

Use %syssec% to increment PWM Output

#1 Post by Dorfrog » 03 Nov 2023, 08:13

Hello

I've been trying to make a PWM output based on seconds counting 0-59 gradually increasing the PWM output as the seconds count increases.

In rules, I tried (for example)

On %syssec% do
if [%syssec%]=10
PWM,16,100
elseif [%syssec%]=30
PWM,15,512
endif
endon

So far I cannot make it dance - gpio16 does not output any voltage.

By contrast, I can do plenty with
On temperature#temp do
etc,
etc

Can you please guide me as to where I have gone wrong?
I'm using NTP time - is that an issue? Can I capture seconds another way?
Thanks

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

Re: Use %syssec% to increment PWM Output

#2 Post by TD-er » 03 Nov 2023, 08:22

You can't act on such events as there will not be any event named "12" or whatever the current seconds value is.

I think you should start a looptimer.
See: https://espeasy.readthedocs.io/en/lates ... oop-timers

Code: Select all

On System#Boot do    //When the ESP boots, do
  looptimerset_ms,1,1000  // Start loop timer 1, 1000 msec interval
endon

On Rules#Timer=1 do
  if %syssec%=10
    PWM,16,100
  elseif %syssec%=30
    PWM,15,512
  endif
Endon
N.B. the system variables (wrapped in %...%) do not need []

N.B.2
Not sure if GPIO 16 (on ESP8266) can do PWM as it is a special pin with limited capabilities.

Dorfrog
New user
Posts: 9
Joined: 25 Feb 2019, 00:53

Re: Use %syssec% to increment PWM Output

#3 Post by Dorfrog » 03 Nov 2023, 09:38

@TD-er

Thanks so much for your reply
The output (to a voltmeter) works as expected. It's perfect.
I'll read up on looptimers, I'm sure I will have plenty of applications for it.

I have noted your comment about system variables.
Also PWM works with ESP8266 / GPIO16 output. This is the only GPIO that has a pulldown, so I'm glad it works.

Again thanks so much, it is appreciated.

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

Re: Use %syssec% to increment PWM Output

#4 Post by TD-er » 03 Nov 2023, 10:23

Good to know PWM still is working on GPIO 16. (on ESP8266)
However it isn't the only one with a pull-down resistor on ESP8266.
GPIO-15 also has a pull-down resistor (and needs to be kept pulled-down during boot)
See: https://espeasy.readthedocs.io/en/lates ... on-esp8266

Dorfrog
New user
Posts: 9
Joined: 25 Feb 2019, 00:53

Re: Use %syssec% to increment PWM Output

#5 Post by Dorfrog » 03 Nov 2023, 10:53

Of course - I should have remembered, It's actually more logical to use GPIO15 as a pulldown, especially at Hardware Boot because there is no high pulse.
PWM works nicely with GPIO15 as well.
GPIO16 can be set as pull-down in your Hardware Menu. I find it a good visual reminder. :D

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

Re: Use %syssec% to increment PWM Output

#6 Post by TD-er » 03 Nov 2023, 11:47

That's because there are pull-up and -down resistors inside the ESP8266
On the Hardware tab I only added those options that are available as internal pull resistor.

However there is a number of boot state pins which need to be in a specific state to boot the ESPEasy 'sketch'.
- GPIO-0 needs to be high
- GPIO-2 needs to be high
- GPIO-15 needs to be low

So these 3 pins will have external pull resistors soldered to the ESP8266.
Either on the PCB or in the encapsulated module (e.g. the ESP-12S has them in the encapsulated module)
But these resistors must be present or else the ESP will not boot.

Whatever is configured on the Hardware tab is set after booting by ESPEasy.

GPIO-1 (TX pin) is a bit odd as it might prevent the ESP8266 from booting if it is pulled low during boot.

Dorfrog
New user
Posts: 9
Joined: 25 Feb 2019, 00:53

Re: Use %syssec% to increment PWM Output

#7 Post by Dorfrog » 04 Nov 2023, 10:31

@TD-er Thank you - I appreciate the additional comments above.

Post Reply

Who is online

Users browsing this forum: No registered users and 34 guests