Wiimote Controller Configuration for Raspberry Pi 2/3

36K10334

Intro: Wiimote Controller Configuration for Raspberry Pi 2/3

Nintendo created the Nintendo Wii which uses Bluetooth to connect its wireless Wiimote controllers. The Raspberry Pi is a palm-sized computer that has been used for all sorts of applications and DIY projects. One of these projects is called RetroPie. It allows users to play classic games with the ability to connect a myriad of controllers. Packages to enable the Wiimote to connect to the Raspberry Pi via Bluetooth have been developed. I will assume that you have Raspbian already working on your Raspberry Pi.

The purpose of this instructable is to guide you through the setup of the Nintendo Wiimote as a controller on your Raspberry Pi 2 or 3.

A basic knowledge of the command line in Linux as well as Raspberry Pi features are required. I will give you all the commands you will need to perform in the Linux terminal.

Time Commitment: This instructable will take 30 minutes to 1 hour.

Required Items:

- Raspberry Pi 2/3 and basic components (HDMI cable, monitor, power adapter, keyboard, mouse)

- Bluetooth adapter if you are using a Raspberry Pi 2

- 1-4 Wiimotes

STEP 1: Update Raspberry Pi Software Packages

Update the existing software on your Raspberry Pi. We will be using the Linux Command line to perform all of the commands.

sudo apt-get update
sudo apt-get upgrade

STEP 2: Install the Wiimote Interface Software Packages

The packages "cwiid" and "wminput" were created to interface the Wiimote and Raspberry Pi via bluetooth. The "cwiid" package is the Linux to Nintendo Wiimote interface. The "wminput" is a Linux event, mouse, and joystick driver for the wiimote using the uinput system.

sudo apt-get install python-cwiid
sudo apt-get install wminput

We also need to install the Bluetooth packages for the Raspberry Pi if you are using a Raspberry Pi 2.

sudo get-apt install bluetooth

STEP 3: Create the Wiimote Rule File

We need to change the udev rules so the uinput device will work with non-root users. We will do this by adding wiimote.rules to /etc/udev/rules.d.

sudo nano /etc/udev/rules.d/wiimote.rules

Copy and paste the following into the file:

KERNEL=="uinput", MODE="0666"     

Press CTRL + X , then press Y, then press ENTER to save your changes.

STEP 4: Reboot the Pi or Restart the Udev Rules to Implement the Changes

In order to implement the changes that you made to the rules file, you must either reboot the Raspberry Pi or restart the udev service.

sudo shutdown -r now

or

sudo service udev restart

STEP 5: Check the Status of the Bluetooth

We will be using the bluetooth to connect to the Wiimotes. Check the status by typing the following:

/etc/init.d/bluetooth status

You should see something like in the picture.

Now we know the Bluetooth is working.

STEP 6: Configuring Wiimote Buttons in Wminput

Each Wiimote will need its own controller mapping. My configuration file will have controller mappings for the Wiimote and Nunchuk Buttons.

Create the file with the following command:

sudo nano /home/pi/mywinput

Copy and paste this into the file:

#WiiMote
Wiimote.A  = BTN_A
Wiimote.B = BTN_B
Wiimote.Dpad.X = ABS_Y
Wiimote.Dpad.Y = -ABS_X
Wiimote.Minus = BTN_SELECT
Wiimote.Plus = BTN_START
Wiimote.Home = BTN_MODE
Wiimote.1 = BTN_X
Wiimote.2 = BTN_Y
# Nunchuk
Nunchuk.C = BTN_C
Nunchuk.Z = BTN_Z

Press CTRL + X , then press Y, then press ENTER to save your changes.

STEP 7: Activate the LED's on the Wiimote

The Wiimote will work without this step, but if you would like to see that your Wiimote is connected or which controller mapping is currently mapped to that Wiimote, follow this step.

Add the following to the bottom of the file you just created:

sudo nano /home/pi/myinput
Plugin.led.Led1 = 1
#Plugin.led.Led2 = 1
#Plugin.led.Led3 = 1
#Plugin.led.Led4 = 1

Remove the "# "on the line for the LED's you want to light up. You can go from no LED's lit to all LED's lit to everything in between.

Press CTRL + X , then press Y, then press ENTER to save your changes.

STEP 8: Get Wiimote Addresses

We will create an executable script that will search for Wiimotes and connect them to the Raspberry Pi. To do this we need that addresses of the Wiimotes.

Scan for Wiimotes by typing:

hcitool scan

Press the 1 and 2 buttons simultaneously. After a bit you should see something similar to the screenshot.

