7
\$\begingroup\$

I am looking for a guide on connecting WiiMote with Unity 5 as an Input device. I found this library here but I do not understand how to install it and what the prerequisites are for it to work.

\$\endgroup\$
  • 1
    \$\begingroup\$ In the past (on 4.x free), I've used an external program, GlovePIE (or OSCulator on Mac), to interface with the device, and pass messages to Unity via Open Sound Control messages. There's a library called OSCuMote to do this. It works for quick & dirty prototyping, but is probably not a release-quality approach. (UniWii sounds better, but I don't have personal experience using it so I'd be guessing) If the OSC approach is sufficient for your needs, let me know in a reply and I'll write up the details as an answer. \$\endgroup\$ – DMGregory May 4 '15 at 14:44
  • \$\begingroup\$ Well this is for a University project to learn how to communicate with external devices (e.g. kinect, occulus rift, wiimote, leapmotion etc). The thing is Nintendo has this all set up on their own so the developer does not have to worry about this, but there is no support for Unity 5 as of yet) \$\endgroup\$ – John Demetriou May 4 '15 at 14:46
  • \$\begingroup\$ @DMGregory i'm trying not to over complicate things just a simple gyro and button input from WiiMote \$\endgroup\$ – John Demetriou May 4 '15 at 16:14
  • \$\begingroup\$ stackoverflow.com/q/36111435/3118024 \$\endgroup\$ – Bradman175 Aug 25 '16 at 1:41
  • \$\begingroup\$ @Bradman175 That question was asked one year after mine :) \$\endgroup\$ – John Demetriou Aug 25 '16 at 6:32
1
\$\begingroup\$

