Hi,
I tried to run "from machine import PWM" on my pyboard 1.1 that follows the guideline at https://docs.micropython.org/en/latest/ ... e.PWM.html
But why dose it give such error prompt of "ImportError: can't import name PWM"?
Why ImportError: can't import name PWM on pyboard 1.1?
Re: Why ImportError: can't import name PWM on pyboard 1.1?
First thing to do in repl is:
then
I think
then
maybe quotes around machine and machine.PWM
Code: Select all
help('modules')
Code: Select all
import machine
dir(machine)
then
Code: Select all
dir(machine.PWM)
Re: Why ImportError: can't import name PWM on pyboard 1.1?
Thanks for the help.davef wrote: ↑Tue May 17, 2022 3:19 amFirst thing to do in repl is:thenCode: Select all
help('modules')
I thinkCode: Select all
import machine dir(machine)
thenmaybe quotes around machine and machine.PWMCode: Select all
dir(machine.PWM)
It seems to be an STM32 port specific quirk, see the answer in following post
viewtopic.php?f=15&t=11310&p=61888
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Why ImportError: can't import name PWM on pyboard 1.1?
It's worth noting that the pyb module includes a number of useful STM-specific enhancements.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Why ImportError: can't import name PWM on pyboard 1.1?
The pyboard has different methods. See PWM, particularly pyb.Pin and pyb.Timer:
Code: Select all
from pyb import Pin, Timer
p = Pin('X1') # X1 has TIM2, CH1
tim = Timer(2, freq=1000)
ch = tim.channel(1, Timer.PWM, pin=p)
ch.pulse_width_percent(50)