Jun 23, 2014

CMoy Headphone Amp Build

A friend of mine told me about the Chu Moy (CMoy) headphone amp, sounded interesting - just google it, it's all over the web. If you just want a headphone amp, the FIIO E6 @$27.99 USD is highly recommended. Watch out for counterfeits, though! You won't save any money self-assembling from parts vs. buying a CMoy ready-made. 

I wanted to make my own just for the learning experience. I saved a few dollars out of pocket because I had all the resistors and some capacitors in inventory, also some heaphone jacks and an 8 pin IC socket. Here's a list of the parts I ordered:

Cost (USD)
OPA2132PA Op Amp
10K Potentiometer with
on/off switch
Aluminum Knob
0.15uF Film Capacitors (2)
Fred's Amps Circuit Board

Fred's has a good set of instructions here. The build is easy, less than an hour for an experienced builder, but you need to pay close attention to the polarity of the electrolytic caps and the battery leads.

Because the headphone jacks I used were taller than Fred's specs, I couldn't use the punch-out template he supplied. I made several attempts at drilling/punching holes, but somehow things were off a tiny bit and I couldn't achieve a nice, snug fit.

I looked around for an alternative in my inventory of saved tins. Hmn. The Trader Joe's "Extra Dark Chocolate Wedges" round tin seemed up to the job. I simply made crude cut guidelines on the side of the tin and cut a space out with a nibbler tool. Followed that up with a bit of sanding the rough edges with a rotary tool. For attaching the board to the tin, I turned to the magic go-to tool, Sugru. It insulates, it decorates, it attaches, it smooths! It's the wonder room-temperature curing silicone.

Now, I have a tin that not only fits my battery, but is a nice size and shape to store my coiled up ear buds and headphone cable. 

I really enjoy having a discrete volume control over fiddling with buttons on an iPhone or other device. The CMoy is a nice upgrade to the sound - definitely noticeable, but not hit-you-over-the-head dramatic. Instruments and voices are more defined, the bass is improved and the sound stage is a little fuller. Nice!

UPDATE: 7/12/2014
Made an acrylic case for the amp - laser cut 1/8 in green translucent.

Raster etch logo is clip art of a sound wave mirrored on each side of the text; text in Boombox TTF font, converted to curves. 

Jun 17, 2014

Back in Black - a DIY raspberry pi Boombox: Inspiration

One of the items on my geek bucket list has been to build my own version of a boombox. The boombox was introduced by Philips in 1969. Refinements were introduced by Japanese manufacturers and introduced to the US in the 70's. They became a hit with urban youth. By the 80's, boomboxes had reached an age of gigantism - bigger, blasty, bassy. See the Wiki for det's.

My desire was to build a box that echoed back to the old school days, but took modern design cues. I wanted a box that looked good, sounded good (well, loud, anyway) and I could customize easily.

As a prototype, I built the Day & Night Sampler, a little music player in a re-purposed tin box. The "Back in Black" (BinB) Boombox started with what I learned in that build and grew from there. This was a journey, where I made several prototypes to visualize what I thought the boombox needed.

I reached a point where I was happy with the basic frame of the BinB, but it was missing something - the magic something i like to call 'minimal viable blinkenlights'. It just had to have flashing LEDs.

I had read (and experimented with) John Boxall's tutorial on using the Sparkfun Spectrum Shield. The Spectrum Shield works with an Arduino to display two channels of 7 audio frequency bands each. I used a VFD to test the Spectrum Shield display. It worked, but not very dramatic.

About this time, I saw the work of David J. Watts on Adafruit's Show & Tell Hangout. David presented a very creative small boombox.  His used the MSGEQ7 IC, which is also the heart of the Spectrum Shield, to display the frequency bands on a matrix of LEDs. Hmn... John Boxall showed how to do that with a Freetronics Dot Matrix Display, also an LED matrix. "What a minute! I have a Sure 0832 LED matrix someplace in inventory...[rummages around for awhile]... Yeah, here it is. I can use that to look like the graphic equalizer on old boomboxes."

But it was still missing... something. Well, what if I put in some Adafruit Neopixel Rings where the tweeters would normally go on a boombox? Googled around a bit and discovered the work of Chris Wilson on youtube, using an Adafruit Neopixel Strip as a VU Meter.  Perfect. A few easy tweaks to Chris' code and I had Neopixel rings bumpin' in blue to the beat.

