Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"?

like image 725
Alex Avatar asked Oct 05 '13 22:10

Alex


1 Answers

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.

like image 171
harsmar Avatar answered Oct 29 '22 15:10

harsmar