.wav
audio files.Lab concepts abstracted away by libraries:
Synopsis: A button is pressed to toggle the frequency selection, or held (>1s) to switch between playing audio from Bluetooth or the SD card. While in frequency selection mode, the ADC is continuously running and reading values from a voltage divider containing a potentiometer (knob), while the LCD is displaying the current selected value (read from the ADC on interrupts) and the transmitter is playing on the previous established frequency. While not selecting, the ADC is turned off in order to save energy, and the transmitter is playing on the established frequency (selected when the mode changes), while the LCD displays it. While playing audio from the SD card, the power supply is cut from the Bluetooth receiver, and wav
files are played, in order, from the disk. A press of the button skips to the next song.
On setup, several registers are configured:
Then, using library calls, LCD and FM transmitter are set up. A default transmitting Frequency of 90.0Hz is set, and the region is EUROPE.
Two interrupt handlers are set up, INT0 and ADC:
The main execution loop converts the ADC raw value into a transmitting frequency (between 87.5MHz and 108MHz) and displays it on the screen if in selection mode.
The initial plan was to use Adafruit Si4713 as an FM transmitter. It was a circuit with more advanced capabilities (such as broadcasting text info about the radio “station”), and more (>0) documentation on the Internet. The order came late from China, and, to make matters worse, the chip was broken (wasn't even responding to a I2C address sweep). I couldn't find any replacement of the same model.
The replacement, KT0803K has almost no documentation online, the retailer, ElecHouse, doesn't even list the product on their website and the only provided demo code didn't work with an ESP32 (the initial microcontroller choice). More so, it accepts input only as 3.5mm jack, so I had to buy a compatible Bluetooth receiver (MH-M28).
Finally, SD card readers were very hard to find, as all customary sellers have gone out of stock. I managed to get one, but a new challenge arose: how to connect a GPIO pad audio output to a jack input? The answer was the Bluetooth receiver: it has both jack and pads output (connected to eachother), so I could drive the audio signal from the pads straight to the jack.