I tried to look into the UniWii library linked in the question, but the Windows download page appears to be a broken link at the moment, and forum threads about it are mostly 4 years old. :(

The basic idea it uses, a native plugin DLL referenced from C# with [DllImport] mappings, is a good one. I've used this successfully for interfacing with the Kinect and Playstation Move controllers, so if you find a working download of an up-to-date version of this plugin, it's probably a better & more robust option that what I'm about to present below.


The method I've used to get Wii Remote information into Unity (or Flash) is to install an external program like GlovePIE on Windows or OSCulator on Mac. These programs do Programmable Input Emulation, effectively communicating with a wide variety of devices and giving you tools to control how they talk to each other.

Both expose the ability to send & receive data via Open Sound Control messages, which we'll listen for within Unity to read the data coming from the Wii Remote.

I'll describe the GlovePIE method because I'm most familiar with working on Windows.

  1. Make sure your computer's Bluetooth adapter is on.

  2. Run GlovePIE and fill a new script with something like this:

(You can save this as a new ".PIE" file to load it later)

var.port = 54934

debug = "On: " + Wiimote1.Exists + " Wiimote battery level: " + Wiimote1.Battery + " Rotation: " + Wiimote1.YawSpeed

SendOsc("localhost", var.port, "/wii/1/start", true)
SendOsc("localhost", var.port, "/wii/1/acceleration", tostring(Wiimote1.gx), tostring(Wiimote1.gy), tostring(Wiimote1.gz))
SendOsc("localhost", var.port, "/wii/1/rotationSpeed", tostring(Wiimote1.PitchSpeed in radians), tostring(-Wiimote1.YawSpeed in radians), tostring(Wiimote1.RollSpeed in radians))
SendOsc("localhost", var.port, "/wii/1/analog", tostring(Wiimote1.Nunchuk.JoyX), tostring(Wiimote1.Nunchuk.JoyY))
SendOsc("localhost", var.port, "/wii/1/buttonA", int(Wiimote1.A))
SendOsc("localhost", var.port, "/wii/1/buttonB", int(Wiimote1.B))
SendOsc("localhost", var.port, "/wii/1/buttonC", int(Wiimote1.Nunchuk.C))
SendOsc("localhost", var.port, "/wii/1/buttonZ", int(Wiimote1.Nunchuk.Z))
SendOsc("localhost", var.port, "/wii/1/button1", int(Wiimote1.One))
SendOsc("localhost", var.port, "/wii/1/done", true)
  1. Click the "Run" button in GlovePIE. It's now scanning for Wii Remotes.

  2. Set the Wii Remote on a flat surface (so the initial calibration is stable)

  3. Press the 1 & 2 buttons on the Wii Remote at the same time.

All 4 lights on the remote should blink - the Wii Remote is scanning for receivers

  1. Wait for Windows to do its "installing new hardware" nonsense.

You can ignore this, including any dialogs saying you need to restart (they lie).

  1. Lights 1 & 4 should come on solid, lights 2 & 3 off.

GlovePIE has found the remote

  1. Lights 2 & 3 should come on solid, lights 1 & 4 off.

GlovePIE is calibrating the sensors. Keep the remote still, or it will calibrate forever (which it sometimes does anyway).

  1. Light 1 should come on solid, the rest off

The remote is registered as player 1 and is sending data over Open Sound Control messages.

The Debug box in GlovePIE should show that the remote exists, report its battery level, and show the current yaw rotation data. (That's the second line of the script above). If you're not getting yaw data when you rotate the controller, then you should power it off and try pairing it again.

  1. You can stop & start your Unity game or PIE script as much as you want and the remote will "just work" until it's turned off.

Note that when you stop the script, the lights turn off, but the remote is still ON and draining the battery. If you're not using the remote for a while, hold the power button to turn it off. You'll have to start again from step 3 when you want to use it again.

Okay, so that's how to get the data into your computer. Now you can use a library like OSCuMote (download link) to read the OSC messages coming in on port 54934 and access the data in your Unity C# scripts.

I'll try to clean up the C# script I wrote for this in my last project and include it as part of this answer.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I was having the same issue all day (not finding the dll) and I think this one is the same code.google.com/p/3div-project/source/browse/trunk/… \$\endgroup\$ – John Demetriou May 4 '15 at 17:39
  • \$\begingroup\$ Small question though about windows 8.1 How did you connect with the wiimote? I mean did you add it in bluetooth devices or something like that before interfacing with it via unity? \$\endgroup\$ – John Demetriou May 6 '15 at 6:17
  • 1
    \$\begingroup\$ @John Demetriou, I'm afraid I've only done this with Windows Vista and 7. Win 7 didn't need any setup under Bluetooth Devices, but I don't know for sure if any extra steps are needed on Windows 8/8.1. I do know that connecting the DualShock 4 only got easier from Windows 7 to 8, so I'd hope that's the case for the Wii Remote too. \$\endgroup\$ – DMGregory May 6 '15 at 8:24
  • \$\begingroup\$ What's the process for dualshock? \$\endgroup\$ – John Demetriou May 6 '15 at 10:58
  • \$\begingroup\$ @John Demetriou, on Win 8, you put it into pairing mode by holding Share & PS buttons until you get a strobing blink from the light bar, then add it via the Bluetooth Devices settings screen. In Win 7 it's more complicated: gamedev.stackexchange.com/questions/87106/… We're straying off-topic though - feel free to contact me directly if you'd like to discuss further. \$\endgroup\$ – DMGregory May 6 '15 at 13:35
0
\$\begingroup\$

Although DMGregory's answer is a really thorough and good I have found a different solution and more robust that suit's my needs. I have found a dll (which I cannot find the link currently but will upload somewhere and edit my answer to encompass the link) and using DLLImport and these functions

[DllImport ("UniWii")]
private static extern void wiimote_start();
[DllImport ("UniWii")]
private static extern void wiimote_stop();
[DllImport ("UniWii")]
private static extern int wiimote_count();
[DllImport ("UniWii")]
private static extern byte wiimote_getAccX(int which);
[DllImport ("UniWii")]
private static extern byte wiimote_getAccY(int which);
[DllImport ("UniWii")]
private static extern byte wiimote_getAccZ(int which);
[DllImport ("UniWii")]
private static extern float wiimote_getIrX(int which);
[DllImport ("UniWii")]
private static extern float wiimote_getIrY(int which);
[DllImport ("UniWii")]
private static extern float wiimote_getRoll(int which);
[DllImport ("UniWii")]
private static extern float wiimote_getPitch(int which);
[DllImport ("UniWii")]
private static extern float wiimote_getYaw(int which);
[DllImport ("UniWii")]
private static extern bool wiimote_getButtonA(int which);
[DllImport ("UniWii")]
private static extern bool wiimote_getButtonB(int which);
[DllImport ("UniWii")]
private static extern bool wiimote_getButtonUp(int which);
[DllImport ("UniWii")]
private static extern bool wiimote_getButtonLeft(int which);
[DllImport ("UniWii")]
private static extern bool wiimote_getButtonRight(int which);
[DllImport ("UniWii")]
private static extern bool wiimote_getButtonDown(int which);
[DllImport ("UniWii")]
private static extern bool wiimote_getButton1(int which);
[DllImport ("UniWii")]
private static extern bool wiimote_getButton2(int which);
[DllImport ("UniWii")]
private static extern bool wiimote_getButtonPlus(int which);
[DllImport ("UniWii")]
private static extern bool wiimote_getButtonMinus(int which);
[DllImport ("UniWii")]
private static extern bool wiimote_getButtonHome(int which);
[DllImport ("UniWii")]
private static extern byte wiimote_getNunchuckStickX(int which);
[DllImport ("UniWii")]
private static extern byte wiimote_getNunchuckStickY(int which);
[DllImport ("UniWii")]
private static extern byte wiimote_getNunchuckAccX(int which);
[DllImport ("UniWii")]
private static extern byte wiimote_getNunchuckAccZ(int which);
[DllImport ("UniWii")]
private static extern bool wiimote_getButtonNunchuckC(int which);
[DllImport ("UniWii")]
private static extern bool wiimote_getButtonNunchuckZ(int which);

I managed to interface with the WiiMote and get the functionality I need.

The original publisher of the dll is no longer supporting it, or don't care any more. I emailed them about it and they still have not replied after a few months. I found it though in a project hosted in google code (here). It's a full project with examples and the .dll.

EDIT Also keep in mind if you are to use this dll for a commercial application you will have to contact the original publisher to get licenced (if you manage to get a response from them). And also I had some issues using this dll while building on a 64-bit machine using 64-bit Unity (if it was built on a 32-bit machine everything was ok and it ran perfectly on both 64-bit and 32-bit)

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ I'm glad you got it sorted! I'll leave the other answer up, in case someone comes browsing this question and wants a DLL-free option. Out of curiosity, will you be needing to do sensor fusion, to turn the accelerometer + gyroscope measures into an orientation estimate? I've got some experience with this in Unity, so give me a shout if you want a hand with it. :) \$\endgroup\$ – DMGregory May 4 '15 at 21:32
  • \$\begingroup\$ @DMGregory What do you mean sensor fusion? \$\endgroup\$ – John Demetriou May 5 '15 at 6:19
  • 1
    \$\begingroup\$ Sensor fusion is when you take flawed/limited measurements from multiple different sensors (like an accelerometer and rate gyroscope) and combine them into a consensus estimate of the full picture - in this case, the orientation of the device. A rate gyro on its own only tells us about change in rotation, and an accelerometer gives a muddled mix of instantaneous acceleration and absolute orientation to the gravity field. Combining the two lets each sensor fill-in for missing data or noise/drift in the other. \$\endgroup\$ – DMGregory May 6 '15 at 8:31
  • \$\begingroup\$ @JohnDemetriou I am in the same situation as you. Can you please share the DLL that you found to work for you. Thank you! \$\endgroup\$ – Andrei Erdoss Jun 15 '15 at 16:29
  • 1
    \$\begingroup\$ @AndreiErdoss updated my answer with link and extra info on the dll \$\endgroup\$ – John Demetriou Jun 17 '15 at 6:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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