And the name... What could be more iconic of an era than the 1980 release of "Back in Black" by AC/DC? Plus, my boombox was black... REALLY black... extreme GLOSSY black. 

Bill of Materials - Next

Back in Black - a DIY raspberry pi Boombox: Bill of Materials

See the Inspiration section.

Bill of Materials

The BinB Boombox reuses many of the components from the Day & Night Sampler build:

  • raspberry pi; I got mine from mcmelectronics.com, $35 plus shipping
  • Patriot WiFi USB dongle, model PCWUSB1150, on sale at Fry's, $7.99; 
  • adafruit perma-prototype board, part ID 723 $5.95
  • adafruit Vacuum Fluorescent  Display 20 Char x 2 Lines, part ID 347 , $29.95 (Since Discontinued!)
  • adafruit panel mount 2.1 mm DC barrel jack, part ID 610  $2.95
  • Syba (C-Media) USB sound adapter, available at amazon.com $7.99
  • 3.5mm headphone extension, male-to-male, under $5 on ebay
  • USB Short Extension cable, Type A Male to Female, about $3-5 from ebay; use with the C-Media USB sound adapter
  • adafruit 8 Bit (TTL) Logic Level Converter for interfacing the VFD to the pi, product ID 735, $1.50
  • adafruit mini remote control, product ID 389 , $5; Or, any surplus remote control you have
  • IR Sensor, TSOP38238, available at adafruit, product ID 157 , $1.95; also Mouser and others
  • SDHC Card, available at adafruit and others, adafruit part ID 102, $7.95
  • Lighted push button switch, about $4.00
  • Misc jumpers and wire
New or changed for this build are:
  • Enclosure/Frame - I used an 18in x 24in sheet of 1/4in black cast acrylic, $45 at Tap Plastics
  • 12V Power Adapter - 3 A or above with 2.1MM DC Plug output (mine was from inventory)
  • Optional - battery; recommend a 12V SLA (Sealed Lead Acid), but will add significant weight
  • Adafruit UBEC - Universal Battery Elimination Circuit to step 12V down to 5V, $9.95
  • Sure Electronics 0832/3208 LED Matrix - under $20 on ebay
  • Adafruit 20W Class D amp, $19.95
  • Adafruit 20W 4 Ohm Speaker (two needed), $14.95
  • Adafruit Neopixel 12 Ring (two needed) for the "VU Meters", $7.50 each
  • Sparkfun Spectrum Shield, $24.95
  • Arduino Stackable Headers from Sparkfun for the Spectrum Shield, $1.50
  • Additional 3.5mm male to male headphone extension (Spectrum Shield to amp)
  • Arduino Uno (substitute can be Leonardo/Clone), $24.95
  • Sugru, Hot Glue, E6000, double-sided tape to fasten things
  • Cable ties. Lots of them. Corral those loose wires.
Required Skills, Next

Back in Black - a DIY raspberry pi Boombox: Required Skills

For this project, you'll need a working knowledge of :
  • Adafruit's Neopixels
  • Rotary Encoders
  • Sure Electronics 0832 LED Matrix (or similar, such as the ones Adafruit sells); or the newer 3208 LED Matrix (differences explained below)
  • Sparkfun Spectrum Shield
Adafruit's UberGuide is an excellent tutorial on Neopixels. If you haven't worked with them before, this is required reading before you proceed. Neopixels have particular requirements - you can damage them by mishandling. Fair warning, read the tutorial.

Bob Rathbone has an excellent treatment on using rotary encoders with the raspberry pi. It can be downloaded from his site (PDF).

For the Sure Electronics 0832, I pieced together information from several sources. Although Sure still makes this LED Matrix, they have rev'ed the hardware. I'm including my findings here as legacy documentation.

The models are confusingly referred to sometimes as 0832, but also as 3208. The older 0832 model uses libraries for the HT1632 chipset; the newer 3208 uses the HT1632C chip set. As far as I can tell, the changeover to the new HT1632C occurred somewhere in the 2010-2011 time frame.  Per this blog based on the setup routine I used successfully,  I was using the 0832. My matrix was identified on the back as DE-DP10XV110. Newer models sport a DE-DP13111 / DE-DP13211 number on the back.  A good write-up on the Sure LED Matrix is available at makehackvoid. The color-to-model designation for the older 0832 seems to be:

  • DP104 = Red
  • DP105 = Green
  • DP106 = Yellow
(from milesburton.com)

I used the HT1632_LedMatrix library available here, simply because I had used it before and it worked with the 0832.Adafruit has a library for the current (as of June 2014) Sure 3208 model.

The Spectrum Shield is straightforward to use - one 3.5mm jack is audio input, the other audio output. Remember to order stackable female headers for using this with an Arduino, available on the same page as the Shield. The code for using the shield in this project is included on github.

John Boxall has written an exhaustive book, Arduino Workshop. He's also provided the book sections online. For the boombox project, I learned from John's work in Chapter 48, MSGEQ7 Spectrum Analyzer, using the Sparkfun Spectrum Shield. We'll be using that chapter later on in the build as a source for a test Arduino sketch.

Initial Setup, Next

Back in Black - a DIY raspberry pi Boombox: Initial Setup

Start with the Software Installation for the Day & Night Sampler. Put a test system together with breadboard and wire jumpers - you can use that as a model to refer to when you make the real deal. Really. Not kidding, here...

Oh, back already? That was fast!

Let's keep going...

By this point, you should have a working raspberry pi mpd system. You need this first, before you proceed with the installations on this page. That gives you a known good starting point which will help when you need to debug things.
If you followed along with the previous build, you should have a raspberry pi, that will:
  • display "Now Playing" song title
  • respond to remote button presses
  • produce sound from speakers (either test speakers or the one's you'll end up using)
If not, troubleshoot it! Most common problems are loose or poorly connecting wires; insufficient power; something missing from the software installation.

It's working? OK, continue..

Make the following changes.

To install the code, download it from here: thisoldgeek rpi-boombox

For code running on the raspberry pi:
  • Delete /etc/init.d/rpi_boombox.
  • Install the python scripts for rpi_boombox_v2.py and rotary_class.py in /home/pi
  • You should haven already installed VFD.py in /home/pi if you followed the above instructions
  • Save the rpi_boombox_v2_init.sh script in a directory of your choice; instructions for installing this script are on this page
    • Make sure you change any reference in those instructions from rpi_boombox to rpi_boombox_v2
