Wednesday 26 August 2015

LM386 Stereo Amplifier

*The information found in my blogs is provided for free; I do want people to use the information and reproduce or expand on my projects. If you produce a blog or publish work using the information found here and are using elements that are unique to my designs, I simply ask that you link back to my blogs and videos and credit the resource as a courtesy to myself and others who take the time to add to the online electronics hobby community. 

The magic surrounding the LM386 is mostly because of how common it is, how easy to use it is and the cost. I purchased a bulk package of these IC's off of eBay some time ago. They have made their way into a few radio and audio projects, and I will have no issue using them all in future projects.




I recently built a small arcade machine around a Raspberry Pi computer, and I needed a solution for providing the audio component. This was not the easiest way to get sound into the cabinet, but I feel it took the customization up, and added a component showing that I could handle DIY electronics too, and I don't need everything to be "plug and play".

 While most of the parts I already had available to me, I feel that sourcing the parts from the fine vendors in China over eBay drove the cost of this project down. I would be surprised if the cost of this board was greater than 5 bucks. The most expensive part of this project was buying the actual speakers, which I found at the local surplus store at a reasonable price.

Q: I thought the LM386 IC was only capable of handling one signal, stereo is two signals?
A: True, this is why we used two chips to produce the desired results!

 

Q: How do you get two separate signals going to two different chips to amplify at the same level?
A: With a dual potentiometer! (In this project I selected a dual 10K potentiometer with a logarithmic taper).


Q: Can I drive my giant speakers with this?
A: Nope, think headphones and small projects (~1/2 watt per channel).

Q: Why don't I just buy an audio module off of eBay instead of building my own?
A: You're only learning how to buy stuff, build something on your own and learn.

