When I moved to my new place in the beautiful canton of Valais – I did not re-activate my old Turntable and Amplifier and just left them in a corner.
Today I decided to reactivate my devices again but to my disappointment I could hear only some scratching sounds form my loudspeakers when I turned the different controls.
I took my Technics SU-Z2 amplifier apart, cleaned it from the dust and applied plenty of Contact Spray to the dials and switches and I am very happy: it’s working again!
My old Amplifier is cool, but I also wanted to have some modern functionality as well like
– Streaming Music from the Internet
– Streaming over Bluetooth from my Mobile Phone
DAC Hardware
The ESP32 is a cheap choice to build a simple Music Player because it supports Bluetooth and WIFI out of the box together with I2S communication. So I ordered a Pcm5102 Dac Decoder I2S Player Assembled Board from China.
I did not want to wait for the DAC device to arrive and fortunately we can also use the built in DAC of the ESP32 to generate the sound.
Web Radio Software
If you have a ESP32-LyraT board available you can use the esp-adf framework which provides an impressive set of functionality.
The easiest way to get a working solution if you have a regular ESP32 is to use one of the following projects
– https://github.com/karawin/Ka-Radio32
– https://github.com/Edzelf/ESP32-Radio
– https://github.com/MrBuddyCasino/ESP32_MP3_Decoder
Ka-Radio32
To keep things simple, I decided to install the Ka-Radio32 because it already comes with the binaries and does not need any build.
So I just downloaded the binaries and flashed them with
git cline https://github.com/karawin/Ka-Radio32.git
cd Ka-Radio32/binaries
esptool.py \
--chip esp32 --port /dev/cu.SLAB_USBtoUART --baud 460800 --before default_reset \
--after hard_reset write_flash -u --flash_mode dio \
--flash_freq 40m --flash_size detect \
0x1000 bootloader.bin \
0x10000 KaRadio32.bin \
0x8000 partitions.bin
Then I Connected my MacBook to the new SSID WifiKaRadio to perform your initial configuration which was available on http:// 192.168.4.1.
The cool thing is that you can configure the application via the Web GUI to use the internal DAC from the ESP32. I added a Streaming URL: e.g. http://23.92.61.218:9002/ und connected the DAC pins G26/G27 and GND with the AUX input of my Amplifier w/o additional hardware.
I confirm that this is working together with my Technics SU-Z2!
Building my Own Solution
Now it was time to write some code for my own solution which should provide the following functionality:
– Compatible with Arduino IDE
– Internet Radio Streaming
– Streaming via Bluetooth
I decided to use the following Audio library which makes the solution very easy:
Here is an example Sketch which streams a MP3 from a radio URL using the interal DAC of the ESP32:
#include "AudioFileSourceICYStream.h"
#include "AudioGeneratorMP3.h"
#include "AudioOutputI2SNoDAC.h"
#include "WiFi.h"
// Enter your WiFi setup here:
const char *SSID = "mySSID";
const char *PASSWORD = "pwd";
// Randomly picked URL
const char *URL = "http://strm112.1.fm/blues_mobile_mp3";
AudioGenerator *audio;
AudioFileSourceHTTPStream *file;
AudioOutputI2S *out;
void setup() {
Serial.begin(115200);
delay(1000);
WiFi.disconnect();
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PASSWORD);
// Try to connect to Wifi forever
while (WiFi.status() != WL_CONNECTED) {
Serial.println("...Connecting to WiFi");
delay(1000);
}
Serial.println("Connected");
audioLogger = &Serial;
file = new AudioFileSourceICYStream(URL);
file->SetReconnect(5, 0);
out = new AudioOutputI2S(0, 1); // (0,1) is using the internal DAC
audio = new AudioGeneratorMP3();
audio->begin(file, out);
}
void loop() {
if (audio->isRunning()) {
audio->loop();
}
}
This was pretty simple!.
Im my next blog I will show how to stream bluetooth e.g. from a Mobile Phone to the ESP32 using the Arduino IDE…
ps.
In the meantime I have developed with my own Audio Library, so check out the related MP3 Streaming Player Blog
3 Comments
Massimo · 26. September 2021 at 17:37
Hi, Phil
Thanks to your code I can listen an internet radio with the board LoLin32 Lite
Just with the internal DAC and an amplifier pam8403 the audio is good.
I would like listen the BBC World Service
http://stream.live.vc.bbcmedia.co.uk/BBC_WORLD_SERVICE
But there is a lot of noise.
Maybe the streaming is not mp3? Do you know where to find the correct link for streaming this bbc radio?
Thanks 🙂
pschatzmann · 27. September 2021 at 11:15
You can try https://stream.live.vc.bbcmedia.co.uk/bbc_world_service
To find streaming URL I recommend the https://api.radio-browser.info/ project: e.g. https://de1.api.radio-browser.info/xml/stations/bycountrycodeexact/gb gives all Radio stations in GB
Juan C Galvez · 18. December 2020 at 16:05
Hi Phil.
Just a correction. DAC pins are G25 and G26 instead of G26 and G27.