Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnecting issues #322

Closed
jkoenig72 opened this issue Oct 12, 2017 · 1 comment
Closed

Reconnecting issues #322

jkoenig72 opened this issue Oct 12, 2017 · 1 comment

Comments

@jkoenig72
Copy link

jkoenig72 commented Oct 12, 2017

Hi,

try to use USB Host Shield with a Bluetooth dongle in combination with one of those cheep mini bluetooth controllers for my e-skateboard

Almost there - by using the PS4BT example plus a few minor modifications:

  • want a fixed pairing. Just to one bluetooth address. Should not reconnect to something else. By adding the BT address to the main sketch and pass it through.
  • Want to to shutdown is slowly in case connection is lost. I was expecting that PS4BT.connected() will do that, but I need to include another boolen var connected and simply make it public to check. Done.

Open issue is reconnecting:

void loop() 
{
  Usb.Task();

  //&& Btd.incomingPS4
  if (PS4.connected()) 
  {
    if (Btd.connected!=false)
    {
      Serial.print("Value: ");
      Serial.println(PS4.getAnalogHat(LeftHatX));
    }
  }  
}

How to do it? It works 1st time when Arduino starts (or when I reset the board). But when I switch off and on again the controller it does not successfully re-connects. As I said, it does when its reboots.

Then I detected that its the same - it ONLY works when I initialized with

PS4BT PS4(&Btd, PAIR);

In contrast

PS4BT PS4(&Btd);

Does not work. Debug out is

HCI Disconnected from Device
Wait For Incoming Connection Request
Keyboard is connecting
Class of device: 00 05 40
Incoming Connection Request
Remote Name: MOCUTE-036_B53-70E8
Connection established
Connected to Device: 16:07:15:03:70:E8
Received Key Request
Wait For Incoming Connection Request
HCI Disconnected from Device
Wait For Incoming Connection Request

Any idea?

Complete sketch:

/*
 Example sketch for the PS4 Bluetooth library - developed by Kristian Lauszus
 For more information visit my blog: http://blog.tkjelectronics.dk/ or
 send me an e-mail:  kristianl@tkjelectronics.com
 */

#include <PS4BT.h>
#include <usbhub.h>

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>

uint8_t bta[6] = {0xE8,0x70,0x03,0x15,0x07,0x16};

USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb, bta); // You have to create the Bluetooth Dongle instance like so

/* You can create the instance of the PS4BT class in two ways */
// This will start an inquiry and then pair with the PS4 controller - you only have to do this once
// You will need to hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in pairing mode
PS4BT PS4(&Btd, PAIR);

// After that you can simply create the instance like so and then press the PS button on the device
//PS4BT PS4(&Btd);

bool printAngle, printTouch;
uint8_t oldL2Value, oldR2Value;

void setup() {
  Serial.begin(115200);
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); // Halt
  }
  Serial.print(F("\r\nPS4 Bluetooth Library Started"));
}
void loop() 
{
  Usb.Task();

  //&& Btd.incomingPS4
  if (PS4.connected()) 
  {
    if (Btd.connected!=false)
    {
      Serial.print("Value: ");
      Serial.println(PS4.getAnalogHat(LeftHatX));
    }
  }  
}
@Lauszus
Copy link
Collaborator

Lauszus commented Oct 12, 2017

Please do not open up multiple issues. Please stick with the one you have already opened: #321.

Regarding your request for only connect to a fixed Bluetooth address, then there is already a issue open for that: #261.

@Lauszus Lauszus closed this as completed Oct 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants