JHZ
Posts: 23
Joined: Wed Sep 07, 2016 8:23 am

Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 5:43 am

Hi,

I am playing with Raspberry Pi 3 GPIO and make it work with LEDs. I was thinking to get audio input and output through GPIO. I have something like https://cdn-shop.adafruit.com/1200x900/1935-03.jpg and https://cdn.shopify.com/s/files/1/0851/ ... 1431785120. I read many documents and tried to find tutorials but could not find any easy solution (at least not feasible for me). I found many posts on this forum too but no body posts the solution after if they got success.
I would like you to guide me if there is any easy solution or guide which I can follow to make it work.
Thank you for suggestions and guideline.

W. H. Heydt
Posts: 10762
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 5:48 am

Easiest solution is to get a USB audio dongle that has an input. Bear in mind that there are no analog GPIO pins on a Pi. Audio output on a Pi (other than HDMI) is done using PWM signaling.

JHZ
Posts: 23
Joined: Wed Sep 07, 2016 8:23 am

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 5:58 am

Thank you for your reply sir. I understand the audio input is beyond my capabilities but for audio output can you refer me any documentation that shows audio output through GPIO.
Last edited by JHZ on Thu Jan 12, 2017 6:08 am, edited 1 time in total.

W. H. Heydt
Posts: 10762
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 6:05 am


JHZ
Posts: 23
Joined: Wed Sep 07, 2016 8:23 am

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 6:10 am

W. H. Heydt wrote:You can start with this: https://www.raspberrypi.org/documentati ... -config.md
No, I mean with GPIO. I know the basic configurations of raspberry pi.

mattmiller
Posts: 2100
Joined: Thu Feb 05, 2015 11:25 pm

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 8:14 am

Do you just want a buzzer type sound?

If so - you just need to switch an output on and off at the right speed

e.g

Code: Select all

loop for 3 secs
  pin on
  wait 0.0005 secs
  pin off
  wait 0.0005 secs
should produce a 1KHz tone for 3 secs

Also - these sort of little boards will allow you to detect sounds
http://www.ebay.co.uk/itm/Sound-Detecti ... 3641.l6368



or are you looking for speech/music quality (and if so - why is the normal audio out not an option for you?)

JHZ
Posts: 23
Joined: Wed Sep 07, 2016 8:23 am

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 8:25 am

Thank you for your reply and the link, it is really useful. Actually I am working on a project of very limited budget in which I can not afford expensive speakers and I have to play music form Pi (quality doesn't matter). I was provided with mini metal speaker (linked in my first post) that I have to connect with GPIO pins. I found something similar here http://frederickvandenbosch.be/?p=1447 but he is using another board that supports pHAT DAC. I am looking for library that can support my speaker to attach with GPIO pins directly.
Once again thank you.

fruitoftheloom
Posts: 20481
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 8:37 am

JHZ wrote:Thank you for your reply and the link, it is really useful. Actually I am working on a project of very limited budget in which I can not afford expensive speakers and I have to play music form Pi (quality doesn't matter). I was provided with mini metal speaker (linked in my first post) that I have to connect with GPIO pins. I found something similar here http://frederickvandenbosch.be/?p=1447 but he is using another board that supports pHAT DAC. I am looking for library that can support my speaker to attach with GPIO pins directly.
Once again thank you.
Though this is for RPi Zero it uses the GPIO for audio output:

https://learn.adafruit.com/introducing- ... io-outputs
Retired disgracefully.....

JHZ
Posts: 23
Joined: Wed Sep 07, 2016 8:23 am

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 9:07 am

Though this is for RPi Zero it uses the GPIO for audio output:

https://learn.adafruit.com/introducing- ... io-outputs
Hi thank you for the link sir ! I am going to try it with my Pi and if it worked, I will post back here with detailed solution.

mikerr
Posts: 2774
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 9:33 am

JHZ wrote: Actually I am working on a project of very limited budget in which I can not afford expensive speakers and I have to play music form Pi
Any reason you can't just wire that speaker to the pi headphone socket? headphones are just small speakers...
Android app - Raspi Card Imager - download and image SD cards - No PC required !

JHZ
Posts: 23
Joined: Wed Sep 07, 2016 8:23 am

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 10:22 am

Hi thank you all for you suggestions and guidelines. I just made my speaker work with GPIO. Though the sound is very low that means I need an amplifier. I followed this guide https://learn.adafruit.com/adding-basic ... o?view=all. I had to just add the below line in /boot/config.txt file which changed the mode of PWM pins. I connected my speaker black wire to GPIO13 and red wire to GPIO18 and it worked.

Code: Select all

dtoverlay=pwm-2chan,pin=18,func=2,pin2=13,func2=4
I also had to change the audio configuration to "Force 3.5mm jack" in raspi-config file. Quit easy! :D

Now I am looking for audio input solution as simple as it was. If I couldn't find any then then I will go with mattmiller solution.
Thank you again. :)

User avatar
rpdom
Posts: 14992
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 10:32 am

Do you realise that what you have done is to build the same circuit that is already connected to the A/V jack on the Pi3?

JHZ
Posts: 23
Joined: Wed Sep 07, 2016 8:23 am

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 10:37 am

I don't exactly how it will effect but I did this experiment on my Raspberry Pi 2 Model B and looking forward to do same on my Raspberry Pi 3. Does it change any thing or a bad solution?

texy
Forum Moderator
Forum Moderator
Posts: 5155
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 11:18 am

For output, why can't you use the existing A/V jack?
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

2badmice
Posts: 56
Joined: Thu Nov 03, 2016 9:21 pm
Location: North West England

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 11:21 am

texy wrote:For output, why can't you use the existing A/V jack?

three times it's been offered/asked, not sure it's sinking in?
Pi Noob, please be gentle

JHZ
Posts: 23
Joined: Wed Sep 07, 2016 8:23 am

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 11:26 am

2badmice wrote:
texy wrote:For output, why can't you use the existing A/V jack?

three times it's been offered/asked, not sure it's sinking in?
Sorry guys I got now. It can be used too.

User avatar
flatmax
Posts: 336
Joined: Thu May 26, 2016 10:36 pm

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 11:36 am

I think it depends on what type of audio quality you want in and out.

If you want good quality input (and output), then you should use one of the available GPIO sound cards (some of them are very affordable and have headphone amps. onboard) :
http://elinux.org/index.php?title=RPi_E ... ards#Sound


For primitive $0 input ...
You can do something strange with the GPIO pin 38 which is the i2s input pin. Make sure your piezo buzzer generates >> +1.8V and put one of its leads on pin 38 (i2s audio data input) and the other lead on pin 39 (GND). Then all you need to do is configure a dummy sound card which uses the i2s port ... work out how to setup "snd-soc-dummy-dai" to do that. This may be a good start : viewtopic.php?f=44&t=91237&p=749707
Once you see " snd-soc-dummy-dai <-> " in dmesg, you know it is working and arecord -l should list the dummy card.

After that, you can record audio (with something like audacity) and you should see a terrible waveform which represents the sound field in a bad way !!! But you should be able to use it none the less for primitive triggering concepts.

That should work in some strange way ... the input audio will sound terrible ... but if it is only to trigger leds from input audio, should be fine :)

