-
Notifications
You must be signed in to change notification settings - Fork 186
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
Multiple gamepad 1 PC #225
Comments
I don't believe that ESP32-BLE-Gamepad supports two gamepads over one connect. The Strings pasted to to ESP32-BLE-Gamepad/examples/CharacteristicsConfiguration/CharacteristicsConfiguration.ino Line 10 in 11ee6e9
I think ESP32-BLE-CompositeHID is more modular and has Hope that helps. |
Interesting ... Apologies for the miss read. Never tried to bind two of the same devices at the same time, but should not be a problem. I wonder if using the BLE serial numbers for each devices been different. Thou should have different Mac address and seen as two different devices, but I could be wrong here. ESP32-BLE-Gamepad/examples/CharacteristicsConfiguration/CharacteristicsConfiguration.ino Line 30 in 11ee6e9
Possible make each device with a unique Another possible corner case, did you possible change any BLE characteristics and not delete the BLE device from Windows and reconnect? Been bitten more than once while testing new BLE setups. |
Tried different names, serial, and other bleGamepadConfig settings (VID, PID, GUID) with no success. |
Oh no, broken a few interfaces myself. I need to put some time into testing multiple gamepads on the same host and see if I get the same problem. Things I would do, to try and eliminate possible causes. First would be trying another host, possible a different OS, like maybe your phone. Another would be using a BLE scanner/analyser like LightBlue or nRF Connect on Android and see if two different devices are been listed. Also nice to see the BLE attributes, characteristics, services and descriptors. I hope some of that helps. Please let us know how it goes. |
I tried connecting both(now one esp32 wroom and 1 esp32 c3) to Android. |
I don't have Windows, at least not at the moment setup. I have received a few ESP32-C3, which I did some tests a few weeks back on. I will try and tested today with OSX and Android as the host and even possible another ESP32-C3 running BluePad32. Maybe with Linux too, but let's see. |
Is this because NimBLE-Arduino is using the same IRK? A possible way |
Just for completeness #include <Arduino.h>
#include <BleGamepad.h>
BleGamepad bleGamepad("Custom Contoller Name", "lemmingDev", 100); // Set custom device name, manufacturer and initial battery level
BleGamepadConfiguration bleGamepadConfig; // Create a BleGamepadConfiguration object to store all of the options
int batteryLevel = 100;
// Use the procedure below to set a custom Bluetooth MAC address
// Compiler adds 0x02 to the last value of board's base MAC address to get the BT MAC address, so take 0x02 away from the value you actually want when setting
// I've noticed the first number is a little picky and if set incorrectly don't work and will default to the board's embedded address
// 0xAA definately works, so use that, or experiment
uint8_t newMACAddress[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF - 0x02};
uint16_t loopCheckDelay = 1500;
uint64_t loopCheckMillis;
int rampSpeed = 20; // Adjust the speed of ramping
int direction = 1; // 1 for increasing, -1 for decreasing
void setup()
{
Serial.begin(115200);
Serial.println("Starting BLE work!");
bleGamepadConfig.setAutoReport(false);
bleGamepadConfig.setControllerType(CONTROLLER_TYPE_GAMEPAD); // CONTROLLER_TYPE_JOYSTICK, CONTROLLER_TYPE_GAMEPAD (DEFAULT), CONTROLLER_TYPE_MULTI_AXIS
bleGamepadConfig.setVid(0xe502);
bleGamepadConfig.setPid(0xabcd);
bleGamepadConfig.setModelNumber("1.0");
bleGamepadConfig.setSoftwareRevision("Software Rev 1");
bleGamepadConfig.setSerialNumber("987654321B");
bleGamepadConfig.setFirmwareRevision("2.0");
bleGamepadConfig.setHardwareRevision("1.7");
// Some non-Windows operating systems and web based gamepad testers don't like min axis set below 0, so 0 is set by default
//bleGamepadConfig.setAxesMin(0x8001); // -32767 --> int16_t - 16 bit signed integer - Can be in decimal or hexadecimal
bleGamepadConfig.setAxesMin(0x0000); // 0 --> int16_t - 16 bit signed integer - Can be in decimal or hexadecimal
bleGamepadConfig.setAxesMax(0x7FFF); // 32767 --> int16_t - 16 bit signed integer - Can be in decimal or hexadecimal
bleGamepad.begin(&bleGamepadConfig); // Begin gamepad with configuration options
//esp_base_mac_addr_set(&newMACAddress[0]); // Set new MAC address
//randomSeed(analogRead(A0)); // Seed the random number generator with noise from an unconnected analog pin
}
void loop()
{
if (bleGamepad.isConnected())
{
if (millis() - loopCheckMillis > loopCheckDelay )
{
/*
if(batteryLevel > 0)
{
batteryLevel -= 1;
}
*/
// Update battery level with randomness
batteryLevel += direction * (random(1, 5)); // Ramp up or down by a random value between 1 and 4
// Change direction randomly
if (random(0, 100) < 5) { // 5% chance to change direction
direction *= -1;
}
// Keep battery level within the range of 5 to 95
if (batteryLevel > 95) {
batteryLevel = 95;
direction = -1; // Change direction to decrease
} else if (batteryLevel < 5) {
batteryLevel = 5;
direction = 1; // Change direction to increase
}
Serial.print("Battery Level Set To: ");
Serial.print(batteryLevel);
Serial.println("%");
bleGamepad.setBatteryLevel(batteryLevel);
// delay(30000);
// Delay to control ramp speed
//delay(rampSpeed);
//restart this TIMER
loopCheckMillis = millis();
}
}
} My start up logs for one of the devices, looks like
|
Last post for today on this item ... ;-). I have set my
|
Been thinking more about this issue. Some ideas that we could test. If the same firmware is upload to both devices, which has the same serial number, this could cause this problem I guess. I could see how that could happen pretty easy. I will see if I can reproduce tomorrow. I can also upload my two firmwares images that I made. Android can just be used for testing gamepad, like Game Controller Tester ... I am sure there are others. Another test, try the ESP32 Keyboard or Mouse at the same time as the ESP32 BLE Game. Looking to rule out two of the same frimwares, default mac address uploaded to both devices. Different ESP-IDF Version ( v5.1.4-586-gb6b4727c58-dirty) and/or Arduino Core Version (3.0.4) and/or Bluetooth stack and lastly, software or hardware fault. Doing keyboard and mice tests will rule out Host OS hardware, software and possible drivers. Another idea would be to try two totally different firmware tools, like RealRobots Gamepad Configurator. I think my PoC proves select using test case of multiple guest devices that can connect to a host, if under the correct conditions. If we can found out the conditions that don't work and document them, other people will not fall into these same problems. Also hopeful make it easier for somebody to pick up a failed task and see what progress they can make. Can't wait ti poke at some setup ideas and see what we find. Hoping a boomtasic and fun journey tomorrow. |
This is a very exciting. I used ArduinoIDE to write the original code in one esp32 and realrobots in another, the two can be connected to one Win PC at the same time. I did another experiment. After uploading the RealRobots Gamepad firmware to esp32, I did not use the connect function of RealRobots, but directly used ArduinoIDE to write the original code. This also did not work. |
Could you confirm if you were using NimBLE version 1.4.1 or 1.4.2 for these tests? @sosssego would you be able to confirm the same? I'm trying to track down this problem myself and I'm curious if it relates to issue #229. I'm attempting a fix in #230. |
The version of NimBLE used is 1.4.2. One of my esp32 seems to be broken, so I can't test with 1.4.1 again. |
@leonhoo i think i can confirm it.I have a problem with 1.4.2 i can't use multiple devices and when i tried 1.4.1 it have no problem with it everything worked well |
@leonhoo @OatKungKTZ I managed to get it working over in #230. Try pulling that fix and if that doesn't work, upgrade your NimBLE-Arduino to the 1.5 branch as well. |
@Mystfit i tried once (your method) with 1.4.2 but it's doesn't work ok will try again with 1.5 |
@OatKungKTZ My fix probably isn't the solution but it could be related to upstream issue in the esp-nimble repo which enforces new IRK keys on a fresh boot. This fix is available in esp-nimble 1.5.0 which was merged into Nimble-Arduino at the end of June. Nimble-Arduino 1.5 is not officially released yet so you'll have to clone it instead of using the Arduino library manager. Thank you @leonhoo for pointing me in the right direction regarding IRK. |
Borrowed another esp32 to test again, and the 1.4.1 version still didn't solve the problem. Yes, both esp32s could connect to the computer, but after a short while, one of them would automatically disconnect and reconnect, repeating this action over and over again. |
Give the Nimble-Arduino 1.5 branch a go. |
https://github.com/user-attachments/assets/1ddaa2cf-ece9-40fe-b049-23eaef991a41 #mac Nimble-Arduino 1.5, the issue remains.
|
Any update? Even though I have two different vid pid esp cards, I can't connect the second card while one is paired (even when it's not connected). I have to unpair the first one first. |
I have been playing with PlatformIO, as I ran into problems with funky library versions issues in other problems(at least I did think I was, but it was GPIO differences with different ESP32 boards). I was wondering if anybody would like to test the firmware builds that work for me, not just the source code or PlatformIO project. Try and rule out local library problems. Also wondering, how many people facing this problem is local to Widows host OS? I have tried on multiple OSX versions and platforms (x86_64/aarch64) and multiple Android devices without running into this problem. I really should test some more on Linux, I have enough of the devices near by, just none with a desktop. Last idea for request for feedback, any suggestions on what to add into the debugging sketch that might help with insight to where or what might be the problem. Please add reason why or how the addition with be helpful in the debugging sketch. |
Finally got around to doing the PlatformIO builds and uploads - https://gitlab.com/leet/ble-gamepad-collection/-/tree/main/platformio?ref_type=heads I have included my ESP32-C3-mini binaries, no GPIOs used with only battery level changing. Let's see if this helps anybody. Not sure what else we can try and track down this odd problem. |
I tried to use the BLE gamepad example from Arduino to make 2 gamepads and play cooperative games.
The only difference in code is the name of the gamepad
BleGamepad bleGamepad("Gamepad1");
BleGamepad bleGamepad("Gamepad2");
When trying to connect the second gamepad windows Failed and asked to try again.
Trying again resulted in the same issue.
I used 2 generic ESP32 devkit V1.
Connecting the controllers alone works ok.
Is there anything else I need to change in the code between the 2 gamepads?
example code:
The text was updated successfully, but these errors were encountered: