DIY蓝牙宏键盘

7,397

45

1

简介:DIY蓝牙宏键盘

About: Hey everyone! My name is Brian and thanks for checking my Instructables. I'm a software developer by trade but I've recently gotten into Arduino development after discovering the esp8266 chip, a WiFi enable…

在这种指示中,我们将通过ESP32的内置蓝牙进行查看以模拟蓝牙键盘。

蓝牙HID(人机界面设备)是蓝牙键盘和鼠标使用的协议,太好了!


和一些ESP32开发板以低于5美元*delivered, this is a really inexpensive and simple way to create wireless custom keyboards such as a Macro keypads. Macro keypads can be used for controlling various application like Video editors or Photoshop, personally I use mine for controlling scenes in OBS when I am making videos or streaming.

我们首先要查看如何使用ESP32 HID键盘库,然后我将向您展示我如何使用它来构建电池供电的蓝牙宏键盘。

用品:

You will also need a lipo battery, I just used a random one I had laying around so I can't link to it!


If your PC doesn't have Bluetooth you can use a dongle like this one:

amazon.co.uk *:https://amzn.to/2uuZovu

亚马逊网站*:https://amzn.to/39oGvtg

Amazon.de*:https://amzn.to/2s9ds8c.

* =联盟

第1步:看看视频

我已经做了一个视频,涵盖了同样的事情,作为这个指导,所以如果你有兴趣,请检查出来!我也经常制作关于ESP8266和ESP32项目的视频,所以也许在我的频道上还有其他你可能会感兴趣的视频!

Step 2: [Optional] Getting Started With an ESP32

ESP32S是与Arduino IDE兼容的微控制器,并包含WiFi和蓝牙。它们也很便宜,所以他们为您的项目非常有用。


您需要将ESP32板定义添加到Arduino IDE中,为此您可以按照ESP32 Arduino项目GitHub页面

第3步:安装ESP32 BLE键盘库

It is possible to use Bluethooth HID on the ESP32 with no external library, but Github user T-Vk has written a library calledESP32-BLE-键盘that makes it more like the standard Arduino keyboard library which makes it much easier to use.


此库在库管理器上不可用,因此您需要从Github下载它。

  • 进行项目发布页面和download the latestEsp32-孔-KeyBoard.zip.
  • 下载后,您可以将其添加到您的Arduino IDE中,但要将其添加到Sketch->包括库然后将zip添加到库和select the ESP32-BLE-Keyboard.zip from the previous step.

第4步:看着这个例子

一旦添加了,我们就可以打开它的示例。这是一个非常好的榜样,因为它展示了你可以用图书馆所实现的一些不同的东西,但我也会在我认为这将是有用的。

您可以通过前进来访问该示例文件->例子->ESP32 BLE键盘->sendkeystrokes.


Setting up a Bluetooth connection

在设置中,它开始在蓝牙连接,此前应该可以与设备配对。

bleKeyboard.begin();

Inside the loop it also checks if it's connected to a device

bleKeyboard.isConnected()

打字

这个例子展示的第一件事是,一旦文本连接起来,它将首先使用

blekeyboard.print(“Hello World”);


Single button presses

它然后展示如何“写入”返回键,这基本上模仿此按钮的单键。

bleKeyboard.write(返回键);

你可以打开门BleKeyboard.h介绍库的文件,以查看像这样定义的所有密钥。您还可以通过单逗号放入ascii字符。

blekeyboard.write('a');


Media Keys

它还演示了如何发送媒体键,这与使用蓝牙耳机控制音量或跳过曲目的方式类似。示例显示了播放/暂停key, but again you can openBleKeyboard.hto see the other options available.

bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE);

按住键键

The final thing the example shows us is how you can press and hold keys, this is useful for creating Macro keyboards. The example shown here is for Ctrl + Alt + Delete

bleKeyboard.press(KEY_LEFT_CTRL);

blekeyboard.press(key_left_alt);

blekeyboard.press(key_delete);

然后它调用releaseAll,正如您可能猜到的那样,releaseAll释放所有按下的键。

blekeyboard.releaseall();

如果您希望使用要释放的键使用reforma命令,您也可以释放特定键

按键释放(按键删除);

第5步:图书馆的其他提示

We covered the main functionality of the library in the previous step, but here are some extra things that I think might be useful to know


使用外部触发器

使用诸如按钮按下的外部触发,始终最好控制这样的隐藏设备。如果您使用计时器并且出现问题,它可能会尴尬地断开连接。想象一下,如果不小心编程它以每100ms按下Ctrl + Alt + Del,则必须尝试关闭蓝牙!

Changing the device name

默认情况下,设备名称将显示为“ESP32 BLE键盘”,可以在您创建库的实例时更改。您可以设置设备名称,制造商和初始电池电量。

Blekeyboard Blekeyboard(“蓝牙设备名称”,“蓝牙设备制造商”,100);

Setting the battery level (not working for me at least)

The library claims you can also set the battery level but it didn’t work for me on my Windows PC (it stayed with whatever the initial value was) and my android phone didn’t show the level of it all. Here is the command for it in case it works for you

bleKeyboard.setBatteryLevel (50)

设备兼容性

I ran successfully ran the example on my Windows 10 PC, Android phone and my Mac (although it's still running Sierra somehow!)

它也只能一次连接到一个设备。

故障排除配对

如果您有一些问题配对,请尝试在设备搜索时重新启动ESP32。我也曾经必须在我的电脑上打开和关闭我的蓝牙,以便搭配它。

第6步:宏键盘

Now that we have the basics out of the way, let's make something practical out of it!

In a上一篇指南I showed how to make the simplest Macro keypad out of a Arduino pro Micro and cheap keypad. For each button on the keypad it sends a different combination of button which could be used to control applications, personally I use it for OBS, the software I use for recording videos and for when I stream. This seems like a good project to port over the the ESP32 so we can make a wireless version.

为此,我将使用意外的制造商Tinypico ESP32董事会. The main reason for choosing it is a very power efficient board and has the circuitry for running off and charging a Lipo battery built in, so all I need to do is plug a battery in.

如果它的行距和Pro-Micro一样,而且我可以利用我之前制作的突破板,这一点也不吸引人,那我就是在撒谎!

The keypad requires 8 GPIO pins to operate, and the TinyPICO has 8 GPIO pins in a row so we’ll use them. You can simple connect the keypad to the TinyPICO as shown in the above image.

第7步:宏键盘的代码

The code for the Macro Keypad sketch can be found onmy Github.

以及安装在上一步中的Blekeyboard库,您还需要安装键盘库,可以通过将图书管理器打开来执行此操作Sketch->包括库->Manage Libraries

在图书馆manager, search for "keypad" and install the one byMark StanleyAlexander Brevig


一个配置如果您使用的是不同于TinyPICO的ESP32,则可能需要确定键盘引脚,它们设置在rowPins和colPins数组中。从键盘正面看,从左侧开始,前4个引脚为行引脚,后4个引脚为列引脚。

一旦完成,将代码上传到董事会和您should test at this stage it's working.

第8步:让我们制作无线!

如前所述,TinyPICO内置了处理Lipo的电路,所以我们只需要连接它。它带有JST连接器,可以焊接到底部,或者你可以使用Bat和GND引脚,如果你想通过引脚来完成。

如果您使用的是JST连接器,请仔细检查电池的极性匹配Tinypico,没有标准应该有线连接,以便您的电池可能不匹配。

使用它之前检查Lipo电池的电压,健康的面糊应为3V或更高,电池用正确的JST连接器找到了0V!

I ended up using an 18650 cell in an holder and soldering it to the JST connector of the dead battery.

The TinyPICO reduces its power consumption when running off battery by not powering any of it’s LEDs, so even if it doesn’t look on, hopefully it is! A future improvement of the project might be to pulse the onboard dotstar LED on startup just to let you know it actually turned on and maybe again when it connects. For now you can check in your systems Bluetooth menu that it is on and connected ok.

Step 9: Testing It Out!

让我们来测试它,如果我打开Obs的热键部分,我可以点击不同的操作来记录将控制它的按钮组合,为此,我们可以单击键盘上的按钮,它将更新。

单击“应用”后,您不应该能够使用键盘来控制OBS中的场景。

第10步:谢谢阅读!

Hopefully you found this Instructable useful. I'd love to hear about what you would make with this type of setup. Please let me know in the comments below, or join me and a bunch of other makers on我的discord服务器,我们可以在哪里讨论这个主题或任何其他制造者相关的,人们真的很有帮助,所以这是一个闲逛的好地方

我还要对我的朋友们表示衷心的感谢GitHub赞助商who help support what I do, I really do appreciate it. If you don’t know, Github are matching sponsorships for the first year, so if you make a sponsorship they will match it 100% for the next few months.

谢谢阅读!

Be the First to Share

    Recommendations

    • Microcontroller Contest

      Microcontroller Contest
    • Automation Contest

      Automation Contest
    • 让它发光比赛

      让它发光比赛

    Discussions

    0
    Ecabrera938.

    Question9 months ago

    你好,我有一些麻烦
    tack smashing protect failure!
    abort() was called at PC 0x400dbebc on core 0
    Backtrace: 0x40091448:0x3ffd6b20 0x40091679:0x3ffd6b40 0x400dbebc:0x3ffd6b60 0x4010e179:0x3ffd6b80 0x40133e0d:0x3ffd6be0 0x4013444d:0x3ffd6c00 0x4013f18a:0x3ffd6c20 0x401148c2:0x3ffd6c40 0x4008e089:0x3ffd6c70