Using HC-06 to send information to an android device just as it does with USB

So. I made a gamepad with an arduino leonardo using this library.

I connected it to my computer with USB - it worked perfectly.
I connected it to my tablet with USB (OTG) - it worked perfectly.

Now I'm trying to implement bluetooth using an HC-06, but I can't find anything to guide me. I investigated, and while I could pair my device with the HC-06, I found that I need a "vessel" program or something like that so the HC-06 links to my android device properly. I tried to search for the solution, but instead of finding how to control android with an arduino, I just found lots of videos and tutorials about how to control an arduino with android :))

So now I can't find anything to guide me in this project, I don't know how to send bluetooth information to my android device just as it does via USB. Is there any app, program or library that I can use to make it possible?

Here's my code:

#include <Joystick.h>

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
  8, 0,
  true, true, false,
  false, false, false,
  false, false,
  false, false, false);

void setup() {
  // Initialize Button Pins
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);

  // Initialize Joystick Library
  Joystick.begin();
  Joystick.setXAxisRange(-1, 1);
  Joystick.setYAxisRange(-1, 1);
}

// Last state of the buttons
int lastButtonState[12] = {0,0,0,0,0,0,0,0,0,0,0,0};

void loop() {

  // Read pin values
  for (int index = 0; index < 12; index++)
  {
    int currentButtonState = !digitalRead(index + 2);
    if (currentButtonState != lastButtonState[index])
    {
      switch (index) {
        case 0: // UP
          if (currentButtonState == 1) {
            Joystick.setYAxis(-1);
          } else {
            Joystick.setYAxis(0);
          }
          break;
        case 1: // RIGHT
          if (currentButtonState == 1) {
            Joystick.setXAxis(1);
          } else {
            Joystick.setXAxis(0);
          }
          break;
        case 2: // DOWN
          if (currentButtonState == 1) {
            Joystick.setYAxis(1);
          } else {
            Joystick.setYAxis(0);
          }
          break;
        case 3: // LEFT
          if (currentButtonState == 1) {
            Joystick.setXAxis(-1);
          } else {
            Joystick.setXAxis(0);
          }
          break;
        case 4: // A
          Joystick.setButton(0, currentButtonState);
          break;
        case 5: // B
          Joystick.setButton(1, currentButtonState);
          break;
        case 6: // X
          Joystick.setButton(2, currentButtonState);
          break;
        case 7: // Y
          Joystick.setButton(3, currentButtonState);
          break;
        case 8: // START
          Joystick.setButton(4, currentButtonState);
          break;
        case 9: // SELECT
          Joystick.setButton(5, currentButtonState);
          break;
        case 10: // L
          Joystick.setButton(6, currentButtonState);
          break;
        case 11: // R
          Joystick.setButton(7, currentButtonState);
          break;
      }
      lastButtonState[index] = currentButtonState;
    }
  }

  delay(10);
}

Vexrus:
I found that I need a "vessel" program or something like that so the HC-06 links to my android device properly.

It sounds like complete nonsense. IF you have gotten what you want with the cable, you can send the same data via bluetooth with no change in the programme. Anything else is at the Android end, i.e. choice of terminal programme etc.

You might find the following background notes useful.

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

but it really is little more than connecting bluetooth in the proper manner and you are off.

Thanks for your reply. I tried to use various terminal apps on the arduino and wrote a little program:

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{
  Serial.println("Hello");
  delay(1000);
  Serial.println("How are you?");
  delay(1000);
}

It didn't work in any of the apps, it didn't transmit anything. Any idea why this could be happening? I already checked the wires, they are supposed to be well connected.

I made a gamepad with an arduino leonardo

I tried to use various terminal apps on the arduino and wrote a little program

 Serial.begin(9600);

The bluetooth module connection to the Leonardo needs to be on Serial1.

The Arduino Leonardo board uses Serial1 to communicate via TTL (5V) serial on pins 0 (RX) and 1 (TX). Serial is reserved for USB CDC communication. For more information, refer to the Leonardo getting started page and hardware page.

So... basically I just have to replace all the "Serial" in the code with "Serial1"?

Okay, after a lot time investigating, I found the solution. I inverted the TX and RX wires. That's it :confused:

Ok, but now I need to find an app which runs in the background and supports every usb functionality.

Ok, but now I need to find an app which runs in the background and supports every usb functionality.

Are you trying to obtain HID functionality over Bluetooth? The HC06 only supports SPP.

For HID you need something based on the RN42 HID.

I have seen internet postings about how to flash RN42 HID firmware into the HC05/06 because they use the same processor chip BC417.

Vexrus:
Okay, after a lot time investigating, I found the solution. I inverted the TX and RX wires. That's it :confused:

I think you mean that you transposed the Rx and Tx wires.

JohnLincoln:
I think you mean that you transposed the Rx and Tx wires.

Yeah, sorry, I'm not English.

cattledog:
Are you trying to obtain HID functionality over Bluetooth? The HC06 only supports SPP.

For HID you need something based on the RN42 HID.

I have seen internet postings about how to flash RN42 HID firmware into the HC05/06 because they use the same processor chip BC417.

That sounds interesting. I'll keep this post updated when I continue.