Friday, May 5, 2017

Hubs 'N DACs

Having a lot of fun lately with some extra Raspberry Pi Zeros, some Zero hubs, and several DACs to build LAN-connected Internet radio and .mp3 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.

But with no audio out and limited USB, 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 bargain $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.

Audio Solutions

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!)
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.

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.

Zero Hubs

Getting additional USB ports onto your Zero can be accomplished by using 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:

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:

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:

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! :
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!

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:

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:
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).

No comments:

Post a Comment