Fast Audio Spectrum Analyzer
by emdee401 in Circuits > Microcontrollers
1446 Views, 25 Favorites, 0 Comments
Fast Audio Spectrum Analyzer
This design is nothing if not amazing! Imagine 3500 Colored LEDS dancing around to the music at a very high refresh rate. All controlled by a single $2 micro controller that is fed music using a Bluetooth connection.
Best of all it's open source so anyone can build it!
- Bluetooth audio connection
- driving 3584 pixelleds using 14 serial connections, simultaniously
- I2S audio output
- 120 FPS
- background animation
- Cartoon characters on display
Did I mention that it is really fast? 120 frames per second...So that means the microcontroller will drive 3584 leds in 8.3 mSeconds. And each frame will show new actual frequency data of the incoming signal.
As a bonus it will also show an animated background while a few cartoon characters make their appearance on screen.
Enough bragging... lets start building!
Supplies
1 pcs EPS32 DEVKIT
14 pcs LED panel 16 x 16 leds
1 pcs power supply I Used MeanWell S-25-5 Output 5V / 5A
1 pcs PCB ( more on that later)
some sockets, headers and wires
14 pcs fuse 1AT
1 pcs I2S audio board CJMCU-5102
If you want to hear audio, you will also have to connect a set of (amplified) speakers
Understanding the Electronics
Looking at the PCB , the one thing that will get your attention is the many fuses; 14 in total! Each fuse has a value of 1At. So theoretically, this unit could draw a current of up to 14A. However, this is not the case. First of all, the coding of the EPs32 is designed to limit the maximum current that is send to each led panel. However, in case a short circuit occurs on a output, this fuse will kick in. the maximum current of each led has to stay under 1/256 A = 3.9mA.
The microcontroller connects to 14 led panels and each panel has 256 leds. This brings the total number of leds to 3584. That are a lot of leds to be driven sequentially. To safe time ( and because of a technical limitation of the leds) each panel uses it's own ESP32 Pin and software driver. Essentially, 14 panels are driven simultaniously. This method makes driving these LED panels a fast operation. Fast enough to get a refresh rate of the total led display ( 14 panels) of 120 frames per second! How amazing is that!
The hardware also included some extra options but not all are in use at the moment. Because of the complex FFT algorytm and used buffers, the interval RAM of the ESP32 is almost overflowing....Let's just say, we put it to good use :-). So as soon as I manage to finetune the code to free up more interval RAM, more functions will be added.
At the moment the pushbutton SW1 is in use the change displayed paterns while a potmeter is used to set the brightness of the panel.
Audio is connected using the onboard bluetooth interface that comes with the EPS32. Simply stream your music over bluetooth. Because we also want to listen to the music when we display it, a I2S audio board is added that can be connected to your amplified speakers.
That's the electronics in a nutshell.
Downloads
Preparing the PCB
Without PCB
You can build this setup without the use of the designed pcb by using a wired breadboard or a breadboard PCB. Although possible, because of the many wires that might not be the best way to go. I did do this for my first prototype but I designed a complete PCB because it's more reliable and al the led panels draw up a lot of current that could heat up your breadboard.
Using the designed PCB
There are a few ways to get your hands on a pcb for this project.
First and best option ( cheapest) is to buy it in my Tindie store. Most components are already assembled.
Buy PCB from Tindie Store <-- click the link to buy
Second option it to order a PCB at PCBway.com. PCBway sponsored the pcb prototype for this project.
They offer great PCB service and more. Here is the link:
https://www.pcbway.com/project/shareproject/Fast_Audio_Spectrum_Analyzer_dd08de94.html
I will include all information in this instructable for you to complete the pcb, no matter what option you choose.
Step 1: separate the user interface pcb from the main pcb.
When you get your hands on a pcb, the first thing you need to do is to seperate the main pcb from the user interface. You can discard any side strips that were part of the production process.
Step 2: assemble all the basic components( skip this step if you puchased the pre-assembled PCB from my webshop)
The basis components you need to add in case you buy a bare pcb are listed in the attachment.
Step 3: assemble remaining components
At this point you will add the remaining components to complete the PCB.
- 14x fuse of 1At TR5 I used Farnell 9516131
- 1x ESP32 Devkit 1 I buy those at Aliexpress
- 1x I2s Audio board I buy those at Aliexpress make sure you have the right version as there are several. I bought CJMCU-5102 compare photo's to find the right version.
Take note that you should install the ESP32 and audio board using pin headers and sockets.
Now your PCB is ready to be programmed but we have to do some wiring first!
Downloads
Assembling the Led Display
Choose the position of each led panel carefully
What I mean by that is that you should be aware of what wire is comming from wich panel. This is important so it will be easy to identify the positions later. If you mixed up led panel positions, the total led display will be mixed up. If this happens, it is easy to fix by simply swopping led panel connectors. However, it might be a puzzle with 14 panels.
Stitching the panels
I used a sticky spray ( glue in a spray can) to glue all the panels onto a wooden board. I finalized the edges of the board with a small wooden boards to make it look like a framed painting. The idea is to pore some epoxy substance over the displays to make it all look as a finished display. Because the panel is still in a state of development, I did not to so yet.
make sure you attach wires to each panel before you glue those down to the board. I recommend to use 3 wires for each led panel to be connected to the pcb. So that's 42 wires in total. I drilled holes in the board at the exact place that wires are attached to the led panel. That way I can always access those if needed. We will not by daisy chaining any panels so there is no need for you to connected wires to the output pins of the display.
Connecting the Wires
Connecting the Led panels to the right output lines
Make sure that you know which panel is where in your layout. The drawing shows a frontal view as if you are looking into the panel. The P numbers are the reference designators on the pcb. All you need to do is wire up each panel to the right connector. pay attention to the pin layout of the connectors.
- Pin 1: +5V
- Pin 2: data line
- Pin 3: Gnd
Need help to identify pin 1? --> check out the silkscreen marking on the pcb for each connector; the arrow < indicates pin 1.( it's not vissible on the assembled pcb but you can check the pcb image that is included.
Connecting the user interface to the main pcb
you need to connect U3 on the main PCB to U2 of the user interface. this is a 1:1 connection. Meaning that pin 1 of U2 is connected to pin 1 of U3, pin 2 to pin 2..and so on...
Connecting the power supply
Before you start hooking up your build to an USB port of a computer, you have to make sure the power supply is connected and switch on! NEVER operate this device on usb power only. With this number of leds, even the lowest brightness will quickly fry the diode on your ESP32....trust me...I have a bunch of those in a box labeled: "Fried by impatience"
So you need to hook up a 5V power supply that can handle a few amps, to your pcb before operating the thing. Connect the gnd and +5V wires of your power supply to connector CN1 of the PCB
There is an extra pin configured to act as a power enable pin. It can be found on connector P1 and it can be used if you decide to use a PC power supply that has an enable pin. Check out the schematic for details.
Preparing the Arduino IDE for Your ESP32
Using the ESP32 boards with your Arduino IDE software
Before you can compile your sketch and upload it to your ESP32 board, you need to install the ESP32 library if you haven't already.
You can do so by clicking the board manager in the menu of the software. Look for ESP32 by espressif systems and install version 1.06. Other versions might work but I didn't test!
If the ESP32 by espressif isn't listed when you search using the board manager, you need to add the following line to the Preferences from the File menu:
https://dl.espressif.com/dl/package_esp32_index.json
add it in the files for "Additional Boards Manager URLs"
Board Configuration
Setting up the correct memory mapping for your DEVKIT ESP32 board.
When you first install the ESP32 board libary, when selecting the DOIT ESP32 DEVKIT board, the memory mapping is set to default. In this default mode the onboard memory is devided into chucks. Each chunck has a purpose and a fixed size and we need to change that. If you don't, the code cannot compile because the compiler will tell you it to big because the esp doen't have enough memory.
We need to change the memory map by selecting another configuration in the menu. The way to do this depends on the version of the ESP32 library that you are using. so you have two options:
- simply select it in the menu
- If this option is not available, you need to change the board configuration file.
I will show you both possibilities.
Selecting the right board config from the menu.
In the arduino IDE menu select:
Tools-->Partition Scheme-->No OTA (Large APP)
If you select default, uppon compiling you will get an error that you there isn't enough memory.So make sure to select the No OTA option before you compile.
Changing the board configuration file
If you don't see a Partition Scheme item in the tools menu, you will have to update your boards.txt file.
Find the file in your arduino15 installation directory. Default that something like this:
C:\Users\chord\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6
so it's in your AppData local directory under ARduino15 etc...
look for boards.txt, open it and find the section for DOIT ESP32 DEVKIT V1
find the line: esp32doit-devkit-v1.menu.FlashFreq.40.build.flash_freq=40m
add the following lines and save the file:
esp32doit-devkit-v1.menu.PartitionScheme.default=Default
esp32doit-devkit-v1.menu.PartitionScheme.default.build.partitions=default
esp32doit-devkit-v1.menu.PartitionScheme.minimal=Minimal (2MB FLASH)
esp32doit-devkit-v1.menu.PartitionScheme.minimal.build.partitions=minimal
esp32doit-devkit-v1.menu.PartitionScheme.no_ota=No OTA (Large APP)
esp32doit-devkit-v1.menu.PartitionScheme.no_ota.build.partitions=no_ota
esp32doit-devkit-v1.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
esp32doit-devkit-v1.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA)
esp32doit-devkit-v1.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
esp32doit-devkit-v1.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
esp32doit-devkit-v1.menu.PartitionScheme.fatflash=16M Fat
esp32doit-devkit-v1.menu.PartitionScheme.fatflash.build.partitions=ffat
close the arduino IDe and reopen it before you do a new compile. Again, make sure you select No OTA (Large APP) from the menu before you compile
Compiling and Uploading the Sketch
Opening the sketch.
You can download the latest sketch here:
https://github.com/donnersm/BluetoothAnalyzer
Open the sketch if you haven't already. The sketch is ready to be compiled for a working setup simular to the one I build. If you planning to change stuff like used IO lines, you need might have to change some config parameters before you compile.
Compiling the sketch
Make sure you select the right option from the menu before compiling:
Tools-->Partition Scheme-->No OTA (Large APP) ( see previous section for more info)
Connect your ESP32 board using your USB cable and press upload.( compile and upload)
In the first release, only one potmeter has a function. The other two will be implemented at a later time.
Just Skip the Arduino IDE Part and Program Over USB
Ok, so you read this much already...High time for a small reward. If you are planning to make a copy of my design we can speed up some things.. No hassle with libraries, version, arduino compiling etc.
I made it easy for you as you can simply program the code into the arduino by hooking it up to your USB and by using the webbrowser.
There is however 1 condition. This only works if you are building the same hardware in regards to ESP32 pinout and usage. If you changed it or if you made modifications to the original code, this will not work for you.
Wanne try? Connect your ESP32 DOIT devkit 1 to your usb port and use Chome or Edge to visit:
donnersm.github.io/BluetoothAnalyzer/flash.html
Simply follow the online instructions and you are good to go.
Again, this will not work with firefox.
Operating the Unit
Operating this most impressive Audio Analyzer.
- Hook up a set of (amplified) speakers or simular to listen to audio.
- I used a set of amplified computer speakers to start with.
- make connection over bluetooth
- Just find and connect to the analyzer named Lightnsound
- Start playing your audio file on your device
- use the pushbutton to switch background on and off and of to change colors
- Use the potmeter to set the brightness of the panel
- If to dimm, some of the characters might disappear.
DEMO
Take a look at this great finished product
Special Thank You
I put great effort in the PCB design and I did some minor modifications to the software.
However, I cannot take all of the credits because I had some help from:
Antti Yliniemi who wrote the original code and allowed me to use and tune it.
https://github.com/yliniemi/bluetooth-spectrum-analyzer
https://www.youtube.com/@acidangel162
Antti used a Led Driver written by Yves Bazin