Expand description
Interface for the PWM peripheral.
RPPAL controls the Raspberry Pi’s PWM peripheral through the pwm
sysfs
interface.
§PWM channels
The BCM283x SoC supports two hardware PWM channels. By default, both channels
are disabled. To enable only PWM0 on its default pin (BCM GPIO 18, physical pin 12),
add dtoverlay=pwm
to /boot/firmware/config.txt
on Raspberry Pi OS or /boot/firmware/usercfg.txt
on
Ubuntu. If you need both PWM channels, replace pwm
with pwm-2chan
, which enables PWM0 on BCM
GPIO 18 (physical pin 12), and PWM1 on BCM GPIO 19 (physical pin 35). More details on enabling
and configuring PWM on other GPIO pins than the default ones can be found in
/boot/overlays/README
.
The Raspberry Pi’s analog audio output uses both PWM channels. Playing audio and simultaneously accessing a PWM channel may cause issues.
Some of the GPIO pins capable of supporting hardware PWM can also be configured for use with other peripherals. Be careful not to enable two peripherals on the same pin at the same time.
§Troubleshooting
§Permission denied
If new
returns an io::ErrorKind::PermissionDenied
error, make sure
/sys/class/pwm
and its subdirectories has the appropriate permissions for the current user.
Alternatively, you can launch your application using sudo
.
§Not found
If new
returns an io::ErrorKind::NotFound
error, you may have
forgotten to enable the selected PWM channel. The configuration options
to enable either of the two PWM channels are listed above.
Structs§
- Provides access to the Raspberry Pi’s PWM peripheral.
Enums§
- PWM channels.
- Errors that can occur when accessing the PWM peripheral.
- Output polarities.
Type Aliases§
- Result type returned from methods that can have
pwm::Error
s.