In this project I knew I would be stealing power from the 5V rail on the Raspberry Pi. For your information: LM386 IC would like to see 4-12VDC, except for the LM386N-4, which likes to see 5-18VDC. (It's common to see LM386 Projects supplied from 9V batteries).

Another consideration: depending on the project, you may wish to use a small value capacitor (Think 0.01uF or 0.001uF) to remove the DC component of an audio signal, this was necessary for my FM radio project: TEA5767 FM RADIO W/ ARDUINO.

It's up to you how you make the connections!
I ended up hacking a 3.5mm extension cable in half to get a male audio adapter for my circuit (I simply soldered the wires directly to my perf. board. I used screw terminals to hook up some small stranded wires as the speaker wire running to the speakers.

The only really unique aspect about this project is the linear taper dual potentiometer. If you google the datasheet for the LM386 you will see several different configurations, and some may be more well suited to your project than what I'm using. I decided to use the configuration with the lowest part count.

****Use bypass caps to reduce noise and clean up the audio****
(See schematic)

 *You don't need to use electrolytic capacitors, I just used what I had - replace 220uF with a poly type if available.

I added the bypass caps after I built the board, I would use space more effectively if I repeated this project.

There you have it, a cheap and easy stereo amplifier for small projects!

Thursday 16 July 2015

Tabletop Arcade Machine


 *The information found in my blogs is provided for free; I do want people to use the information and reproduce or expand on my projects. If you produce a blog or publish work using the information found here and are using elements that are unique to my designs, I simply ask that you link back to my blogs and videos and credit the resource as a courtesy to myself and others who take the time to add to the online electronics hobby community. 
 
While trying to decide on a project for a capstone project, I thought it would be fun to build an arcade machine; No one was on board, so we instead built a home automation/monitoring system (boring). Link to Home Automation Project

Moving along... I decided that I still wanted a machine anyway, so it might not be as polished as it
would have been if I made it as a capstone project, but it definitely has all the components needed for a good time! My only partner for this home project was my son Max.

The system is based around the popular Raspberry Pi model B computer (Check the link if you don't know about this computer), running the RetroPie software, which is available free (or donation) which boots your machine directly into a menu which allows you to select your emulator.

The first thing I did was acquire a monitor, which I actually picked up at a college asset sale in October (8 months ago). It was only $5 for a 17" monitor, and I don't think the aspect is quite 4:3, but it is close, which makes it more suitable for emulating older consoles. If you were to use a modern 16:9 screen, you would either have black bars on the left and right sides, or you would be stretching the image. Cocktail games are actually meant to be run on a monitor flipped 90 degrees, so the black space on the sides with a 16:9 monitor with cocktail games would be very large! If I build another machine, I will either hunt down a suitable CRT monitor, or another "square" monitor. The only issue with a VGA monitor on the Pi is that the Pi has an HDMI port, which I handled by using an HDMI to VGA adapter from eBay, which worked out just fine! Expect to pay less than $5 bucks, and make sure it actually has the support circuitry, and isn't just a "dumb" adapter.

The next component to worry about was the joystick and buttons. I dug around on eBay, and it looked like my best bet was to buy a kit. It's hard to link to auctions that end, but here's a try: joystick I bought
 This is a  picture of the kit if you wish to find the auction or buy one similar. The seller was fair, and I did receive it in a timely manner. I was however unimpressed with the buttons. The final arcade machine has the board with the controls screwed in, so I can remove it later, as I may yet swap them out. They do seem to do the trick and haven't given me much trouble, but they are a non-standard size; I didn't have a hole-saw the proper size, so the fit wasn't great. I did do an unboxing video for this set on YouTube. I was pretty upset in the video, but it worked out, the seller was fine, and the USB joystick adapter board did work fine with Mame/RaspberryPi, so if you're on a budget, you may still consider this set as an option.

 


The next step in the project wasn't mandatory, but it did simplify the project. I took the monitor apart so that I could remove it from the stand and enclosure, and also so I could try to steal power for the Raspberry Pi from it. I made the assumption that the circuitry and buttons on the monitor were being powered by a 5V supply line, and I was curious to see if I could tap into that.
I moved ahead and took the monitor apart and attached a cut-off MicroUSB cable to a 5V power line inside the monitor's guts and I was successful at powering the Pi. The only draw back to this is that I don't know what the max current output of the monitors 5V rail is, so this may fail in the future, or be unable to supply a Raspberry Pi 2 down the road; for now, I'll take it! The 5V rail is also used to power the audio system. The bonus of this technique is that I can simply plug the power cord into the monitor to power the entire project!



I had to decide on dimensions for the cabinet now, and the only thing I really knew for sure was the size of the monitor. I went into draftSight and started drawing out what I thought would work well, and I came up with this:
DWG File

To build the cabinet, I decided on a 4'x4' sheet of 1/2" MDF, as it was only $20 at Home Depot and the texture is preferable to plywood. Cutting and painting was the most time-consuming aspect of the project. Here is the video we made of us cutting out the parts using a table-saw and a jig-saw.
 
The panels were assembled by pre-drilling holes then putting nails in. A better method would be to use a router and cut grooves in, but I made due with what I had, and it worked out just fine. If you don't drill first, you will most certainly split the wood! I also cut the bottom part of plastic off the monitor which originally held the user buttons (I simply used a back-saw).

To add sound to the project, I decided to use LM386 amplifiers attached to speakers I picked up from the surplus store. I had all the electronics parts I needed on hand, so it worked out well. You may consider using computer speakers instead, but I feel my approach made the project a little more personal.
Link to Stereo LM386 Amplifier project
(It is complex enough that I don't want to get into too much detail here). This is a video demonstration of the LM386's in a stereo configuration, mechanically joined by two  logarithmic potentiometers, and being powered off of a 5V pin from the Raspberry Pi:
It's worth noting: The Raspberry Pi has no shielding, so even if you're listening to the audio with headphones, you will notice click and popping and noise. I may in the future put a metal shield which is bonded around both the Pi and my sound board. If you look closely in my video, you will also notice that the shielding on the cable I used for speaker wire is tied to ground to help suppress it from picking up additional noise. I think I made this video before attaching some 104 (0.1uF) caps directly in front of the + and - supply to the LM386 chips, which helped a lot with knocking noise off from the Pi.

Here we have the unveiling of the arcade cabinet:

This is pretty much how it will stay until I get the new Raspberry Pi. The project was fun, and I think I enjoyed building it more than I like playing on it! You may find you need to go into the RaspPi config and overclock it to 900MHz (if you're using an original Pi, not the Pi 2), as I was having some stutters in some games, but at 900 MHz, most of the stuff I was doing ran just fine.


 There you have it, the Pi Arcade Machine. I know this project has been beat to death, and loads of
information has been done, but hopefully this info still encourages or helps someone out. This has also been one of my more popular projects (as far as social media goes), and I'm happy to add more Raspberry Pi projects to the internet! Thanks for checking this out, and I'll leave you with one last thing, my blooper reel from building the cabinet.