Bluetooth for sound streaming and data transfer

Andy Belov

Well-known member
Need bluetooth for sound streaming and data transfer

I have this crazy idea of having a bluetooth module connected to Teensy 4.0, which can stream sound from the Audio Board to bluetooth headphones or a sound system, and at the same time be connected to an Android phone, for controlling Teensy from it.
I found out that the protocol for sound streaming is called A2DP and I got a BK8000 chip on a breakout board for that.
The problem is that there is not much documented about all this. Can't find any good Arduino examples with sound streaming, forget about 2 devices connected at the same time.

Will appreciate any experience shared in this area.

Again, I want it to be connected to an Android phone for control functions, and to a wireless headphones.
The bluetooth will live on Teensy 4.0.
 
Last edited:
Interesting idea. I googled around a bit, trying to see how feasible the idea is, here is what I found:

* There's an Arduino library for using the AT command set to control the BK8000L, no audio streaming over the serial port as far as I see. There's a datasheet in this repository too (https://github.com/tomaskovacik/kic...atasheet/F-6188_BK8000L/BK8000L_datasheet.pdf). Library here: https://github.com/tomaskovacik/BK8000L

* "Connected to 2 devices at the same time" is not possible for these embedded modules as far as I know, from my limited bluetooth tinkering. If the BK8000L supported multiple profiles (serial port profile, SPP, for example) you could use the A2DP profile and the SPP profile at the same time *on the same connected device*.

With a different bluetooth module, one with I2S input for example, you could stream audio directly from the Teensy. But this BK8000L module is more meant for streaming analog audio. You'll need a codec or DAC connected to the Teensy in order to get audio into it.
 
Last edited:
I think that the Tympan Rev D will do this.

The Tympan is aimed at open source hearing aid algorithms, but in reality, it is a general purpose digital audio platform. Full Disclosure: I'm part of the Tympan team.

At its heart, it's a custom-made Teensy 3.6 (we buy the required bootloader chip from PJRC) that includes:

* Audio codec: TI AIC3206
* Bluetooth Module: BC127, which includes BT audio capability (see Sparkfun's tutorial here)

(Note, the Tympan Rev C uses an older BT module that does not do BT audio...so be sure to consider only the Tympan Rev D)

The Tympan definitely does all the audio processing that you want (though at Teensy 3.6 speeds, not Teensy 4.0). The hardware does indeed connect the audio input/output to the bluetooth module so that you can use the Bluetooth audio streaming profile(s) for fun hacks.

Whether the BC127 module supports the specific mode of audio streaming that you want...well, that depends upon the capabilities of the Sparkfun library (or your ability to roll your own code to exploit the BC127 hardware).

Myself, I have successfully used the Tympan as a BT Audio interface for receiving audio from my phone for playback on my home stereo. In this case, the BT module is an audio "sink", as it merely receives the BT audio data and doesn't try to send any BT audio data. Still, I think that this success is a good omen for your project.

The trick for your project is that you want to be a BT "source" to pump audio out via BT to a 3rd-party BT speaker. I've never tried that myself. To see if you can do it, you'll have to look at the Sparkfun BC127 library to see if that might work for you. The Sparkfun tutorial does have an example where the module is configured as a source, but note that their demo has the BC127 merely communicating to another BC127 module (one as source, one as sink)...and not to a 3rd party BT speaker. Therefore, YMMV when using your own setup.

Chip
 
Last edited:
Or, instead of Tympan, you could consider buying the BC127 module that's available from Sparkfun and wiring it to your Teensy 4.0 + Audio shield. Or you could consider any other BT Audio capable BT module.

In the Tympan circuit, we simply connected the analog audio input/output of the audio codec to the analog audio output/input of the BT module. There's nothing special there. You can control the BT module via one of the Teensy's serial ports. It's reasonably straight forward.


Whatever hardware route you choose, I find that the hardest part get getting BT audio to work is if, heaven forbid, you need to set up the module in some way that the Sparkfun library doesn't already support. It's not a hard thing to do; it's just very annoying, if you're inexperienced.

If you find that you need to manually change one of the module's many internal settings, you'll need to jump out of the module's "DATA" mode and into its "COMMAND" mode. Usually it's done over a serial link (such as from the Teensy). All the commands (and replies) are simply text that you send (or get) via the serial link. While this sounds easy, it's very sensitive to certain formatting issues. For example, you have to use just the right <CR> or <LF> without inadvertently sending both. If you send both, it never responds the want that you think it should. If you don't know this, you can spend a lot of time thinking that your hardware is broken. Grr.

Similarly, if you're trying to write a script to automate this text-based interaction (and so that you can better control which <CR> or <LF> you're sending), be aware that you gotta time the sending of the "$$$" and the final "$" just right so that your script sorta looks like a human typing it. If you know this, you can easily accomodate it with a little trial-and-error use of delay() statements. But, if you didn't know that the timing of character(s) is important, you could end up banging your head against the wall for a long time. So annoying. Remember, knowledge is power!

Chip
 
Interesting idea. I googled around a bit, trying to see how feasible the idea is, here is what I found:

* There's an Arduino library for using the AT command set to control the BK8000L, no audio streaming over the serial port as far as I see. There's a datasheet in this repository too (https://github.com/tomaskovacik/kic...atasheet/F-6188_BK8000L/BK8000L_datasheet.pdf). Library here: https://github.com/tomaskovacik/BK8000L

* "Connected to 2 devices at the same time" is not possible for these embedded modules as far as I know, from my limited bluetooth tinkering. If the BK8000L supported multiple profiles (serial port profile, SPP, for example) you could use the A2DP profile and the SPP profile at the same time *on the same connected device*.

With a different bluetooth module, one with I2S input for example, you could stream audio directly from the Teensy. But this BK8000L module is more meant for streaming analog audio. You'll need a codec or DAC connected to the Teensy in order to get audio into it.

This is exactly what I need. I'm making a guitar "pedal" and want it to work as a wireless guitar transmitter, so that you can run around like young Eddie Van Halen. I'll use the Audio Board line out for that. Just need to find out how to connect all this together.
 
Thanks, Chip. Very valuable information. I think I'll do just that and add yet another simple bluetooth just for talking to the phone.
 
This is exactly what I need. I'm making a guitar "pedal" and what it to work as a wireless guitar transmitter, so that you can run around like young Eddie Van Halen. I'll use the Audio Board line out for that. Just need to find out how to connect all this together.

Ah... well, to be honest, I probably would not use Bluetooth then, for one reason: latency. Plain old A2DP has like 200-300 milliseconds of latency which pretty much ruins it IMHO.

You can get a low latency firmware for the BC127 modules that Chip referred to, which I think takes it down to 40 milliseconds of latency... but you have to find and flash the BC127 with that special firmware. Eventually I would like to give that a try and see how annoying of a process it is. It might not be that bad, but who knows.
 
A2DP has like 200-300 milliseconds of latency

Had no idea about this. Good to know. All I'm looking for is to save time digging around how to connect all this. I'm going to try it all anyway and see if it's good enough for an amature guitar player who wants a wireless and programmable guitar effect module.
And I want it to be very affordable. Don't really spend $25 just on a bluetooth module. The BK8000 goes for $1.34 on Alibaba: https://www.aliexpress.com/item/327..._expid=d6385144-2991-4da3-8409-f4ff6dc8a724-0
I'll keep you posted.

Thanks for all help.
 
Well, I don't want to discourage you too much, but it sounds like a big part of your project will include Android development... and let's just say, I write software for a living and I won't touch Android. It is just awful to develop for.

iPhone on the other hand, I have no idea.
 
Ok. That concludes my research here. I didn't know about the high latency of A2DP. I guess it's good for playing musing, but not for something requiring latency below 10 msec.
I'm not giving up on that, just don't want to spend too much time right now. My first "pedal" version will have a basic bluetooth for the phone control and an old good phone plug.
Thanks again, everybody.
If I find something new about all this, I'll share it with you.
 
I'm reading this (and other threads), dismayed at the lack of simple examples/tutorials on hooking up BT to a teensy in order to stream/transmit audio to a third party receiver. I built my own BT speakers (w/o an 1/8" input jack) so I know how to open them to add a jack, but it strikes me as very sad that such a simple use case for BT with a microprocessor would have no documentation that I can find on the internet!! That, plus I have to hack into my speakers and then use a 25' cord when I'd rather use radio. :(

Latency is not an issue for me.
 
Back
Top