Skip to content

Incompatible with ESP8266 (pwm.duty) #8

@jose1711

Description

@jose1711

On Wemos D1 mini (ESP8266) I am getting:

Traceback (most recent call last):
  File "<stdin>", line 34, in <module>
  File "/lib/buzzer_music.py", line 263, in tick
AttributeError: 'PWM' object has no attribute 'duty_u16'

The lack of said attribute can be confirmed by:

from machine import Pin, PWM
p = PWM(Pin(12))
print(dir(p))
# returns ['__class__', 'deinit', 'duty', 'freq', 'init'] on ESP8266 platform

In order to make it work on ESP8266 while retaining Pico compatibility this can be done:

if hasattr(pwm, 'duty_u16'):
    pwm.duty_u16(self.duty)
else:
    pwm.duty(self.duty)

While testing with D1 mini buzzer shield (https://www.wemos.cc/en/latest/d1_mini_shield/buzzer.html) I also had to lower duty (set to 100) as the default value (2512) only produced almost inaudible clicks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions