Is there any way to output audio signals through GPIO and is there any disadvantage with this way?

  • 1
    One very interesting method of outputting any audio signal via any digital I/O pin using minimal hardware is this: romanblack.com/BTc_alg.htm
    – slebetman
    Commented Jun 10, 2016 at 9:25

3 Answers 3


The audio jack channels (left and right) are provided by PWM driven GPIO (channel 0 by GPIO 12 or 18, and channel 1 by GPIO 13 or 19).

So if you connect appropriate circuitry to those GPIO you will get audio.

See BCM2835 ARM Peripherals for details on the GPIO and PWM peripheral.


Some background

On recent Pis the audio jack output is provided by PWM channels 0 and 1. PWM channel 0 is fed to GPIO40 which is connected to the (stereo) right channel, and PWM channel 1 is fed to GPIO45 which is connected to the (stereo) left channel.

These PWM channels may additionally be fed to user accessible GPIO.

PWM channel 0 may be routed to GPIO12 and GPIO18.

PWM channel 1 may be routed to GPIO13 and GPIO19.

You route PWM to a GPIO by setting a particular GPIO mode as follows:

  • GPIO12 - set mode ALT0
  • GPIO13 - set mode ALT0
  • GPIO18 - set mode ALT5
  • GPIO19 - set mode ALT5

See page 102 of the Broadcom spec reference above.

There are various ways of setting a GPIO mode.

My pigs utility uses the M command.

E.g. pigs m 18 5 will set GPIO18 to mode ALT5.

  • Do I need to use both channels ? and why there are or there, say I'm using Pi 3 and what is the number of the GPIOs that have hardware PWM ? According to this, there is only one pin has PWM, that is pin 12 (GPIO18).
    – Van Tr
    Commented Jun 10, 2016 at 8:14
  • @IlDivinCodino You can use one or two channels. Stereo requires two, mono one. My answer mentions the usable GPIO, Or means you can use either GPIO (or both if you can find a reason to do so).
    – joan
    Commented Jun 10, 2016 at 8:21
  • @joan's own (IIRC) pigpio library allows PWM over arbitrary pins - I wonder how many audio channels you could get that way.
    – Chris H
    Commented Jun 10, 2016 at 9:47
  • 1
    @ChrisH pigpio DMA timed PWM is restricted in that only a fixed number of frequencies may be generated with a limited number of steps between off and fully on. That's fine for lots of applications, but probably not audio (I don't know how PWM is used to generate audio so this is a guess on my part).
    – joan
    Commented Jun 10, 2016 at 10:01
  • 2
    @joan, It's the discrete frequencies that would be more of an issue (a 50:50 duty cycle is probably best for maximum volume). So it would be good for an alarm but not for general playback. I might have a chance to play with it over the weekend.
    – Chris H
    Commented Jun 10, 2016 at 10:19

Just as Joan's answer already suggests, the Pi's analog audio out is just that. Adafruit has an article describing this circuitry in detail for use with the Pi Zero (which comes without it), see here.

  • you should have an description for the article, just put the link is not a good way to answer in stackexchange. Sometime the link could be die.
    – Van Tr
    Commented Jun 13, 2016 at 7:27
  • 2
    1) it's not just putting the link, it's giving context (albeit just a little as I admit), 2) link rot is not likely a problem as it is an internal link within raspberrypi.SE, not an external link (I thus would argue it will be just as persistent as your question). The idea was to not repeat the information provided there and not closing both questions as dupes to one another (because they are not, imho).
    – Ghanima
    Commented Jun 13, 2016 at 19:10

Raspberry Pi 4 / Raspberry Pi Zero Systems with Debian/Rasbian Buster

If you are using the latest version of the Raspberry Pi OS at the time of writing you may require this dtoverlay to remap audio from the AV Jack to the GPIO pins.

dtoverlay=audremap,pins_12_13 # for pins 12 and 13
dtoverlay=audremap,pins_18_19 # for pins 18 and 19

See pinout.xyz for information on these pins.

GPIO12 & GPIO13 are Physical pin numbers 32 and 33.

GPIO18 & GPIO19 are Physical pin numbers 12 and 35.

These commands remap or redirect the analog (PCM) audio to the GPIO pins.

If you view the signals on a scope you will observe that they are square waves. If you want "analog" output, such as that which comes out of the AV Jack, you will require a low and high pass filter combination. Such a filter exists on the R-Pi 4 board before the 3.5 mm jack. There is no such filter when routing signals to GPIO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.