Building the BlueBox, an ESP32 Powered Bluetooth Speaker
What could possibly be more enjoyable than chilling, listening to your favourite music being played on a well-engineered Bluetooth speaker? Well for most people, spending countless hours, way too much money and pulling out your own hair in frustration just to get to hear some slightly better than sh*t sounding music from your very own Bluetooth speaker doesn’t sound enjoyable. This is the story of how I did exactly that.
Where It All Started
For a while now I have been interested in building my own Bluetooth speaker. I have always had a keen interest in audio-related circuits, specifically amplifiers. This interest most likely stems from a final year engineering practical I worked on. We were all tasked with building a multi-stage audio amplifier that could deliver at least 1W of power, designed from first principles and we had to design our own PCB. Boy did I have fun with that practical! In the end, I designed a not-too-bad sound amplifier that indeed delivered 1W of power while only consuming ~3W of power (resistors are supposed to glow right?). I think my highlight of the practical was watching the faces of other students as they powered on their amplifiers for the first time. Watching the expression on their faces go from that of excitement to dismay as the traces on their PCB literally vaporise was priceless. We were given a class on trace width-versus-current rating and why it is important. Some people clearly skipped this class and ended up learning the hard way.
Since then I worked on a few electronics projects with varying degrees of success but nothing I could write home about. After moving abroad and spending 2 years in lockdown I found myself without any tools and longing to work on something electronics-related. I took a final look through the box of goodies that I had brought over with me and found that I still had an ESP32, 2 breadboards, and an I2S DAC chip that I had soldered to a DIP adapter a few years back. That night I ordered a breadboard jumper kit, a SparkFun LCD module, and an amplifier chip.
The Hills Are Alive With the Sound of… Wtf Is That Sound?
The moment the delivery person rang my doorbell I ran to the door like a little child excited for ice-cream. I was so excited to get to the components and start tinkering that I took the afternoon off from work. Well, I was still working from home at the time so putting my mouse on an analogue wristwatch to keep my Teams status active was pretty much like taking off. I set out installing the ESP-IDF SDK on my desktop and wiring everything up so that the circuit would be ready for when I flash the glorious code that will run my Bluetooth speaker to the ESP32. I had been tinkering for around 10 hours when my wife came into my office to let me know it was 3 am and suggested it was time for bed. You know in Iron Man when Tony Stark starts working in his lab and the scene is a montage of his coding and tinkering with the scene ending with a working prototype of some cool new gadget? Well… this was not that! After 10 solid hours of effort, I had a mess of wires and code that didn’t do anything useful. The LCD screen wouldn’t display anything other than some random pattern and the amplifier literally output no sound whatsoever, not even static.
The days that followed all followed the same pattern. “Take off” a little early and tinker into the late evening or early morning with each day edging closer to a working prototype. I eventually got the LCD to display some text after figuring out that I had been initializing the display all wrong. It took me almost a week to figure out that the I2S chip I had soldered to the adapter all those years back wasn’t soldered on properly. The lack of a soldering iron proved to be a little challenging but I found out that heating a butter knife on the gas stove gets it hot enough to melt solder. I also learnt that this usually leads to angry stares from the wife. All in all, it took me around 2 weeks of late-night tinkering to get a somewhat functional circuit on breadboard that I could connect to using Bluetooth and stream some music.
I should come right out and say that the sounds that came out of this first version were not something you would voluntarily listen to for extended periods. While, yes, it was the music that I was streaming that came out of the speakers, it didn’t sound very good. Turns out, breadboard is not very good for high-speed digital applications like I2S and SPI. The fast-switching digital signals capacitively couple to anything and everything. I could quite literally hear the text change on the LCD screen.
Psst… Hey Kid, Want Some PCB?
The idea that I was edging closer to something that I could actually put into an enclosure and call my very own Bluetooth speaker got me so excited. The hours of late night tinkering had left me on a high. Over the previous 2 weeks, I had learnt a multitude of new things, from how I2S and SPI work to implementing an RTOS eventing system written in C. Best of all, I had something I could hold in my hands and proudly say that I had made this. This feeling drove me to take it one step further and attempt putting the whole thing on a PCB because you know, why not? Following the same pattern as before, I dove into tinkering and learning as much as I could about PCB design. I transferred the circuit design into a schematic on CircuitMaker and added some extra circuitry. Before long I had what looked to me like the most beautiful PCB design ever! For those of you who actually design PCBs, I am sorry for what you are about to see.
After figuring out what the hell Gerber files are and how to export them, I sent the design off to be manufactured. It was going to take 2–3 weeks for the PCB and stencil to arrive back so this gave me plenty of time to order the required components from Mouser, order a hot-air rework station and get some tools. I was going to be soldering some small SMD components and needed tweezers. The logical thing to do after spending plenty of money to make sure I ended up with quality tools was to order a set of tweezers that looked too well-priced to be true. The lesson I learned was that cheap tweezers are often plastic tweezers and plastic tweezers melt when used with a hot-air gun. Not to worry though, my wife’s eyebrow tweezers turned out to be metal and worked like a charm.
When the PCB finally arrived I had all the components and tools ready to start. Over the course of a whole evening, I painstakingly placed each little component and used the hot-air gun to reflow. I was definitely not elegant in this process at all. Having never worked with SMD components, yet alone a rework station, I ended up needing to do a lot of reworking. I even managed to pull the pads off the PCB while moving one of the chips. This resulted in me having to desolder everything and start on a new board, luckily I ordered 10.
It Lives!
After many hours of soldering, reworking and at least 47kg of flux, I had a fully populated PCB. I cannot describe the excitement I felt when I plugged in the USB-C cable, the blue LED lit up, and my desktop pinged to indicate that it had detected a new device! This was confirmation that the power circuitry and USB-to-Serial converter chip was working correctly. I rushed to open the ESP-IDF monitor tool to see if it could detect the ESP32 and communicate correctly. Moments later the bootloader text flashed across my terminal indicating that serial communications were working and the ESP32 was able to boot! All I needed to do now was to flash the ESP32 and everything would work… right? After a few attempts at flashing the ESP32, I figured out that I had routed something wrong on the PCB and that it couldn’t automatically get into download-mode as expected. Luckily, a well-timed manoeuvre of shorting one of the pins to ground puts the ESP32 into download-mode so I was eventually able to flash it. I flashed a modified version of the original firmware, with the main difference being making sure it could work with the changed LCD driver and IO mappings. I was pleasantly surprised that it did not sound nearly as bad as I expected it would. With the right enclosure, I am sure that it could sound good enough to use around the house.
What all does it have?
- ESP32-WROOM
- 16-bit stereo output @ 44.1kHz via I2S DAC
- Dual channel, 3W class D amplifier
- 240x240 LCD display
- 6 push button inputs
- Li-Po Charging & Power Circuity, i.e. can charge or run off a Li-Po
- USB-C with 5V/1A support
What all does it do?
- UI for displaying time, song details, and status
- Bluetooth audio streaming
- WiFi for syncing with NTP (doesn’t work too well with Bluetooth enabled due to RAM constraints)
- Exposes configuration/status via BLE
- 5-band graphic equalizer
It’s a Never-Ending Story but That’s Okay
As I would take a few more days to figure out, this was not the end of the road for my project turned obsession. Since flashing the first version of firmware to the PCB I have spent countless hours tinkering, learning, and improving. Whenever I get the chance I try to optimize the firmware or squeeze just one more feature into the code. But for now, I leave you with what the UI looks like at the time of writing.
I am hoping to find time to clean up the code just enough to share on GitHub and will update the article with the link when I do.