Introduction
My previous article about making a Spectrum analyzer with Arduino showed a proof of concept code for getting & rendering the Audio Spectrum data to both the screen and to an Arduino hardware. Since the original article I've been working on an improved version. If you haven't read the original article then, I strongly advise it for reading.
Background on Fourier Transform
In the previous article I haven’t talked much about the Spectrum analysis process. The Spectrum data is obtained using Fourier Transformation, which is based on Fourier's theorem. Fourier's theorem in layman's terms states that every wave can be reproduced as a series of simple sine waves. So the Fourier Transformation finds the component sine wave's frequencies and their amplitudes. In the used displaying method the frequencies are specified & fixed on a logarithmic base from 0Hz to 22KHz, corresponding to our ear's working. After this the Amplitudes are represented as bar graphs.
For Fourier transformation the FFT (Fast Fourier Transform) algorithm is used in almost every implementation, because it's fast enough. The Bass.dll & Bass.WASAPI.dll libraries have built in methods for FFT transformation.
You can read more About the Fourier Transform in this wikipedia article.
Modifications and Improvements
The problem with the original hardware design is that it's meant to be a prototype, therefore It's not a project to make during the weekend, If you would like
to build it, then additional work is required, like designing a PCB. Designing a PCB can be frustrating and hard if you’re doing it for the first time. To overcome this problem and to make the assembly easier I designed a PCB and Circuit diagram for it.
But that's not the only improvement. Originally I used a pair of MAX7221 constant current LED drivers, which are nice, but to get decent resolution it would require at least 8 of them, and wiring them would be a pain. Fortunately you can by HT1632C based LED displays on e-bay for a couple of bucks. The HT163C is also a constant current LED driver, but it's specifically designed for LED matrices, so one chip can drive 8x32 pixels, which is nice. Additionally it uses serial, SPI like transmission, so only 5 wires are required for the 8x32 pixel LED array. To get a decent vertical resolution I used two displays, so the final display matrix is 16 pixels in height, and 32 pixels in width.
Fortunately there's an Arduino library for the HT163C, so it's not needed to reinvent the wheel. During the software's development I found that the
library's provided routines are slow for drawing the spectrum data, so I modified the library with new methods that allow direct modification of the display buffer. The modified Library code is of course included in the release.
Another modification is that the project uses an Arduino Nano instead of an Uno. The Nano has the same microcontroller as the Uno, but it's smaller in size, and it uses a mini USB connector instead of an USB-B. Also, it can be purchased on e-bay for a couple of bucks.
When I was finished with the new hardware prototype I found it a bit boring, so I made it a bit more interesting. A 16x32 display holds many possibilities,
and I had a thermistor and an RTC (Real Time Clock) board, that I haven't used in a while, so I built them into the final design, so when the device is powered, but not used as an Audio Spectrum display shows you the current time & temperature.
The RTC is a MAX DS1307 board, which also can be purchased on ebay. The Thermistor is just a temperature dependent resistor, that's wired like a voltage divider, so it produces different voltages for different temperatures. Accessing & using the DS1037 isn't difficult, because it also has very good Arduino library that can be found here. (note: All required libaries are included in the code, you don't need to download them sperately)
The Board Design
The Board and the Schematics were created sing Eagle. Eagle PCB is currently one of the following Industry leading PCB design software’s, and the original Arduino boards were designed with eagle. The Board and the Schematics are released under the terms of Creative Commons Attribution-Share Alike 4.0 International license.
In layman's terms this means that you can do whatever you want with the design as long as you give credit for the Original Design.
Unfortunately I'm not an expert in PCB design, so my friend & colleague Zsolt Molnár helped in designing the board. One of the design specifications was that it needed to be made & assembled at home.
A lot of Open Hardware designs lack this feature by using SMD components. Soldering SMD components can be really hard for beginners & they require special tools. This board only uses Though hole components and a one sided PCB, that can be etched at home. Tutorials about Home PCB etching or milling can be found at various sites. In the Points of interest section I mention a few. But I warn you that it's not that easy as it sounds. It requires a lot of practice to master this skill :)
Alternatively you can order the PCB from a local PCB manufacturer using the provided files.
Code & Communication
The Code is divided into two parts. A microcontroller program and a PC software. The PC software is based on the implementation presented in the previous article, but it has been reworked.
The first major difference is that the spectrum bars have been removed to reduce the CPU requirements. The previous program used WPF progress bars, and it produced a 100% load on a single core. In a future version I might add a display based on a WritableBitmap.
The Second major difference is in the communication, which is packed based, instead of counting received bytes.
This is required, because the display supports various modes, like, spectrum, inverted spectrum, levels mode & Time configuration.
Each message is 34 bytes. The first byte determines the display mode, then comes 33 bytes data and a closing byte with a hexadecimal value of 0xFF.
The Arduino code is divided in three files & at the moment it's a bit messy, because of the global variables, but as soon as I have more time I will clean it up.
The code can be found at github, more specificaly at the https://github.com/webmaster442/BassPlayer repository. This is the repository of my work in progress music player. It also uses the Bass.dll components, therfore the player and the Spectrum analyzer share a part of their codebase. The Player has some nice features, but it has some issues, because I haven't had the time to fix them all.
Video demo
Here's a video demonstration that I made a few months ago when I was developing the prototype. It shows all of the modes, except the Inverted spectrum, because it was added last week.
Parts list:
-
DS1307 RTC board - 1 piece
[Ebay link]
-
HT1632 Display modules - 2 pieces
[Ebay link]
-
Arduino Nano
[Ebay link] or [Amazon link]
-
10K 0.3W resistors - 3 pieces
-
10K Thermistor - 1 piece
-
16V, 4700µF capacitor - 1 piece
-
Wago PCB terminal blocks type: W237-102 - 5 pieces
-
10K or 100K Potentiometer - 1 piece (used for controlling the diplay brightness)
Points of Interest
History
- 2015-07-21: Initial release