loading

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 /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 /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.

<p>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?</p>
Try sudo apt-get install python-cwiid.
Could use this to configure the wii remote as a gun for gun games ?
<p>Awesome. If you can hook up a wiimote with a raspberry pi you could get all kinds of gesture controls to work with your projects.</p>

About This Instructable

4,758views

84favorites

License:

More by SteveR246:Wiimote Controller Configuration for Raspberry Pi 2/3 
Add instructable to: