Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Bluefruit SPI Friend as HID Device with Rapsberry Pi Pico
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Bluefruit SPI Friend as HID Device with Rapsberry Pi Pico

by AngryChihuahua04 on Fri Feb 26, 2021 9:05 pm

Hello to all! I am semi-new to the world of coding and electronics as I have some experience with normal Raspberry Pi boards, but new to microcontroller boards such as the Pico. I am also very new to Bluetooth commands and protocol, so please forgive me for any errors in the code. I am currently working on a project that uses the Pico with the Adafruit Bluefruit SPI Friend. The main purpose is to have some buttons connected to the Pico and to broadcast the HID commands such as VOLUME+ and VOLUME- from the Pico to a connected device. I have it wired up to the Pico as shown in the picture below.
resized pico.jpg
Picture of the wired up Pico
resized pico.jpg (452.64 KiB) Viewed 142 times

I am able to successfully power the board and broadcast a new name for the Bluetooth module. However, the error I am running into is when I use the AT+BLEKEYBOARDEN=1 command. When this command is run, the console gets an error that says "RuntimeError ('Timed out waiting for a response.',) If this command is omitted, my device can connect to it just fine. Any suggestions on how to fix this?
Code: Select all | TOGGLE FULL SIZE
import board
import busio
import digitalio
from adafruit_bluefruitspi import BluefruitSPI
import time

spi_bus = busio.SPI(clock=board.GP2, MOSI=board.GP3, MISO=board.GP4)
cs = digitalio.DigitalInOut(board.GP5)
irq = digitalio.DigitalInOut(board.GP6)
rst = digitalio.DigitalInOut(board.GP1)
bluefruit = BluefruitSPI(spi_bus, cs, irq, rst, debug=False)

connected = None

print("Initializing Bluetooth module")
bluefruit.init()
bluefruit.command_check_OK(b"AT+FACTORYRESET", delay=1)

#Print Bluetooth Module Info
print(str(bluefruit.command_check_OK(b"ATI"), "utf-8"))

bluefruit.command_check_OK(b"AT+GAPDEVNAME=Glasses")
bluefruit.command_check_OK(b"AT+BLEPOWERLEVEL=0")

#Main Loop
while True:
    try:
        print("Waiting for a connection to Bluefruit LE Connect ...")
        # Wait for a connection ...
        dotcount = 0
        while not bluefruit.connected:
            print(".", end="")
            dotcount = (dotcount + 1) % 80
            if dotcount == 79:
                print("")
            time.sleep(0.5)

        connected = bluefruit.connected
        print("Connected to Glasses!")

        connection_timestamp = time.monotonic()
        while True:
            # Check our connection status every 3 seconds
            if time.monotonic() - connection_timestamp > 3:
                connection_timestamp = time.monotonic()
                if not bluefruit.connected:
                    break

            bluefruit.command_check_OK(b"AT+BLEKEYBOARDEN=1")
            bluefruit.command_check_OK(b"ATZ")
           
    except RuntimeError as e:
        print(e)
        continue

Any help is appreciated!

AngryChihuahua04
 
Posts: 18
Joined: Mon Aug 19, 2019 6:26 pm

Re: Bluefruit SPI Friend as HID Device with Rapsberry Pi Pic

by adafruit2 on Wed Apr 07, 2021 1:35 pm

hmm we really dont recommend this technique anymore, but it sounds like its mostly working. did you try upgrading the module BLE firmware via the app?

adafruit2
Site Admin
 
Posts: 19959
Joined: Fri Mar 11, 2005 7:36 pm

Please be positive and constructive with your questions and comments.