Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 10 of 10

Thread: Bluetooth for sound streaming and data transfer

  1. #1
    Member
    Join Date
    Mar 2019
    Location
    Hoboken, New Jersey, USA
    Posts
    77

    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 by Andy Belov; 10-13-2019 at 03:42 AM.

  2. #2
    Senior Member
    Join Date
    Feb 2015
    Posts
    104
    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/kica..._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 by wcalvert; 10-14-2019 at 05:02 PM.

  3. #3
    Senior Member
    Join Date
    Oct 2015
    Location
    Vermont, USA
    Posts
    195
    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 by chipaudette; 10-14-2019 at 07:32 PM.

  4. #4
    Senior Member
    Join Date
    Oct 2015
    Location
    Vermont, USA
    Posts
    195
    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

  5. #5
    Member
    Join Date
    Mar 2019
    Location
    Hoboken, New Jersey, USA
    Posts
    77
    Quote Originally Posted by wcalvert View Post
    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/kica..._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.

  6. #6
    Member
    Join Date
    Mar 2019
    Location
    Hoboken, New Jersey, USA
    Posts
    77
    Thanks, Chip. Very valuable information. I think I'll do just that and add yet another simple bluetooth just for talking to the phone.

  7. #7
    Senior Member
    Join Date
    Feb 2015
    Posts
    104
    Quote Originally Posted by Andy Belov View Post
    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.

  8. #8
    Member
    Join Date
    Mar 2019
    Location
    Hoboken, New Jersey, USA
    Posts
    77
    Quote Originally Posted by wcalvert View Post
    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/3278...f4ff6dc8a724-0
    I'll keep you posted.

    Thanks for all help.

  9. #9
    Senior Member
    Join Date
    Feb 2015
    Posts
    104
    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.

  10. #10
    Member
    Join Date
    Mar 2019
    Location
    Hoboken, New Jersey, USA
    Posts
    77
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •