0

How can I get any standard audio programs (eg, 'espeak') to route output through the GPIO pins - so that I can use a Piezo Transducer (not a buzzer) attached my GPIO to hear sounds ?

I can do this 'the other way round' : I have already setup Pulse Width Modulation to generate simple square wave signals that correctly made the piezo 'beep': and this also has the side-effect of making the analogue 3.5MM audio jack 'beep' at the same time. (Because this too uses the same [two] PWM generators to generate its audio I learnt recently).

What I want to know is: can any program which outputs audio to the analogue audio output Jack - be routed to a one or two GPIO pins as well ?

1

There are two PWM channels used by the audio jack (left and right I guess).

These audio channels can be directed to zero, one, or more gpios as follows.

channel 0: gpios 12 (alt0), 18 (alt5), 40 (alt0), and 52 (alt1).

channel 1: gpios 13 (alt0), 19 (alt5), 41 (alt0), 45 (alt0), and 53 (alt1).

To direct PWM to a gpio you set the gpio to the particular mode given above.

So if your piezo is connected to gpio18 set that gpio to mode ALT5 to hear the audio. Of course if your piezo is a buzzer rather than a speaker don't expect much.

| improve this answer | |
  • Sorry - posted comment on wrong bit ! Where do i make these changes ? – monojohnny Mar 31 '15 at 19:50
  • wiringPi's gpio utility may have a command to set the gpio mode. If not pigpio's pigs utility does. To set gpio 18 to mode alt5 use pigs m 18 5. – joan Mar 31 '15 at 19:58

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