makerdiary / python-keyboard

A hand-wired USB & Bluetooth keyboard powered by Python and more
https://makerdiary.com/m60
MIT License
483 stars 60 forks source link

Bluetooth Problems #13

Open CVYY39 opened 3 years ago

CVYY39 commented 3 years ago

Is anyone using this keyboard with Bluetooth successfully?

I've been trying for a day or two to get it to work reliably. I can get it to connect to either of my two computers (a mac and a PC). It will work for a bit, but then after a while it seems to flake out and start typing random characters, or just stops working altogether.

At one point the keyboard worked itself into some kind of state where I couldn't type. I tried enabling/disabling bluetooth and USB to no avail. I finally fixed it by updating the firmware and restoring all of the files that it came with on the USB drive.

xiongyihui commented 3 years ago

Were these "random characters" triggered by the pair-keys? By default, pressing J and J within 10ms will send "You just triggered pair keys #0". Sending a sequence of keys like that may cause Bluetooth disconnection when Bluetooth signal is not good enough. You can disable these pair-keys by comment out keyboard.pairs = [{35, 36}, {20, 19}] in code.py

CVYY39 commented 3 years ago

No, definitely not. I'm familiar with pair keys and had already changed their function.

It's more like it will be delayed in sending what I type, and then it will start repeating things. Random characters is probably a bad description, I think it is probably related to what I type, just very delayed (like 10+ seconds) and sometimes repeated. I don't think it's a reception issue, because it happens on both the PC and the mac at the same time. My PC BT receiver is about 2 ft from the keyboard, and my Mac OS receiver is maybe 3 ft away. It seems to happen when I switch from one to the other.

xiongyihui commented 3 years ago

It seems that there is a bug when switching between devices. Will look into it.

xiongyihui commented 3 years ago

@CVYY39 The latest code in this repo may fix the issue. The keyboard will release all keycodes when changing devices.

CVYY39 commented 3 years ago

That definitely improved things, but I'm still seeing some issues. Bluetooth seems to work perfectly connected to my Mac laptop. But the Windows desktop stopped accepting any input from the keyboard and, after I removed it as a BT device, no longer shows it as an option for pairing.

I thought it might be my PC's BT receiver, so I ordered a new one. I'll test that.

However, I also tested the keyboard by connecting it to my iPad Pro. I'm seeing the same weird behavior there as I mentioned in the earlier post. I was able to pair the keyboard to the iPad, and for a couple of seconds it seemed to work fine. Then after I had typed a couple of words, it slowed down considerably, and started repeating keys. It then backspaced the words I had typed.

I switched back to the Mac, and it worked again. Then I switched back to the iPad, and it let me type for maybe 20 seconds, and then the same thing happened.

I switched to the Mac again, and it worked again. Then when I switched back, the iPad would not accept any input from the keyboard. After a switched back and forth a few times, the connection to the iPad started working for a while, but the typing lag got longer and longer until it stopped working at all again.

xiongyihui commented 3 years ago

That's weird. I have tested with a Surface Laptop 3 with Windows 2004, an Xiaomi MIX 3 with Android 9 and an iPhone 6s with iOS 13.2. I don't find the same issue yet. I will try to test more devices. Maybe, it is an issue related to the Bluetooth connection interval. Different systems may have different requirements. Currently, we set the connection interval to 11.25. We can remove the following lines to see if the issue still will occur or not.

https://github.com/makerdiary/python-keyboard/blob/f16fac90f9c4d0d1a291b8a3963ded2140909e2f/keyboard/__init__.py#L149-L156