For a project I’m working on, one of the objectives is that the RPi be able to “speak” – just to have some fun.
The RPI can output audio through HDMI and the 3.5mm audio jack. Since I’m going to use the RPi for a small robot, the HDMI audio capabilities are of no interest. So, it only leaves the 3.5MM audio jack, but there’s a problem. The audio is not amplified. For some headphones it’s fine, but for a talking robot, the audio volume is just to low.
How to bypass that ?
Enter Adafruit’s MAX98306.
Requirements
- 1x Raspberry PI
- 1x Speaker ( small speaker from an old PC – 8 Ohms, 0.5 W )
- 1x Adafruit’s MAX98306
- 1x 3.5MM female jack (I’ve salvage one from an old CD-ROM drive)
Speaker
3.5MM female audio jack
MAX98306
Wiring
Heres the wiring for the MAX98306.
Connect an external power source (my case 4xAAA batteries) to the MAX98306 VDD and GND PINs
My 3.5MM audio jack only has 3 PINs. I’ve tried to search for the pinout, but I was unable to find anything. I tried several configurations and this one was the best. Since I’m only going to use one speaker, I’ve connected it to the right speaker PINs of the MAX98306.
Here’s the result
Left PIN (as the image goes) of the JACK connects to L+ and R-. Right PIN connects to R+
Connect the speaker to the right screw-terminal blocks.
Sound configuration
Note: The following section (sound modules and alsa mixer) can be skipped – just check if you already have sound output (connect a set of headphones and play something) or if the snd_bcm2835 module is loaded (ie: lsmodules). By default, the output is auto-detected
Prepare for sound
sudo apt-get install alsa-utils
Reboot the PI and when it gets back online, just load the sound modules and set the output to the 3.5mm stereo jack
sudo modprobe snd_bcm2835 sudo amixer cset numid=3 1
The amixer numid settings are:
0=auto
1=headphones
2=hdmi
Verify your mixer settings
NOTE: The Adafruit’s MAX98306 has a jumper where you can configure the gain.
Check the wiring of the speakers
If you’re wiring two speakers, you can head to Richard Farrar page to check if the speakers are wired correctly and if the RPI is sending the sound right.
He has some mp3 files that you can use to check the left, right and balance
http://www.richardfarrar.com/are-your-speakers-wired-correctly/
Give voice to your RPI
Now it’s time to make your RPi speak. We’re going to use espeak. It is simple to use and it it has Python modules that you can use in your programming.
sudo apt-get install espeak
espeak -ven -p25 "hello World. This is awesome. I'm running an audio stuff here"
Install a CLI audio player
sudo apt-get install mpg321
Play something
mpg321 Paloalto-\ Last\ Way\ Out\ Of\ Here.mp3
And you should have audio playing !
References
https://jeffskinnerbox.wordpress.com/2012/11/15/getting-audio-out-working-on-the-raspberry-pi/