The library is capable of connecting multiple wiimotes but will most likely start giving problems when more than 4 our connected. Using this library you can receive the following types of data from the wiimote:
- Motion Sensing
- Infrared Tracking
- Button Events
- Joystick Positioning
- LED and Rumble Control
see example on how to use and plz leave feedback and rate. Thanks
Last Update: 12/14/11
- Created a tutorial show a method of creating a Wireless Voltage Meter using Wiimote, Pic chip and Autoit.
- The instructable is located here if your intrested. The package zip is at the bottom of the post. Be sure to let me know if your having any problems. Thanks
Change Log:
Spoiler
Update: 11/30/11
Update: 11/30/11
- Did pretty much a rewrite. The interface app uses two threads now. One for reciving msgs from autoit and one for reciving msgs from the wiimote. Worked very well.
- Added nunchuck, Classic Controller, and Guitar support. note the example for this update is weak and only really for testing purposes.
- Made major changes to communcations between C app and Autoit. All request are sent to Wiimote through _SendMessage(). This allows for a true response from C app verify that the request was carried out. Special thanks to Martin for figuring it out for me

- Added ability to connect and control multiple wiimotes from the same script.
- Created filter process for motion and IR data. This allows only most recent data to be processed. Very useful (and possible much needed) when connecting to multiple wiimotes.
- Added new function _Wii_AutoPair to automatically permanently pair wiimote to pc. This allows the pc to remember wiimote after its powered off.
- Made changes to connection process and made options for communications style between C app and Autoit. See new function _Wii_Startup()
- _SetMotionSensingHandler() has been removed and and replaced with two two functions: _Wii_SetOrientationHandler() and _Wii_SetGforceHandler()
- Made changes to Button handler. Buttons are now sent as integers representing the buttons instead of strings.
- Found bug in wiiconnect() where sometimes it was missing the message that the wiimote connected successfully.
- Added 2 more functions. _Wii_SetStatusHandler() and _Wii_Close(). see Header below for descriptions.
- Added 3 more functions. _Wii_SetAccelThreshold(), _Wii_SetSmoothAlphaMode(), _Wii_SetSmoothAlpha(). see Header below for descriptions.
- Added 4 new functions. _Wii_Resync(), _Wii_Disconnect(), _Wii_GetIRSensitivity(), _Wii_SetIRSensitivity. see Header below for descriptions.
- Added another example using GDI+ to draw IR Dot Tracking.
- Changed parameters in _Wii_Connect(). Added $MaxWiimotes the lets the user define how many wiimotes are currently paired with the pc.
- Made lots of improvements to the AutoitPort.exe msg handler. Lots of redundant, repeated data has been reduced from being sent.
- AutoitPort.exe and Wiiuse.dll binarys are now embedded in the udf. No need to use Fileinstall() if compiling now.
- Changed _Wii_Connect() to allow user to select a specific wiimote. this will let you create a seperate scripts to handle each wiimote. Also removed function handler parameters. Didnt like them there.
- Fixed some bugs in IR tracking. Problem was No event is fired when # of IR Dots goes from 1 to 0 leaving invalid(old) values.
- _Wii_CheckMsg() is now a public function and should be added to user scripts main loop for better response time from wiimote.
- Updated FFLabels UDF to current version fixing some color issue bugs.
- Removed LED indicator from AutoitPort.exe startup. That was wrong. User can set LED themself if need.
- Fixed bug in button press events. Home button got removed somehow

- Rewrote Example to include Flicker Free Labels. Looks so much cleaner now.