Take note of the addresses of your Wiimotes or open another terminal

Note: You might have to redo it if the scan did not find the Wiimotes. If pressing 1 and 2 does not work, try using the red sync button under the battery cover on the Wiimote

STEP 9: Create a Shell Script to Connect the Wiimotes

Now we need to create a script that will connect the Wiimotes when we run it.

Create a directory and file for the script.

Make a directory by typing:

mkdir /home/pi/bin

Create the file by typing:

sudo nano /home/pi/bin/connectwii.sh

Copy and paste this into the file:

#!/bin/bash
sleep 1 # Wait until Bluetooth services are fully initialized
hcitool dev | grep hci >/dev/null
if test $? -eq 0 ; then
    wminput -d -c  /home/pi/mywminput 00:19:1D:48:D8:FD &
    wminput -d -c  /home/pi/mywminput 00:22:D7:C2:A6:B9 &
else
    echo "Blue-tooth adapter not present!"
    exit 1
fi

Note: you need a wminput line for each wiimote you are using.

Replace the addresses above with the addresses of your wiimotes.

If you have different controller mappings for different Wiimotes, replace “mywminput” with your controller mapping. See the example screenshot.

Press CTRL + X , then press Y, then press ENTER to save your changes.

STEP 10: Make the Script Executable

Make the script just created executable by typing:

sudo chmod 775 /home/pi/connectwii.sh

STEP 11: Reboot and Test the Script

Reboot your Raspberry Pi and test your script

sudo shutdown –r now
sudo modprobe uinput
/home/pi/connectwii.sh

Press 1 and 2 on the Wiimotes you want to connect.

You should see the LEDs light up when they are connected.

When all of your Wiimotes are connected, press CTRL + C to close your script.

STEP 12: Test the Wiimote

Install jstest-gtk to test your Wiimote as a controller.

sudo apt-get install jstest-gtk
jstest-gtk

You should see a gui that shows all valid inputs to test.

Select the Wiimote.

Press the buttons to see the Button Presses Register. In the picture, I am pressing the A button. You can see it register because the "Buttons 4" box transitions from white to black.

The Wiimote is configured, and you are ready to play!

STEP 13: Now You Are Ready to Play!

Run the script and connect your Wiimotes before you run your games and emulators.

You are ready to use your Wiimotes as controllers.

Go to https://github.com/retropie/retropie-setup/wiki/First-Installation to learn how to get RetroPie for you Raspberry Pi.

23 Comments

I can't get step 8 to work. No matter how hard I try I can not for the life of me get my wiimote to connect to the Pi, although I've only tried this with one controller. Could it be the wiimote's fault? If not, what do I do?

If you want the programme to start when you boot your Pi then just follow this:

1. Type in "sudo nano /etc/profile.d/10-retropie.sh" (don't copy quotes!)

2. Before the line [ "`tty`" = "/dev/tty1" ] type "rebootWithoutWiimotes=0sudo /home/pi/bin/

connectwii.sh" (or whatever you called it)

3. Then press ctrl + X followed by Y then enter.

4. Then type "sudo reboot"

5. ENJOY!!!

Is there a way to use the nunchuk joystick as a joystick?

Great tutorial but you should really fix all the typos and mistakes, some users will have issues with the steps you have provided.

Im not at all an expert at this, but I did notice that there's a /bin on some of the commands and not on the others, so I was unable to do a couple of things. but when I tried to run the script, it wouldn't open the uinput.....So I'm stuck. Just gonna have to resort to using the logitech for my nintendo games. Any help anyone?

Slight modifications I had to make: -

- where it states '/home/pi/connectwii.sh' replace with '/home/pi/bin/connectwii.sh'

- create the file as 'mywminput' not 'mywinput' or use 'sudo mv /home/pi/mywinput /home/pi/mywminput'' to rename the file if already created

I got it to work with Emulation station....so I can select games, but can't play them using the wiimote.....I've scoured the internet looking for a good tutorial on mapping....nothing works. Any help is greatly appreciated. THANKS!

Good Instructable - have got it configured and working, the controller paired and the test app running successfully. However what I'd like to do it use the buttons on the controller to control gpio pins. Could anybody let me know how I would go about referencing this in a python script? Thanks

Thanks for this tutorial, it really helped!

However, MichaelG671 is right, there are a few holes. I got my controllers working by applying the following patches:

If
using two or more controllers, create a separately numbered
"/home/pi/mywinput" file for each (e.g. mywinput1, mywinput2, etc. [See
below]), fixing the LED code at the bottom to match the controller order
(i.e. remove '#' from Led2 line and put it in front of Led1 line,
etc.). Here is the cleaned up code for the buttons/LEDs to play and
display correctly:

-----STEP 6 & 7-----
Both of the code for these steps go into the same file, not separate files, as the "mywinput" and "myinput" typo (?) suggests.

Create a file. If you have more than 1 controller, I used this system:
"sudo nano /home/pi/mywinput1"
"sudo nano /home/pi/mywinput2"
etc.

#WiiMote
Wiimote.A = BTN_X
Wiimote.B = BTN_Y
Wiimote.Dpad.X = -ABS_Y
Wiimote.Dpad.Y = -ABS_X
Wiimote.Minus = BTN_SELECT
Wiimote.Plus = BTN_START
Wiimote.Home = BTN_MODE
Wiimote.1 = BTN_B
Wiimote.2 = BTN_A
#Nunchuk
Nunchuk.C = BTN_C
Nunchuk.Z = BTN_Z

Plugin.led.Led1 = 1
#Plugin.led.Led2 = 1
#Plugin.led.Led3 = 1
#Plugin.led.Led4 = 1

-----STEP 9-----
Next, here is the "/home/pi/bin/connectwii.sh" file code that correctly identifies the above written file/s:

#!/bin/bash
sleep 1 # Wait until Bluetooth services are fully initialized
hcitool dev | grep hci >/dev/null
if test $? -eq 0 ; then
wminput -d -c /home/pi/mywinput1 00:19:1D:48:D8:FD &
wminput -d -c /home/pi/mywinput2 00:22:D7:C2:A6:B9 &
else
echo "Oopsies! Bluetooth adapter not present."
exit 1
fi

-----STEP 10-----
Text to type in cmd line should read:
"sudo chmod 775 /home/pi/bin/connectwii.sh"

-----STEP 12-----
It installed okay, but "jstest-gtk" didn't work for me at all. Regardless, controllers work fine.

Remember,
if your Pi boots straight into RetroPie, you must exit EmulationStation
and reconnect the Wiimotes by running STEP 11 (without reboot,
obviously) every time you restart. They get lost at every shutdown. :(

root@retropie:/home/pi# /home/pi/bin/connectwii.sh

/home/pi/bin/connectwii.sh: line 12: syntax error: unexpected end of file

root@retropie:/home/pi#

any advice with the above error? much appreciated

#!/bin/bash

sleep 1 # Wait until Bluetooth services are fully initialized

hcitool dev | grep hci >/dev/null

if test $? -eq 0 ; then

wminput -d -c /home/pi/mywminput 00:26:59:F8:67:84 &

wminput -d -c /home/pi/mywminput E0:E7:51:29:32:F2 &

else

echo "Blue-tooth adapter not present!"

exit

Compare your script with the one in the article - One thing I see is that you are missing the "fi" at the end.

thanks for your quick reply...... i think i may need to start from scratch. I am finding ( or think i am) some dependencies throughout this doc (please correct me if i am wrong).

directories we are creating and referencing:

mkdir /home/pi/bin

but we are pointing to : /home/pi

sudo nano /home/pi/myinput

but the screen shot shows : "mywminput" vs mywinput.

am i off or headed in the right direction?

With the following:

#!/bin/bash

sleep 1 # Wait until Bluetooth services are fully initialized

hcitool dev | grep hci >/dev/null

if test $? -eq 0 ; then

wminput -d -c /home/pi/mywinput E0:E7:51:29:32:F2 &

wminput -d -c /home/pi/mywinput 00:26:59:F8:67:84 &

else

echo "Blue-tooth adapter not present!"

exit 1

fi

I was able to register the wimote as a bluetooth device, however in retropi controller config it comes up as a keyboard and i am only able to map the dpad (as keyboard up, down, left, right arrow). No buttons are recognized.

Noob question.... but how can i get this text for button mapping and the LEDs to my Pi which is hooked to my TV and I'm on my laptop reading this. I'm sure this is a basic ass question but I'm pretty new to the whole Raspberry Pi RetroPie thing. Thanks in advance.

How are you connected to your Raspberry Pi? Do you have a keyboard and mouse plugged in or are you using SSH from your laptop?

So I finally figured out to use putty... But now my pi 3 can detect the Mac address for the wiimote, but when I go to connect using python to test it tells me there are no Wiimotes connected, and emulation station can't detect then either. I followed a couple tutorials but no luck.

Dear SteveR246 - the 'sudo apt-get install cwiid' does not work on the stock retropi system - could you please add some clue which repostiory / git source do we need to add to install the cwiid?

More Comments