linux_author
Posts: 244
Joined: Sat Apr 02, 2016 7:04 pm
Location: Gulf of Mexico
Contact: Website

Hubs and DACs

Sun May 14, 2017 9:25 pm

Having a lot of fun lately with some extra Raspberry Pi Zeros, some Zero hubs, an RPi3, and several DACs to build LAN-connected Internet radio, .mp3 players, and video players. I like the Zero footprint, and as you all know, the Raspberry Pi Zero and Zero W are great little computers that don't ding your wallet - by themselves, and the RPi3 is also a bargain.

But with no audio out and limited USB on a zero, you'll need to add a few items to your project if you want some tunage and connectivity. The Raspberry Pi Zero W handily provides wifi - a real deal $10 computer that I predict will introduce many new products and a new standard in SBCs, but again, you'll need to add audio for any sound-related project. And if you want to host additional devices, such as thumb drives, mouse, or keyboard, you'll need some additional USB ports.

I suppose the cheapest way to get audio on the Zero is through a USB audio dongle. You can find these devices - which provide audio in and audio out connectors - everywhere for about a Lincoln (US$5). They work well with GNU/Linux, and most are C-Media devices easily recognized and configured for use by the kernel (gone are those terrible days of having to rebuild the kernel every time install a new sound card!)
Image
The problem is that you will most likely still need the sound amplified in order to play music on your speakers. Some dongles offer mute buttons, and some speakers are USB powered, but then only offer physical controls for volume, bass, etc.

Getting your hands on an amplifier for a stereo speaker project is kinda easy. I have scavenged a number of small amplifier boards from 3V battery powered speakers found in thrift stores and at flea markets. You can also buy one of the boards Adafruit sells to interface with your Zero's audio output.

For much better sound, Digital-to-Analog-Converters, or DACs, come in several form factors and flavors for the Raspberry Pi family. I have several: Pimoroni's PHAT DAC, a PiZeroAudio DAC, and Adafruit's Speakerbonnet.

i configure my DACs using Alsa and the hifiberry /boot/config.txt overlay:

Code: Select all

dtoverlay=i2s-mmap
dtoverlay=hifiberry-dac
dtparam=spi=on
then create an /etc/asound.conf containing:

Code: Select all

pcm.hifiberry {
type softvol
slave.pcm "plughw:0"
control.name "Master"
control.card 0
}

pcm.!default {
type plug
slave.pcm "softvol"
}

pcm.softvol {
slave {
pcm "sysdefault"
}
control {
name "softvol"
card 0
}
and if you want, an .asoundrc in your home directory:

Code: Select all

pcm.!default {
type plug
slave.pcm "softvol"
}

pcm.softvol {
slave {
pcm "sysdefault"
}
control {
name "softvol"
card 0
}
}
you'll need to select the DAC soundcard in your Raspbian Preferences Audio menu item; Menu->Preferences->Audio Device shows the 'snd_rpi_hiberry_dac (Alsa mixer) (Default)' selected - make it the default!

And as we all have additional USB devices, to get additional USB ports onto your Zero, use a hub. Like cheap audio amps, I have also scavenged old 4-port dongle hubs for Zero projects, such as this FrankenZero, a complete Desktop computer with wifi, sound, and a VGA port:
Image
Hardware developers have come up with some nice Zero-footprint hubs at a reasonable cost. Putting together some of the required bits for an audio project that will work well with speakers can be interesting! Here is a MakerSpot hub (highly recommended), with a Pimoroni PHAT DAC, and an Adafruit 7W audio amplifier - great sound out of this one:
Image
Amplified sound is provided by the screw jacks on the side of the amp board, with power (5V) supplied by the Zero's GPIO bus. The DAC's output is drawn from its RCA connectors:
Image
I've incorporated another hub, the new Hubpixed, which works with the rpi0 1.3 and W, and have an inexpensive DAC attached - note there is no amplifier! :
Image
But my favorite solution is the Adafruit Stereo Speaker Bonnet, which has the DAC and amp on a single board, and also provides your RPi's i2c and power GPIO pins in a separate area on the board - brilliant! i have this board installed in a Western Digital PiDrive enclosure on an RPi3 - great sound out of this one!
Image
Here are some tips and tricks with the speaker bonnet:
1. i have found that cutting a 4-pin Grove connector works great as a JST-4 plug - this makes hooking up stereo wires a lot easier or to route the stereo lines out to my RPi's enclosure
2. after a bit of research and command-line foo, i found the proper incantation to play video during Raspbian Pixel desktop sessions on an RPi3 and have the audio routed through the speaker bonnet (great sound!)

hint: vlc, as currently distributed, won't work! you must use omxplayer and you must specify the Alsa card number of the bonnet... for example:

Code: Select all

omxplayer -b -o alsa:hw:0,0 ManBearPig.avi
(the -b option creates a black background in case your video is smaller than your desktop)

at some time i'm going to try to recompile vlc for hardware acceleration... i understand that v2.2.4 will build properly at this point in time...

3. typing the omxplayer command line works, but is a pain in the ass if you're kicking back on the couch and using a Logitech remote keyboard and mouse; in this case, you'll want to create an association using a right-click on a movie file in the pcmanfm (file manager) window:
Image
you'll want to make sure that omxplayer is launched in a terminal, or you'll lose control of the program once the video starts playing (i.e., no volume control, pausing, or quitting); after you click 'OK' you will see the 'doit' option when you right-click your movie file - this is the easiest way for me to launch omxplayer without typing a command line.

tip: you'll need to create this custom launch option separately for .avi or .mp4 files - to save a hassle and time, rename your .mkv files to end in .avi (they're the same file internally - at least this has been my experience).

hope this helps some folks out there!

willie
on the happy video Gulf of Mexico

Return to “General discussion”

Who is online

Users browsing this forum: Burngate, DougieLawson, fbe, W. H. Heydt, wolf.z and 54 guests