Audio output via digital PWM

The audiopwmio module contains classes to provide access to audio IO.

All classes change hardware state and should be deinitialized when they are no longer needed if the program continues after use. To do so, either call deinit() or use a context manager. See Lifetime and ContextManagers for more info.

Since CircuitPython 5, Mixer, RawSample and WaveFile are moved to audiocore.

class audiopwmio.PWMAudioOut(left_channel: microcontroller.Pin, *, right_channel: Optional[microcontroller.Pin] = None, quiescent_value: int = 32768)

Output an analog audio signal by varying the PWM duty cycle.

playing :bool

True when an audio sample is being output even if paused. (read-only)

paused :bool

True when playback is paused. (read-only)


Deinitialises the PWMAudioOut and releases any hardware resources for reuse.


No-op used by Context Managers.


Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.

play(self, sample: audiocore._AudioSample, *, loop: bool = False)

Plays the sample once when loop=False and continuously when loop=True. Does not block. Use playing to block.

Sample must be an audiocore.WaveFile, audiocore.RawSample, or audiomixer.Mixer.

The sample itself should consist of 16 bit samples. Microcontrollers with a lower output resolution will use the highest order bits to output. For example, the SAMD21 has a 10 bit DAC that ignores the lowest 6 bits when playing 16 bit samples.


Stops playback and resets to the start of the sample.


Stops playback temporarily while remembering the position. Use resume to resume playback.


Resumes sample playback after pause().