-
Notifications
You must be signed in to change notification settings - Fork 192
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
Input is only recognized when first paired #251
Comments
You have not listed your sketch nor versions of used libraries, so I am making alot of guesses. ESP32-BLE-Gamepad v6.1 and NimBLE-Arduino v2.1.2? Have you tried any of the ESP32-BLE-Gamepad example sketches? Do they work? Next, if you make any changes to your sketches, I would always suggest deleting/unpairing host OS from the device, as changes to the setup are not changed on the host OS due to attributes been cached on first pairing. I would also enable serial debugging, where the button inputs are also echoed to the serial console, just to make sure your logic and hardware is correct and triggering. Lastly, have you tried on a different host OS device, like Android device, where the bluetooth hardware and stack generally are a little less fluid or borkable? Looking for as much info that could help, do any of the other Bluetooth example sketches work for ESP32? Have you done debugging with something like Punchthrough's LightBlue? |
Sorry for not providing other infos! Here is the code for testing that I'm currently running: #include <Arduino.h>
#include <BleGamepad.h>
BleGamepad bleGamepad;
BleGamepadConfiguration bleGamepadConfig;
void setup()
{
Serial.begin(115200);
bleGamepadConfig.setAutoReport(false);
bleGamepadConfig.setControllerType(CONTROLLER_TYPE_GAMEPAD);
bleGamepadConfig.setButtonCount(3);
bleGamepad.begin(&bleGamepadConfig);
delay(3000);
}
void loop()
{
if (bleGamepad.isConnected())
{
bleGamepad.press(BUTTON_1);
bleGamepad.sendReport();
delay(1000);
bleGamepad.release(BUTTON_1);
bleGamepad.sendReport();
delay(1000);
}
} I'm running it on PlatformIO, the library version is 0.6.1 and NimBLE is 2.1.2.
Yes I have tried the examples, they do work but I still get the connection issue. On Android I just tried to connect the device and it said that the device connected needed an app. No I didn't use Punchthrough's LightBlue or anything similar, just Windows native "gamepad debugger" and the HMLT gamepad testes, it's nice to mention that it works on both but only when first paired. Oh and yes, I do unpair and pair it back when I change the code! I actually just downloaded ArduinoIDE to see if I get any lucky since there were people with the same problem but reinstalling the IDE fixed the issue. Will test it soon! |
I have not tested your sketch, but two things stand out, first, why the long delay in the setup? Maybe you not coming out of the setup for the button actions to happen? I have never needed to add a delay in the setup. Second, your PlatformIO seems to be missing the NimBLE library, this might just be a typo, this is my last test looks like https://gitlab.com/leet/ble-gamepad-collection/-/tree/main/platformio/ESP32-BLE-Gamepad-test-a?ref_type=heads. I would suggest using more serial output text for debugging, so that you know that you are actually know that the button actions are meant to be running. Very odd that it works the first time and not after. Not had this problem myself. I was able to use the HTML Gamepad Test on my Android device with my test setups. BLE-Mouse and/or BLE-keyboard both work without issues? Not sure what else to suggest. |
Well the NimBLE is not listed in the platformio.ini since BLEGamepad is a fork of it, isn't it? I can see the library being used with BLEGamepad without any issue, can compile and everything, even see and connect the device so I guess that not being listed there is not the problem. I just connected it to my android device and went to the HTML Gamepad Test and it always works, I unplug the ESP32 from my pc and plug it back on, it auto connects to my android device and the website is showing the input being pressed as it should. Well, I guess it is an issue with my BT dongle? |
Hey! So I just tested with BLE-Keyboard and it just works. I see in the library that NimBLE is disabled by default. Maybe something with NimBLE? Is it possible to use BLE-Gamepad without NimBLE? |
Hey @Sflofler , I have an issue open and even worked on a PR to have access to both BLE stacks - #142. But I have not got it to work nor do I think there is enough interested to use ESP32-BLE-Gamepad without NimBLE-Arduino. Plus I think I have two other suggestions I did think of last night. If you just looking to get your project possible working and moving forward, maybe look ESP32-BLE-CompositeHID, which is basically making an XInput device. My thinking is that XInput device like the XBox Gamepad is way more tested than BLE Gamepad as there are very few BLE Gamepad devices, unlike BLE keyboards & mice. The other option, at least from testing, debugging and trying to track down what could be the problem, if you have another ESP32 module, could setup a Bluepad32 Host device. This is alot more work and I think it might not be a path any might do, but could be the start of a 3rd-Party USB Bluetooth dongle for input devices only - Something like BlueRetro, but with USB interface. 🤔 |
Hi everyone,
It's quickly done, just a few clicks and moving the EN Pin to the surface of my buttonbox with a small microswitch isn't an issue. The bigger issue is that my racing sims detect is as a new device every time, so I have to re-map all 20 buttons before driving. |
Thanks @RaazP , not ideal, but is a work around, especially if you don't have resources to debug the problem. I have not seen this on my Macs nor my RetroPies, thou I have not done lots of testing with this problem. Next set of things I can think of, is listing OS and version, Bluetooth hardware and version and possible driver release for Bluetooth hardware? Basically need to find out what is the common effected setup, then we might be able to track down the problem or hopefully see some sort of commonality. |
I've tested a bit more and the good news: It's the code! Update 1: The SingleButton.ino works fine, the MultipleButtons.ino example doesn't and shows the same re-connect issue, so I'm gonna try to adjust the MultipleButtons example until it works. Update 2: I deleted my long custom sketch and found out, that it might be the combination of When I put them into the SingleButton.ino, the re-connect issue happens. Update 3: The AutoReport and sendReport break the SingleButton sketch, but the issue still happens, when I disable the two lines in the MultipleButtons sketch. Update 4: The "MultipleButtonsDebounce" example works flawlessly. Although setAutoReport(false) and sendReport() are used. Sadly, my skills aren't there yet to find out the difference and why the debounce example with 10 buttons works, while the normal one doesn't. And also why the Denounce example breaks with 22 configured buttons.. Update 5: Now it goes really weird! So I basically tricked the "bug" and would be completely fine with this, but I'd really like to get 4 of the buttons registered as "Hat", not as button. Using the hat functions in my buttonplate sketch doesn't work, since the MultipleButtonsDebounce sketch doesn't set any hats. Conclusion for now:
Original post: So apparently it has nothing to do with hardware, Windows or drivers. I'm still quite a noob at coding, so it's 50% understanding what I did, 25% stitching together code from examples etc. and 25% writing my own code. Thanks in advance! This works fine: /*
* This code programs a number of pins on an ESP32 as buttons on a BLE gamepad
*
* It uses arrays to cut down on code
*
* Uses the Bounce2 library to debounce all buttons
*
* Uses the rose/fell states of the Bounce instance to track button states
*
* Before using, adjust the numOfButtons, buttonPins and physicalButtons to suit your senario
*
*/
#define BOUNCE_WITH_PROMPT_DETECTION // Make button state changes available immediately
#include <Arduino.h>
#include <Bounce2.h> // https://github.com/thomasfredericks/Bounce2
#include <BleGamepad.h> // https://github.com/lemmingDev/ESP32-BLE-Gamepad
#define numOfButtons 10
Bounce debouncers[numOfButtons];
BleGamepad bleGamepad;
byte buttonPins[numOfButtons] = {0, 13, 17, 18, 19, 23, 25, 26, 27, 32};
byte physicalButtons[numOfButtons] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
void setup()
{
for (byte currentPinIndex = 0; currentPinIndex < numOfButtons; currentPinIndex++)
{
pinMode(buttonPins[currentPinIndex], INPUT_PULLUP);
debouncers[currentPinIndex] = Bounce();
debouncers[currentPinIndex].attach(buttonPins[currentPinIndex]); // After setting up the button, setup the Bounce instance :
debouncers[currentPinIndex].interval(5);
}
BleGamepadConfiguration bleGamepadConfig;
bleGamepadConfig.setButtonCount(numOfButtons);
bleGamepadConfig.setAutoReport(false);
bleGamepad.begin(&bleGamepadConfig);
// changing bleGamepadConfig after the begin function has no effect, unless you call the begin function again
Serial.begin(115200);
}
void loop()
{
if (bleGamepad.isConnected())
{
bool sendReport = false;
for (byte currentIndex = 0; currentIndex < numOfButtons; currentIndex++)
{
debouncers[currentIndex].update();
if (debouncers[currentIndex].fell())
{
bleGamepad.press(physicalButtons[currentIndex]);
sendReport = true;
Serial.print("Button ");
Serial.print(physicalButtons[currentIndex]);
Serial.println(" pushed.");
}
else if (debouncers[currentIndex].rose())
{
bleGamepad.release(physicalButtons[currentIndex]);
sendReport = true;
Serial.print("Button ");
Serial.print(physicalButtons[currentIndex]);
Serial.println(" released.");
}
}
if (sendReport)
{
bleGamepad.sendReport();
}
// delay(20); // (Un)comment to remove/add delay between loops
}
}
This doesn't work on re-connect: /*
* This code programs a number of pins on an ESP32 as buttons on a BLE gamepad
*
* It uses arrays to cut down on code
*
* Before using, adjust the numOfButtons, buttonPins and physicalButtons to suit your senario
*
*/
#include <Arduino.h>
#include <BleGamepad.h> // https://github.com/lemmingDev/ESP32-BLE-Gamepad
BleGamepad bleGamepad;
#define numOfButtons 10
byte previousButtonStates[numOfButtons];
byte currentButtonStates[numOfButtons];
byte buttonPins[numOfButtons] = {0, 13, 17, 18, 19, 23, 25, 26, 27, 32};
byte physicalButtons[numOfButtons] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
void setup()
{
for (byte currentPinIndex = 0; currentPinIndex < numOfButtons; currentPinIndex++)
{
pinMode(buttonPins[currentPinIndex], INPUT_PULLUP);
previousButtonStates[currentPinIndex] = HIGH;
currentButtonStates[currentPinIndex] = HIGH;
}
BleGamepadConfiguration bleGamepadConfig;
//bleGamepadConfig.setAutoReport(false);
bleGamepadConfig.setButtonCount(numOfButtons);
bleGamepad.begin(&bleGamepadConfig);
// changing bleGamepadConfig after the begin function has no effect, unless you call the begin function again
}
void loop()
{
if (bleGamepad.isConnected())
{
for (byte currentIndex = 0; currentIndex < numOfButtons; currentIndex++)
{
currentButtonStates[currentIndex] = digitalRead(buttonPins[currentIndex]);
if (currentButtonStates[currentIndex] != previousButtonStates[currentIndex])
{
if (currentButtonStates[currentIndex] == LOW)
{
bleGamepad.press(physicalButtons[currentIndex]);
}
else
{
bleGamepad.release(physicalButtons[currentIndex]);
}
}
}
if (currentButtonStates != previousButtonStates)
{
for (byte currentIndex = 0; currentIndex < numOfButtons; currentIndex++)
{
previousButtonStates[currentIndex] = currentButtonStates[currentIndex];
}
//bleGamepad.sendReport();
}
delay(20);
}
} |
I am experiencing the same thing where after a disconnect, I have to go through the entire re-pairing process to get my buttons to work again. Tried downgrading to 0.5.4 and 0.5.6 with NimBLE 1.41 but my code doesn't seem to be compatible. NimBLE 2.1.3 was just released, but I see the same issue with 0.6.2. Edit: To see if maybe it was the board, I tested 2 other ESP32-WROOM-32Ds and had the same issue. |
@travisrroy , if you have a second ESP32, why not try Bluepad32 as a host and see if that has the same problem with your project. Else test with a mobile device like android. Or Install Lightblue. Another idea, enable the battery level ramping and rolling, see if you can see that, even if the input does not work. Serial debugging, to confirm input should be firing too. I could make Bluepad32 basic firmwares for ESP32 and ESP32-C3, for testing has hosts. Not sure what else might be useful for testing and debugging? |
Tested working, (does not press buttons automatically you have to ground one of "buttonPins") maybe the Autoreply fails to actually update anything past initial connection? Also versions... Also should mention (possibly incorrectly) importing settings for analog driving axes from the DrivingControllerTest.ino (which also fails after intial connection for me) caused the previously working on re-connect program to stop working. Further edit.... Having a buffer overflow in setup didn't feel right so set numOfButtons to what i needed to test and didn't work. Only using 6 buttons and minimum value that worked was 18 buttons. so the same +12 offset as worked for 10 buttons. Do not have a debugger setup so can't go look at ram and see what set of "pins" its reading that makes it work; Tried shoving a null (0x0) in there and that changed nothing so buffer overflow it is. |
Thank you all for contributing! #define CONFIG_BT_NIMBLE_LOG_LEVEL 1 This is the line that makes all the difference: I NimBLEServer: subscribe event; attr_handle=39, subscribed: true This is what I did and what shows the issue: // forgot device
// flashed
// opened serial monitor in Arduino IDE
// reset button
// BT device search & connected
// buttons pressed and working in-game
ets Jul 29 2019 12:21:46
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4688
load:0x40078000,len:15460
ho 0 tail 12 room 4
load:0x40080400,len:4
load:0x40080404,len:3196
entry 0x400805a4
I NimBLEDevice: BLE Host Task Started
I NimBLEDevice: NimBle host synced.
I NimBLEServer: mtu update event; conn_handle=0 mtu=255
I NimBLEServer: subscribe event; attr_handle=8, subscribed: true
I NimBLEServer: subscribe event; attr_handle=44, subscribed: true
I NimBLEServer: subscribe event; attr_handle=39, subscribed: true
ALPS 5 pushed.
ALPS 4 pushed.
ALPS 3 pushed.
ALPS 1 pushed.
ALPS 2 pushed.
ALPS_Encoder_B_Pressed
ALPS_Encoder_A_Pressed
// reset button
// auto re-connected
// buttons pressed, NOT working in-game
// but code is working, serial output shows them fine
ets Jul 29 2019 12:21:46
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4688
load:0x40078000,len:15460
ho 0 tail 12 room 4
load:0x40080400,len:4
load:0x40080404,len:3196
entry 0x400805a4
I NimBLEDevice: BLE Host Task Started
I NimBLEDevice: NimBle host synced.
I NimBLEServer: subscribe event; attr_handle=8, subscribed: true
I NimBLEServer: subscribe event; attr_handle=44, subscribed: true
I NimBLEServer: mtu update event; conn_handle=0 mtu=255
ALPS 5 pushed.
ALPS 4 pushed.
ALPS 3 pushed.
ALPS 1 pushed.
ALPS 2 pushed.
ALPS_Encoder_B_Pressed
ALPS_Encoder_A_Pressed If I first flash the standard MultipleButtonsDebounce.ino with numOfButtons = 22, the two blocks in the serial monitor are identical: // forgot device
// flashed MultipleButtonsDebounce.ino with numOfButtons = 22;
// reset button
// BT connected
// buttons pressed and working
ets Jul 29 2019 12:21:46
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4688
load:0x40078000,len:15460
ho 0 tail 12 room 4
load:0x40080400,len:4
load:0x40080404,len:3196
entry 0x400805a4
I NimBLEDevice: BLE Host Task Started
I NimBLEDevice: NimBle host synced.
I NimBLEServer: mtu update event; conn_handle=0 mtu=255
I NimBLEServer: subscribe event; attr_handle=8, subscribed: true
I NimBLEServer: subscribe event; attr_handle=44, subscribed: true
I NimBLEServer: subscribe event; attr_handle=39, subscribed: true
Button 6 pushed.
Button 6 released.
Button 6 pushed.
Button 6 released.
// reset button
// auto re-connected
// buttons pressed and working
ets Jul 29 2019 12:21:46
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4688
load:0x40078000,len:15460
ho 0 tail 12 room 4
load:0x40080400,len:4
load:0x40080404,len:3196
entry 0x400805a4
I NimBLEDevice: BLE Host Task Started
I NimBLEDevice: NimBle host synced.
I NimBLEServer: subscribe event; attr_handle=8, subscribed: true
I NimBLEServer: subscribe event; attr_handle=44, subscribed: true
I NimBLEServer: subscribe event; attr_handle=39, subscribed: true
I NimBLEServer: mtu update event; conn_handle=0 mtu=255
Button 6 pushed.
Button 6 released.
Button 6 pushed.
Button 6 released. |
I teste the |
@Sflofler did you removed /deleted /unpaired the device on the host OS and try Host OS are known to cache the ble setup and changes you make while |
@LeeNX Yes, everytime I upload a new code I do remove the paired device from Windows Bluetooth Devices! |
Thanks @Sflofler. Last suggestion if you willing to test for today, how about switching between two know working sketches, just to rule out some typo or IDE/editor issue. Try the Best of luck. |
So, I just had some ESP32 arrive and did some testing Both on ESP32 and ESP32-C3 -> controls work on first upload, remove device and it reconnects, but controls no longer work |
@lemmingDev this is on Windows, right? I am sure I have tested this on OSX and Android, but maybe that was an older release. I will try again today and also try Bluepad32 as Host too. I will report back later today. |
Yeah - Windows Just tested, and reconnections to Android seem fine, and functionality persists May be an issue with Windows compatibility. I wonder what's changed in either NimBLE or Windows? |
I had no issues on Android with the first sketch that I uploaded in this issue, which is this one: #include <Arduino.h>
#include <BleGamepad.h>
BleGamepad bleGamepad;
BleGamepadConfiguration bleGamepadConfig;
void setup()
{
Serial.begin(115200);
bleGamepadConfig.setAutoReport(false);
bleGamepadConfig.setControllerType(CONTROLLER_TYPE_GAMEPAD);
bleGamepadConfig.setButtonCount(3);
bleGamepad.begin(&bleGamepadConfig);
delay(3000);
}
void loop()
{
if (bleGamepad.isConnected())
{
bleGamepad.press(BUTTON_1);
bleGamepad.sendReport();
delay(1000);
bleGamepad.release(BUTTON_1);
bleGamepad.sendReport();
delay(1000);
}
} Reconnection worked everytime and button press was also fine! If I had to take a guess I would say it's something with NimBLE + Windows becaus when I tested BLE-Keyboard without activating NimBLE It worked! I don't have the sketch anymore but It was also very simple, I used the touch sensor on the ESP32 to open the Calculator on Windows. |
Well, like the title says, input is only registered when first paired with ESP32. I'm using windows joypad/game controllers to debug if an input is pressed, also tested with HTML gamepad tester btw.
I also changed the debug level for the NIMBLE library to get almost everything that I could while testing it and it actually behaves differently when first paired and when I restart the ESP32.
It is important to mention that the device re-pairs with windows, it says connected! But it doesn't register any input!
This is the log I get when I first pair with windows:
And I don't get it when I restart the ESP32.
I've seen people complain about the same thing but the majority of the issues/posts on the internet was closed because it doesn't happen with everyone, by the looks of it.
Does the log give any clue about this issue? I'm currently trying to deeply debug it but I thought I should also open an issue during the proccess!
Thanks!
The text was updated successfully, but these errors were encountered: