streaming music from an Android phone via ESP32 to AUX IN

megabite
Posts: 18
Joined: Wed Nov 22, 2017 12:56 pm

streaming music from an Android phone via ESP32 to AUX IN

Postby megabite » Tue Jul 17, 2018 4:17 pm

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

User avatar
krzychb
Posts: 232
Joined: Sat Oct 01, 2016 9:05 am
Contact:

Re: streaming music from an Android phone via ESP32 to AUX IN

Postby krzychb » Tue Jul 17, 2018 4:27 pm

Hi megabite,
Checkout pipeline_bt_sink example from Espressif Audio Development Framework (ESP-ADF).

megabite
Posts: 18
Joined: Wed Nov 22, 2017 12:56 pm

Re: streaming music from an Android phone via ESP32 to AUX IN

Postby megabite » Tue Jul 17, 2018 8:35 pm

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?

User avatar
krzychb
Posts: 232
Joined: Sat Oct 01, 2016 9:05 am
Contact:

Re: streaming music from an Android phone via ESP32 to AUX IN

Postby krzychb » Tue Jul 17, 2018 10:00 pm

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.

megabite
Posts: 18
Joined: Wed Nov 22, 2017 12:56 pm

Re: streaming music from an Android phone via ESP32 to AUX IN

Postby megabite » Wed Jul 18, 2018 11:38 am

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?

megabite
Posts: 18
Joined: Wed Nov 22, 2017 12:56 pm

Re: streaming music from an Android phone via ESP32 to AUX IN

Postby megabite » Fri Jul 20, 2018 11:17 am

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.

BuddyCasino
Posts: 262
Joined: Sun Jun 19, 2016 12:00 am

Re: streaming music from an Android phone via ESP32 to AUX IN

Postby BuddyCasino » Fri Jul 20, 2018 11:38 am

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

megabite
Posts: 18
Joined: Wed Nov 22, 2017 12:56 pm

Re: streaming music from an Android phone via ESP32 to AUX IN

Postby megabite » Sat Jul 21, 2018 2:06 pm

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:

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

What do I do to fix this?

User avatar
krzychb
Posts: 232
Joined: Sat Oct 01, 2016 9:05 am
Contact:

Re: streaming music from an Android phone via ESP32 to AUX IN

Postby krzychb » Sat Jul 21, 2018 9:33 pm

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.

megabite
Posts: 18
Joined: Wed Nov 22, 2017 12:56 pm

Re: streaming music from an Android phone via ESP32 to AUX IN

Postby megabite » Sat Jul 21, 2018 11:54 pm

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?

Who is online

Users browsing this forum: Adham Aboud, MSN [Bot] and 19 guests