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

Input is only recognized when first paired #251

Open
Sflofler opened this issue Jan 3, 2025 · 21 comments
Open

Input is only recognized when first paired #251

Sflofler opened this issue Jan 3, 2025 · 21 comments

Comments

@Sflofler
Copy link

Sflofler commented Jan 3, 2025

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:

D NimBLEServer: Gatt Read event
D NimBLEServer: >> handleGapEvent:
D NimBLECharacteristicCallbacks: onStatus: default
D NimBLEServer: << handleGapEvent

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!

@LeeNX
Copy link
Contributor

LeeNX commented Jan 3, 2025

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?

@Sflofler
Copy link
Author

Sflofler commented Jan 3, 2025

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.

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200
lib_deps = lemmingdev/ESP32-BLE-Gamepad@^0.6.1

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!
But if I don't change the code, disconnect the ESP32 from my pc and connect it back on, just for power, the bluetooth connection goes fine but the input recognition doesn't work anymore.

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!

@LeeNX
Copy link
Contributor

LeeNX commented Jan 3, 2025

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.

@Sflofler
Copy link
Author

Sflofler commented Jan 3, 2025

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?

@Sflofler
Copy link
Author

Sflofler commented Jan 3, 2025

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?

@LeeNX
Copy link
Contributor

LeeNX commented Jan 4, 2025

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 Espressif Systems is moving toward using NimBLE-Arduino as the default stack (thou I might be wrong on all cases).

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. 🤔

@RaazP
Copy link

RaazP commented Jan 5, 2025

Hi everyone,
I somehow didn't see this issue and LeeNX kindly linked it to me.
Nothing to help, just stating that I'm having exactly the same issue.
My workaround for now is:

  1. Windows -> forget device
  2. ESP32 -> Reset
  3. Windows -> search BT devices and connect

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.
EDIT: That part actually isn't true. It was my error while testing all this. Forgetting the Device and adding it again, then restarting the games works fine.

@LeeNX
Copy link
Contributor

LeeNX commented Jan 5, 2025

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.

@RaazP
Copy link

RaazP commented Jan 5, 2025

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!
The bad 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
bleGamepadConfig.setAutoReport(false);
and
bleGamepad.sendReport();

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.
I've attached the MultipleButton code at the end, so you don't have to open the examples yourself.

Update 4: The "MultipleButtonsDebounce" example works flawlessly. Although setAutoReport(false) and sendReport() are used.
However, making it a 22 Button Sketch (all Pins with in-built Pull-ups) as individual buttons breaks it.
I can set "setButtonCount(22)" though, without configuring the pins & buttons.
I then see 22 buttons in Windows, but of course only 10 of them work.
No re-connect issue. (Important in Update 5)

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..
But there's the path to follow, if someone has the time and energy to work it out.
Sadly, I'm not sure if I can manage to adjust the hat-switch, button-matrix (keyboard.h) and rotary encoder codes into the "debounce-style".
(Update 5 finds out, that I don't have to do that)

Update 5: Now it goes really weird!
I can flash the "MultipleButtonsDebounce" with "setButtonCount(22)", but only configure 10 pins. Then connect it to my PC and it works perfectly.
I can then flash my buttonplate sketch with the 3x4-button-matrix, 6 buttons and two rotary encoders (essentially just 22 buttons, with a statemachine for encoders) just fine, without going to the BT settings and doing the usual forget device -> add device.
If I do that, it breaks.
I even unplugged the ESP32, restarted the PC, plugged-in the ESP32 and it works flawlessly.

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.
If I add "bleGamepadConfig.setHatSwitchCount(1);" to the MultipleButtonsDebounce sketch, it breaks on re-connect.

Conclusion for now:

  1. Flash with MultipleButtonsDebounce, but setButtonCount(22), instead of (10). Or however as many buttons you need.
    But don't change anything else!
  2. Add device in Windows BT settings
  3. Flash with custom sketch, which contains the actual code for all the buttons.
  4. DON'T forget+add device! Just let it re-connect automatically after flashing.
  5. Windows now thinks it's still the MultipleButtonsDebounce device, but all buttons (22 for me) work as they should and re-connecting works like a charm, even after restarting the PC, disabling BT etc.

Original post:
When using the SingleButton.ino from the examples, all my ESP32 boards work flawlessly. Both on my Surface Pro 8 and my Desktop PC. Pressing reset, unplugging etc. no issues at all, happily reconnecting and pressing button 1 on pin 13.

So apparently it has nothing to do with hardware, Windows or drivers.
I've also put the boards on my breadboard with everything connected, but still using the SingleButton example and it works fine, so it also doesn't seem to be an electric problem.

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.
I would understand, if my code wouldn't work at all, but I really can't find anything in it, that would cause issues on re-connecting.

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);
    }
}

@travisrroy
Copy link

travisrroy commented Jan 7, 2025

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.

@LeeNX
Copy link
Contributor

LeeNX commented Jan 7, 2025

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

@uggima
Copy link

uggima commented Jan 7, 2025

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 22

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
    }
}

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...
NimBLE-Arduino 2.1.3
ESP32-BLE-Gamepad-0.6.1
Bounce2 2.72

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.
Dropping changes from DrivingControllerTest and updating the default axes with a "bleGamepad.setAxes" with some uint16_t's worked fine. (maybe should be int16's? but it works for me).

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.

@RaazP
Copy link

RaazP commented Jan 8, 2025

Thank you all for contributing!
I've enabled these in the nimconfig.h:

#define CONFIG_BT_NIMBLE_LOG_LEVEL 1
#define CONFIG_NIMBLE_CPP_LOG_LEVEL 3
#define CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED 1
#define CONFIG_NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT
#define CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT
#define CONFIG_NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT

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.

@Sflofler
Copy link
Author

Sflofler commented Jan 9, 2025

I teste the SingleButton example, straight copied it and pasted and It worked but when I added another button in the exact same way that is shown in the example It stopped working.

@LeeNX
Copy link
Contributor

LeeNX commented Jan 9, 2025

@Sflofler did you removed /deleted /unpaired the device on the host OS and try
re-pairing between changes?

Host OS are known to cache the ble setup and changes you make while
testing, like new buttons do not get picked up and even break device usage.

@Sflofler
Copy link
Author

Sflofler commented Jan 9, 2025

@LeeNX Yes, everytime I upload a new code I do remove the paired device from Windows Bluetooth Devices!

@LeeNX
Copy link
Contributor

LeeNX commented Jan 9, 2025

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 FlightControllerTest.ino from the examples and see if that breaks. It also has a different device name, which could be something to look into.

Best of luck.

@lemmingDev
Copy link
Owner

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

@LeeNX
Copy link
Contributor

LeeNX commented Jan 9, 2025

@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.

@lemmingDev
Copy link
Owner

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?

@Sflofler
Copy link
Author

Sflofler commented Jan 9, 2025

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.

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

6 participants