Lightguns were the last thing on my list to configure for my arcade machine. This is an attempt at documenting how to get WiiMotes to work in a Modern version of Mame on Linux. I’m using XUbuntu, but it should work on most things.
Important information I figured out along the way:
-http://spritesmods.com/?art=wiimote-mamegun - This had most of the information. Unfortunately it is out of date. His MAME patch has since been merged into MAME and his instructions for the MAME part are wrong. I’ve stolen much from there to document it in one place. If part isn’t clear, see his guide up until the Mame setup.
-Bluetooth pairing with the WiiMotes does work using the present BlueZ stack (provided you have a non -TM labeled WiiMote) but it isn’t automatic when you turn on the WiiMotes. I couldn’t figure out how to force the pairing even when the devices were trusted.
-XWiiMote is getting there but doesn’t support IR yet when I was testing it. Stick to WMInput with cwiid like this guide shows.
I’m going to setup two WiiMotes so that MAME sees two light guns. I’m using a bluetooth dongle for this and an IR Source.
IR Source choices:
-Wireless Sensor Bar
-Modified wired bar, many of the old style wire bars run off 5V. If your’s does, you can take off the end and solder on a USB connection (Pin 1 and 4 on USB, center two are data). Power the sensor over a USB port on your mame box! Careful the LEDs will only light with the wires in one direction. You can find snap on USB ends around the internet. I tied a knot in my wire before installing the end to function as strain relief.
Step 1) Get WiiMotes working as Mice.
apt-get install bluetooth wminput lswm evtest
You’ll need to load a module in the kernel
sudo modprove uinput
You won’t want to do this at each boot so tell Linux to load the module.
sudo nano /etc/modules
On the last line add:
Try to connect a WiiMote (You’ll want to disconnect it from the Wii, red button on console while it is on). Press 1+2 on the WiiMotes (possibly need the red button on back of WiiMote) and run:
You can do this one at a time or have both flashing when you start lswm. It’s going to list out the address of the WiiMotes it has detected. Copy them down.
Let’s test one without the IR source. Run the following after pressing the 1+2 buttons:
sudo wmimput ONEofTHEaddressesHERE
Tilt the WiiMote and your mouse should move on screen.
Edit the config file to use IR:
sudo nano /etc/cwiid/wminput/ir_ptr
On these lines: “Plugin.ir_ptr.X = ~ABS_X” (and the Y line), remove the tilde and save. They should look like “Plugin.ir_ptr.X = ABS_X”. You can add custom mappings here for each button if you like. Documentation is abundant online. I’m going to use the stock settings.
Run wminput with this profile:
sudo wminput -c ir_ptr ONEofTHEaddressesHERE
Setup the WiiMote scripts to run at boot. Once you pair your WiiMote (pressing 1+2) they will start functioning as a mouse.
Download this file: http://www.novaslp.net/download/wiimote/wiimote (Modified from Sprites for 2 WiiMotes). You’ll need to modify two lines near the top that read WM_BDADDR1 and WM_BDADDR2. Switch them to be the two addresses of your WiiMotes that you got from LSWM
Place it in: /etc/init.d using cp.
chmod 755 /etc/init.d/wiimote
sudo update-rc.d wiimote defaults 80 20
If you aren’t on a Debian distro, make sure this gets run at startup after bluetooth starts. This runs wminput with IR source flags as a daemon in the background.
Reboot. When you start back up, press 1+2 on the WiiMotes and see if they function as mice.
Step 2) Make X server recognize them as named devices.
X already can take the input and use them as Mice but it has internal names. We need to specify names for them so that we can tell Mame what they are called. We’ll do this by modifying the Xorg.conf. If you are on a modern version of X, you may not have one. We can generate one though! I found documentation here: http://ubuntuforums.org/showthread.php?t=2123353
First figure out what ID uinput gave your WiiMotes. Connect them (press 1+2) and then check out /dev/input/
It’s probably the last two objects but just to be sure, use evtest to check them out.
Once we know which two are WiiMotes, we need to tell X about them.
Press CTRL-ALT-F1 and login
sudo service lightdm stop
(This kills XWindows on XUbuntu, If you are on plain Ubuntu sub gdm for lightdm)
sudo Xorg -configure
Edit the newly (sudo nano xorg.conf.new) generated file and add the following:
Option "Device" "/dev/input/event4"
Option "SendCoreEvents" "True"
Option "Device" "/dev/input/event5"
Option "SendCoreEvents" "True"
Change the devices to the devices you discovered using evtest. WiiMote0 and WiiMote1 are going to be the names we tell Mame to use.
Add these devices to the server layout section of the X config also.
You can see my completed Xorg.conf here: http://www.novaslp.net/download/wiimote/xorg.conf
Yours should look similar, but most likely not exactly the same.
Save and copy the file to where it needs to be:
sudo cp xorg.conf.net /etc/X11/xorg.conf
Restart X or reboot to restart it.
sudo service lightdm start
For me, X would crash/quit when I’d log in. If this happens to you make sure that your users .Xauthority file isn’t owned by root.
ls -la ~/.Xauthority
If it is owned by root, run the following:
chown usernamehere:usernamehere ~/.Xauthority
Assuming X started, your WiiMotes should still function as Mice.
Step 3) Configure Mame
Edit your mame.ini (mine sits in /home/username/.mame)
Under core input options, switch the following to be set like this:
For games that use Offscreen reload, point to the lower right site of the screen and pull the trigger to reload.
Mame will detect these as WiiMotes but sets them up as joysticks. This is okay but we’ll need to tell it that we don’t have a deadzone otherwise the WiiMote will stall around mid screen.
Add a line to the Mame.ini:
Find the core input enable options and tell it the following device settings
After that add two lines to tell mame which lightgun is which.
Save this file. Start mame and enter the controls setup for player 1 and 2 (Default is tab key)
Clear all the lightgun controls except the X and Y positions.
Lightgun X Analog for player 1 should read Joy 1 A0 Nintendo WiiMote and Lightgun Y Analog for player 1 should read Joy 1 A1 Nintendo WiiMote. If it has any extra settings, clear the setting by pressing Delete then hit Enter to set a new mapping. Move your WiiMote up/down and left/right to set the respective axis. I also cleared settings for Axis increments and decrement.
I also set default button B to be fire (Mame button 1) and button A (Mame button 2) to be alternate reload.
Try a light gun game. Inside the games you’ll be able to access the Tab menu and set controls specific for that game. Here is where you’ll be able to adjust sensitivity and enable it to show a positional cursor.
If you want to set these in the default config file for mame instead of through the UI, my settings for the AXIS were:
If everything here worked you should see silky smooth movement of a cursor in light gun games on Mame. Congrats!
Let me know if you have any problems with this configuration!