Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with ESP8266 (pwm.duty) #8

Closed
jose1711 opened this issue Aug 6, 2022 · 1 comment
Closed

Incompatible with ESP8266 (pwm.duty) #8

jose1711 opened this issue Aug 6, 2022 · 1 comment

Comments

@jose1711
Copy link

jose1711 commented Aug 6, 2022

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.

@james1236
Copy link
Owner

Thank you, sorry for taking so long to get around to implementing this. I have not tested the committed code, so lets hope it doesn't break anything!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants