Pair (and Bond)

Now you can power up the keyboard button device with a battery (or USB power) and it will begin to advertise.

On your mobile device or computer with BLE, pick the device (the first time you connect it may have a generic name such as CIRCUITPYd133, later it may have the name Bluefruit Keybutton Control when it reconnects), and agree to the Pairing prompt. (Note, these photos are with a different device, but the process is identical.)

The devices will be paired, and automatically bonded so they can auto reconnect later.

Once connected, the keys will act just like any wireless keyboard to send input to your mobile device or computer. Try opening up a text editor and then press the five buttons.

In the sample code here's what each button will send:

  • button_1 = BACKSPACE
  • button_2 = the word "Bluefruit"
  • button_3 = the letter "L"
  • button_4 = the letter "e"
  • button_5 = ENTER

Customization

You can customize the code so your buttons send other keycodes. Here's a list of HID keycodes and modifiers to check out.

To customize the keycodes, look at this section of the code:

if not button_1.value:  # pull up logic means button low when pressed
            #print("back")  # for debug in REPL
            k.send(Keycode.BACKSPACE)
            time.sleep(0.1)
 
        if not button_2.value:
            kl.write("Bluefruit")  # use keyboard_layout for words
            time.sleep(0.4)
 
        if not button_3.value:
            k.send(Keycode.SHIFT, Keycode.L)  # add shift modifier
            time.sleep(0.4)
 
        if not button_4.value:
            kl.write("e")
            time.sleep(0.4)
 
        if not button_5.value:
            k.send(Keycode.ENTER)
            time.sleep(0.4)

This guide was first published on Jan 22, 2020. It was last updated on Jan 22, 2020.

This page (BLE Key Button Usage) was last updated on Jan 21, 2020.

Text editor powered by tinymce.