can't import name pwm

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
dragon12
Posts: 3
Joined: Fri Sep 10, 2021 5:21 pm

can't import name pwm

Post by dragon12 » Fri Oct 22, 2021 1:04 pm

For some reason I cannot find PWM module:

Code: Select all

MicroPython v1.17-68-g35fb90bd5-dirty on 2021-09-24; NUCLEO-F401RE with STM32F401xE

Type "help()" for more information.
>>> from machine import pwm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: can't import name pwm
>>> dir(machine)
['__class__', '__name__', 'RTC', 'ADC', 'DEEPSLEEP_RESET', 'HARD_RESET', 'I2C', 'PWRON_RESET', 'Pin', 'SOFT_RESET', 'SPI', 'Signal', 'SoftI2C', 'SoftSPI', 'Timer', 'UART', 'WDT', 'WDT_RESET', 'bitstream', 'bootloader', 'deepsleep', 'disable_irq', 'enable_irq', 'freq', 'idle', 'info', 'lightsleep', 'mem16', 'mem32', 'mem8', 'reset', 'reset_cause', 'sleep', 'soft_reset', 'time_pulse_us', 'unique_id']
>>> 
The same on another board:

Code: Select all

MicroPython v1.17-6-g9792c9105 on 2021-09-03; NUCLEO-L476RG with STM32L476RG

Type "help()" for more information.
>>> from machine import pwm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: can't import name pwm
>>> dir(machine)
['__class__', '__name__', 'RTC', 'ADC', 'DEEPSLEEP_RESET', 'HARD_RESET', 'I2C', 'PWRON_RESET', 'Pin', 'SOFT_RESET', 'SPI', 'Signal', 'SoftI2C', 'SoftSPI', 'Timer', 'UART', 'WDT', 'WDT_RESET', 'bitstream', 'bootloader', 'deepsleep', 'disable_irq', 'enable_irq', 'freq', 'idle', 'info', 'lightsleep', 'mem16', 'mem32', 'mem8', 'reset', 'reset_cause', 'rng', 'sleep', 'soft_reset', 'time_pulse_us', 'unique_id']
>>> 
Could somebody explain what I'm doing wrong?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: can't import name pwm

Post by Roberthh » Fri Oct 22, 2021 1:23 pm

On the STM32 port pwm is part of the pyb.Timer module. See: https://docs.micropython.org/en/latest/ ... hlight=pwm

dragon12
Posts: 3
Joined: Fri Sep 10, 2021 5:21 pm

Re: can't import name pwm

Post by dragon12 » Fri Oct 22, 2021 1:38 pm

Roberthh wrote:
Fri Oct 22, 2021 1:23 pm
On the STM32 port pwm is part of the pyb.Timer module. See: https://docs.micropython.org/en/latest/ ... hlight=pwm
Thank you for helping me with this. I assumed that machine is common hardware library and all its modules present on all boards.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: can't import name pwm

Post by Roberthh » Fri Oct 22, 2021 2:25 pm

I ran into that same problem a few days ago. STM32 was the first hardware platform for MicroPython. And not all changes have been mapped back to that platform. There are legacy extensions and omissions.

Post Reply