-
Notifications
You must be signed in to change notification settings - Fork 190
Open
Description
On Raspberry Pi Pico, this results in the PWM frequency = 0 Hz and the backlight is disabled, regardless of the duty cycle set.
Apparently some platforms set a default frequency, some don't. The Pico doesn't. I think it's best if we are deliberate and specific with our frequency choice, rather than leaving up to the varying platform defaults, considering that the driver is meant to be 'generic'.
This is a complete showstopper for a newbie who doesn't know why they have a blank display!
The code:
if hasattr(machine, "PWM"):
if isinstance(self.bl,int): self.bl=machine.PWM(machine.Pin(self.bl,machine.Pin.OUT))
elif isinstance(self.bl,machine.Pin): self.bl=machine.PWM(self.bl)
Let's make it more legible, so we can see the intent:
from machine import Pin, PWM
if hasattr(machine, "PWM"):
if isinstance( self.bl, int ):
self.bl = PWM( Pin(self.bl, Pin.OUT) )
elif isinstance( self.bl, Pin ):
self.bl = PWM( self.bl )
Now let's fix it. It needs modifying in two places:
from machine import Pin, PWM
PWM_FREQ = const(1000)
if hasattr(machine, "PWM"):
if isinstance( self.bl, int ):
self.bl = PWM( Pin(self.bl, Pin.OUT), freq=PWM_FREQ )
elif isinstance( self.bl, Pin ):
self.bl = PWM( self.bl, freq=PWM_FREQ )
or maybe:
from machine import Pin, PWM
PWM_FREQ = const(1000)
if hasattr(machine, "PWM"):
# Convert from pin# to Pin()
if isinstance( self.bl, int ):
self.bl = Pin(self.bl, Pin.OUT)
# Create PWM()
if isinstance( self.bl, Pin ):
self.bl = PWM( self.bl, freq=PWM_FREQ )
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels