Difference between revisions of "Bluetooth mouse"

From ArchWiki
Jump to navigation Jump to search
(update interlanguage links (https://github.com/lahwaacz/wiki-scripts/blob/master/update-interlanguage-links.py))
 
(36 intermediate revisions by 19 users not shown)
Line 6: Line 6:
 
{{Related articles start}}
 
{{Related articles start}}
 
{{Related|Bluetooth}}
 
{{Related|Bluetooth}}
{{Related|Bluez4}}
 
 
{{Related|Mouse polling rate}}
 
{{Related|Mouse polling rate}}
 
{{Related articles end}}
 
{{Related articles end}}
  
This article describes how to set up a [[Bluetooth]] mouse through the command line without relying upon a graphical application.
+
This article describes configuration & troubleshooting steps specific to Bluetooth mice. The information here builds on the main [[Bluetooth]] article, and assumes the user has already followed any installation, configuration, or troubleshooting from that article.
  
== Installation ==
+
== Configuration ==
 +
=== Apple Magic Mouse scroll speed ===
 +
If the scroll speed is too slow, you can try
 +
# rmmod hid_magicmouse
 +
# modprobe hid_magicmouse scroll_acceleration=1 scroll_speed=55
  
Install the {{Pkg|bluez}} package which contains the current Linux bluetooth stack (Bluez5). You may also want to install {{Pkg|bluez-utils}} which provides the ''bluetoothctl'' utility. See [[Bluetooth]] for more information.
+
Scroll speed can be set from 0 to 63.
  
If you would prefer to configure bluetooth through the older Bluez4 stack then install the {{Aur|bluez4}}{{Broken package link|{{aur-mirror|bluez4}}}} package from the [[AUR]]. Please consult the [[Bluez4]] article for more information.
+
If the speed suits you, you can make the change permanent in {{ic|/etc/modprobe.d/}}
 +
{{hc | /etc/modprobe.d/hid_magicmouse.conf |<nowiki>
 +
options hid_magicmouse scroll_acceleration=1 scroll_speed=55</nowiki>}}
  
{{Warning|Bluez4 has been deprecated. It is strongly recommended that you use Bluez5 instead.}}
+
=== Apple Magic Mouse middle click ===
 +
If you find the middle click to be too finicky, you can disable it
 +
# rmmod hid_magicmouse
 +
# modprobe hid_magicmouse emulate_3button=0
  
== Bluez5 instructions ==
+
If this setting suits you, you can make the change permantent in {{ic|/etc/modprobe.d/}}
 +
{{hc | /etc/modprobe.d/hid_magicmouse.conf |<nowiki>
 +
options hid_magicmouse emulate_3button=0</nowiki>}}
  
{{Tip|Ensure that the bluetooth daemon is started before continuing.}}
+
=== Mouse pairing and dual boot ===
  
Bluez5 provides the ''bluetoothctl'' utility which provides a simple interface for configuring bluetooth devices.
+
When dual booting Windows and Linux, you may find yourself having to repair your Bluetooth mouse again and again. This will happen every time you switch OS, because when you pair your device, your Bluetooth service generates a unique set of pairing keys.
  
The text below is an example of how you can connect a bluetooth mouse using ''bluetoothctl'':
+
First, your computer stores the Bluetooth device's mac address and pairing key. Second, your Bluetooth device stores your computer's mac address and the matching key. This usually works fine, but the mac address for your Bluetooth port will be the same on both Linux and Windows (it is set on the hardware level). However, when you re-pair the device in Windows or Linux, it generates a new key. That key overwrites the previously stored key on the Bluetooth device. Windows overwrites the Linux key and vice versa.
  
# bluetoothctl
+
To fix the problem, follow the instructions on [https://unix.stackexchange.com/questions/255509/bluetooth-pairing-on-dual-boot-of-windows-linux-mint-ubuntu-stop-having-to-p this post at StackExchange].
[bluetooth]# list
 
Controller <controller mac> BlueZ 5.5 [default]
 
[bluetooth]# select <controller mac>
 
[bluetooth]# power on
 
[bluetooth]# scan on
 
[bluetooth]# agent on
 
[bluetooth]# devices
 
Device <mouse mac> Name: Bluetooth Mouse
 
[bluetooth]# pair <mouse mac>
 
[bluetooth]# trust <mouse mac>
 
[bluetooth]# connect <mouse mac>
 
  
In order for the device to start on boot you may have to create a [[udev]] rule. Please see [[Bluetooth#Bluetoothctl]] for more information.
+
if using a Bluetooth LE device use [https://gist.github.com/5shekel/8b4998a69903438a6aac2f01a44463d3 this] python script,  slightly edited to adapt for arch, originally discussed [https://unix.stackexchange.com/a/413831/43422 here].
  
{{Tip|In case you were using USB Bluetooth dongle and moved it to another USB port, you may need to remove the mouse's MAC address in ''bluetoothctl'' with ''remove <mouse mac>'' command and repeat the entire procedure again.}}
+
== Troubleshooting ==
  
== Bluez4 instructions ==
+
=== Mouse lag ===
  
=== Kernel modules ===
+
If you experience mouse lag you can try to increase the polling rate. See [[Mouse polling rate]] for more information.
  
No additional actions are necessary if the bluetooth service is started using systemd. If it does not work try the following command:
+
You can try to set the minimum/maximum latency for the mouse in BlueZ [https://bbs.archlinux.org/viewtopic.php?pid=1860951#p1860951]:
  
# modprobe -v btusb bluetooth hidp l2cap
+
Add or modify the following section in {{ic|/var/lib/bluetooth/<mac-of-your-adapter>/<mac-of-your-mouse>/info}} (adapt the path accordingly):
  
It loads the kernel modules you need, if they were not loaded automatically.
+
[ConnectionParameters]
 +
MinInterval=6
 +
MaxInterval=9
 +
Latency=44
 +
Timeout=216
  
=== Test ===
+
Also, you can use {{ic|hcitool}} (in {{aur|bluez-hcitool}}) to change latency parameters of the device:
 +
# HANDLE="$(hcitool con | grep '<Bluetooth Mouse mac address>' | awk '{print $5}')"  # get the device handle
 +
# hcitool lecup --handle $HANDLE --latency 0 --min 6 --max 8
  
The following command should show your bluetooth adapter:
+
Note that this method is only effective for the current connection. If the mouse gets disconnected, you'll need to execute again.
  
{{hc|# hciconfig|
+
Alternatively, you can change the default latency settings via debugfs. See {{ic|/sys/kernel/debug/bluetooth/hci0/conn_{latency,{min,max}_interval} }}.
hci0:  Type: BR/EDR  Bus: USB
 
      BD Address: 00:22:43:E1:82:E0  ACL MTU: 1021:8  SCO MTU: 64:1
 
      UP RUNNING PSCAN
 
      RX bytes:1062273 acl:62061 sco:0 events:778 errors:0
 
      TX bytes:1825 acl:11 sco:0 commands:39 errors:0
 
}}
 
  
=== Configure bluetooth mouse ===
+
This example will solve the lag problems, but you must un pair and pair the mouse:
  
The method described here is based in three steps, in this order:
+
# echo 0 > /sys/kernel/debug/bluetooth/hci0/conn_latency
 +
# echo 6 > /sys/kernel/debug/bluetooth/hci0/conn_min_interval
 +
# echo 7 > /sys/kernel/debug/bluetooth/hci0/conn_max_interval
  
# Make the PC learn about the bluetooth mouse.
+
=== Problems with the USB dongle ===
# Grant the mouse permissions to connect.
 
# Make the mouse learn about the PC.
 
  
=== Search your mouse ===
+
If you have trouble with your USB dongle, you may also want to try:
  
First make your mouse discoverable. For example some mouse need to press a button. Then issue the following command:
+
# modprobe -v rfcomm
  
{{hc|# hcitool scan|
+
At this point, you should get an hci0 device with:
Scanning ...
 
        00:07:61:F5:5C:3D      Logitech Bluetooth Mouse M555b
 
}}
 
  
Your mouse bluetooth mac address will be similar to {{ic|12:34:56:78:9A:BC}}. You may also find it in the documentation or on the mouse itself.
+
# hcitool dev
  
=== Connecting the mouse ===
+
Sometimes the device is not active right away. Try starting the interface with:
  
To scan the device (you may need to use {{ic|su -c}} or {{ic|sudo}}):
+
# hciconfig hci0 up
  
hidd --search
+
and searching for devices as shown above.
hcitool inq
 
  
To connect the device:
+
=== Mouse always disconnect ===
  
hidd --connect <bdaddr>
+
If the mouse stops working but works again after restarting bluetooth, you may need to [[Power_management#USB_autosuspend|disable USB autosuspend]] for the selected device.
  
To show your currently connected devices:
+
The issue may also lie in the device timeout and HID settings. See [[#Thinkpad Bluetooth Laser Mouse problems]].
  
hidd --show
+
=== Thinkpad Bluetooth Laser Mouse problems ===
The mouse should show up in this list. If it does not, press the reset button to make it discoverable.
 
  
{{Note|If you have the ipw3945 module loaded (wifi on HP computer) bluetooth would not work.}}
+
If you are experiencing that your Thinkpad Bluetooth Laser Mouse rapidly connects and then (after a few milliseconds) disconnects again every few seconds (when you move the mouse or press a button), try pairing it with the code {{ic|0000}} instead pairing without a code.
  
==== Connecting the mouse at startup ====
+
If the above is unhelpful, the issue may be in the device timeout settings. Edit/create the file {{ic|/etc/bluetooth/input.conf}} and apply the following changes:
  
{{Out of date|This section of the article discusses instructions for the [[SysVinit]] init system. [[SysVinit]] has been replaced by [[Systemd]].}}
+
# Configuration file for the input service
Edit {{ic|/etc/conf.d/bluetooth}}:
+
# This section contains options which are not specific to any
 +
# particular interface
 +
[General]
 +
 +
# Set idle timeout (in minutes) before the connection will
 +
# be disconnect (defaults to 0 for no timeout)
 +
IdleTimeout=0
 +
 +
#Enable HID protocol handling in userspace input profile
 +
#Defaults to false(hidp handled in hidp kernel module)
 +
UserspaceHID=true
  
# Arguments to hidd
+
These changes will prevent device timeout in order to remain connected. The second setting enables userspace HID handling for bluetooth devices. Restart {{ic|bluetooth.service}} to test changes. You also may need a reboot and to re-pair the device.
HIDD_OPTIONS="--connect <enter here your bluetooth mouse mac address>"
 
  
and test the new settings:
+
=== Problems with the Logitech BLE mouse (M557, M590, anywhere mouse 2, etc) ===
  
/etc/rc.d/bluetooth stop
+
In some case, the mouse is paired but not moving when used. The device add to be trusted and unblocked.
hidd --killall #(drop mouse connection)
+
First of all open a terminal and run {{ic|bluetoothctl}}
/etc/rc.d/bluetooth start
+
# Power off the bluetooth: {{bc|[bluetooth] # power off}}
 +
# Power on the bluetooth, then enable the pairing method on the mouse if needed" {{bc|[bluetooth] # power on}}
 +
# List the available bluetooth devices, you have to copy the mouse device ID ''XX:XX:XX:XX:XX:XX'': {{bc|[bluetooth] # scan on}}
 +
# Unpair the device if already paired: {{bc|[bluetooth] # remove ''XX:XX:XX:XX:XX:XX''}}
 +
# '''Trust''' the device: {{bc|[bluetooth] # trust ''XX:XX:XX:XX:XX:XX''}}
 +
# Pair the mouse with the computer: {{bc|[bluetooth] # pair ''XX:XX:XX:XX:XX:XX''}}
 +
# Connect the computer with the mouse: {{bc|[bluetooth] # connect ''XX:XX:XX:XX:XX:XX''}}
 +
# '''Unblock''' the device control: {{bc|[M585/M590] # unblock}}
 +
# Power the bluetooth off and on.
  
{{Note|The above instructions to start the mouse at startup do not work with the now outdated 3.11 bluetooth packages. New versions such as the current (3.32) packages are not affected.}}
+
If the mouse does not work directly, just power off and power on the mouse.
  
If you are using an older version, then to start the mouse at startup, add:
+
== See Also ==
  
hidd --connect <enter here your bluetooth mouse address (No capitals!!!)>
+
* [https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/settings-storage.txt BlueZ settings storage]
 
 
to your {{ic|/etc/rc.local file}}.
 
 
 
{{Note|You can connect any bluetooth mouse and/or keyboard without any further configuration and without knowing the device address. You can do it by adding the --master and/or --server option in HIDD_OPTIONS depending on your device.}}
 
 
 
== Troubleshooting ==
 
 
 
=== Mouse lag ===
 
 
 
If you experience mouse lag you can try to increase the polling rate. See [[Mouse polling rate]] for more information.
 
 
 
=== Problems with the USB dongle ===
 
 
 
If you have trouble with your USB dongle, you may also want to try:
 
 
 
# modprobe -v rfcomm
 
 
 
At this point, you should get an hci0 device with:
 
 
 
# hcitool dev
 
 
 
Sometimes the device is not active right away. Try starting the interface with:
 
 
 
# hciconfig hci0 up
 
 
 
and searching for devices as shown above.
 

Latest revision as of 09:18, 21 September 2019

This article describes configuration & troubleshooting steps specific to Bluetooth mice. The information here builds on the main Bluetooth article, and assumes the user has already followed any installation, configuration, or troubleshooting from that article.

Configuration

Apple Magic Mouse scroll speed

If the scroll speed is too slow, you can try

# rmmod hid_magicmouse
# modprobe hid_magicmouse scroll_acceleration=1 scroll_speed=55

Scroll speed can be set from 0 to 63.

If the speed suits you, you can make the change permanent in /etc/modprobe.d/

 /etc/modprobe.d/hid_magicmouse.conf 
options hid_magicmouse scroll_acceleration=1 scroll_speed=55

Apple Magic Mouse middle click

If you find the middle click to be too finicky, you can disable it

# rmmod hid_magicmouse
# modprobe hid_magicmouse emulate_3button=0

If this setting suits you, you can make the change permantent in /etc/modprobe.d/

 /etc/modprobe.d/hid_magicmouse.conf 
options hid_magicmouse emulate_3button=0

Mouse pairing and dual boot

When dual booting Windows and Linux, you may find yourself having to repair your Bluetooth mouse again and again. This will happen every time you switch OS, because when you pair your device, your Bluetooth service generates a unique set of pairing keys.

First, your computer stores the Bluetooth device's mac address and pairing key. Second, your Bluetooth device stores your computer's mac address and the matching key. This usually works fine, but the mac address for your Bluetooth port will be the same on both Linux and Windows (it is set on the hardware level). However, when you re-pair the device in Windows or Linux, it generates a new key. That key overwrites the previously stored key on the Bluetooth device. Windows overwrites the Linux key and vice versa.

To fix the problem, follow the instructions on this post at StackExchange.

if using a Bluetooth LE device use this python script, slightly edited to adapt for arch, originally discussed here.

Troubleshooting

Mouse lag

If you experience mouse lag you can try to increase the polling rate. See Mouse polling rate for more information.

You can try to set the minimum/maximum latency for the mouse in BlueZ [1]:

Add or modify the following section in /var/lib/bluetooth/<mac-of-your-adapter>/<mac-of-your-mouse>/info (adapt the path accordingly):

[ConnectionParameters]
MinInterval=6
MaxInterval=9
Latency=44
Timeout=216

Also, you can use hcitool (in bluez-hcitoolAUR) to change latency parameters of the device:

# HANDLE="$(hcitool con | grep '<Bluetooth Mouse mac address>' | awk '{print $5}')"  # get the device handle
# hcitool lecup --handle $HANDLE --latency 0 --min 6 --max 8

Note that this method is only effective for the current connection. If the mouse gets disconnected, you'll need to execute again.

Alternatively, you can change the default latency settings via debugfs. See /sys/kernel/debug/bluetooth/hci0/conn_{latency,{min,max}_interval} .

This example will solve the lag problems, but you must un pair and pair the mouse:

# echo 0 > /sys/kernel/debug/bluetooth/hci0/conn_latency
# echo 6 > /sys/kernel/debug/bluetooth/hci0/conn_min_interval
# echo 7 > /sys/kernel/debug/bluetooth/hci0/conn_max_interval

Problems with the USB dongle

If you have trouble with your USB dongle, you may also want to try:

# modprobe -v rfcomm

At this point, you should get an hci0 device with:

# hcitool dev

Sometimes the device is not active right away. Try starting the interface with:

# hciconfig hci0 up

and searching for devices as shown above.

Mouse always disconnect

If the mouse stops working but works again after restarting bluetooth, you may need to disable USB autosuspend for the selected device.

The issue may also lie in the device timeout and HID settings. See #Thinkpad Bluetooth Laser Mouse problems.

Thinkpad Bluetooth Laser Mouse problems

If you are experiencing that your Thinkpad Bluetooth Laser Mouse rapidly connects and then (after a few milliseconds) disconnects again every few seconds (when you move the mouse or press a button), try pairing it with the code 0000 instead pairing without a code.

If the above is unhelpful, the issue may be in the device timeout settings. Edit/create the file /etc/bluetooth/input.conf and apply the following changes:

# Configuration file for the input service
# This section contains options which are not specific to any
# particular interface
[General]

# Set idle timeout (in minutes) before the connection will
# be disconnect (defaults to 0 for no timeout)
IdleTimeout=0

#Enable HID protocol handling in userspace input profile
#Defaults to false(hidp handled in hidp kernel module)
UserspaceHID=true

These changes will prevent device timeout in order to remain connected. The second setting enables userspace HID handling for bluetooth devices. Restart bluetooth.service to test changes. You also may need a reboot and to re-pair the device.

Problems with the Logitech BLE mouse (M557, M590, anywhere mouse 2, etc)

In some case, the mouse is paired but not moving when used. The device add to be trusted and unblocked. First of all open a terminal and run bluetoothctl

  1. Power off the bluetooth:
    [bluetooth] # power off
  2. Power on the bluetooth, then enable the pairing method on the mouse if needed"
    [bluetooth] # power on
  3. List the available bluetooth devices, you have to copy the mouse device ID XX:XX:XX:XX:XX:XX:
    [bluetooth] # scan on
  4. Unpair the device if already paired:
    [bluetooth] # remove XX:XX:XX:XX:XX:XX
  5. Trust the device:
    [bluetooth] # trust XX:XX:XX:XX:XX:XX
  6. Pair the mouse with the computer:
    [bluetooth] # pair XX:XX:XX:XX:XX:XX
  7. Connect the computer with the mouse:
    [bluetooth] # connect XX:XX:XX:XX:XX:XX
  8. Unblock the device control:
    [M585/M590] # unblock
  9. Power the bluetooth off and on.

If the mouse does not work directly, just power off and power on the mouse.

See Also