Simple Volume Knob banner

Simple Volume Knob

4 devlogs
10h 16m 10s

Rotary knob emulating a Bluetooth keyboard, that lets you control the speakers volume from the comfort of your own sofa.
Made using Raspberry Pi Pico W, with code written in Rust using the Embassy framework.

Loading README...

Szczurek

It works! (kind of)

After much work, we have a working rotary knob that can control the volume of the device it is connected to.
Rust embedded ecosystem is still pretty new, so I wasn’t able to find any library for making a HID device with Bluetooth LE. Instead, I had to manually write out the GATT services. Fortunately, it was easier than I thought, with only two being required for a working device. I also had to drop down to Windows (from my usual Linux) for a moment to generate a HID descriptor using the Waratah tool (https://github.com/microsoft/hidtools).

However, the biggest trouble, which took most of the time assigned to this devlog was getting the bluetooth device to connect and not get disconnected by OS or throw some error and disconnect itself. I spent probably another six hours not counted here, staring at logs, btmon, and searching about bluetooth pairing. So far, I haven’t managed to get a JustWorks pairing to work, and instead settled on a fake pin pairing. The device pretends it is displaying a pin to the user, and letting him confirm it, when actually it just automatically confirms it, and the user also does so on the device he intends to control. I believe the trouble with JustWorks authentication is caused by - guess it - trouble! - the BLE library I am using (pun intended). Another possibility is Linux causing problems or it might even be both.
I’m planning to open an issue on trouble github about this, and maybe the library can get fixed.

This project, while functional now, is also not yet done.
I still need to implement proper pairing data storage, so the device can reconnect after being powered off, I need to connect knob press to mute, and I need to make a physical package for the device, so it is actually usable. The authentication without pin is also something I would love to get working.

The video showcases the knob being used with a phone because it was easier to record, but it works with a pc too obviously.

0
Szczurek

Knob rotation is fixed!
Now every turn is detected correctly, yay.
The solution?
Even more bit patterns.

Attachment
0
Szczurek

Bluetooth stack is up!
This was mostly copy-paste work from the examples folder of trouble, the BT stack by Embassy, with some tweaks and few small things to figure out.
Below you can see a screenshot from the NRF Connect mobile app, which lets you discover and debug Bluetooth devices around, recognising my device.
I also spent some more time messing with the knob, to see how it works, however so far I didn’t manage to fix the every other rotation reporting.
Next comes the hard part which is figuring out how to make Pico appear as a HID device, get accepted by different OS’es (I read windows might have some additional requirements), and how to send keypresses.

Attachment
0
Szczurek

The knob is working! (kinda)
I wrote the code to handle the input from the knob, and now it prints into debug log when rotated left or right. However for some reason it detects only every other rotation (you need to rotate it twice in on direction to get a print). This is to be fixed. I’m also considering using interrupts for this (for fun), but the Embassy documentation is pretty lacking, so I will leave this for later.

Attachment
0