Sending commands from custom made Bluetooth device to android phone to control music player

4

I have created a simple Bluetooth device using following components

  • HC05 module
  • Arduino Uno board (with re-programmable micro-controller)

I am wondering if it is possible to send commands from my BT device, as if these commands were sent from Bluetooth headset?

What I mean is:

  • we send 0x00000055 keycode - and the music pauses (KEYCODE_MEDIA_PLAY_PAUSE)
  • we send 0x00000058 - previous song starts playing (KEYCODE_MEDIA_PREVIOUS)
  • ...

Here is the full list of keycodes which android uses: http://developer.android.com/reference/android/view/KeyEvent.html

I can probably create a separate app, which will read incoming commands and simulate headset button presses, but that is not what I want. As far as I'm concerned - some of the headsets are plug-and-play, meaning that no additional apps must be installed on android device. Here is the code I am currently use to send commands to Android phone:

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

enum { LED_PIN = 6 };
enum LedState { LED_ON, LED_OFF, LED_BLINK };

LedState led_state;

void setup()
{
  led_state = LED_OFF;
  pinMode(LED_PIN, OUTPUT);

  pinMode(9, OUTPUT);
  digitalWrite(9, LOW);
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);  // HC-05 default speed in AT command more
}

const int COMMAND_MUSIC = 85;

void loop()
{
digitalWrite(LED_PIN, HIGH);
delay(100);
digitalWrite(LED_PIN, LOW);
delay(100);

delay(10000);

// trying to play or pause once in 10 seconds
BTSerial.write(0x00000055);
//BTSerial.print(0x00000055, HEX);

}

Both devices are paired but music player on my phone stays unaffected by these commands..Is it possible to control music player without creating a side app for "incoming commands from BT"?

bluetooth
arduino
headset
asked on Stack Overflow Oct 5, 2013 by Alex

2 Answers

4

Question is if your board supports AVRCP controller BT profile?

If it does you "only" need to connect against your phones AVRCP target BT profile. When you have a AVRCP BT connection there is specified commands how to pause and skip songs.

This is how the "plug and play" headset does.

Read more about Bluetooth profiles. http://en.wikipedia.org/wiki/Bluetooth_profile

Looking at your code you have set up a serial link towards a phone. This link uses SPP profile and you will only be able to send raw data over that link. If this is the only profile that your BT stack on your Arduino Uno board have you will be forced to create an application on the phone side to be able to read the raw data and do something with it e.g. pause music.

Hope this cleared things little for you.

answered on Stack Overflow Apr 23, 2014 by harsmar
1

Probably it is to late for you, but maybe I can help someone else.

Firstly, Bluetooth devices like BT headphones, keyboards etc, are known as HID (Human Interface devices). HC05 are not one of this out of the box, but there is a solution introduced by Evan Kale (link: https://www.youtube.com/watch?v=BBqsVKMYz1I) how to update one of this using serial port connection.

Other solution is to buy BT HID module, but they are more expensive (about 10 times)

answered on Stack Overflow Feb 16, 2018 by Przemysław Gęsieniec • edited Feb 16, 2018 by Haroldo Gondim

User contributions licensed under CC BY-SA 3.0