Please note: Friday June 18 is a holiday celebrating Juneteenth, please allow extra time for your order to arrive and plan accordingly.
0

ESP32 & adafruit_ble
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ESP32 & adafruit_ble

by Cpt_Waistcoat on Thu Jun 10, 2021 4:19 pm

Hi All,

I recently got into CircuitPython, and have been experimenting with a Rpi PICO, an Adafruit AirLift, and the BLERadio / HIDService libraries to create a bluetooth keyboard emulator.
Whilst the code doesnt error, it also wont successfully pair with my phone. However I've utilised example code previously using the BLERadio, UART, and the Bluefruit Connect App to successfully pair with my phone and share data, so I'm unclear why the below code won't work. The phone states "Couldn't pair with CircuitPython HID because of an incorrect PIN or passkey". Any support would be greatly appreciated. :)

Code: Select all | TOGGLE FULL SIZE
import board
import time
import adafruit_ble
from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.standard.device_info import DeviceInfoService
from adafruit_ble.services.standard.hid import HIDService
from adafruit_ble.services.nordic import UARTService
from adafruit_airlift.esp32 import ESP32
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode

esp32 = ESP32(
    reset=board.GP16,
    gpio0=board.GP9,
    busy=board.GP14,
    chip_select=board.GP13,
    tx=board.GP0,
    rx=board.GP1,
)

adapter = esp32.start_bluetooth()

ble = BLERadio(adapter)

hid = HIDService()

device_info = DeviceInfoService(software_revision=adafruit_ble.__version__,
                                manufacturer="Adafruit Industries")

advertisement = ProvideServicesAdvertisement(hid)
advertisement.appearance = 961
scan_response = ProvideServicesAdvertisement()
scan_response.complete_name = "CircuitPython HID"

# uart = UARTService()
# advertisement = ProvideServicesAdvertisement(uart)



if not ble.connected:
    print("advertising")
    ble.start_advertising(advertisement, scan_response)
else:
    print("already connected")
    print(ble.connections)

keyboard = Keyboard(hid.devices)
time.sleep(2)

while True:
    while not ble.connected:
        pass
    print("Start typing")

    while ble.connected:
        print("connected")
        keyboard.send(Keycode.DOWN_ARROW)
        time.sleep(0.4)
        keyboard.send(Keycode.DOWN_ARROW)
        time.sleep(0.4)
        keyboard.send(Keycode.DOWN_ARROW)
        time.sleep(0.4)
        print("issued keystroke")
        break
    break



Cpt_Waistcoat
 
Posts: 1
Joined: Thu Jun 10, 2021 4:05 pm

Please be positive and constructive with your questions and comments.