Difference between revisions of "Bluetooth mouse"

From ArchWiki
Jump to: navigation, search
(Connecting the mouse)
m (Mouse always disconnect: style)
(33 intermediate revisions by 17 users not shown)
Line 1: Line 1:
 
[[Category:Mice]]
 
[[Category:Mice]]
 
[[Category:Bluetooth]]
 
[[Category:Bluetooth]]
[[cs:Bluetooth Mouse]]
+
[[cs:Bluetooth mouse]]
[[ru:Bluetooth Mouse]]
+
[[ja:Bluetooth マウス]]
 +
[[ru:Bluetooth mouse]]
 
{{Related articles start}}
 
{{Related articles start}}
 
{{Related|Bluetooth}}
 
{{Related|Bluetooth}}
 
{{Related|Bluez4}}
 
{{Related|Bluez4}}
{{Related|Bluetooth mouse configuration}}
+
{{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 how to set up a [[Bluetooth]] mouse through the command line without relying upon a graphical application.
 
 
== Installation ==
 
== Installation ==
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 {{ic|bluetoothctl}} utility. See [[Bluetooth]] for more information.
 
  
If you would prefer to configure bluetooth through the older Bluez4 stack then install the {{AUR|bluez4}} package from the [[AUR]]. Please consult the [[Bluez4]] article for more information.
+
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.
{{warning|Bluez4 has been deprecated. It is strongly recommended that you use Bluez5 instead.}}
 
  
 
== Bluez5 instructions ==
 
== Bluez5 instructions ==
{{tip|Ensure that the bluetooth daemon is started before continuing.}}
 
  
Bluez5 provides the {{ic|bluetoothctl}} utility which provides a simple interface for configuring bluetooth devices.
+
{{Tip|
 +
* Ensure that the bluetooth daemon is started before continuing.
 +
* Ensure that the bluetooth device is not blocked by [[rfkill]].
 +
}}
 +
 
 +
The ''bluetoothctl'' utility provides a simple interface for configuring bluetooth devices. The text below is an example of how you can connect a bluetooth mouse using ''bluetoothctl'':
  
For example, autoconnecting a bluetooth mouse can be done as described below:
+
# bluetoothctl
  # bluetoothctl
+
[bluetooth]# list
  [bluetooth]# list
+
Controller <controller mac> BlueZ 5.5 [default]
  Controller <cmac> BlueZ 5.5 [default]
+
[bluetooth]# select <controller mac>
  [bluetooth]# select <cmac>
+
[bluetooth]# power on
  [bluetooth]# power on
+
[bluetooth]# scan on
  [bluetooth]# scan on
+
[bluetooth]# agent on
  /// enable scanning mode on your mouse
+
[bluetooth]# devices
  [bluetooth]# devices
+
Device <mouse mac> Name: Bluetooth Mouse
  Device <mmac> Name: Bluetooth Mouse
+
[bluetooth]# pair <mouse mac>
  [bluetooth]# trust <mmac>
+
[bluetooth]# trust <mouse mac>
  [bluetooth]# pairable on
+
[bluetooth]# connect <mouse mac>
  [bluetooth]# pair <mmac>
 
  [bluetooth]# connect <mmac>
 
  
 
In order for the device to start on boot you may have to create a [[udev]] rule. Please see [[Bluetooth#Bluetoothctl]] for more information.
 
In order for the device to start on boot you may have to create a [[udev]] rule. Please see [[Bluetooth#Bluetoothctl]] for more information.
  
== Bluez4 instructions ==
+
{{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.}}
The instructions discussed beyond this point concern Bluez4.
+
 
=== kernel modules ===
+
== Troubleshooting ==
No additional actions are necessary if the bluetooth service is started using systemd. If it does not work try following.
 
  
The command
+
=== Mouse lag ===
# modprobe -v btusb bluetooth hidp l2cap
 
loads the kernel modules you need, if they were not loaded automatically.
 
  
=== Test ===
+
If you experience mouse lag you can try to increase the polling rate. See [[Mouse polling rate]] for more information.
The following command should show your bluetooth adapter:
 
  
{{hc|# hciconfig|
+
=== Problems with the USB dongle ===
hci0:  Type: BR/EDR  Bus: USB
+
 
      BD Address: 00:22:43:E1:82:E0 ACL MTU: 1021:8  SCO MTU: 64:1
+
If you have trouble with your USB dongle, you may also want to try:
      UP RUNNING PSCAN
+
 
      RX bytes:1062273 acl:62061 sco:0 events:778 errors:0
+
# modprobe -v rfcomm
      TX bytes:1825 acl:11 sco:0 commands:39 errors:0
+
 
}}
+
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 ===
  
== Configure Bluetooth Mouse ==
+
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.
The method described here is based in three steps, in this order:
 
  
# Make the PC learn about the bluetooth mouse.
+
The issue may also lie in the device timeout and HID settings. See [[Bluetooth#Thinkpad Bluetooth Laser Mouse problems]].
# Grant the mouse permissions to connect.
 
# Make the mouse learn about the PC.
 
  
=== Search your mouse ===
+
=== Apple Magic Mouse scroll speed ===
First make your mouse discoverable. For example some mouse need to press a button. Then issue the following command as root:
 
  
{{hc|# hcitool scan|
+
{{Style|Configuration is not troubleshooting.}}
Scanning ...
 
        00:07:61:F5:5C:3D      Logitech Bluetooth Mouse M555b
 
}}
 
  
Your mouse bluetooth 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.
+
If the scroll speed is too slow, you can try
 +
# rmmod hid_magicmouse
 +
# modprobe hid_magicmouse scroll_acceleration=1 scroll_speed=55
  
== Connecting the mouse ==
+
Scroll speed can be set from 0 to 63.
hidd --search
 
hcitool inq
 
to scan the device (you may need to use {{ic|su -c}} or {{ic|sudo}})
 
 
hidd --connect <bdaddr>
 
to connect the device.
 
 
hidd --show
 
will show your currently connected devices. 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 wont work.}}
+
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>}}
  
== Connecting the mouse at startup ==
+
=== Apple Magic Mouse middle click ===
{{out of date|This section of the article discusses instructions for the [[sysvinit]] init system. [[Sysvinit]] has been replaced by [[Systemd]].}}
 
Edit /etc/conf.d/bluetooth:
 
# Arguments to hidd
 
HIDD_OPTIONS="--connect <enter here your bluetooth mouse address>"
 
  
and test the new settings:
+
{{Style|Configuration is not troubleshooting.}}
/etc/rc.d/bluetooth stop
 
hidd --killall (drop mouse connection)
 
/etc/rc.d/bluetooth start
 
  
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 you are using an older version, then to start the mouse at startup, add:
+
If you find the middle click to be too finicky, you can disable it
  hidd --connect <enter here your bluetooth mouse address (No capitals!!!)>
+
  # rmmod hid_magicmouse
to your /etc/rc.local file.
+
# modprobe hid_magicmouse emulate_3button=0
  
Note #2: 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.
+
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>}}
  
== Troubleshooting ==
+
=== Mouse pairing and dual boot ===
=== Mouse lag ===
 
If you experience mouse lag you can try to increase the polling rate. There is a wiki article describing the procedure: [[Mouse Polling Rate]].
 
  
=== Problems with the USB dongle ===
+
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.
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
+
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.
# hcitool dev
 
  
Sometimes the device is not active right away - try starting the interface with
+
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].
# hciconfig hci0 up
 
and searching for devices as shown above.
 

Revision as of 15:49, 23 November 2017

This article describes how to set up a Bluetooth mouse through the command line without relying upon a graphical application.

Installation

Install the bluez package which contains the current Linux bluetooth stack (Bluez5). You may also want to install bluez-utils which provides the bluetoothctl utility. See Bluetooth for more information.

Bluez5 instructions

Tip:
  • Ensure that the bluetooth daemon is started before continuing.
  • Ensure that the bluetooth device is not blocked by rfkill.

The bluetoothctl utility provides a simple interface for configuring bluetooth devices. The text below is an example of how you can connect a bluetooth mouse using bluetoothctl:

# bluetoothctl
[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.

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

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.

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 Bluetooth#Thinkpad Bluetooth Laser Mouse problems.

Apple Magic Mouse scroll speed

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: Configuration is not troubleshooting. (Discuss in Talk:Bluetooth mouse#)

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

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: Configuration is not troubleshooting. (Discuss in Talk:Bluetooth mouse#)

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.