PWM doc example not working on RP2 #12162
-
I got error in the second line already from doc example on release 1.20.0 on RP Pico. Reproducible on older releases too. MicroPython v1.20.0 on 2023-04-26; Raspberry Pi Pico with RP2040
It seems to me that something is not fully ported to RP2. Thank you for your contributions. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
That is changed in the nightly builds. |
Beta Was this translation helpful? Give feedback.
-
Also another reason to note the warning at the top of the latest documentation page:
The examples in the v1.20.0 RP2 PWM docs work as expected with v1.2.0: from machine import Pin, PWM
pwm0 = PWM(Pin(0)) # create PWM object from a pin
pwm0.freq() # get current frequency
pwm0.freq(1000) # set frequency
pwm0.duty_u16() # get current duty cycle, range 0-65535
pwm0.duty_u16(200) # set duty cycle, range 0-65535
pwm0.deinit() # turn off PWM on the pin The examples from the latest RP2 PWM docs, however, fail with v1.20.0: from machine import Pin, PWM
# create PWM object from a pin and set the frequency of slice 0
# and duty cycle for channel A
pwm0 = PWM(Pin(0), freq=2000, duty_u16=32768)
… The latest docs may contain features not implemented in the most recent release, so please check the docs version (in the "Versions and downloads" tab) against the version of MicroPython you're running. Sometimes the docs are wrong, though, but this one is a version thing. |
Beta Was this translation helpful? Give feedback.
-
Oh, just days after 1.20.0 release. Thanks to both to take time for explaining this in detail! I'm really sorry for the confusion! Will try again in a few days and close this to treat the issue properly. |
Beta Was this translation helpful? Give feedback.
-
Other then case bellow it works as expected. It gives ERROR in NB v1.20.0-327-gd14ddcbdb on 2023-07-27: TypeError: extra positional arguments given.
At least I understand the docs the way that this should work. Or am I wrong? |
Beta Was this translation helpful? Give feedback.
-
Except Pin and freq all arguments are keyword only. You cannot supply them as positional argument. And you must supply either duty_u16 or duty_ns. If you supply both, the behavior is not specified. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your kind, patient and informative response, now it makes much more sense. |
Beta Was this translation helpful? Give feedback.
Also another reason to note the warning at the top of the latest documentation page:
The examples in the v1.20.0 RP2 PWM docs work as expected with v1.2.0: