Tuesday, 5 June 2007

Wiimote under FreeBSD using bsdmoted

I have recently acquired a Wii and the Wiimote is an interesting creation indeed. Some attempts to reverse engineer it has been made and I found that FreeBSD has a driver. Sadly though, it lacks good documentation so I thought that I would walk through what I made in order to make it work.

First of all, we need to enable Bluetooth device support by loading the ng_ubt Bluetooth module into the kernel.

If you want it to load upon boot add the following line to /etc/loader.conf

/etc/loader.conf
ng_ubt_load="YES"

And load the module immediately in order to detect any Bluetooth devices. Afterwards check dmesg in order to check if any device was detected. In my case I had to remove the BT USB stick and then insert it again for it to work properly. Somehow it seems that the O/S won't detect it properly if ng_ubg wasn't loaded when the device was first detected.

# kldload ng_ubt

Then we need to make config for the Bluetooth daemon, the default conf will do just fine.

# cp /usr/share/examples/netgraph/bluetooth/rc.bluetooth /etc/rc.bluetooth
# chmod +x /etc/rc.bluetooth
# /etc/rc.bluetooth start ubt0

Now we are on to starting the bthid daemon. First let's use the default conf. If you are unable to start bthid due to some load command (yes, I admit that I have forgot which command it was AND lost the link to the solution). Then you need to upgrade to the latest STABLE RELENG_6, where the problem has been solved.

# cp /usr/src/usr.sbin/bluetooth/bthidd/bthidd.conf.sample /etc/bluetooth/bthidd.conf
# /etc/rc.d/bthid start

Now on to getting your Wiimote's BD_ADDR. You will probably have a bundle of BT devices nearby if you live in an apartment. I detected "Willy's mobile" for example. Press 1 and 2 simultaneously on the Wiimote and it will enter a detectable mode. Then execute a following command and note down all BD_ADDR of the devices that responds.

# hccontrol -n ubt0hci inquiry
[a list of devices]

When you request the name of the device (the Wiimote should still be blinking on happily in 1 + 2 detectable mode) it should respond accordingly. It will of course use another BD_ADDR.

# hccontrol -n ubt0hci remote_name_request 12:34:56:78:9A:BC
BD_ADDR: 12:34:56:78:9A:BC
Name: Nintendo RVL-CNT-01

Now you need to fetch the bsdmoted source. Get the latest version from. http://sourceforge.net/projects/bsdmoted/
Extract it somewhere and cd into the directory. Then clean, compile, install clean.

# make clean
# make
# make install
# make clean

You now need to configure bsdmoted with some info from the Wiimote. Execute the following command to do this.

# bthidcontrol -a 12:34:56:78:9A:BC query >> /usr/local/etc/bsdmoted.conf


Now you only need to start the bsdmoted daemon.

# bsdmoted

The binds are the following:
A is the left mouse button.
B is the right mouse button.
+ and - are used to calibrate the sensitivity .
Use 1 and 2 to switch between IR-mode and tilting mode.

I did not get the IR-mode working, but perhaps you do. Enjoy!

Recommended reading:
The FreeBSD handbook on Bluetooth.

bsdmoted links:
The bsdmoted Sourceforge page.
Chuan-Heng Hsiao's bsdmoted page (videos showing that it actually works).

1 comments:

Bug said...

I am using bsdmoted 0.4.0 on FreeBSD 7.
bsdmoted 0.4.0 is conflicts with bthidd, so i need to stop it. Simple steps to get it work:
1) Get the BD_ADDR
hccontrol -n ubt0hci inquiry
2) compile and install bsdmoted
3) bthidcontrol -a BD_ADDR query >> /usr/local/etc/bsdmoted.conf
4) Press the red sync button besides the batteries && bsdmoted -d