NSLU2-Linux
view · edit · print · history

HowTo.ConnectWiimoteDebianPython History

Hide minor edits - Show changes to markup

August 26, 2008, at 06:04 AM by Diarmuid --
Changed lines 30-31 from:

http://www.lukulu.com/files/wii.pys

to:

http://www.bluekulu.com/files/wii.pys

February 14, 2008, at 01:54 PM by Diarmuid Wrenne --
Changed lines 23-24 from:

Use the code from www.wiili.org/index.php/Wiiewer and respect the license DWTFYWT public licence.

to:

Use the code from http://www.wiili.org/index.php/Wiiewer and respect the license DWTFYWT public licence.

Changed lines 30-31 from:

www.lukulu.com/files/wii.pys

to:

http://www.lukulu.com/files/wii.pys

February 14, 2008, at 01:53 PM by Diarmuid Wrenne -- wiimote on debian with python and pybluez
Changed line 16 from:

apt-get bluez-utils

to:

apt-get bluez-utils\\

Changed lines 23-26 from:

Use this code and respect the license.

Change the address as required. Don't worry about pairing and all the rubbish. It's not needed. The critical thing is to make sure bluetooth is going

to:

Use the code from www.wiili.org/index.php/Wiiewer and respect the license DWTFYWT public licence.

Change the address as required. Don't worry about pairing and all the rubbish. It's not needed. The critical thing is to make sure bluetooth is going using hcitool dev and hcitool scan.

Changed lines 28-102 from:


#!/usr/bin/python

  1. Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
  2. This program is free software. It comes without any warranty, to
  3. the extent permitted by applicable law. You can redistribute it
  4. and/or modify it under the terms of the Do What The Fuck You Want
  5. To Public License, Version 2, as published by Sam Hocevar. See
  6. http://sam.zoy.org/wtfpl/COPYING for more details.

from bluetooth import BluetoothSocket?, BluetoothError?, L2CAP? import thread, time

WIDTH = 512 HEIGHT = 256 # Don't change this one ADDRESS = '00:1E:35:06:E5:CE' # Change this one, of course

  1. Listening thread

def listener():

    global connected, sensor
    fdin.settimeout(0.1)

    while connected == 1:
        try:
            msg = fdin.recv(23)
        except BluetoothError?:
            continue
        if len(msg) >= 7:
            for c in range(3):
                sensor[c] = ord(msg[4 + c])

    fdin.close()
    fdout.close()
    connected = -1
  1. Try to connect to Wiimote

print 'connecting to Wiimote ' + ADDRESS + ', please press buttons 1 and 2' fdin = BluetoothSocket?(L2CAP?) fdin.connect((ADDRESS, 0x13)) fdout = BluetoothSocket?(L2CAP?) fdout.connect((ADDRESS, 0x11)) if not fdin or not fdout:

    raise 'could not connect to Wiimote, check the address'
  1. Run listener

old = [127] * 3 sensor = [127] * 3 connected = 1 thread.start_new_thread(listener, ()) fdout.send("\x52\x12\x00\x31") x = 0 y = 0 z = 0

  1. Main display loop

while connected == 1:

    for c in range(3):

        if c == 0:
            x = sensor[c]
        if c == 1:
            y = sensor[c]
        if c == 2:
            z = sensor[c]
    print "s,(x,y,z)
    time.sleep(0.5)

while connected == 0:

    time.sleep(0.5)

\\

to:

ps. Use my code as it does not require pygame and has a simpler output. www.lukulu.com/files/wii.pys

Now that you have that done, scratch your head and wonder the age old question of geekery ... "why?"

February 14, 2008, at 01:44 PM by Diarmuid Wrenne --
Added lines 1-102:

Copied from http://www.nslu2-linux.org/wiki/HowTo/ConnectWiimoteDebian
Edited for the Debian Slug

In this page I will describe how to connect a Nintendo wiimote on your slug. This document follows on from the debian link ConnectWiimoteDebian. In that page just go as far as the following bit that gets the address of the mote.

hcitool scan

Please note the address of the wiimote is returned. This number is the address of the wiimote.

I log in as root. use sudo otherwise

Install Python, bluez and python-bluez


apt-get bluez-utils apt-get python
apt-get install python-bluez

I tried installing from code, but the compile failed. There is the python-bluez package which is why I love this platform. ARM rules. Create a file called wii.py

Use this code and respect the license.

Change the address as required. Don't worry about pairing and all the rubbish. It's not needed. The critical thing is to make sure bluetooth is going

Easy Peezy Lemon Squeezy!!
#!/usr/bin/python

  1. Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
  2. This program is free software. It comes without any warranty, to
  3. the extent permitted by applicable law. You can redistribute it
  4. and/or modify it under the terms of the Do What The Fuck You Want
  5. To Public License, Version 2, as published by Sam Hocevar. See
  6. http://sam.zoy.org/wtfpl/COPYING for more details.

from bluetooth import BluetoothSocket?, BluetoothError?, L2CAP? import thread, time

WIDTH = 512 HEIGHT = 256 # Don't change this one ADDRESS = '00:1E:35:06:E5:CE' # Change this one, of course

  1. Listening thread

def listener():

    global connected, sensor
    fdin.settimeout(0.1)

    while connected == 1:
        try:
            msg = fdin.recv(23)
        except BluetoothError?:
            continue
        if len(msg) >= 7:
            for c in range(3):
                sensor[c] = ord(msg[4 + c])

    fdin.close()
    fdout.close()
    connected = -1
  1. Try to connect to Wiimote

print 'connecting to Wiimote ' + ADDRESS + ', please press buttons 1 and 2' fdin = BluetoothSocket?(L2CAP?) fdin.connect((ADDRESS, 0x13)) fdout = BluetoothSocket?(L2CAP?) fdout.connect((ADDRESS, 0x11)) if not fdin or not fdout:

    raise 'could not connect to Wiimote, check the address'
  1. Run listener

old = [127] * 3 sensor = [127] * 3 connected = 1 thread.start_new_thread(listener, ()) fdout.send("\x52\x12\x00\x31") x = 0 y = 0 z = 0

  1. Main display loop

while connected == 1:

    for c in range(3):

        if c == 0:
            x = sensor[c]
        if c == 1:
            y = sensor[c]
        if c == 2:
            z = sensor[c]
    print "s,(x,y,z)
    time.sleep(0.5)

while connected == 0:

    time.sleep(0.5)

\\

view · edit · print · history · Last edited by Diarmuid.
Originally by Diarmuid Wrenne.
Page last modified on August 26, 2008, at 06:04 AM