In this project I want to implement an internet radio with the ESP32 and a different audio library than in the solution with the ESP8266. This program shows how to use the ESP32-audioI2S library from "Wolle" aka "schreibfaul" to build a internet radio It is an adaptation of his example program Simple_WiFi_Radio.
ESP32 MAX98357A --------------. .-----------------. GPIO_NUM_25 o --> o LRC | GPIO_NUM_26 o --> o BCLK | GPIO_NUM_27 o --> o DIN | | o Gain | Spkr | o SD | _/| GND o --> o GND o---| | 5V o --> o Vin (5V) o---|_ | --------------´ `-----------------´ \| Same wiring with UDA1334A
In contrast to the internet radio with the ESP8266, the serial interface is available for inputs and outputs with the ESP32. Therefore I abandoned the simple one-button UI and designed a more comfortable user interface as a CLI menu.
The program is based on Wolle schreibfauls library ESP32-audioI2S and is an adaption of his example code Simple_WiFi_Radio. Check out his examples to leran more.
The program excerpt shows only the setup() routine, the audio initialization and the main loop, in which the MP3 stream of the radio station is played and the menu is handled.
/** * Initialize the audio subsystem */ void initAudio() { audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT); audio.setVolume(currentVolume); // 0...21 audio.connecttohost(currentUrl); } void setup() { Serial.begin(115200); initWiFi(); initAudio(); } void loop() { static uint32_t msPrevious = millis(); static bool done = false; audio.loop(); // show menu once after all status and info messages have been displayed if (!done && waitIsOver(msPrevious, 5000)) { done = true; showMenu(); } // handle keystrokes and the menu if (Serial.available()) doMenu(); }
Interested? Please download the entire program code. The zip-file contains the complete PlatformIO project.
My programming environment is not the native Arduino™ IDE but PlatformIO™ on top of Microsoft's Visual Studio Code™. This combination offers many advantages and allows a much better structuring of the code into several modules especially when we adopt The Object Oriented way.