Are you tired of not being able to use your Bluetooth keyboard and mouse with certain devices or in certain situations? Do you wish you could wake up your sleeping devices or access the BIOS or OS select menu? If so, then you’re in luck! In this article, we’ll show you how to build a Bluetooth to USB HID relay using a Raspberry Pi.
The concept is simple. By leveraging Linux’s gadget mode, we can make the Raspberry Pi act as a USB HID (Human Interface Device). This means that from the host’s perspective, it appears like a regular USB keyboard or mouse. Essentially, you can think of your Pi as a multi-device Bluetooth dongle.
Example Code Implementations:
- Implementation 1: Auto-discovery & Multi-device Support
import bluetooth_2_usb
bluetooth_2_usb.setup(auto_discover=True)
bluetooth_2_usb.run()
This code snippet enables the auto-discovery mode, which automatically detects and relays all readable input devices (keyboard and mouse) without the need for manual configuration.
- Implementation 2: Specific Input Devices
import bluetooth_2_usb
devices = ['/dev/input/event1', 'A1:B2:C3:D4:E5:F6']
bluetooth_2_usb.setup(device_ids=devices)
bluetooth_2_usb.run()
Here, specific input devices are specified in the device_ids
list. The Bluetooth devices corresponding to the specified paths or MAC addresses will be relayed.
- Implementation 3: Grab Devices & Debug Mode
import bluetooth_2_usb
devices = ['/dev/input/event2']
bluetooth_2_usb.setup(device_ids=devices, grab_devices=True)
bluetooth_2_usb.run(debug=True)
In this example, the grab_devices
argument is set to True
, which means that events on the relay device will be suppressed. Additionally, the debug mode is enabled for more detailed logging.
These code implementations demonstrate the flexibility and ease of use of the bluetooth_2_usb
package. Whether you want to relay all input devices, specific devices, or even grab devices, the package provides a simple and intuitive API.
By following the installation instructions, you can set up the Bluetooth to USB HID relay on your Raspberry Pi. Once installed and configured, you can connect the Pi to your target device or host using the appropriate USB port. Your Bluetooth keyboard and mouse will now work seamlessly with the target device.
While the package handles the relay functionality, it also provides additional features such as auto-reconnect, robust error handling, and installation as a systemd service. These features make the Bluetooth to USB HID relay a reliable and convenient solution.
In terms of technology, this project utilizes the following:
- Raspberry Pi: The Raspberry Pi acts as the hardware platform for running the Bluetooth to USB HID relay.
- Bluetooth: The package leverages Bluetooth technology for connecting and relaying input devices.
- USB: The Raspberry Pi’s USB capability is utilized to relay the Bluetooth input devices as USB HID devices.
- HID: HID (Human Interface Device) is the standard protocol for input devices such as keyboards and mice.
- Linux: The project takes advantage of Linux’s gadget mode and evdev library for handling input devices.
In conclusion, building a Bluetooth to USB HID relay with a Raspberry Pi opens up new possibilities for using Bluetooth input devices with a wider range of devices and situations. Whether you want to wake up sleeping devices, access the BIOS or OS select menu, or simply use Bluetooth devices in restricted environments, this project provides a practical and versatile solution.
Remember to check out the official documentation and GitHub repository for more information and updates on the bluetooth_2_usb
package. Happy hacking!
Note: The bluetooth_2_usb
package is released under the MIT license, making it open-source and free to use and modify.
Leave a Reply