Raspberry Pi + Headphone Jack + Amplifier + Potentiometer =

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
dershum
 
Posts: 24
Joined: Wed Aug 28, 2013 10:19 am

Raspberry Pi + Headphone Jack + Amplifier + Potentiometer =

Post by dershum »

Greetings! Hoping I could get some guidance/assistance on a question.

I'm planning out a project using an RPi, and would like to have both speakers (using one of the TPA2012 amplifies) and also a headphone jack so that when headphones are connected, the audio will switch to the headphones. I'd also like to be able to control the volume using a potentiometer.

So I've done some research, drawn some pictures, and I THINK I have it sorted. I have most of the parts (except the headphone jack with the disconnect switches) and wanted to make sure I've got this planned right before I order the rest of my parts.

My understanding (so far) is that the headphone jack on the RPI would wired to the R+/L+ on the external headphone jack (pins 3/4), with the GND going through the potentiometer to control the volume. Then, pins 2/5 on the headphone jack could be connected to the R+/L+ on the Amplifier board, and the GND also connected through the potentiometer. See beautiful (?) diagram below.
2016-12-02 17_43_46-Untitled 1 - LibreOffice Draw.png
2016-12-02 17_43_46-Untitled 1 - LibreOffice Draw.png (16.86 KiB) Viewed 1122 times
So a couple of questions:

I'm having a tough time following the pinouts on the datasheet for the headphone jack. I THINK that pins 2/5 are the ones that are open (not connected) when a headphone jack is connected - and therefore the R+/L+ from the RPi headphone jack would be sent to the amplifier. Does this sound correct?

If I route the GND from the RPi headphone jack through a potentiometer, that SEEMS like it would allow me to control the volume from the RPi through the external headphone jack, and also to the amplifier. Does this sound right?

Are there any other gotchas or mistakes I'm making? Any help would be greatly appreciated!

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi + Headphone Jack + Amplifier + Potentiomete

Post by adafruit_support_mike »

You have the signal connections from the headphone jack to the power amp right.

Using a pot connected to GND wouldn't give you useful volume control though. The pot would form a voltage divider with the output impedance of the RasPi's audio outputs, and you'd have to waste a lot of power to lower the volume.

What you need is a dual potentiometer:

https://www.digikey.com/product-search/ ... ageSize=25

Connect the ends of each pot between one of the RasPi's audio outputs and GND, then connect the pot wipers to pins 3 and 4 on the headphone jack.

The human ear responds to audio waves logarithmically, so to make the volume change uniformly as you turn the pot wiper, you need what's known as a log-taper pot. The wiper voltage stays well below 50% of the input voltage across 90% of the wiper's range. That's okay because we hear the change between 1% and 2% of the signal better than we hear the change btween 50% and 90%.

Log taper pots are kind of expensive, but you can fake one by putting a resistor in parallel with the wiper.. about 1/3 of the total pot value is about the best approximation of an exponential curve. For a 10k pot, connect a 3.3k resistor between the wiper and GND.

User avatar
dershum
 
Posts: 24
Joined: Wed Aug 28, 2013 10:19 am

Re: Raspberry Pi + Headphone Jack + Amplifier + Potentiomete

Post by dershum »

Mike, thanks so much for the quick reply!

I think the only question I have left is the resistance of the pot. According to wikipedia, the typical line-out voltage should be somewhere between +1.7v and -1.7v.

https://en.wikipedia.org/wiki/Line_level

So I'm guessing that the voltage range for the pot to handle would be 3.4 volts. Since I'm not sure what the target amperage of the minimum output should be (.01 amp would be 340ohm, .001 amp would be 3400ohm) I'm not sure what the max resistance should be.

At least that's assuming that ohms law is the one I want and I'm targeting the right range of voltages.

Thanks again for all the help!

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi + Headphone Jack + Amplifier + Potentiomete

Post by adafruit_support_mike »

The standard value for a volume pot is 10k.

There are two broad categories of audio amplifier: preamps and power amps. Preamps take signals that swing a few microvolts or millivolts and increase their voltage to +/-1v or so. Power amps take signals that might be able to deliver a few milliamps and increase the current to a few amps. The circuit techniques that make a good preamp make a bad power amp (and vice versa) so it's normal to build a signal chain using one of each.

That means your power amp doesn't need a strong input signal. The voltage on the wiper of a 10k pot should be plenty.

User avatar
mud2005
 
Posts: 30
Joined: Wed Jun 14, 2017 2:56 pm

Re: Raspberry Pi + Headphone Jack + Amplifier + Potentiomete

Post by mud2005 »

I'm trying to accomplish the same thing, audio to speakers is disabled when headphones are plugged in, and volume control that controls both headphones and speakers.
I came up with this diagram and was hoping someone could verify this is correct?
Also, my volume pot is 50K Ohm, will that work ok?
What is the best gain setting for this setup?
wiring_audio5.jpg
wiring_audio5.jpg (93.74 KiB) Viewed 870 times

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi + Headphone Jack + Amplifier + Potentiomete

Post by adafruit_support_mike »

I'm afraid that won't be able to drive headphones. Those need more current than you can get from a 10k potentiometer.

You'd need to move the audio jack between the MAX98306 amplifier and the speakers. That way the potentiometer controls the signal to the MAX98306 at all times, and plugging in headphones swaps the amplifier's output between the headphones and the standalone speakers.

User avatar
mud2005
 
Posts: 30
Joined: Wed Jun 14, 2017 2:56 pm

Re: Raspberry Pi + Headphone Jack + Amplifier + Potentiomete

Post by mud2005 »

Thanks for the reply, I'm not sure I understand.
I currently use headphones plugged directly into PI and the volume is high enough.
Are you saying the potentiometer will decrease the headphone volume due to lack of current flow and it won't be as loud as when headphones are plugged into the PI directly?
or do you mean I should put the headphone jack after the amp so I can get even louder output in headphones?

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi + Headphone Jack + Amplifier + Potentiomete

Post by adafruit_support_mike »

mud2005 wrote:Are you saying the potentiometer will decrease the headphone volume due to lack of current flow and it won't be as loud as when headphones are plugged into the PI directly?
Yes.

Most headphones need at least 200mA to 300mA to make the voice coil move enough to produce sound. The most current that can possibly flow through a 10k potentiometer connected to a 3.3V source is 330 microamps.. about a thousand times less than the headphones need.

User avatar
mud2005
 
Posts: 30
Joined: Wed Jun 14, 2017 2:56 pm

Re: Raspberry Pi + Headphone Jack + Amplifier + Potentiomete

Post by mud2005 »

I was about to post a new diagram, but I tested this circuit by connecting some alligator clip wires to a potentiometer and it did work and was very loud and I was able to control the volume level nicely.
Isn't the potentiometer 10k maximum resistance and when at 100% volume the current flows normally? So if it only puts out 330 microamps at 10k that's 0 volume anyway?

I also just realized in your first post in this thread you state:
connect the pot wipers to pins 3 and 4 on the headphone jack


So it's sounds like this diagram is correct? Did I miss something?

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi + Headphone Jack + Amplifier + Potentiomete

Post by adafruit_support_mike »

Well, I'm not going to argue with the hardware.. it has more staying power.

Apparently you have a set of headphones that can handle low current well, or a potentiometer with a fairly low value.

User avatar
mud2005
 
Posts: 30
Joined: Wed Jun 14, 2017 2:56 pm

Re: Raspberry Pi + Headphone Jack + Amplifier + Potentiomete

Post by mud2005 »

I'm doing a bit more research on this and found some similar info. Apparently I can put the headphones before the amp, but when turning down the volume it cuts out very quickly due to the low current.

I'm going to try and wire up the headphones after the amp and see if I get better results. I changed the diagram, hopefully I got it right this time?
I can't test this for a few days, but I'll post back and report if it worked.
wiring_audio7.png
wiring_audio7.png (282.5 KiB) Viewed 828 times

User avatar
mud2005
 
Posts: 30
Joined: Wed Jun 14, 2017 2:56 pm

Re: Raspberry Pi + Headphone Jack + Amplifier + Potentiomete

Post by mud2005 »

Well I finally got a chance to test this circuit and I have a major issue. I was getting sound from speakers when I set output in retropie to PCM and volume to 100%, it was actually sounding really good.
But when I plugged in headphones I would get really loud static when they were partially plugged in, I plugged and unplugged a few times and now I get no sound at all.
I think I blew the amp, any ideas why that would have happened? I checked the wiring multiple times.
The headphones did work before it blew, but there was really bad interference, it sounded like an engine idling when the volume was turned down.

EDIT: well I just unplugged the amp and plugged some headphones directly into PI to make sure sound was still working and it was, then when I plugged the amp back in it's now working.
I'm afraid to plug in the headphones though, any ideas why I would get super loud static when plugging them in, even if the volume is at 0?

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi + Headphone Jack + Amplifier + Potentiomete

Post by adafruit_support_mike »

That sounds like a connection problem.

Post a photo showing the actual hardware and we'll take a look. 800x600 images usually work best.

User avatar
mud2005
 
Posts: 30
Joined: Wed Jun 14, 2017 2:56 pm

Re: Raspberry Pi + Headphone Jack + Amplifier + Potentiomete

Post by mud2005 »

thanks so much, but all I have right now is an image with everything crammed in a case.
I have enough extra parts at this point that I can recreate this circuit outside of my project.
I'm going to order some more wire and post back in about a week or 2 with a much better picture.
project.png
project.png (882.03 KiB) Viewed 782 times

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi + Headphone Jack + Amplifier + Potentiomete

Post by adafruit_support_mike »

That does look pretty tight.

If you have access to an oscilloscope you can probe various points along the signal path from the RasPi's audio output to the speakers to see where the noise occurs. If you don't have a 'scope, you'll have to rely on more primitive methods like tapping every solder joint and connector in the signal path with a bamboo skewer to see if the noise changes.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”