For code running on the Arduino:
    • Download the HT1632_LedMatrix Library from github (not my repository)
      • This is for the Sure LED 0832 Matrix. If you want to use a different LED Matrix, you will need to adjust which library you use and, most likely, some Arduino code
    • Copy the HT1632_LedMatrix lib to your sketchbook/libraries folder
    Gather the new Hardware
    There are three new pieces of hardware to get working:
    • Neopixel 12 ring(s) (two needed)
      • Solder wires to GND, +V and Data In
    • Sure 3208 LED Matrix
    • rotary encoder - you can solder a small protoboard like the picture below and reuse it again for your final build

    Also, there are added jumper wire connections to the GPIO's of the raspberry pi:
    • 3 pins for the rotary encoder
    • 1 pin for a HIGH/LOW toggle switch to the arduino
    Test the Spectrum Shield
    Solder up long female headers to the Sparkfun Spectrum Shield and plug it into your Arduino. By now, you should have read John Boxall's MSGEQ7 Spectrum Analyzer Tutorial, number 48 in his series of tutorials. Download example 48.1 to your Arduino. Connect a 3.5mm headphone extension cable from the USB sound dongle on the raspberry pi to the input of the Spectrum Shield. With a serial monitor running on your Arduino, do you see audio frequency values rolling by? Good!

    Test the Neopixels
    • Copy the sketch boombox_music_visualizer.ino to your sketchbook folder
    • Start Arduino and upload the boombox_music_visualizer.ino to your target Arduino board
      • The LEDs are set to ON on startup in the sketch. Change led_toggle to read like the following line to force them OFF on start;
        int led_toggle = 0; // takes input from Rpi to turn lights on/off
      • Unplug your Arduino
    • Run a jumper wire from raspberry pi pin  to pin X on the Arduino
      • This will toggle ALL the LEDs HIGH/LOW (ON/OFF) from the Arduino
    • Attach a single NeoPixel to the Arduino
      • DIN = Pin XX, GND to GND, +V to +V
    • Restart the Arduino, with the toggle jumper, NeoPixel and headphone extension in place
    • Play some music through the raspberry pi, gradually increasing volume; you should see the NeoPixel react

    Make the Frame, Next

      Back in Black - a DIY raspberry pi Boombox: Make the Frame

      The boombox enclosure is a U-shaped frame from 1/4" thick black cast acrylic. The original sheet for this is 18" x 24". I got mine from the local Tap Plastics. That is the largest size material that can fit in the bed of the Epilog Laser 60W I used at TechShop San Francisco, where I fabricated the frame. The cut file in CorelDraw format is in the github repository here.

      I want through a series of prototypes, from simple to arty, to visualize what I wanted the boombox to look like. In the end, I went with a very clean presentation, with an integrated handle.

      Boombox Enclosure Prototyopes

      If you are using this drawing, always make a test strip of your cuts on scrap material of the same thickness first. This will ensure you get good cuts on your expensive final target material. Laser power may vary from machine to machine, even in the same make/model. That could lead to improper cuts - not cut through. Another reason to do a test strip is to make sure the cut sizes are correct. I like to make test cuts and use my actual hardware to test if size tolerances are correct. Tip: It's a good idea to save your scraps and cuttings for future use.
      Test Strip Tip: Etch the actual size for different tests (eg;, rotary encoder) 
      I saved the circles cut out from the switch tests and used them later on. The Neopixel rings have a hole in the center - when mounted, you can look into the nest of wires in the boombox. I used the circles as light baffles mounted on the backs of the Neopixels to achieve a nice, uniform look. More later.

      The file is rotated 90 degrees from vertical (portrait) to conform to the dimensions of the laser bed. At least two copies of each cut are laid down, one on top of the other, in the drawing. This is a technique to make several passes to cut all the way through on each element of a file, useful for laser cutting thicker material. It's an alternative to "printing" the whole file several times. Still, I had to "print" a couple of elements a second or even third time to get a clean cut. It happens... Cut the acrylic with the adhesive masking paper on to reduce smoke smudging.

      I used the following settings:
      • Vector Speed=12, Pwr=90, Freq=5000
      • Raster – S=75, P=30 ("Back in Black" logo and heat bend guidelines) 

      Next, prepare the frame for heat bending into a U-shape by removing the masking paper. I used the TechShop SF Formech FLB500 Heat Strip Bending System, a very nice tool available to members:
      Because of the thickness of the material, I let the Formech heat up for at least 20 minutes at temp setting 5. I had previously etched some guidelines on the acrylic to help position the sheet for accurate bending. The Formech has numbered gradations to help you allign material - just match a guideline to a gradation on each side of the sheet for even heating. You'll want to leave the material in place until the acrylic softens, approximately 3 minutes, but your time may vary. The acrylic is ready for the forming jig when you can easily "flick" up the material edge closest to you: give it a soft push and it should bend up easily. The material will also show a visible sag right at the heat application area when it's ready to be worked.

      I heated the material in the Formech twice, for two 90 degree bends. Do the inner bend, closest to the front face of the boombox first. To get the bends, TechShop also had an angle jig:

      The angle adjustment knob, shown in blue in the photo, is loosened on both of the two black semi-circles. Then you position the white vertical back to the angle you want to achieve. For thick material like 1/4" acrylic, you really have to exert some pressure on the material in the jig to press and hold it to the desired angle. Four minutes held in the jig should suffice. The acrylic will still need more time to cool completely. When cool, make the second bend, the one that forms the back of the boombox.

      Here's a video on the Formech FLB500 in action:

      Wire it Up - Power, Next

      Back in Black - a DIY raspberry pi Boombox: Wire it Up - Power


      The BinB boombox has a different power setup from the prototype - it can be battery powered or AC powered. If you want to run the boombox often on battery, the recommended choice is an SLA (Sealed Lead Acid) battery of good quality. These will usually add about 5 lbs/2.3kg to the boombox, and cost about $20USD and up, depending on amp hours.

      Since I was  going to use a battery only for short demonstrations, I bought a cheap one from ebay:
      Later, I found out these are of poor quality and can even be dangerous in some circumstances.  Not recommended! See the forum thread at dvxuser.

      Here's my original diagram (on a napkin!) for the power distribution scheme:

      • PB = OSH Latching Push-button Switch, in-line to +V
        • NC = Normally Closed; and of course, by NC I really meant NO, Normally Open terminal
        • C    = Common 
        • LiPo +V and Wall +V are tied together with the C terminal of the Push-button switch; NO is tied to the +12V rail of the distribution circuit board
        • When the Push-button is latched, +12V flows to circuit board
      • DC In = 2.1 mm jack
        • with the center positive plug inserted, the "switched" negative terminal is cut out of the circuit; the LiPo battery negative/GND is attached to the switched terminal, so it's cut out of the circuit when attaching to wall power
        • the other negative/GND (-) terminal is always attached to the circuit
      • LiPo Battery is attached via another DC 2.1mm jack
      • PB LED = LED internal to the OSH Switch (with built-in resistor), powered when PB is latched "on"
      • UBEC = Universal Battery Elimination Circuit, a Buck Converter for down converting from 12v to 5v
        • Amp for speakers is fed from 12V rails
        • USB hub is fed from 5V rails
          • raspberry pi powered from USB hub
          • Arduino powered from USB hub
      NOTE: The UBEC is wired between the 12V and 5V rails; the drawing makes the rails look like they are tied together. NO! Don't tie the rails together!

      Here's are as-built photos:
      DC In & OSH Push-button Switch

      Power Distribution Circuit Board

      Wire it Up - LEDs, Next

      Back in Black - a DIY raspberry pi Boombox: Wire it Up - LEDs

      The LEDs for the BinB Boombox are powered by the Sparkfun Spectrum Shield on top of an Arduino.

      Spectrum Shield

      I needed more +V and GND connections than were available. I used a cut-down piece of Adafruit perma-proto board and created a +V and a GND rail by soldering on female headers. I stuck this in the prototyping area of the Spectrum Shield with double-sided tape. Audio input from the Raspberry Pi is at the top of this picture, where the thumb is.

      All of the LED effects are triggered from the Raspberry Pi with a remote control press. When GPIO 24 is set HIGH, the LEDs are on; when set LOW, they are off. GPIO 24 is connected to pin 10 on the Arduino.

      From Arduino Pin
      NeopixelPin1  (Left as you face the boombox) 8
      pi_toggle 10
      CS1 (#3) 2
      WR (#5) 7
      DATA (#7) 6
      +5V (#12) 5V
      GND (#11) GND

      From CS1 in the table on, the connections are from the Sure 0832 LED Matrix. 

      Sure 0832 LED Matrix

      I used Sugru to attach the Sure Matrix and the VFD to the acrylic frame.

      The proto-board below the VFD is for the rotary encoder. The rotary encoder is connected to the Raspberry Pi, so:

       Rotary Encoder wired to Adafruit Perma-Proto Board

      Don't forget to add a 470 Ohm Resistor to the DIN (data in) line of the NeoPixels per the NeoPixel Uber Guide.

       NeoPixel 12 Ring - Two Needed

      Remember back on the Make the Frame page, I said to keep the circles cut out from the Test Strip? Now we'll use them to cover the hole in the mounted NeoPixel Rings and block out the inside of the boombox.

      NeoPixel Ring with scrap acrylic circle glued on as light baffle

      The VFD pinouts and connection to the Raspberry Pi were detailed in my earlier post on the Day & Night Sampler.

      Final Steps:
      • Screw Speakers into Frame
        • I spray-painted white nylon screws black
      • Solder the Class D Amp with supplied Potentiometer
        • Run 3.5mm cable Out from Spectrum Shield
        • Attach Speaker Wires and adjust Pot
      • Secure Raspberry Pi, Arduino, Amp, Power Distribution Board, USB Hub
        • Use Double-Sided Tape, E6000 or Hot Glue as appropriate
      • Run Cables from USB Hub to power Raspberry Pi & Arduino
      • Plug in a 12V Wall Wart (3A or higher) to the DC In Jack and Press the Push-Button switch
        • LED should light up
        • After about 1 minute, the Raspberry Pi should be ready to play music 
      ...And cable ties - lots and lots of cable ties.
      There's a slightly changed layout for the Remote on this version of the boombox.

      Make sure the LEDs are switched on by pressing the Toggle (Back) button.

      With the volume turned up past 50%, you should be rewarded with something like this:

      No soundtrack on this video. Feel free to hum along with "Back in Black" by AC/DC and Rock Out (in the privacy of your own home)!