I was asked to write a small guide about how to connect the Wii remote with the computer and how to access all the sensors and buttons.

There are one problem a lot of people find when they try to use the Wii Remote with the computer. The problem is the so called Bluetooth Stack.. Easily explained it is the software the Bluetooth device uses to connect with the rest of the computer. It is what makes it possible to read and write to a Bluetooth device.

Different Bluetooth devices might use different preferred stacks. There are different kinds of stacks. The most common are called BlueSoleil, Widcomm and the default Windows Stack.

Some API:s only work with a single stack and that makes it hard for programmers to access the Wii Remote, especially when the Bluetooth stack your Bluetooth Dongle work with seems kind of random and hard to find out when you buy it.

For me the default Windows Bluetooth Stack worked good with my laptops integrated bluetooth card, but most people won't be so lucky and may have to try different stacks och buy different dongles. There are however lots of information about this on the web and Google will make your life easier.

Okey.. Now if you have got the correct Bluetooth stack up and running, we can move on.

Since I used the default Windows Bluetooth stack I'll tell you how to pair the Wii Remote with your computer using that.

This is how I do it:
1. Locate the Bluetooth icon in the taskbar.
2. Right click and select "Add Bluetooth Device"
3. Now press and hold the "1" and "2" buttons. Keep holding until I tell you to let go.
4. Check the "My device is set up and ready.." box and click next.
5. Select the device that called something with nintendo, wii or remote.
6. Click next.
7. When you receive a message that the device was added successfully and is ready to be used, you can let go of the "1" and "2" buttons and celebrate because you are now ready to access it with your API.

I tried two different ways of programming for the Wii Remote:

A - GlovePIE
B - WiiFlash

A - GlovePIE http://glovepie.org
or Glove Programmable Input Emulator is a program that emulates different input devices. It works with lots of different input devices, everything from the Playstation SixAxis and the Wii Remote to MIDI controllers and head trackers.

What it does is basically map a input device to a other output device. You can use the Playstation SixAxis as a mouse or Wii Remote as a MIDI controller to controll your favorite music software. So.. You can use any input device to simulate another device.

With this software you can access all the values from the accelerometers, buttons and the IR camera on the Wii Remote.

B - WiiFlash http://wiiflash.bytearray.org/
This is the API we used in our demo. It consists of two parts:

1 - A socket server accessible from Flash
2 - An API used to connect to the server and access all the different values.

The socket server is needed because flash can't access Bluetooth devices directly and is a plug-n-play program.. No configuration needed.

The API is really straight forward and it is really easy to access all the values from the sensors.

There are just a few lines of code to access the values. Here is for example how to access the IR-camera and get the tracking data from it and assign the values to two variables:

//Flash Actionscrip3 code written in the first frame of the movie:
// -- 1 --
import org.wiiflash.Wiimote;
import org.wiiflash.events.WiimoteEvent;
import flash.events.*;
// -- 2 --
var myWiimote:Wiimote = new Wiimote();
var xpos;
var ypos;
// -- 3 --
myWiimote.connect();
myWiimote.addEventListener(WiimoteEvent.UPDATE, onUpdated);
// -- 4 --
function onUpdated(pEvt:WiimoteEvent):void{
xpos = stage.stageWidth - (myWiiremote.ir.x1*stage.stageWidth);
ypos = stage.stageHeight - (myWiiremote.ir.y1*stage.stageHeight);
}
//End of Code

1. Okey.. So first we import the required libraries.
2. Then we define some variables and our Wii Remote object.
3. Then we connect to the Wii Remote(it is really not connecting to the Wii Remote but instead it connects to the server..) we also add an eventlistener so we can tell if something happens with the Wii Remote.
4. The we write the function the eventlistener calls. Here we assign the variables xpos and ypos the value of the first Infrared "blob" the camera sees. The camera can detect up to four "blobs" and their position can be accessed with the myWiiremote.ir.x1 and ...y1 commands.. (and the other blobs with x2, x3 and so on..)

Well.. To sum up.. The Bluetooth stack is the biggest problem... Only some stacks works with certain Bluetooth dongles... Only some stacks works with some APIs... When successfully paired with the computer it is easy to access the values from the sensors... And the Wii Remote has some powerful sensors(three axis accelerometer and 1024*768 100fps IR-camera with integrated hardware tracking.)

Well that what I can think of for now.. Enjoy!

0 kommentarer: