PWM on Laboris fw

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
ttmetro
Posts: 104
Joined: Mon Jul 31, 2017 12:44 am

PWM on Laboris fw

Post by ttmetro » Wed Oct 18, 2017 10:34 pm

I cannot find a working PWM example for ESP32 with Laboris fw (I use a Huzzah32 board). The following code won't blink the led:

Code: Select all

from machine import Pin, PWM
pwm = PWM(Pin(13), freq=1, duty=512)
# pwm.duty(512)
Also, uncommenting the last statement gives an error:

Code: Select all

ledc: ledc_set_duty(339): LEDC channel error
Does anyone have a working example? I'd like to use this for motor PWM control (and similar stuff).
Bernhard Boser

ttmetro
Posts: 104
Joined: Mon Jul 31, 2017 12:44 am

Re: PWM on Laboris fw

Post by ttmetro » Wed Oct 18, 2017 10:48 pm

Figured it out. This problem occurs only if the PWM channel on the particular pin has been allocated already. Resetting the board will fix this.

Follow-up question: is there a way to "dis-allocate" a PWM channel, so it can be used again?
Bernhard Boser

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: PWM on Laboris fw

Post by loboris » Wed Oct 18, 2017 11:08 pm

You can use deinit method:

Code: Select all

MicroPython ESP32_LoBo_v2.0.4 - 2017-10-08 on ESP32 board with ESP32
Type "help()" for more information.
>>> 
>>> from machine import Pin, PWM
>>> pwm = PWM(Pin(13), freq=1, duty=512)
>>> 
>>> pwm.duty(100)
>>> pwm.freq(10)
>>> 
>>> pwm
PWM(13, freq=10, duty=100)
>>>
>>> pwm.deinit()
>>> pwm
PWM(13)
>>>
>>> pwm = PWM(Pin(13), freq=10, duty=512)
>>> pwm.duty(100)
>>> pwm
PWM(13, freq=10, duty=100)
>>> 

ttmetro
Posts: 104
Joined: Mon Jul 31, 2017 12:44 am

Re: PWM on Laboris fw

Post by ttmetro » Thu Oct 19, 2017 12:13 am

Thanks!
Bernhard Boser

Post Reply