Tag Archive for 'bluetooth'

Programming with the WiiMote (II)

I will use in the following posts Ubuntu Linux (8.04) as operating system, that I’ll give some specific tips only for it, on other systems some things might work different, but the code should work without modification everywhere. At first we need to install some software requirements, the python wrapper for the WiiMote and for general Bluetooth actions the bluez python wrapper:

sudo apt-get install python-cwiid python-bluez

To start simple, we have to read out the adress of the WiiMote we use, this is done by activating our bluetooth device, pressing 1+2 on the WiiMote and running the following command:

hcitool scan

After about 10 seconds this will produce an output like this:

00:1F:45:8B:22:6F    Nintendo RVL-CNT-01

The first of this two columns is the identifier of your WiiMote which we will need for our first python script. For the beginning we only want to connect with our WiiMote and let the LEDs blink. Knowing the Hardware adress of the WiiMotes simplifies the connection via python:

import cwiid

wiimote = cwiid.Wiimote(”00:1F:45:8B:22:6F”)

Now after we connected to the WiiMote via Python(you still need to press 1+2 while the connection is initiated) we want let the LEDs blink. This is done by setting the wiimote.led to valid mask. For example, if you want to turn on the LEDs 1, 3 and 4 this is done via this short code snippet:

wiimote.led = cwiid.LED1_ON | cwiid.LED3_ON | cwiid.LED4_ON

To let them blink, we put all in this in a never-ending while loop and get the following whole script:

import cwiid
import time

wiimote = cwiid.Wiimote("00:1F:45:8B:22:6F")

while True:
    time.sleep(0.1)
    s.led = cwiid.LED1_ON | cwiid.LED4_ON
    time.sleep(0.1)
    s.led = cwiid.LED2_ON | cwiid.LED3_ON

Programming with the WiiMote (I)

This year we will make a workshop at my school about programming with the WiiMote. In parallel to this workshop I will give a small round-up every week on our process in the form of a tutorial. Things mentioned in this tutorial are not all from the workshop since this article is published before any meeting of our workshop.

As the first step, we want just see what information the WiiMote provides. We are using the programm “WMGui”. The WiiMote is connected to use with this program by the following:

  1. Turn on the bluetooth of you PC
  2. Start wmgui
  3. Press the buttons 1 and 2 of the WiiMote simultaneously to make it discoverable
  4. Choose File->Connect in the wmgui-menu

By default only the Buttons section is enabled, here a button is highlighted green if it is pressed. You could press any button without fear, at the moment they do not modify anything. The most interesting thing on the WiiMote for a common user are the acceleration sensors which we could enable by Settings->Acc Data. X, Y, Z show the acceleration in the different coordinate directions. Acc shows the acceleration of the motion in all directions. Roll shows the position of the WiiMote, exactly its sidewards position, 0 is when it rests upside up on the table. Pitch shows the position on the other axis(front/back). There are only 2 values of positioning since the WiiMote could only be turned on two axes, front up/down or turning sidewards. People already knowing more about the WiiMote will be more interested in the IR camera which is activated through Settings->IR Data. If you want to play a bit, take a look under Controls->…, this gives you the probability to switch on the different LEDs on the WiiMote and to let it rumble!

Keep up for coming posts getting into detail with the WiiMote, we will start programming ;-)