-
Notifications
You must be signed in to change notification settings - Fork 710
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
ESP32 BT-HID Device #230
Comments
I'm afraid there is nothing yet in the BLE C++ classes that would make your request possible. Maybe a question posted to one of the forums here might give some positive results: It is my loose understanding that HID support is based on Bluetooth classic (BR/EDR) as opposed to BLE and, so far, these classes only cover BLE functions. |
Thank you very much @nkolban. I already found a project for esp-idf for HID and BT but I was hoping for an example for the arduino IDE. I have no experience with IDF and the tool chain and how to integrate those stuff with arduino. Maybe this will come in the future. |
Do you have a link to the HID and BT project that uses ESP-IDF? I'd like to file that and have a look to see what it would take to eventually encapsulate that in the C++ libraries. That would be the first step towards an Arduino encapsulation. |
The most complete and supported solution seems to be the BTStack port for the esp32 for IDF here |
OOOh thats cool. But scary as well. If I get a sense of that story, it is a replacement for the Bluetooth stack supplied by Espressif (which I believe is based on Bluedroid stack implementation). |
Yes so this might be a problem to have both stacks available at the same time in an Arduino library. The example under https://github.com/asterics/esp32_mouse_keyboard uses the bt.h from the regular Espressif library so (see ble_hidd_demo_main.c). |
@chegewara Have you build an Arduino project for that already? I would be interested :-) |
Oh no, just fooled my laptop by setting appearance(). The rest of code has nothing to do with hid keyboard. But i may do some research and see if this is hard to do. |
I have some good news and some bad news. Good news that work is in progress. Bad news is driver crash under windows with error code 0x0a(device cant start). I can say for sure what is the reason, but its a chance that hid keybord requires secure connection and we dont have implemented it yet. My next step will be to rewrite code in esp-idf and see what happen and maybe add some security there. EDIT more good news, my samsung s4 connects to esp32 hid keyboard, so now i have to find way to send some text |
I have good news. Esp32 hid keyboard is connecting with my android phone and i can send text. This mean hid keyboard works, at least software part. Still is some work to do but we know it can be done. |
@chegewara great work, would you share your current project to play around with it? I just need a running starting point for the Arduino IDE :-) |
Im not sure yet, i will provide code or share links ive been using during research. Im thinking about writing blog article about this. For now maybe this will help you a bit: https://docs.mbed.com/docs/ble-hid/en/latest/api/md_doc_HIDService.html |
This is very important documentation if you want to play with HID devices. Appendix E gives some good look at what descriptors are required to setup hid device: |
Services and characteristics:
|
@chegewara I managed to run the BlueKitchen ESP32 Port for ESP-IDF (https://github.com/bluekitchen/btstack/blob/master/example/hid_keyboard_demo.c) it runs on my ESP32 board and sends continuously text messages to may mac book and to my android phone as soon as you pair them. The whole setup for the ESP-IDF and libraries is quite complicated so I cannot use this process for teaching. This is why I was looking for a nice wrapper for the Arduino IDE so that you can fire up a example project, hit flash and project runs :-) |
Can you wait few days, im still working on arduino code. At the moment im just sending random letter but i still missing one thing. My code requires that notifications to be turned on on client side (my android phone). At the moment only way to achieve this is to open nRF connect, connect to esp32 hid and turn on notifications. |
This is what i did so far. There is still a lot to do but it should send random character in loop:
|
@chegewara Great work!!! It works like a charm on my Android phone. I can also connect the ESP32 with iOS and Mac OS, but no characters appear there - guess this is the security issue problem you were talking about. For testing I used two ESP32 Hellcat LoRa boards. One board is sending a string over LoRa, to the other board which is connected as HID device on Android transferring all input received as keystrokes. |
Any news about this? |
@ripper121 What news do you need? Its working for few weeks now. There is one example added. If you have questions, issues or suggestions im open and ready to help. |
Is there a Arduino Lib for this or is it only possible with the SDK? |
It should work with arduino too. Last time i checked it did work with arduino. |
Yesss thx its working :) |
Hi great work, I tried it on my windows 10, but couldn't manage to make it work. After that I've got: "Driver error" - It connects and pairs ok, but doesn't work. Monitor log: any hint? |
Hi,
btw, ive been testing hid examples with windows 10 and there is no need to edit registers to make it works If you can post report map i will try to check it, also screenshot with error would be great |
Running perfectly now. Thank you all for the clarifications. |
Hi, I'm really knew to Arduino and C++. I think I'm at the right place, I'm trying to make a page turner for an Ipad app, and so far, this is the thread that got me the furthest to reach my goal. I'm sorry in advance if it's supposed to be "so simple", but how and where in the code (thank you @chegewara ) am I supposed to declare the keyboard character ? And if I want to link the keyboard character to an event (pressing a button, indeed), how would I do so ? Thank you guys ! |
Look at the examples in the IDE. There are examples for buttons and examples for this ble keyboard library. You really just need to merge them and use common sense. |
Wow, thanks so much ! It's almost done, and I basically just replaced some lines on the example. |
Am looking to modify @T-vK mouse library to be an absolute mouse so I can use it for a wireless IR lightgun, similar to the SAMCO project https://github.com/samuelballantyne/IR-Light-Gun/tree/master/Samco_2.0 where they use the AbsMouse library. I've got it working, where I can pass the modified library the X,Y coordinates I'd like it to go to, and it goes really well. One limitation is that you have to pass in the screen resolution when starting the library. This can be a hassle where you want to use your lightgun in many different emulator and the resolution may change from game to game, Question: Is there a way to have the ESP query what resolution Windows 10 is running, then pass that information back to the ESP over BLE so the library can use the current resolution? I guess I could make a calibration button to throw it into regular BT serial mode, make a C# app that passes the values to the ESP, save them to SPIFF, and then reboot to use the values. Sending the values to the ESP without a calibration app would be heaps better though |
I would have to dig some more in HID specification, i dont remember now if its possible. |
I don't think that's possible without your own driver/script/app on Windows. Be aware that the screen resolution can change at any time and you get pretty interesting results for multimonitor setups, especially if they run different resolutions on each monitor or their virtual placement is customized. |
Worst case scenario you can have button/buttons to select resolution from most common. |
Thanks for the well reasoned replies. I would be very interested to see how to incorporate serial communication as a composite device. At the end of the day though, maybe a button to select resolutions on the device is the way to go. I do like problem solving though and I can't help thinking that adding serial on top of BLE mouse/keyboard would be super great and might come in useful for others. |
So, any idea if it's possible to run serial (where a COM port number is allocated and data may be sent at say 115200 or 250000 baud) at the same time as BLE keyboard/mouse? |
Sure it is possible. |
Hi Thanks for the reply |
In theory it should be possible, but i didnt work with classic bluetooth, so i cant help with that. |
I didn't even think to try running Classic BT at the same time as BLE. I just assumed you'd need to add some type of BLE COM port wizardry. I threw together a sketch with both of them and it compiles. Thanks! |
Seems it can be done |
Hi! Greetings again! PS. It's important for me because I'll use this device for gaming... when mice works this way you may get a headache during rotating view :D It's not so visible while using it in perfect conditions but very visible when i compare my bluetooth mice(real) and this soltion PSS. Ive made some wireshark sniffing and every move() frame sent by esp is 16 bytes long. |
Hi, Everything depends how you build mouse from HID point of view. Usually mouse is using relative data, which means you are sending how far move pointer from current position. Then, after sending that you probably want to send value 0x0 or pointer will continue moving. If you are asking about other uC to make this project i would rather suggest to try nrf52840, 53811, 52833. NRF chips are specialized BLE chips with very good power consumption ratio. esp32 is too powerful to only build mouse. Problem with nrf is that you have to learn new RTOS, because of lack good arduino support. |
Thank you for your answer! :-) Latest tests ive made by arduino IDE and the oscillator was set on 240Mhz. Unless you mean the internal BLE transmission rate (dunno how i can set it up tho tomorrow I'll check all the documentation. Maybe it can help really.) And about sending the stop value... well... you really made me think where's the mistake in the code. I remember that at first try ive took your keyboard example and modified it to be usable as a mouse, tho it didn't require a stop val. It was just moving cursor the given pixels in y and x once. If it's really supposed to work as you say then it's much better and the mistake is just a matter of a bug in my code. It casts new light on the case :D. Thanks for the chip proposition also. Now i have plan B if esp wont work. Thanks again! |
To send stop moving you just have to send X = 0x0 and Y = 0x0, just like in keyboard you have to send key = 0x0 or it will be repeated by system. I think its the same way in case of mouse, but its a small chance and you dont have to send 0x0 for mouse. To make sure you can try to send X = 100 just 1 time and see if mouse pointer will move only 1 time or more. nrf chips are enough powerful to handle keyboard + mouse + even more, especially nrf52840. |
Implement change suggested by ossvr at nkolban/esp32-snippets#230 (comment) This solved reconnection problem I faced with Macbook Pro with MacOS Catalina
|
Hi All Any idea how to get Windows Game Controller panel to list the actual device name? In my library https://github.com/lemmingDev/ESP32-BLE-Gamepad the name is set and comes up correctly in device manager and Bluetooth settings In the game controller panel however, it just lists the number of axis and buttons as the name. Hoping someone may be able to point me in the right direction |
On a perhaps related note: It should be noted that I edited the the https://github.com/T-vK/ESP32-BLE-Mouse library in order to make this library, so I have a feeling some values could be set wrong too. I know my usage is set correctly in the HID report descriptor
however I'm not sure about the following which were blindly copied
If I change the pnp hex values above slightly: eg 0xabcd to 0xabcc so it thinks it's a new device, then Windows correctly changes the amount of buttons to: |
@chegewara @srounce @boonkerz @hetlelid @olehs @bleader @lemmingDev @xcarcelle @cezarymalek @ossvr @maximeCote819 @T-vK @hmatulis @ripper121 @gitmh Hello, I want to create a braille device for the deafblind that works for hid, could you help me with a code so that it recognizes as a braille device the device where I want to create it is in the esp32 https://usb.org/sites/default/files/hutrr78_-_creation_of_a_braille_display_usage_page_0.pdf |
I'm having trouble connecting my ESP-WROOM-32 to my computer. I (1402) BLUETOOTH_Init: Class: 5, Name: ESP32, Mode: 1 Any idea what could cause this? |
Is it possible to use the ESP32_BLE_Arduino library to build a HID-Keyboard to send keystrokes to another device? My goal: I would like to connect a ESP32 board to a BT device like an iPad and send a space character. I found https://github.com/asterics/esp32_mouse_keyboard but can't figure out how to this running in Arduino IDE. Any help would be appreciated - I found a lot of users asking for a similar feature for the ESP32.
The text was updated successfully, but these errors were encountered: