Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to connect a Wiimote. I'm running natty and would like to control an audio-player with my Wiimote. Is that possible?

share|improve this question
up vote 11 down vote accepted

Edit: Rinzwind tipped me off on a launchpad project called "wiican". Apparently it is implemented as an indicator applet and allows to customise your wii-actions. You could bind e.g. amarok -t to a wiibutton.

You're in luck, and you don't even know how much. It took me a while and a bit of research but: I wrote a script to do just that a while back. It works with Amarok and Totem, though it could easily be modified to control other players (provided they have a command line interface). Give me a few minutes to write a few comments together. Then I will edit this answer and post it.

  • Features:
    • Check battery status of the Wiimote.
    • Switch an led on the Wiimote.
    • Start Amarok.
    • Pause/contiue playing.
    • Skip to next/last track.
    • Control the system volume over alsamixer

You will need python and python-cwiid Install python-cwiid / sudo apt-get install python-cwiid installed. You can do that while waiting.


Blow is the script. Just run it in a terminal.

# indent-mode: spaces, indentsize: 4, encoding: utf-8
# © 2011
# Use permitted under MIT license:
"""A Wiimote script to control totem and amarok under Ubuntu.

Provides a rudimentary interface to:
-Check battery status of the Wiimote.
-Switch an led on the Wiimote.
-Start Amarok.
-Pause/contiue playing.
-Skip to next/last track.
-Control the system volume over pulseaudio

Needs the package 'python-cwiid', 'amarok' and or 'totem' to be installed.


wiimote -- the wiimote object
led -- the status of the led (on/off)


import cwiid
import sys
import os

def main():
    """PC-side interface handles interaction between pc and user.

    b -- battery status
    l -- toggle led
    q -- quit
    h -- print help
    global wiimote

    #Print help text ont startup
    print 'Confirm each command with ENTER.'
    hlpmsg =    'Press q to quit\n'\
                'b for battery status\n'\
                'l to toggle the led on/off\n'\
                'h or any other key to display this message.'
    print hlpmsg

    #Main loop for user interaction
    doLoop = True
    while doLoop:
        c =
        if c == 'b':    # battery status
            state = wiimote.state
            bat = int(100.0 * state['battery'] / cwiid.BATTERY_MAX)
            print bat
        elif c == 'l':  # toggle led
        elif c == 'q':  # exit program
            doLoop = False
        elif c == '\n': # ignore newlines
        else:           # print help message when no valid command is issued
            print hlpmsg

    #Close connection and exit

def connect_wiimote():
    """Connets your computer to a Wiimote."""
    print 'Put Wiimote in discoverable mode now (press 1+2)...'
    global wiimote
    while True:
            wiimote = cwiid.Wiimote(#add address of Wiimote here for speedup)
    wiimote.mesg_callback = callback
    #Set Wiimote options
    global led
    led = True
    wiimote.led = cwiid.LED1_ON
    wiimote.rpt_mode = cwiid.RPT_BTN

def callback(mesg_list, time):
    """Handels the interaction between Wiimote and user.

    A and B together    -- toggle led
    A                   -- play/pause
    up / down           -- fast forward / backward
    right / left        -- next / previous trakc
    + / -               -- increase / decreas volume

    for mesg in mesg_list:
        # Handle Buttonpresses - add hex-values for simultaneous presses
        # Buttons not listed: 0x4 - B, 0x1 - 2, 0x2 - 1 | just babytown frolics
        if mesg[0] == cwiid.MESG_BTN:
            if mesg[1] == 0x8:      # A botton
            elif mesg[1] == 0xC:    # A and B together
            elif mesg[1] == 0x800:  # Up botton
            elif mesg[1] == 0x100:  # Left botton
            elif mesg[1] == 0x200:  # Right botton
            elif mesg[1] == 0x400:  # Down botton
            elif mesg[1] == 0x10:   # Minus botton
            elif mesg[1] == 0x1000: # Plus botton
            elif mesg[1] == 0x80:   # home botton
        # Handle errormessages
        elif mesg[0] == cwiid.MESG_ERROR:
            global wiimote

def change_volume(change):
    """Changes system's master volume."""
    cmd = "amixer get Master | grep 'Front Left' | grep -oP '(?<=Playback\ )\d+'"
    fin,fout = os.popen4(cmd)
    currVol = int( )
    newVol = currVol + change
    os.system( "amixer set Master "+str(newVol) )

def toggle_led():
    """Toggles first led on Wiimote on/off."""
    global led
    if led == True:
        led = False
        wiimote.led = 0
        led = True
        wiimote.led = cwiid.LED1_ON

def player_control(action):
    """Controls Amarok or Totem - depending on wich one is running.

    Totem takes precedence over Amarok if running. If none is running, Amarok
    will be started ant take the command.

    print action
    # Check if totem is running
    cmd = "ps -A | grep -oP 'totem'"
    fin,fout = os.popen4(cmd)
    isTotem =
    isTotem = isTotem.find('totem') != -1
    # Do the actual player action
    if action == 'nexttrack':
        if isTotem:
            cmd = "totem --next"
            cmd = "amarok -f"
    elif action == 'lasttrack':
        if isTotem:
            cmd = "totem --previous"
            cmd = "amarok -r"
    elif action == 'playpause':
        if isTotem:
            cmd = "totem --play-pause"
            cmd = "amarok -t"
    elif action == 'ffwd':
        if isTotem:
            cmd = "totem --seek-fwd"
    elif action == 'fbwd':
        if isTotem:
            cmd = "totem --seek-bwd"

share|improve this answer
Wow. Thanks a lot. You're the killer! A GUI would have been nice too but nevermind. It's perfect. – jordannormalform Jun 13 '11 at 0:33
Glad you like it. A gui would be overkill for just toggling a led and query the battery status. But feel free to write it on your own. – con-f-use Jun 13 '11 at 0:39

There is also a GUI program that sits on the system tray, called "Wiican". I used to use on previous versions of ubuntu before 11.04 (Natty) but now I can't seem to know how to install it with the PPA found at

It just connects and configures buttons as you wish, yet not perfect but I would call it great

will update the post once I find out how to install.

Edit: I was able to find a package at this link

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.