Read coordinates from a BLE Mouse

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
tshippy
 
Posts: 2
Joined: Sun Jan 15, 2023 11:27 pm

Read coordinates from a BLE Mouse

Post by tshippy »

I have a Clue that I am trying to connect to a mouse. The BLE Gatt for HID devices indicates there is some message that has bits for left, middle, and right buttons as well as x and y coordinates of the mouse. I want to read that message to be able to track the distance I have moved the mouse and to use the mouse buttons as an input device for the clue. I've search Github for examples and the one I need:
https://github.com/adafruit/Adafruit_Ci ... central.py
doesn't work.
Following other examples, I've been able to scan for peripherals and find the mouse I am using and connect to it, but I can't figure out how to get the list of services, characteristics, reports... Whatever element that contains the data from the mouse.
Has anyone else tried this? Any pointers would be appreciated.

User avatar
FriehoffT
 
Posts: 56
Joined: Wed Sep 11, 2019 7:30 am

Re: Read coordinates from a BLE Mouse

Post by FriehoffT »

Just for your info: I am also very interested to have a code sample that shows how to be a BLE Central in CP
Thomas

User avatar
tshippy
 
Posts: 2
Joined: Sun Jan 15, 2023 11:27 pm

Re: Read coordinates from a BLE Mouse

Post by tshippy »

I've made a little progress using the ble_json_central.py example on github. I modified the uuids in the ble_json_service and it now uses the mouse uuid to create a connection. However it throws an error when it calls the _discover_remote function in the BLEConnection object. Specifically this line:
results = self._bleio_connection.discover_remote_services((uuid.bleio_uuid,))
throws this error:
Traceback (most recent call last):
File "code.py", line 26, in <module>
File "/lib/adafruit_ble/__init__.py", line 107, in __getitem__
File "/lib/adafruit_ble/__init__.py", line 70, in _discover_remote
ConnectionError: Not connected

That shouldn't be happening because that call comes right after this check in the main module:
if connection and connection.connected:

I suspect I need to pair the devices instead of (or in addition to) connecting them. Or maybe there is some additional step to establish an encrypted connection to a mouse.

I'm happy to post all my code if anyone else is looking at this. I have a lot of years programming, but I'm new to python and BLE and I suspect I am overlooking something relatively simple.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”