Feb 10, 2016

S2 Spa Soother - Wire up the Circuit and Test

Before we proceed,  we need to load up our OS.

I used Raspbian Jessie for this build.

For the next steps, we will be working directly on the raspberry pi zero via SSH and wireless. I rarely use the GUI for Raspberry Pi, so can't help you using that. I used this great post from David Maitland on how to set up the Pi Zero "headless". Warning! This requires linux to edit the SD card.

Sound testing is coming up next. To prepare for this, solder on female headers to the Raspberry Pi Zero like so:

We're using the Raspberry Pi Zero for sound. Too bad it doesn't have a line output!

Fortunately, Adafruit has a nice tutorial on this: Adding Basic Audio Output to  Raspberry Pi Zero. LadyAda shows us some sweet reverse engineering on how to get PWM audio out of the Pi Zero.

Read the post on learn.adafruit.com for some capacitor substitutions LadyAda made to this circuit.

I followed along with the fairly simple schematic and got some low-volume sound:

To get louder mono sound out, I grafted on an LM386-based amplifier to the output. You can buy these cheap on Amazon, or make your own fairly quickly. I used the post at hackaweek, the web site of Dean Segovis, on how to make a simple LM386 amp.

Here's Dean's schematic:

It took about 90 minutes to put the PWM LM386 circuits together on a breadboard (I work slow).

Once I had it working, I made a soldered version on a perma-proto board.

You can test and debug your circuit using double-ended alligator clips, one end to plus/minus on a small speaker, the other to plus/minus from the LM386 amplifier. You can test the speaker by SSH-ing to the Pi Zero in a terminal; then, from a command line by enter "speaker-test". If successful, this will produce "pink noise" (similar to "white noise") that will at least let you know sound is coming out.

I found out much later that I was picking up significant noise. I googled for a solution and found one that worked. I added a 1N4001 Diode in-line on the 5V rail anywhere before the LM386; the "banded" side/cathode of the Diode faces toward the LM386. Also added a 470uF Capacitor across the rails, positive to 5V, negative to GND, soldered before the LM386. This eliminated the noise.

Hard to see, but there's a 1N4001 Diode in there, as well as the 470uF Capacitor

For testing the code in the next step, we'll need to solder up the buttons. The buttons for sound choices will be soldered to a cut-down piece of 1/2 breadboard sized perma-proto board. This actually makes it easier for final assembly - not so many wires, and don't have to solder directly to the tiny switch pins. Cut the perma-proto board in half, length-wise down the middle. Use a full half for the buttons. The other half you will cut a piece out 3 columns x 5 rows wide. This will be used later for the power button on the front of the box.

Optional: I later cut another small piece of perma-proto to hold screw terminals. These are not required, but made it easier to attach the speaker wires to the LM386: speaker wires to one side of cut perma-proto, then LM386 GND/Audio Input to the screw terminals.

Warning: FR4-based circuit boards are not intended to be cut by the consumer and pose a health risk from the dust particles. Wear eye protection, gloves and a fiberglass-rated dust mask!

Piece of other half of perma-proto board will be used for power switch in final assembly

One leg of the momentary pin will be soldered to the +V rail. Clip the other leg where it meets the 5V rail so it doesn't touch the rail - this leg will be connected to the Pi Zero pin. Connect the +V rail to a 5V output on the Pi Zero; I used Board Pin 4. The Pi Zero-connected leg of each button will be soldered to a PTH (Plated Thru-Hole) column. Then, solder a jumper wire to the pin on the leg NOT connected to +5V. Connect Button1 to Board pin 11, and so on as shown in the following diagram:

Button Connections to Pi Zero Board Pins

Tip: Snip tabs off  bottom of switch 
to make it lay flat against the board

This was an earlier prototype - shows the wiring to pins; 
Hot glue the soldered board to the shim with the
momentary switches aligned with holes
(Click to embiggen)

As a final step for preparing the Button Board, use Loctite (CA) to glue the Button tops to the actuators of the momentary switches:
Momentary Switches in place and Button Tops being added

We'll need some more software packages installed to fully test our circuit, coming up in Install Code and Test

No comments:

Post a Comment