For 6.115 (Microcomputer Project Laboratory), I was tasked with using the Cypress PSoC-059 (Programmable System on Chip) and a $20 budget to propose, design, and develop a project. My project was a Bluetooth speaker and visualizer capable of streaming music from Bluetooth and displaying a music spectrum analyzer.
Goal: A phone sends an audio signal to the PSoC-059 through Bluetooth. The PSoC generates the audio through an on-board DAC (digital-to-analog converter) and sends it to an op-amp for amplification and pass-through to a 3.5mm audio jack. Simultaneously, the PSoC will compute a Fast Fourier Transform (FFT) on a buffer of the signal to generate a spectrum analyzer.

Parts:
I used the HC-05 to receive Bluetooth data and stream it to the PSoC through serial UART. I also used an ILI 9341 TFT LCD display to present the spectrum analyzer using SPI (Serial Peripherial Interface). For audio, I used an LM386 to amplify the PSoC's generated output.
The Process
Getting Started:
To easily debug, I began by trying to play wired audio through an FTDI USB to Serial converter. I wrote a Python program to transmit a given wave file.
Why Wave?
Easiest way to play music would be to use WAV files since they are a simple array of waveform data points ranging from 0 to 255. Although this is generally not a great idea due to bandwidth, it sufficed for this project. Mp3 file decoding would have been too complex for the PSoC and my time frame, while a dedicated decoder would have been out of the budget range.
Insert picture of wav file format
Debugging:
I began by playing a hard-coded 1 second 6 kHz 8-bit mono audio clip on repeat and verifying that the sound could be played and accurately resembled the audio file. This meant that I would have to transmit (8 bits)*(6000 points/second)*(1 channel) = 48,000 bits every second.
Insert picture of audacity and oscilloscope
To play longer than this, I needed to stream music data. Using the USB-Serial connector previously mentioned, I was able to feed the music data. At 57,600 baud, 1.2 seconds of music data was streaming every second. To ensure the correct music tempo was preserved, I used a linked list queue to store the incoming data and dequeued at the baud rate according to an internal clock.
Once the queue approached overflow, the PSoC would send a "STOP" signal to the computer. After enough data was dequeued, the PSoC would send a "START" signal to continue receiving data.
LED Visuals:
To display an LED synchronized with the music, I first tried to determine the LED brightness based on the audio amplitude. However, I found an LED that synchronized with beat drops to give a better effect, so I set the LED brightness based on volume deltas.
Fast Fourier Transform:
To determine the audio spectrum of the