User avatar
rpiMike
Posts: 1749
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Pi Zero PWM Audio not working on Buster

Sun May 10, 2020 4:34 pm

I've previously built the Pi Zero PWM audio circuit based on Adafruit's tutorial:

https://learn.adafruit.com/adding-basic ... iring-2-36

As far as I remember I only needed to add the dtoverlay to /boot/config.txt:

Code: Select all

dtoverlay=pwm-2chan,pin=18,func=2,pin2=13,func=4
This all still works on Raspbian Stretch.

Code: Select all

aplay /usr/share/sounds/alsa/Front_Center.wav
Plays 'front center' voice.

However replacing the sd card with the latest Raspbian Buster with dtoverlay and I no longer get sound.

Code: Select all

aplay /usr/share/sounds/alsa/Front_Center.wav
No sound.

Code: Select all

pi@raspberrypi:~ $ raspi-gpio get 13
GPIO 13: level=0 fsel=2 alt=5 func=ARM_TCK
pi@raspberrypi:~ $ raspi-gpio get 18
GPIO 18: level=0 fsel=4 alt=0 func=PCM_CLK
Any ideas?

hippy
Posts: 10586
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Pi Zero PWM Audio not working on Buster

Sun May 10, 2020 4:55 pm

Don't know if it will help but I had been using 'gpio -g mode 13 alt0' rather than setting device tree gubbins to tie GPIO13 to audio PWM.

I believe that was with Buster but could have been Stretch. NOte that's Gordon Henderson's 'gpio' not 'raspi-gpio'.

User avatar
rpiMike
Posts: 1749
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Pi Zero PWM Audio not working on Buster

Sun May 17, 2020 1:28 pm

Swapping pins 13 and 18 in the dtoverlay seems to get sound working!

Code: Select all

dtoverlay=pwm-2chan,pin=13,func=2,pin2=18,func=4
I now get:

Code: Select all

pi@raspberrypi:~ $ raspi-gpio get 13
GPIO 13: level=1 fsel=4 alt=0 func=PWM1
pi@raspberrypi:~ $ raspi-gpio get 18
GPIO 18: level=1 fsel=2 alt=5 func=PWM0
The following now works:

Code: Select all

omxplayer file.mp3 --adev local

User avatar
rpiMike
Posts: 1749
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Pi Zero PWM Audio not working on Buster

Sun May 17, 2020 1:42 pm

Hmmm - seems I only get one channel ??!!

trejan
Posts: 3615
Joined: Tue Jul 02, 2019 2:28 pm

Re: Pi Zero PWM Audio not working on Buster

Sun May 17, 2020 2:00 pm

rpiMike wrote:
Sun May 17, 2020 1:28 pm
Swapping pins 13 and 18 in the dtoverlay seems to get sound working!

Code: Select all

dtoverlay=pwm-2chan,pin=13,func=2,pin2=18,func=4
You've got func twice. It should be func and func2 to match up with pin and pin2.

You need to swap it back as you don't have a valid combination. It should be:

Code: Select all

dtoverlay=pwm-2chan,pin=18,func=2,pin2=13,func2=4

Code: Select all

Name:   pwm-2chan
Info:   Configures both PWM channels
        Legal pin,function combinations for each channel:
          PWM0: 12,4(Alt0) 18,2(Alt5) 40,4(Alt0)            52,5(Alt1)
          PWM1: 13,4(Alt0) 19,2(Alt5) 41,4(Alt0) 45,4(Alt0) 53,5(Alt1)
        N.B.:
          1) Pin 18 is the only one available on all platforms, and
             it is the one used by the I2S audio interface.
             Pins 12 and 13 might be better choices on an A+, B+ or Pi2.
          2) The onboard analogue audio output uses both PWM channels.
          3) So be careful mixing audio and PWM.
          4) Currently the clock must have been enabled and configured
             by other means.
Load:   dtoverlay=pwm-2chan,<param>=<val>
Params: pin                     Output pin (default 18) - see table
        pin2                    Output pin for other channel (default 19)
        func                    Pin function (default 2 = Alt5) - see above
        func2                   Function for pin2 (default 2 = Alt5)
        clock                   PWM clock frequency (informational)

User avatar
rpiMike
Posts: 1749
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Pi Zero PWM Audio not working on Buster

Sun May 17, 2020 2:14 pm

Thanks trejan

Now using:

Code: Select all

dtoverlay=pwm-2chan,pin=18,func=2,pin2=13,func2=4

Code: Select all

raspi-gpio get 13,18
GPIO 13: level=0 fsel=4 alt=0 func=PWM1
GPIO 18: level=1 fsel=2 alt=5 func=PWM0
It seems sound to left channel plays from both, sound to right channel plays from both, sound to both channels muffled?

