Introduction: ATtiny85 Spectrum Analyzer With Fix_FFT
ATtiny85 spectrum analyzer for music to RGB LED with FFT
Excited with the new discovery of FHT library. Yours truly definitely want to give it a try on an ATtiny85. After hours massaging the code to make it to work, sadly, none come to functionality (yet). According to this site http://forum.dev.arduino.cc/index.php?topic=26175... ATtiny has as small footprint ""ATtiny85 on-board, 8K of flash, 512 byte of SRAM, 512 bytes of EEPROM"" hence can't work with FHT. However, yours truly beg to differ. He noticed that some code in the FHT.cpp can't compile due to reduced instruction sets on ATtiny85. More about that after some workaround can be found.
Nonetheless, yours truly really want to have some fun with sound to light on Arduino's poor cousin, the ATtiny85. Life is so boring without some LEDs' goodness. Just come to recall that, years ago yours truly have done a DIY spectrum analyzer using a modified FFT that use 8bits only, runs off an arduino and LOL shield http://shin-ajaran.blogspot.sg/2011/07/diy-arduino-vu-spectrum-analyzer.html. This modified 8 bit FFT came for a forum discussion http://forum.arduino.cc/index.php?topic=38153.0 . Reusing the same library but has to be modified to for Arduino IDE v1.06 and later by replacing with in the fix_FFT library.
Now first, enjoy the end product of this make
1. Electrect and amplifier circuit; reuse the electret amplifier mentioned in an earlier post http://shin-ajaran.blogspot.sg/2014/11/arduino-spectrum-analyzer-for-music-to.html;
2. ATTiny85 breakout board; reuse the MitG PCB which is a breakout board for ATtiny85 made earlier http://shin-ajaran.blogspot.sg/2014/01/setting-up-hardware-for-using-arduino.html
3. RGB LED; a common anode is used
4. Diffuser; a 3D printed LED holder and Fibre Optic cable is used
Step 1: Assemble the Circuitry
Assemble an electret amplifier
This make assumes an LM386 as the audio amplifier http://www.ti.com/lit/ds/symlink/lm386.pdf for the electret microphone is available.There are many manufacturers of LM386, one of the is TI. Refer to the link above for spec sheet and then scroll down to the diagram "amplifier with minimum parts". If you need help on making a LM386 based audio amplifier, this instructable https://www.instructables.com/id/Know-Your-IC-LM386/ is helpful on getting started.
Data out from the electret amplifier is connected to an analog pin of the ATtiny85. In the case of this bespoke ATtiny85 breakout board: the MitG PCB, it is pin A2; vcc and gnd also connected to the break out board
Assemble a ATtiny85 breakout board of your choice
ATtiny85 breakout board can be assembled on a breadboard, or a custom made PCB of your choice
Step 2: Program the ATtiny85
use an ISP of your choice to program the ATtiny85
An example of ATtiny85 ISP shield can be found from this link
The operational details of programming an ATtiny85 can be found from this link
Now the goodies!!
Source code for the ATtiny85 spectrum analyzer is on my gist
Step 3: Question to Ponder About Mapping of Audio Frequency to Colour Spectrum
The questions come begging: How to map audio frequency to the colour spectrum??
Drawing inspiration from yours truly secondary school physics: human voice ranges from 85Hz to 255Hz; male voice is at lower frequency bands 85Hz-180Hz whereas female voice is at higher frequency bands 165Hz to 255Hz. As for human hearing, it is from 20Hz to 20K Hz. Furthermore, each musical instruments has it's own frequency range, and as we know, music composes of a variety of frequency stemming for human voice and/or musical instruments. Hence, the choice of strategy will be reflected in the colour observed while a piece of music is played.
Strategy: mapping audio frequency to colour spectrum
1. Mapping of human hearing e.g 20Hz to 20K Hz to 16777216 of possible RGB colours
1a. Mapping of whole audio frequency bands to 6777216 of possible RGB colours.
2. Choosing 3 channels deliberately; one each from the low, mid, and high frequency bands as observed using the spectrum visualizer mentioned earlier. The 3 channels of low, mid, and high corresponds to Blue, Green, and Red; with the intensity of the colour corresponds to the amplitude of that chosen channel. The output of RGB LED will then be "blended".
3. Similar to 2, but instead of choosing the channels deliberately, this algo is to group frequency bands into larger low, mid, and high frequency bands; within each of this group of larger frequency bands , the amplitude that is used to turn on the corresponding LED is the result of averaging all the amplitude from the frequency bands.
4. Similar to 2,3, but first apply a Low Pass Filter at the frequency bands.
5. LED activated by predefined threshold on frequency band6. ........
It seems to yours truly, finding an ideal mapping of music genre to colour is going to be an never ending story.
Step 4: Make Awesome Stuff!
Have fun massaging the code into what you have visualize for sound to light.
Speaking of which, how about a christmas tree that changes the colour of the light according to a christmas song?!
Post a link to your instructable too!
Participated in the
Make it Glow!