ESP32 Spectrum Analyzer Taps Into Both Cores

We probably don’t need to tell the average Hackaday reader that the ESP32 is a powerful and extremely flexible microcontroller. We’ve seen some incredible projects using this affordable chip over the last few years, and by the looks of it, the best is yet to come. That’s because it always takes some time before the community can really figure out how to get the most out of a piece of hardware.

Take for example the Bluetooth audio player that [squix] was recently working on. Getting the music going was no problem with the esp32-a2dp library, but when he wanted to add some visualizations the audio quality took a serious hit. Realizing that his Fast Fourier transform (FFT) code was eating up too much processor power, it seemed like a great time for him to explore using the ESP32’s second core.

[squix] had avoided poking around with the dual-core nature of the ESP32 in the past, believing that the second core was busy handling the WiFi communication. But by using the FreeRTOS queue system, he wrote some code that collects audio data with one core and runs the actual FFT magic on the other. By balancing the workload like this, he’s able to drive the array of 64 WS2812B LEDs on the front of the Icon64 seen in the video after the break.

Even if you’re not terribly interested in running your own microcontroller disco, this project may be just the example you’ve been waiting for to help get your mind wrapped around multitasking on the ESP32. If you want to master a device with this many tricks up its sleeve, you’ll need all the help you can get.

14 thoughts on “ESP32 Spectrum Analyzer Taps Into Both Cores

      1. Thank you, I wasn’t aware of the Goertzel algorithm. I was also wondering if sequentially low/high pass filters might accomplish the same but couldn’t find any description for that. FFT is the one hammer I know;-)

  1. If a processor running at 160mhz is not able to run your fft algorithm then there is something seriously wrong with that algorithm. A 16 bit uc running at 20mhz runs fft fine at 100hz update rate on the audio spectrum range.

    Regardless, its a good experience for how to fire up the second core.

        1. A2DP can transport a Mp3 or even AAC stream. Decoding time depends on the bitrate. I could get the ESP8266 working reliably only with 96kbit/s mono mp3. I totally buy that a more intensive AAC stream at possibly even higher bitrate keeps one core of tje ESP32 completely busy.

    1. Not all machine languages are created equal (by far). If my info is correct, the ESP instruction set takes a lot more instructions to do the same things a more normal processor does in few. I also heard there is quite a bit of fooling around with moving things between very slow flash and the operating ram to make the ram look larger. All hidden by the tools, but still there.

    2. I have an unidentified board from something marked as FFT/Micro Board. It has an 80c88 and a 12Mhz crystal, but I was assuming that was halved to 6Mhz. It has some fast ADCs and analog signal conditioning, so I assume it’s actually for Fourier Transforms and not some other FFT. However, it would have been running machine code from ROM, no OS in the way.

    3. Back in the day I had a demo on the Amiga (IFT-Scope) that ran a realtime (50/60Hz) full-screen FFT on either a playing MOD file or sampled audio from a standard parallel port sampler – a standard A1200 is 14MHz / 2Mb RAM including video RAM.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.