- Added new functions _Wii_GetBatteryStatus(),_Wii_GetLEDStatus(), _Wii_SetIRVRes($x, $y), _Wii_SetOrientThreshold($fThreshold) _Wii_SetLeds($iLed), _Wii_SetIRAspectRatio(),_Wii_SetIRSBPosition($iMode = 0)
- Added GForce x,y,z values to motion sensing array.
- Your button handler is now passed an array with the first element indicating what type of button event it was (Press,Release,Just Pressed).
- Added a _IsButtonHeld function which makes assigning button combinations very easy. LED toggling too.
- Added IR tracking and some fuctions to change the fuction handlers you have set. This way the can change what the keys do throughout the program.
- Added ability to turn on and off motion sensing, IR tracking and Rumble. Just to play around you can use a tv remote for some IR tracking functionality..
Functions:
Spoiler
AutoIt
; #INDEX# ======================================================================================================================= ; Title .........: Autoit Wiimote Library ; AutoIt Version : 3.3.6.1 ; Language ......: English ; Description ...: Functions to assist in communicating with the wiimote. UDF uses a built in exe writen in c to communicate with autoit. ; The app is written using the wiiuse library. ; Author(s) .....: Brian J Christy (Beege) ; Martin ; Michael Laforest - Wiiuse Library http://www.wiiuse.net/docs/index.htm ; Ward - LZF Compression Machine Code UDF ; Remarks........: This udf works by assigning functions to handle specific data reported from the wiimote. The functions are split up into ; the types of output devices the wiimote and its accessories have. All functions are reported a Wiimote ID showing which ; wiimote the data came from. The starting id is 0 and increments by 1. The assigning of wiimote ids is done by the wiiuse library ; and will vary depending on how many wiimotes are paired on the system and how many of those wiimotes are currently connected. ; If you only have one wiimote on the system you dont have to worry about specifying an id for any of the functions. If you have more ; than 1 wiimote paired and on the system, _Wii_AssociateID() can be used to map the address to the correct id. For the data that ; could come from a number of different controllers (for example button data), a controller type will be specifed. The values for ; the types of controllers are as follows: ; ; Controller Types: ; W = Wiimote - capable of sending orientation, gforce, IR, and button data. ; N = Nunchuck - capable of sending orientation, gforce, joystick, and button data ; C = Classic Controller - capable of sending shoulder button(2), joystick(2), and button data ; G = Guitar - capable of sending wammy bar, button, and joystick data ; ; Button Values: ; D = Down ; U = Up ; L = Left ; R = Right ; H = Home ; - = Minus ; + = Plus ; C = C (Nunchuck) ; Z = Z (Nunchuck) ; ZL = ZL (Classic Controller) ; ZR = ZR (Classic Controller) ; FL = FL (Classic Controller Shoulder button fully pressed) ; FR = FR (Classic Controller Shoulder button fully pressed) ; All other buttons are exactly the button name. (A=A, B=B) ; ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_Wii_Startup: Starts Wiimote interface app and sets maximium number of wiimotes to connect to. ;_Wii_Find: Finds and connects up to max wiimotes set in _Wii_Startup ;_Wii_AssociateID: Associates a wiimotes physical address to wiimote id. ;_Wii_IsButtonHeld: Checks to see if a button is being held ;_Wii_CheckMsg: Checks wiimote for any new data. Called in main loop ;_Wii_SetLeds: Set the enabled LEDs. ;_Wii_SetRumble: Enable or disable the rumble. ;_Wii_RequestStatus: Request the wiimote controller status. ;_Wii_SetMotionSensing: Set if the wiimote should report motion sensing. ;_Wii_SetIRTracking: Set if the wiimote should track IR targets. ;_Wii_SetIRVRes: Set the virtual screen resolution for IR tracking. ;_Wii_SetIRPosition: Set the XY position for the IR cursor. ;_Wii_SetAspectRatio: Set the aspect ratio of the TV/monitor. ;_Wii_SetBTStack: Set the bluetooth stack type to use. ;_Wii_SetSmoothAlpha: Set the wiimote smoothing alpha value. ;_Wii_SetSmoothing: Enables smoothing of orientation values ;_Wii_SetOrientThreshold: Set the orientation event threshold. ;_Wii_SetAccelThresh: Set the accelerometer event threshold. ;_Wii_SetNunChuckOrientThreshold: Set the orientation event threshold for the nunchuk. ;_Wii_SetNunChuckAccelThresh: Set the accelerometer event threshold for the nunchuk. ;_Wii_Resync: Try to resync with the wiimote by starting a new handshake. ;_Wii_SetTimeout: Set the normal and expansion handshake timeouts ;_Wii_SetIRSensitivity Set the IR sensitivity. ;_Wii_SetConnectionHandler: Sets the function to call when a connection event has happened. ;_Wii_SetOrientationHandler: Sets the function to call when new orientation sensor data is avalible. ;_Wii_SetGForceHandler: Sets the Function to call when new GForce sensor data is avalible. ;_Wii_SetIRHandler: Sets the Function to call when IR Tracking data is avalible. ;_Wii_SetIRDotHandler: Sets the function to call when IR Tracking data from a single IR source is avalible. ;_Wii_SetStatusHandler: Sets the function to call when new status data is avalible. ;_WiiSetWhammyBarHandler: Sets the function to call when new wammy bar data is avalible. ;_Wii_SetClassicSholderHandler: Sets the function to call when one of the classic controller top sholder buttons is being patially pressed ;_Wii_SetJoyStickHandler: Sets the function to call when new JoyStick data is avalible. ;_Wii_SetButtonHandler: Sets the function to call when new button data is avalible. ; ===============================================================================================================================
Example:
Spoiler
AutoIt
#region example #AutoIt3Wrapper_UseX64=n #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <array.au3> #include "Restart.au3" #include "FFLabels.au3" #include "Wiimote.au3" ;~ $g_WIIDEBUG = True Global $Form1 = GUICreate("Wii", 740, 427, 383, 210) Global $Group5 = GUICtrlCreateGroup("Buttons Pressed", 368, 16, 345, 149) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") Global $Edit1 = GUICtrlCreateEdit("", 392, 36, 302, 117) GUICtrlSetData(-1, "") GUICtrlCreateGroup("", -99, -99, 1, 1) Global $Group7 = GUICtrlCreateGroup("IR Tracking", 16, 16, 345, 321) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") Global $Group10 = GUICtrlCreateGroup("Visible IR Dot 1", 28, 43, 153, 121) GUICtrlCreateLabel("Raw XY:", 41, 86, 45, 17) GUICtrlCreateLabel("XY:", 41, 63, 16, 17) GUICtrlCreateLabel("Size:", 41, 108, 39, 17) GUICtrlCreateLabel("Order:", 41, 131, 39, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $cbIRTrack = GUICtrlCreateCheckbox("Enable IR Tracking", 37, 303, 169, 21) Global $Group12 = GUICtrlCreateGroup("IR Struct Data", 28, 175, 313, 121) GUICtrlCreateLabel("VRes XY:", 41, 218, 50, 17) GUICtrlCreateLabel("Total Dots:", 41, 195, 67, 17) GUICtrlCreateLabel("Abs XY:", 203, 218, 50, 17) GUICtrlCreateLabel("XY:", 41, 240, 41, 17) GUICtrlCreateLabel("Z:", 203, 240, 41, 17) GUICtrlCreateLabel("Offset XY:", 42, 264, 62, 17) GUICtrlCreateLabel("Distance:", 203, 194, 58, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $Group2 = GUICtrlCreateGroup("Visible IR Dot 2", 187, 43, 153, 121) GUICtrlCreateLabel("Raw XY:", 200, 86, 45, 17) GUICtrlCreateLabel("XY:", 200, 63, 16, 17) GUICtrlCreateLabel("Size:", 200, 108, 39, 17) GUICtrlCreateLabel("Order:", 200, 131, 39, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $Group1 = GUICtrlCreateGroup("Motion Tracking", 368, 175, 345, 162) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlCreateLabel("Roll:", 391, 195, 30, 17) GUICtrlCreateLabel("Abs Roll:", 391, 218, 55, 17) GUICtrlCreateLabel("Abs Pitch:", 549, 218, 62, 17) GUICtrlCreateLabel("Pitch:", 549, 195, 37, 17) Global $cbMotion = GUICtrlCreateCheckbox("Enable Motion Tracking", 392, 297, 153, 27) GUICtrlCreateLabel("GForce X:", 391, 239, 61, 18) GUICtrlCreateLabel("GForce Z:", 549, 239, 61, 18) GUICtrlCreateLabel("GForce Y:", 391, 264, 61, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $Toggles = GUICtrlCreateGroup("Toggles", 16, 344, 697, 61) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") Global $cbled1 = GUICtrlCreateCheckbox("LED1", 191, 369, 49, 17) Global $cbled2 = GUICtrlCreateCheckbox("LED2", 262, 369, 49, 17) Global $cbled3 = GUICtrlCreateCheckbox("LED3", 333, 369, 49, 17) Global $cbled4 = GUICtrlCreateCheckbox("LED4", 404, 369, 49, 17) Global $cbRumble = GUICtrlCreateCheckbox("Rumble On", 475, 367, 81, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) Global $alastIR[7] Global $aLastVIR[7] Global $lbVIR1XY = _GUICtrlFFLabel_Create($Form1, '', 100, 63, 75, 17, 9, -1, -1, 2) Global $lbVIR1Rxy = _GUICtrlFFLabel_Create($Form1, "", 100, 86, 75, 17, 9, -1, -1, 2) Global $lbvir1size = _GUICtrlFFLabel_Create($Form1, "", 100, 108, 75, 17, 9, -1, -1, 2) Global $lbVIR1order = _GUICtrlFFLabel_Create($Form1, "", 100, 131, 75, 17, 9, -1, -1, 2) Global $lbvir2xy = _GUICtrlFFLabel_Create($Form1, "", 255, 63, 75, 17, 9, -1, -1, 2) Global $lbvir2rxy = _GUICtrlFFLabel_Create($Form1, "", 255, 86, 75, 17, 9, -1, -1, 2) Global $lbvir2size = _GUICtrlFFLabel_Create($Form1, "", 255, 108, 75, 17, 9, -1, -1, 2) Global $lbvir2order = _GUICtrlFFLabel_Create($Form1, "", 255, 131, 75, 17, 9, -1, -1, 2) Global $lbirdots = _GUICtrlFFLabel_Create($Form1, "", 100, 195, 75, 17, 9, -1, -1, 2) Global $lbirxy = _GUICtrlFFLabel_Create($Form1, "", 100, 240, 75, 17, 9, -1, -1, 2) Global $lbiroffsetxy = _GUICtrlFFLabel_Create($Form1, "", 100, 264, 75, 17, 9, -1, -1, 2) Global $lbirvres = _GUICtrlFFLabel_Create($Form1, "", 100, 218, 75, 17, 9, -1, -1, 2) Global $lbirdist = _GUICtrlFFLabel_Create($Form1, "", 255, 194, 75, 17, 9, -1, -1, 2) Global $lbirabsxy = _GUICtrlFFLabel_Create($Form1, "", 255, 218, 75, 17, 9, -1, -1, 2) Global $lbirz = _GUICtrlFFLabel_Create($Form1, "", 255, 240, 75, 17, 9, -1, -1, 2) Global $lbRoll = _GUICtrlFFLabel_Create($Form1, "", 445, 195, 80, 17, 9, -1, -1, 2) Global $lbAbsRoll = _GUICtrlFFLabel_Create($Form1, "", 445, 218, 80, 17, 9, -1, -1, 2) Global $lbgfx = _GUICtrlFFLabel_Create($Form1, "", 445, 239, 80, 17, 9, -1, -1, 2) Global $lbgfy = _GUICtrlFFLabel_Create($Form1, "", 445, 264, 80, 17, 9, -1, -1, 2) Global $lbPitch = _GUICtrlFFLabel_Create($Form1, "", 605, 195, 80, 17, 9, -1, -1, 2) Global $lbAbsPitch = _GUICtrlFFLabel_Create($Form1, "", 605, 218, 80, 17, 9, -1, -1, 2) Global $lbgfz = _GUICtrlFFLabel_Create($Form1, "", 605, 239, 80, 17, 9, -1, -1, 2) Global $Retrys, $Found For $Retrys = 1 To 5 $Found = _Wii_Startup($Form1) If @error Then Switch @error Case 1, 2 ConsoleWrite('Fatal Startup Error: ' & @error & @CRLF) Exit Case 3 ConsoleWrite('!Error :: No Wiimotes Found. Make sure the wiimote is turned on.' & @CRLF) Sleep(2000) EndSwitch If $Retrys = 5 Then If _Wii_AutoPair() Then Sleep(5000) _ScriptRestart() EndIf EndIf Else ExitLoop EndIf Next Global $Wii = _Wii_Connect() If @error Then MsgBox(1,'Error', 'Could not connnect to wiimote') Exit EndIf _Wii_SetButtonHandler($Wii, '_ButtonPressed') _Wii_SetIRTrackingMode($Wii, 1) _Wii_SetIRDotTrackingHandler($Wii, '_Individual_IR_Track') _Wii_SetIRTrackingHandler($Wii, '_IR_Track') GUICtrlSetState($cbIRTrack, $GUI_CHECKED) _Wii_SetOrientationHandler($Wii, '_Motion') _Wii_SetGforceHandler($Wii, '_GForce') _Wii_SetMotionSensingMode($Wii, 1) GUICtrlSetState($cbMotion, $GUI_CHECKED) ConsoleWrite(_Wii_GetBatteryStatus($Wii) & @CRLF) Global $nMsg, $count = 0, $looptime = TimerInit() While 1 _Wii_CheckMsgs() $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $cbMotion If GUICtrlRead($cbMotion) = $GUI_CHECKED Then _Wii_SetMotionSensingMode($Wii, 1) Else _Wii_SetMotionSensingMode($Wii, 0) EndIf Case $cbRumble _Wii_ToggleRumble($Wii) Case $cbIRTrack If GUICtrlRead($cbIRTrack) = $GUI_CHECKED Then _Wii_SetIRTrackingMode($Wii, 1) Else _Wii_SetIRTrackingMode($Wii, 0) EndIf Case $cbled1, $cbled2, $cbled3, $cbled4 _LED($Wii) EndSwitch WEnd Func _LED($Wii) Local $iLeds = 0 If GUICtrlRead($cbled1) = $GUI_CHECKED Then $iLeds += 16 If GUICtrlRead($cbled2) = $GUI_CHECKED Then $iLeds += 32 If GUICtrlRead($cbled3) = $GUI_CHECKED Then $iLeds += 64 If GUICtrlRead($cbled4) = $GUI_CHECKED Then $iLeds += 128 _Wii_SetLeds($Wii, $iLeds) EndFunc ;==>_LED Func _GetButtonString($iButton) Switch $iButton Case 1 Return 'A' Case 2 Return 'B' Case 3 Return 'UP' Case 4 Return 'DOWN' Case 5 Return 'LEFT' Case 6 Return 'RIGHT' Case 7 Return 'MINUS' Case 8 Return 'PLUS' Case 9 Return 'ONE' Case 10 Return 'TWO' Case 11 Return 'HOME' EndSwitch EndFunc #region Handlers Func _ButtonPressed($aButton) Switch $aButton[0] Case 5;'P' ;~ ConsoleWrite('PRESSED ' & $aButton[1] & @CRLF) Case 6;'J' If _Wii_IsButtonHeld($Wii, 2) And $aButton[1] <> 2 Then GUICtrlSetData($Edit1, 'Combo B+' & _GetButtonString($aButton[1]) & @CRLF & GUICtrlRead($Edit1)) Else GUICtrlSetData($Edit1, 'Button Just Pressed: ' & _GetButtonString($aButton[1]) & @CRLF & GUICtrlRead($Edit1)) EndIf Case 7;'R' ;~ ConsoleWrite('RELEASED ' & $aButton[1] & @CRLF) EndSwitch EndFunc ;==>_ButtonPressed Func _Motion($aMotion) _GUICtrlFFLabel_SetData($lbRoll, $aMotion[0]) _GUICtrlFFLabel_SetData($lbAbsRoll, $aMotion[1]) _GUICtrlFFLabel_SetData($lbPitch, $aMotion[2]) _GUICtrlFFLabel_SetData($lbAbsPitch, $aMotion[3]) EndFunc ;==>_Motion Func _GForce($aGF) _GUICtrlFFLabel_SetData($lbgfx, $aGF[0]) _GUICtrlFFLabel_SetData($lbgfy, $aGF[1]) _GUICtrlFFLabel_SetData($lbgfz, $aGF[2]) EndFunc ;==>_GForce Func _Individual_IR_Track($aVIR) Switch $aVIR[0] Case 0 ConsoleWrite($aVIR[2] & ', ' & $aVIR[3] & @CRLF) _GUICtrlFFLabel_SetData($lbVIR1XY, $aVIR[2] & ', ' & $aVIR[3]) _GUICtrlFFLabel_SetData($lbVIR1Rxy, $aVIR[4] & ', ' & $aVIR[5]) _GUICtrlFFLabel_SetData($lbvir1size, $aVIR[7]) _GUICtrlFFLabel_SetData($lbVIR1order, $aVIR[6]) Case 1 _GUICtrlFFLabel_SetData($lbvir2xy, $aVIR[2] & ', ' & $aVIR[3]) _GUICtrlFFLabel_SetData($lbvir2rxy, $aVIR[4] & ', ' & $aVIR[5]) _GUICtrlFFLabel_SetData($lbvir2size, $aVIR[7]) _GUICtrlFFLabel_SetData($lbvir2order, $aVIR[6]) EndSwitch EndFunc ;==>_Individual_IR_Track Func _IR_Track($aIR) _GUICtrlFFLabel_SetData($lbirdots, $aIR[0]) _GUICtrlFFLabel_SetData($lbirabsxy, $aIR[1] & ', ' & $aIR[2]) _GUICtrlFFLabel_SetData($lbirxy, $aIR[3] & ', ' & $aIR[4]) _GUICtrlFFLabel_SetData($lbirz, $aIR[5]) _GUICtrlFFLabel_SetData($lbirdist, $aIR[6]) EndFunc ;==>_IR_Track#endregion example
Download Updated 11/30/11:
WiimoteMT.html 155bytes
2443 downloadsPrevious Downloads = 279
Download Analog to Digital Package
Wiimote ADC.html 161bytes
4281 downloadsNote: The .html link is just to help me keep track of downloads. Open the .html file and a download dialog will display.
Edited by Beege, 15 December 2011 - 12:17 AM.





