I was fishing around for another app that can make better use of the Teensy as well as the ESP32 functionality so that they both have to pull their own weight a little more.
I ended up working with ChatGPT to create an MP3 internet radio player. It was my first time trying to use ChatGPT for a program development that I otherwise wouldn’t be able to do on my own, though I have played with Gemini a bit.
It was more complicated than I expected to get clean playback but seems well sorted now. It implements the main mechanics of streaming and playing MP3 files controlled via a touch interface on the LCD.
It makes use of the ESP32 for fetching the music files off the internet and streaming the MP3 content to the Teensy over the 4Mbps serial link. It uses SomaFM Radio which is a free streaming service. The channel selections are arbitrary and can easily be changed in the ESP32 code.
The Teensy then uses
@PaulStoffregen MP3 library to decode the incoming MP3 stream and uses the Audio library and the audio adapter to play it. It also handles the display and touch as well as controls the ESP32 over the serial link.
Since the MP3 stream is unidirectional and only using the ESP32 >> Teensy part of the serial link, the Teensy uses the Teensy >> ESP32 part of the serial link for XON/XOFF flow control and sending requests for channel switching, so it still only requires 2 pins total between the microcontrollers which I thought was pretty clever.
The MP3 decode library can be downloaded from here:
https://github.com/PaulStoffregen/Teensy-MP3
Paul’s library had a couple of possible bugs that got fixed in the process by AI (cue
@Mcu32 
) so the
play_mp3queue.cpp library file should be replaced with the one that is attached to be safe.
The ESP32_InternetRadio_V6_1 will need you to add your network name and password as usual.
I set it up initially on the Mini Platform since it didn’t require any wiring to make all the needed connections and I didn’t want to worry about debugging wiring issues along with everything else.
Of course, it will also work on the Teensy/ESP32 stacks with the usual minor serial link changes and hooking up an audio adapter and optionally a display. The code is configured for the ST7796 as used on the Mini, but it will start playing without a display attached.
It was pretty difficult to get the audio to play cleanly, so there are lots of serial print statements and some code snippets that were used to debug the setup. Same for the STATS screen. They were left in as they provide some interesting/useful info for future work.
If you try it, when programming the ESP32 be sure to keep the
USB CDC on boot: disabled or if you enable it to see the ESP32 serial output, be sure to keep the serial monitor window open. If you close it, the ESP32 will stop until you open it again. I believe the ESP32 TX buffer overflows once the PC stops consuming the serial stream and when the window is opened back up, it resets the ESP32 and it's happy again. I haven’t figured out how to prevent that yet, but it's not a big issue if you are aware of it.