User avatar
rpiMike
Posts: 1749
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Pi Zero PWM Audio not working on Buster

Sun May 17, 2020 4:37 pm

Using Stretch, 'speaker-test -c2', works - noise from left or right channels.

Using Buster, 'speaker-test -c2', fails - just get same noise from both channels.

K Em
Posts: 1
Joined: Wed Dec 09, 2020 12:04 pm

Re: Pi Zero PWM Audio not working on Buster

Wed Dec 09, 2020 12:20 pm

Hi everybody,

as this is most recent post about rpi zero PWM audio output that I was able to find, I'll ask here.

I'm following the adafruit Pi Zero PWM audio and I can't make it work. I add the dt overlay to config.txt and confirmed that GPIO 13 and 18 are on their ALT functions with wiringpi (gpio readall). There is a next step to choose forcing 3.5 jack over HDMI in raspi-config. But there is NOTHING ELSE than HDMI in the config.

I'm looking for similar problems for hours now and I haven't find anything. Am I doing something wrong ?

Thank a lot

PS.
RPI Zero with Raspbian version_id 10
it is fresh image but no updates as the zero is not connected to network...

User avatar
rpiMike
Posts: 1749
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Pi Zero PWM Audio not working on Buster

Wed Dec 09, 2020 1:14 pm

This appeared to be fixed on a recent version of Raspberry Pi OS.

I haven't tried on the very latest - I know they have made sound changes!

If you can run updates somehow that would be a good idea.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4069
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Pi Zero PWM Audio not working on Buster

Wed Dec 09, 2020 4:32 pm

The correct overlay is audremap:

Code: Select all

pi@raspberrypi:~$ dtoverlay -h audremap
Name:   audremap

Info:   Switches PWM sound output to GPIOs on the 40-pin header

Usage:  dtoverlay=audremap,<param>=<val>

Params: swap_lr                 Reverse the channel allocation, which will also
                                swap the audio jack outputs (default off)
        enable_jack             Don't switch off the audio jack output
                                (default off)
        pins_12_13              Select GPIOs 12 & 13 (default)
        pins_18_19              Select GPIOs 18 & 19

kk345
Posts: 4
Joined: Mon Feb 01, 2021 2:23 am

Re: Pi Zero PWM Audio not working on Buster

Mon Feb 01, 2021 2:43 am

Hi,

I have been trying to get pwm audio through 3.5mm jack. Tried as given in below link.
https://www.tinkernut.com/2017/04/addin ... workbench/
but it did not work. Then came across this post. Now i am able to get audio but its mono not stereo. I tried a demo using aplay, its says output is mono.

Code: Select all

config.txt:
dtoverlay=audremap, pins_12_13
How do i get stereo output?
Am i missing anything?

Also the audio output has slight hiss. Can anyone share a better filter?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4069
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Pi Zero PWM Audio not working on Buster

Mon Feb 01, 2021 11:42 am

Remove the space from the dtoverlay line - "sudo vcdbg log msg" will be complaining about it.

I believe the mono issue is already fixed - go through the apt update, apt upgrade process.

kk345
Posts: 4
Joined: Mon Feb 01, 2021 2:23 am

Re: Pi Zero PWM Audio not working on Buster

Mon Feb 01, 2021 1:47 pm

Thank you for the reply

saisiv
Posts: 3
Joined: Tue May 12, 2020 2:04 am

Re: Pi Zero PWM Audio not working on Buster

Mon Apr 26, 2021 4:04 am

Hi - seems the 2021-03-04 Lite release does not support stereo audio.

Fresh headless install, audio is routed to pwm via:

dtoverlay=audremap,pins_12_13

I have run the update / upgrade commands and still getting mono audio, does anyone know of a workaround?

Thanks!

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4069
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Pi Zero PWM Audio not working on Buster

Mon Apr 26, 2021 10:12 am

A fresh, non-upgraded RPiOS Lite installation with "dtoverlay=audremap,pins_12_13" gives stereo output as expected.

After "sudo apt-update && sudo apt upgrade" it's still stereo.

Even "sudo rpi-update" (not recommended unless advised to do so) didn't break it.

I recommend using "speaker-test -c 2" to confirm channel usage.

saisiv
Posts: 3
Joined: Tue May 12, 2020 2:04 am

Re: Pi Zero PWM Audio not working on Buster

Mon Apr 26, 2021 6:09 pm

Yes! You are correct. It works.

I was testing with the samples in /usr/share/sounds/alsa:

Front_Left.wav and
Front_Right.wav

... which are mono files. :oops:

Thank You!

Return to “Troubleshooting”