How to transmit sound to Bluetooth speakers?

Using an Uno and a SparkFun Musical Instrument Shield, this program rings a bell every two seconds:

/*
 
 This code works with the VS1053 Breakout Board and controls the VS1053 in what is called Real Time MIDI mode. 
 
 https://www.sparkfun.com/products/10587

 5V : VS1053 VCC
 GND : VS1053 GND
 D3 (SoftSerial TX) : VS1053 RX
 D4 : VS1053 RESET
 
 Attach a headphone breakout board to the VS1053:
 VS1053 LEFT : TSH
 VS1053 RIGHT : RSH
 VS1053 GBUF : GND
 
 When in the drum bank (0x78), there are not different instruments, only different notes.
 To play the different sounds, select an instrument # like 5, then play notes 27 to 87.
 
 To play "Sticks" (31):
 talkMIDI(0xB0, 0, 0x78); //Bank select: drums
 talkMIDI(0xC0, 5, 0); //Set instrument number
 //Play note on channel 1 (0x90), some note value (note), middle velocity (60):
 noteOn(0, 31, 60);
 
 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

byte note = 0; //The MIDI note value to be played
byte resetMIDI = 4; //Tied to VS1053 Reset line
byte ledPin = 13; //MIDI traffic inidicator
int  instrument = 0;


void setup()
{
  Serial.begin(57600);

  //Setup soft serial for MIDI control
  mySerial.begin(31250);

  //Reset the VS1053
  pinMode(resetMIDI, OUTPUT);
  digitalWrite(resetMIDI, LOW);
  delay(100);
  digitalWrite(resetMIDI, HIGH);
  delay(100);
  talkMIDI(0xB0, 0x07, 120); //0xB0 is channel message, set channel volume to near max (127)
}

void loop() 
{

  talkMIDI(0xB0, 0, 0x00); //Default bank GM1
  talkMIDI(0xC0, 98, 0);   //Set instrument number. 0xC0 is a 1 data byte command
  
      //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
      noteOn(0, 98, 60);
      delay(50);

      //Turn off the note with a given off/release velocity
      noteOff(0, 98, 15000);

  delay(2000);

}



//Send a MIDI note-on message.  Like pressing a piano key
//channel ranges from 0-15
void noteOn(byte channel, byte note, byte attack_velocity) {
  talkMIDI( (0x90 | channel), note, attack_velocity);
}

//Send a MIDI note-off message.  Like releasing a piano key
void noteOff(byte channel, byte note, byte release_velocity) {
  talkMIDI( (0x80 | channel), note, release_velocity);
}

//Plays a MIDI note. Doesn't check to see that cmd is greater than 127, or that data values are less than 127
void talkMIDI(byte cmd, byte data1, byte data2) {
  digitalWrite(ledPin, HIGH);
  mySerial.write(cmd);
  mySerial.write(data1);

  //Some commands only have one data byte. All cmds less than 0xBn have 2 data bytes 
  //(sort of: http://253.ccarh.org/handout/midiprotocol/)
  if( (cmd & 0xF0) <= 0xB0)
    mySerial.write(data2);

  digitalWrite(ledPin, LOW);
}

I have an CC2540 CC2541 AT-09 Serial Wireless Module BLE 4.0 Bluetooth Module Compatible HM-10

It seems the pinout only requires ground, Vcc and Rx (to Arduino's Tx). Right?

I've been looking up tutorials and it seems to be mainly about controlling things like LEDs. Is there a way just to connect it to the MIDI pin 3 and have it transmit the audio? Or is it a lot more complicated? Guidance would be appreciated.

All I want to do is to have that bell sound emit from some Bluetooth speakers.

That module just provides a serial data link - not an audio link.

MIDI is just a digital control link - it doesn't pass any audio

You would need a Bluetooth audio transmitter, and plug it into the 3.5mm (?) socket on the shield.

Is there a development or evaluation board that does this? I also have a DX-BT27-A Bluetooth Module.

Probably.

But a commercial device is likely cheaper & simpler; eg,

https://www.amazon.co.uk/Bluetooth-Transmitter-Receiver-Jsdoin-Headphones/dp/B08FT7HJW7

I pushed to use a commercial/consumer device. I'll try again, but I'm told I should be creating something on the circuit level.

Plenty to choose from:

DX-BT27-A

I'll try connecting that to the (-) and either R or L:

I'm not really sure what to do after that.

No - that's another serial port module.

Whoever told you that either doesn't understand what's involved, or seems to be over-estimating your skillset?

No, you need a logic level shifter between the 5V Arduino Uno TX and the 3.3V RXD input.

But that radio module does not send data in the form of Bluetooth audio signals. If you wish to avoid years of study, your only option is to buy a commercial Bluetooth audio transmitter.

1 Like

You can strip the housing from what-ever-thing-you-buy and, connect the buttons to an arduino and be happy :slight_smile:

Eventually will want a production model so this won't do.

How about this one? Seem like it would work.

Have you studied the documentation for that module, and if so, what led you to select it?

It is intended for soldering to a custom PCB, that carries out other functions in addition to all the interfacing.

Application circuit fits. I searched "Bluetooth Transmitter Module A2DP"

Build it and let us know how it goes.

Would be better to have something to go off of.

Is there some way to visually see the difference between Bluetooth audio data compared to... not Bluetooth audio data?

"A2DP" is the Bluetooth Audio Profile:

This is a "Classic" Bluetooth Profile - not BLE.

A BLE module will not have A2DP.

Ya, so I tried to get an ESP32 to do this but was not successful. That's why I got the other Bluetooth modules.

This was the library: ESP32-A2DP. I tried this example sketch: bt_music_sender_write

When plugged into my computer, the ESP32 can be seen and connected to. There is no audio, and when I remove the device from my computer and plug in the ESP32 to a wall outlet, the device displays again. So it is transmitting Bluetooth.

Should I use a different example from the library? I tried pressing the enable and boot button. (On other libraries I needed to do that in order for it to work.) Any ideas on how to hear to the audio file?

Also, I needed to reduce the piano16bit.h file to 33333 lines of code for it to fit in memory.