Matt
Last edited by flatmax on Thu Jan 12, 2017 11:56 am, edited 1 time in total.
Check the Ultra 2 sound card - use our shop instead of Amazon Europe (Amazon USA is live).
Sound card for the Raspberry Pi with inbuilt microphone : www.audioinjector.net
Audio Inector Octo multitrack GPIO sound card

JHZ
Posts: 23
Joined: Wed Sep 07, 2016 8:23 am

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 11:50 am

For primitive $0 input ...
Otherwise, you can do something strange with the GPIO pin 38 which is the i2s input pin. <ake sure your piezo buzzer generates >> +1.8V and put one of its leads on pin 38 (i2s audio data input) and the other lead on pin 39 (GND). Then all you need to do is configure a dummy sound card which uses the i2s port ... work out how to setup "snd-soc-dummy-dai" to do that. This may be a good start : view ... 7&p=749707
Once you see " snd-soc-dummy-dai <-> " in dmesg, you know it is working and arecord -l should list the dummy card.
Thank you for the suggestions, very useful. I was googling from 2 3 days but couldn't even get closer to this. It seems to work with my setup and I dare to do this! :D
Last edited by JHZ on Thu Jan 12, 2017 12:31 pm, edited 1 time in total.

User avatar
flatmax
Posts: 336
Joined: Thu May 26, 2016 10:36 pm

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 11:57 am

Awesome, happy to help :)
Check the Ultra 2 sound card - use our shop instead of Amazon Europe (Amazon USA is live).
Sound card for the Raspberry Pi with inbuilt microphone : www.audioinjector.net
Audio Inector Octo multitrack GPIO sound card

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: Raspberry Pi 3 Audio In/Out through GPIO

Thu Jan 12, 2017 12:42 pm

... or you could increase the budget to $3 & wire in an I2S MEMS mic for proper sound input (you'll need a steady hand ;))
Image

rpiuser2016
Posts: 75
Joined: Tue Jan 12, 2016 1:53 pm

Re: Raspberry Pi 3 Audio In/Out through GPIO

Mon Dec 03, 2018 6:27 pm

Is it possible to output AUDIO from GPIO and from 3.5 JACK at the same time?

JorgeP
Posts: 16
Joined: Thu Dec 07, 2017 12:37 am

Re: Raspberry Pi 3 Audio In/Out through GPIO

Mon Dec 03, 2018 11:55 pm

You can create a DAC using discrete components have a look at http://www.sonicillusions.co.uk/discrete_dac.htm . You can theoretically use a 74HC595 or similar IC to make a low pin count (on the micro controller side) DAC, I would assume an inexpensive 16 channel servo module board can be used for some neat sound effects.

Another micro controller manufacturer uses a discrete component Sigma Delta ADC for audio, see page 3 of 10 of this app note for a schematic, this type of ADC needs to be as close to the MCU pins as possible. the source code example would have to be written for use with Pi as their sample code is in their proprietary language.

Return to “General discussion”