I2S input from second ESP32 (Karadio32) to send audio to a BT Speaker #281
-
Hi, I have built several Karadio32 Internet radios which use the ESP32. Partly also with I2S DAC or I2S Amp (MAX98xx). Now I need a way to stream the I2S output signal of the ESP32 (Karadio32) via Bluetooth to my BT speaker at the Tereasse. I think this project would fit if I donate a second ESP32 that only takes care of the BT audio transmission. Is this possible and can someone give me some guidance on how to configure this? Best regards, Jochen |
Beta Was this translation helpful? Give feedback.
Replies: 20 comments 3 replies
-
I mean a example for BT source with I2S input signals, not BT sink with I2S output. |
Beta Was this translation helpful? Give feedback.
-
Here is an example which is part of the arduino-audio-tools: https://github.com/pschatzmann/arduino-audio-tools/tree/main/examples/examples-basic-api/base-i2s-a2dp However I think the challenge might be to get a stable I2S between 2 ESP32. I have never tried this myself, but if you look in the project there are some discussions and issues of failed attempts. My gut feeling is, that it might be easier to use a simple Serial connection and maybe transmit the encoded data. |
Beta Was this translation helpful? Give feedback.
-
I tried the example sending a sine wave to the BT speaker, that worked fine. The I2S in the BT example is designed to read an i2S microphone, i.e. the master (BT ESP) sends the clock to the slave (microphone). |
Beta Was this translation helpful? Give feedback.
-
Just use |
Beta Was this translation helpful? Give feedback.
-
sorry for asking but where exactly can i find the setting "cfg.is_master = xx;"?
Gesendet: Donnerstag, 11. August 2022 um 04:07 Uhr
Von: "Phil Schatzmann" ***@***.***>
An: "pschatzmann/ESP32-A2DP" ***@***.***>
Cc: "JocB1" ***@***.***>, "Author" ***@***.***>
Betreff: Re: [pschatzmann/ESP32-A2DP] I2S input from second ESP32 (Karadio32) to send audio to a BT Speaker (Discussion #281)
Just use
cfg.is_master = false;
This way the pin_bck and pin_ws will be used as input.
Note however that the ESP32 does not support the pin_mck as input!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Well, to the example that I have sent you 5 days ago. The default setting is cfg.is_master = true; so it has been omitted like many other settings as well. |
Beta Was this translation helpful? Give feedback.
-
OK,
I was in the wrong part...
Now I used your example and changed the settings:
...
// start i2s input with default configuration
Serial.println("starting I2S...");
auto cfg = i2s.defaultConfig(RX_MODE);
cfg.i2s_format = I2S_STD_FORMAT; // or try with I2S_LSB_FORMAT ---- ????
cfg.bits_per_sample = 16;
cfg.channels = 2;
cfg.sample_rate = 48000; // found out with logic analyzer
cfg.is_master = false;
i2s.begin(cfg);
// start the bluetooth
Serial.println("starting A2DP...");
a2dp_source.start("BT-WE", get_sound_data); // This speaker connects
//a2dp_source.start("JBL Flip 4", get_sound_data); // This speaker connects not - but this one is to be used later!
}
...
For finding out the sample rate I coud do some meassurements with a logic analyzer connected to the Karadio32 output (I2S setting, not MERUS setting:
![I2S_Karadio32] (https://user-images.githubusercontent.com/1819346/186661755-a9fbcd8b-1ad9-43d2-abdb-bb9c5e0e2fd4.png)
See the meassure markers on the right side:
Clock frequency: 1.56 MHz
Sample Rate: 47.98 kHz
The ESP32 connects to the BT speaker and the speaker signals this with a corresponding sound.
However, the sound from the Karadio32 is not transmitted. In the serial monitor you can see that the ESP restarts again and again (Guru Meditation).
Do you have any idea what else i can try?
|
Beta Was this translation helpful? Give feedback.
-
I suggest to take one step back: Did you manage to receive the I2S data and send it to CSVStream, so that you can check your I2S connection ? After the connections has started you can query the sample rate from A2DP. It should usually be 44100. |
Beta Was this translation helpful? Give feedback.
-
I tested now the I2S receiving with this sketch: streams-i2s-serial_16bit.ino This is the output, but I´m not sure if this is correct: ....
Do you mean with the "streams-generator-a2dp.ino" sketch to check only the A2DP connection? The incomeing I2S sample Rate I had meassured with 48kHz (Logic Analyzer) so must the sample rate to the BT Speker be the same or could it be different for Incoming I2S and outgoing A2DP? |
Beta Was this translation helpful? Give feedback.
-
This does not look like valid sound waves. Double check that the bits_per_sample are set up identical on both systems. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hmm, this still looks very noisy to me: The volume also looks very low. |
Beta Was this translation helpful? Give feedback.
-
I guess the reboots of the ESP32 are related to this part: // callback used by A2DP to provide the sound data - usually len is 128 2 channel int16 frames This is relatad to a microphone with special characteristics, but we have a source that provides 2 channels. How would that have to be look if the two channels are separate? |
Beta Was this translation helpful? Give feedback.
-
You just need to convert between frames and bytes
|
Beta Was this translation helpful? Give feedback.
-
Thanks, st:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
|
Beta Was this translation helpful? Give feedback.
-
You are right, I was mixing this up with the audio sink where we have this method: I am pretty sure that it needs to be 44100 and I used this in my examples, but I never tried with 48000. |
Beta Was this translation helpful? Give feedback.
-
Today I startet a new try: ESP32 #1: Example streams-generator-i2s (44.1 khz, 2 ch, 16bit - output clk 14 / ws 15 / data 22)
ESP32 #2: Base-I2S-A2DP (Input clock 14 / ws 15 / data 32): /**
#include "AudioTools.h" /**
BluetoothA2DPSource a2dp_source; // // callback used by A2DP to provide the sound data - usually len is 128 2 channel int16 frames // from Author for 2ch 16bit stereo (not a micro) // Arduino Setup // start i2s input with default configuration // start the bluetooth // Arduino loop - repeated processing The two ESP32´s are connected together with the same settings (2ch / 16bit / 44.1 kHz) -> Now we can assume that the sample rate is the same everywhere in the chain. The second ESP connects to the speaker, but there´s no sound.... PS: I use 2x ESP32 wrover - that should not be a problem, right? |
Beta Was this translation helpful? Give feedback.
-
Wrover should work just fine and the setup looks right to me as well. You can e.g. try to send the audio to your browser and double check what this gives. Just remove the filter from the example... |
Beta Was this translation helpful? Give feedback.
-
Hi, I cross-checked again and connected the I2S amplifier MAX98357 to the Sinus Generatur ESP. The sine wave comes out loud, clear and distinct. Noise can not be the problem: I guess that does not fit what with the ESP, which converts I2S to A2DP. (Perplexed) I would still have the possibility at the Karadio32 the sound over spdif output. Is there a code for SPDIF to A2DP? |
Beta Was this translation helpful? Give feedback.
-
Oh, delete everything that is related to the buffer and converter which is not needed! With this correction it should work! |
Beta Was this translation helpful? Give feedback.
Here is an example which is part of the arduino-audio-tools: https://github.com/pschatzmann/arduino-audio-tools/tree/main/examples/examples-basic-api/base-i2s-a2dp
However I think the challenge might be to get a stable I2S between 2 ESP32. I have never tried this myself, but if you look in the project there are some discussions and issues of failed attempts. My gut feeling is, that it might be easier to use a simple Serial connection and maybe transmit the encoded data.