streaming music from an Android phone via ESP32 to AUX IN
streaming music from an Android phone via ESP32 to AUX IN
Hello,
I've been trying to find information on how to use the ESP32 as a Bluetooth client and get it to play audio which it would receive from my Android phone via Bluetooth. I then want the ESP32 to output the audio from the phone so that I can connect the ESP32 to the AUX IN connector of my car radio. And I would like to play the audio on my Android phone using the standard, built-in Android audio player. I've seen exactly this implemented on OEM and aftermarket car radios, and I would like to recreate that functionality using an ESP32 on my car radio which does not support Bluetooth audio and only has AUX IN on a 3.5mm connector.
Are there any libraries in existence for this (preferably Arduino based), and what kind of additional hardware would I need to implement such a project? Would I need an I2S amplifier?
- megabite
I've been trying to find information on how to use the ESP32 as a Bluetooth client and get it to play audio which it would receive from my Android phone via Bluetooth. I then want the ESP32 to output the audio from the phone so that I can connect the ESP32 to the AUX IN connector of my car radio. And I would like to play the audio on my Android phone using the standard, built-in Android audio player. I've seen exactly this implemented on OEM and aftermarket car radios, and I would like to recreate that functionality using an ESP32 on my car radio which does not support Bluetooth audio and only has AUX IN on a 3.5mm connector.
Are there any libraries in existence for this (preferably Arduino based), and what kind of additional hardware would I need to implement such a project? Would I need an I2S amplifier?
- megabite
- ESP_krzychb
- Posts: 400
- Joined: Sat Oct 01, 2016 9:05 am
- Contact:
Re: streaming music from an Android phone via ESP32 to AUX IN
Hi megabite,
Checkout pipeline_bt_sink example from Espressif Audio Development Framework (ESP-ADF).
Checkout pipeline_bt_sink example from Espressif Audio Development Framework (ESP-ADF).
Re: streaming music from an Android phone via ESP32 to AUX IN
Very interesting, thank you. Do you happen to know if there is also an Arduino based implementation of this? I haven't really worked yet with espressif's own sdk environment.
Also, this seems to be for a LyraT board. I have an ESP32 WROOM dev board. Will it work on my WROOM regardless?
Also, this seems to be for a LyraT board. I have an ESP32 WROOM dev board. Will it work on my WROOM regardless?
- ESP_krzychb
- Posts: 400
- Joined: Sat Oct 01, 2016 9:05 am
- Contact:
Re: streaming music from an Android phone via ESP32 to AUX IN
An Arduino based implementation of this framework is not available.
It will work on ESP32-WROOM-32 after code modification to use internal DAC instead of codec chip, see README.md of play_mp3_dac what modification is required.
It will work on ESP32-WROOM-32 after code modification to use internal DAC instead of codec chip, see README.md of play_mp3_dac what modification is required.
Re: streaming music from an Android phone via ESP32 to AUX IN
I was going to use an external I2S decoder chip anyway, because for all I know (please do correct me if I am wrong), the WROOM dev board's onboard DACs cannot produce hi-fi stereo sound that would sound good on my Bose car stereo sound system.
How about this as a decoder breakout for the finished product?
https://www.adafruit.com/product/3678
At the moment, all I would have here to work, borrowed from another project, is a very similar 3W Adafruit I2S amp:
https://www.adafruit.com/product/3006
I take it that for development purposes, there would be no difference between these two, so I could use the 3W amp to develop my code while I would wait for the I2S headphone jack decoder to arrive in the mail?
How about this as a decoder breakout for the finished product?
https://www.adafruit.com/product/3678
At the moment, all I would have here to work, borrowed from another project, is a very similar 3W Adafruit I2S amp:
https://www.adafruit.com/product/3006
I take it that for development purposes, there would be no difference between these two, so I could use the 3W amp to develop my code while I would wait for the I2S headphone jack decoder to arrive in the mail?
Re: streaming music from an Android phone via ESP32 to AUX IN
Update:
I see that there is a code example in esp-idf called a2dp_sink which looks at first glance like it has what I need right out of the box:
https://github.com/espressif/esp-idf/tr ... /a2dp_sink
Being that I am only beginning to understand Bluetooth streaming at the programming level, my question again, will this enable me to stream music from my Android phone to the ESP32 with the built-in Android music player?
Also, I apologize for my lack of knowledge, but what is the best way to set up an IDE within which I can edit the above code example and upload it to my ESP32? So far, I have only worked with the Arduino IDE and Atmel Studio, and I'm not really sure how to set up a toolchain for ESP32-native code.
I see that there is a code example in esp-idf called a2dp_sink which looks at first glance like it has what I need right out of the box:
https://github.com/espressif/esp-idf/tr ... /a2dp_sink
Being that I am only beginning to understand Bluetooth streaming at the programming level, my question again, will this enable me to stream music from my Android phone to the ESP32 with the built-in Android music player?
Also, I apologize for my lack of knowledge, but what is the best way to set up an IDE within which I can edit the above code example and upload it to my ESP32? So far, I have only worked with the Arduino IDE and Atmel Studio, and I'm not really sure how to set up a toolchain for ESP32-native code.
-
- Posts: 263
- Joined: Sun Jun 19, 2016 12:00 am
Re: streaming music from an Android phone via ESP32 to AUX IN
This has a bluetooth mode out of the box, I'm having it hooked up to an amp right now: https://github.com/MrBuddyCasino/ESP32_MP3_Decoder
Re: streaming music from an Android phone via ESP32 to AUX IN
I think I've found a code example in the esp-idf that gives me pretty much what I want. It's the a2dp_sink example.
Unfortunately, I can't get it to compile. I've tried building it with eclipse, as well as with msys32. Both give me compile errors, and this is without having altered the code in any way.
Here's the error output from msys32:
What do I do to fix this?
Unfortunately, I can't get it to compile. I've tried building it with eclipse, as well as with msys32. Both give me compile errors, and this is without having altered the code in any way.
Here's the error output from msys32:
Code: Select all
C:/Users/Me/Desktop/workspace/a2dp_sink/main/main.c:128:9: error: implicit declaration of function 'esp_a2d_register_data_callback' [-Werror=implicit-function-declaration]
esp_a2d_register_data_callback(bt_app_a2d_data_cb);
^
cc1.exe: some warnings being treated as errors
make[1]: *** [/home/Me/esp/esp-idf/make/component_wrapper.mk:286: main.o] error 1
make: *** [C:/msys32/home/Me/esp/esp-idf/make/project.mk:468: component-main-build] error 2
- ESP_krzychb
- Posts: 400
- Joined: Sat Oct 01, 2016 9:05 am
- Contact:
Re: streaming music from an Android phone via ESP32 to AUX IN
I have pulled the latest esp-idf with msys32 and a2dp_sink example compiles correctly.
If not done already, try:
1. Updating ESP-IDF
2. In your 'a2dp_sink' example folder delete 'sdkconfig` and 'sdkconfig.old`
3. Run `make clean`
Finally run 'make menuconfig' and compile the application again.
If not done already, try:
1. Updating ESP-IDF
2. In your 'a2dp_sink' example folder delete 'sdkconfig` and 'sdkconfig.old`
3. Run `make clean`
Finally run 'make menuconfig' and compile the application again.
Re: streaming music from an Android phone via ESP32 to AUX IN
Perfect... it's working now.
One problem - if I suddenly disconnect my phone from the esp32, the esp32 gets stuck in a loop and plays a constant tone indefinitely. It's as if it's stuck outputting the final transmitted 16-bit word.
Can this be solved by uninstalling the I2S driver when the bluetooth connection is shut down?
I was thinking maybe put i2s_driver_uninstall() inside the bt_app_task_shut_down(void) in bt_app_core.c, but having tried that just now, it gave me an error. Then again, I am not quite sure what function arguments I would have to give i2s_driver_uninstall().
Also, I would like a pin on the esp32 to go HIGH when pairing is successful, because I want to use that pin to switch a relay.
The ESP32 will be part of a relay based audio input selector circuit. Not dissimilar to a home amplifier. When the esp32 is successfully paired to a bluetooth audio source, then I want the esp32 to switch the relay to the bluetooth line input, which will be coming from an I2S headphone breakout connected to the esp32. And if there is no live bluetooth connection, I want the input switched over to an alternate audio source which consists of an audio cable connector, so that I can alternatively connect my Android phone just by using its headphone socket.
Having only used the Arduino IDE so far, I am not quite sure how to switch a GPIO pin to high or low within this esp-idf example. What would that code look like?
One problem - if I suddenly disconnect my phone from the esp32, the esp32 gets stuck in a loop and plays a constant tone indefinitely. It's as if it's stuck outputting the final transmitted 16-bit word.
Can this be solved by uninstalling the I2S driver when the bluetooth connection is shut down?
I was thinking maybe put i2s_driver_uninstall() inside the bt_app_task_shut_down(void) in bt_app_core.c, but having tried that just now, it gave me an error. Then again, I am not quite sure what function arguments I would have to give i2s_driver_uninstall().
Also, I would like a pin on the esp32 to go HIGH when pairing is successful, because I want to use that pin to switch a relay.
The ESP32 will be part of a relay based audio input selector circuit. Not dissimilar to a home amplifier. When the esp32 is successfully paired to a bluetooth audio source, then I want the esp32 to switch the relay to the bluetooth line input, which will be coming from an I2S headphone breakout connected to the esp32. And if there is no live bluetooth connection, I want the input switched over to an alternate audio source which consists of an audio cable connector, so that I can alternatively connect my Android phone just by using its headphone socket.
Having only used the Arduino IDE so far, I am not quite sure how to switch a GPIO pin to high or low within this esp-idf example. What would that code look like?
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot] and 89 guests