streaming music from an Android phone via ESP32 to AUX IN

User avatar
ESP_krzychb
Posts: 394
Joined: Sat Oct 01, 2016 9:05 am
Contact:

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

Postby ESP_krzychb » Sun Jul 22, 2018 1:48 pm

I am glad you made it working!

megabite wrote: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.
I would try i2s_stop / i2s_start
megabite wrote: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?
The code is quite simple. Check blink example.

After enabling the GPIO as an output in main() I would then switch it to high or low within bt_av_hdl_a2d_evt() callback.

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 » Sun Jul 22, 2018 7:39 pm

Thank you. I will try out that code as soon as I get home tonight.

One more thing - is there a way I can get the ESP32 to reconnect automatically to my phone when the A2DP connection is lost? And to connect to my phone on its own without me having to actively start the connection in my phone's BT settings?

Just to give you an idea what this is all for, I have a radio in my car that's slightly older and can do Bluetooth phone calls via my Android phone, but not BT music streaming. It has an AUX IN socket for a headphone jack-type connector, so I thought I would build a circuit that serves as a Bluetooth adaptor for that AUX IN connection.

So it would be ideal if my phone would just connect itself to the ESP32 whenever I get in my car and turn the key, just like my car radio connects itself to my phone automatically.


EDIT:


So I've played around with i2s_stop(I2S_NUM_0) and i2s_start(I2S_NUM_0), but I kind of can't work out where in my code I would have to put those two commands. I tried putting i2s_stop() at the end of app_main right before the return command, but it had no effect, I still have that annoying constant tone when the Bluetooth connection is interrupted.

ronyeapen
Posts: 1
Joined: Tue Jan 15, 2019 12:12 pm

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

Postby ronyeapen » Tue Jan 15, 2019 12:33 pm

Hello all,
I am new to ESP32 programming. I read your comments on utilising the a2dp_sink example on the ESP32 IDF examples. I was able to successfully flash the program onto my ESP-WROOM32 board and I used the internal DAC.

But, the sound quality is terrible. There is a constant hissing/buzzing noise as the audio content is being streamed. I have tried the same code on two different ESP-WROOM32 boards, and I get the same problem.

Did anyone else have this issue? Is there something I need to do to fix this problem? Does anyone have any ideas on how I can filter the noise out? Thanks for the help in advance.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Wed Jan 16, 2019 8:16 am

If any, don't use the internal DAC; apart from it being tied to the 3.3V power supply (which probably is noisy on a random devboard fed by a long USB cable), it's also only 8-bit. If you want sound quality, use an external I2S codec fed by a clean power supply.

ristomatti
Posts: 1
Joined: Mon Sep 30, 2019 9:34 pm

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

Postby ristomatti » Mon Sep 30, 2019 10:07 pm

I ran across this thread while searching for example code on transmitting analog audio from an ESP32 (preferably with minimum external components, audio quality is secondary). I did not find what I was looking for but got the idea the OP was looking a relatively easy way to solve a problem that already has ready made solutions which fill most of the requirements and can be bought cheaper than an ESP32 devboard.

Just search for "bluetooth receiver module" on AliExpress/Ebay and you can find boards with Bluetooth, microusb power input and a 3.5mm jack connector for $1-2. Although it's not the most exciting solution, I'd rather spend my energy thinking of other projects to use an ESP32, unless of course the main purpose is to learn how to do something like this.

voxtas
Posts: 1
Joined: Fri May 07, 2021 7:54 am

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

Postby voxtas » Fri May 14, 2021 5:55 pm

Hello is this user "megabite" is still using this forum? I've bachelors work with the same principle as his. Trying to stream audio from phone via bluetooth to cars aux in, and I desperatly need help. Thanks.

ns1668
Posts: 50
Joined: Tue Mar 16, 2021 2:00 pm

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

Postby ns1668 » Wed May 19, 2021 3:14 pm

Check your private messages.

SirBiggle
Posts: 1
Joined: Thu Jun 03, 2021 4:43 pm

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

Postby SirBiggle » Thu Jun 03, 2021 4:58 pm

voxtas wrote:
Fri May 14, 2021 5:55 pm
Hello is this user "megabite" is still using this forum? I've bachelors work with the same principle as his. Trying to stream audio from phone via bluetooth to cars aux in, and I desperatly need help. Thanks.
I have just done something like that. The ESP32 has 2 DAC Converters onboard. The output is on GPIO25 and GPIO26. I have connected them directly with cinch cables to my home amplifier. Basically it should be the same for your car. Additionally to 25 and 26 of course you need GND. That is the analog part to the radio.

The bluetooth part uses the library ESP32-A2DP. you find that on github. https://github.com/pschatzmann/ESP32-A2DP.
The sample given with the lib works for me.

#include "BluetoothA2DPSink.h"

BluetoothA2DPSink a2dp_sink;

void setup()
{
static const i2s_config_t i2s_config =
{
.mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN),
.sample_rate = 44100, // corrected by info from bluetooth
.bits_per_sample = (i2s_bits_per_sample_t) 16, /* the DAC module will only take the 8bits from MSB */
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = I2S_COMM_FORMAT_I2S_MSB,
.intr_alloc_flags = 0, // default interrupt priority
.dma_buf_count = 8,
.dma_buf_len = 64,
.use_apll = false
};

a2dp_sink.set_i2s_config(i2s_config);
a2dp_sink.start("VSX828-SAT/CBL");
}

void loop()
{
}

Who is online

Users browsing this forum: No registered users and 129 guests