Jump to content

Wiimote Scripting - Control and Receive Data from Multiple Wiimotes - Updated:12/14/11 - A Wireless Voltage Meter Example


Beege
 Share

Recommended Posts

Heres a small little package I put together to get some functionality out of the wiimote to use with Autoit. Its works by communicating with the wiimote through a small interface app I wrote in c that uses the wiiuse library v12.

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

In order for this example to work you must first pair the wiimote with your computer. Try using the WiiPair Example script first. This will authentically pair the wiimote to your pc allowing it to remember the pair. If that does not work you can also do it manually. To do this, go to "Devices and Printers" and select "Add a device". Now make the wiimote discoverable. To do this either hold down buttons 1 and 2 or press the sync button underneath the battery cover. When it asks for a code just select pair with no code. If the wiimote is successfully paired and for some reason the example wont work or fail connecting, try running the other example thats in the extra folder. That is a true wiiuseexample written by the developer of Wiiuse. If that one wont work mine wont either. If you have paired the wiimote manually, when the Wiimote is powered off or the battery starts getting really low it will unpair itself from the pc, but will still be shown in "Devices and Printers". To re-pair, remove the wiimote first, then go through the pairing process.

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

Posted Image

Change Log:

Spoiler

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.

Update: 8/15/11

  • 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 :alien:
  • 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.

Update: 7/19/11

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

Update: 7/13/11

  • Added 3 more functions. _Wii_SetAccelThreshold(), _Wii_SetSmoothAlphaMode(), _Wii_SetSmoothAlpha(). see Header below for descriptions.

Update: 7/12/11

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

Update: 7/9/11

  • 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 :huh2:

Update: 6/20/11

  • Rewrote Example to include fflabels
  • Looks so much cleaner now. :ph34r:

Update: 6/20/11

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

Update: 6/19/11

  • 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
; #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
#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.zip

Previous Downloads = 279

Download Analog to Digital Package

Wiimote ADC.html

Note: 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
upload original zip
Link to comment
Share on other sites

Its things like this that makes me want a wii.

The hackability...

But this has alot of potential, and i cant wait to see what pepole do with it...

Maybe i should just buy a wii remote...

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

Its things like this that makes me want a wii.

The hackability...

But this has alot of potential, and i cant wait to see what pepole do with it...

Maybe i should just buy a wii remote...

Thats exactly my thoughts. And yes just the wii remote (and bluethooth) is good enough. Thats all I have. You can get one for less than $20 . IR tracking is next Posted Image

Link to comment
Share on other sites

I dont even have 20$ despite the low exchange rate! :huh2:

But what about having something like:

$OldPitch = $lb_Pitch
Sleep (5);Really short time
$NewPitch = $lb_Pitch

If $NewPitch <= $OldPitch then 
$OldPitch - $NewPitch = $PitchMove
MouseMove(MousePosition - $PitchMove);I dont bother opening the helpfile to get the right syntax.
ElseIf $OldPitch >= $NewPitch then 
$NewPitch - $OldPitch = $PitchMove
MouseMove(MousePosition + $PitchMove)
EndIf

Or something like that to move mouse up/down and the the same for roll.

Then you could move the mouse with Pitch and Roll!

No need for IR tracking! ;)

Now i really want a wii remote!

Im playing xbox with my nephew, he tries to turn the remote instead of using the sticks... If they get a wii i might have to borrow the remote :alien:

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

I will play around with that Posted Image. that could be fun too. right now I always have this running for my button function:

Func _ButtonPressed($sButton)
    Switch $sButton
        Case 'PLUS'
            send('{VOLUME_UP}')
        Case 'MINUS'
            Send('{VOLUME_DOWN}')
        Case 'B'
            Run("C:\Windows\System32\rundll32.exe dwmapi #105")
        Case 'UP'
            Send('{UP}')
        Case 'DOWN'
            Send('{DOWN}')
        Case 'LEFT'
            SEND('{LEFT}')
        Case 'A'
            Send('{ENTER}')
        Case 'RIGHT', 'ONE', 'TWO', 'HOME'
            GUICtrlSetData($Edit1, 'Button Pressed: ' &amp; $sButton &amp; @CRLF &amp; GUICtrlRead($Edit1))
    EndSwitchEndFunc   ;==&gt;_ButtonPressed

The Run("C:\Windows\System32\rundll32.exe dwmapi #105") will initiate the 3D flip and then from there I can kinda move about windows. also a nice remote for the volume. the IR would be more for the whiteboard features (hopefully).Posted Image

Edited by Beege
Link to comment
Share on other sites

Yesterday i was looking for a remote to control my XBMC and my autoit -> arduino -> DMX system.

Then i learned the wiimote actually connects via bluetooth and is dirt cheap,I borrowed a wiimote and got it working with my pc.

today i find your program and all is just wonderful! :huh2:

thanks a lot for this fine work!

two questions:

1. why the additional program? is the dll interface just too complicated for autoit?

2. can you make a function for the buzzer?

Link to comment
Share on other sites

ok, now i understand how your approach is working, i guess it won't be that easy to enable buzzer/led control this way.

or is it just as easy to send commands to your program via StdinWrite()?

but one thing i really miss is button_down and button_up 'events', if you get these from wiiuse.....

maybe i should setup a c compiler and try it myself :huh2:

Link to comment
Share on other sites

ok, now i understand how your approach is working, i guess it won't be that easy to enable buzzer/led control this way.

or is it just as easy to send commands to your program via StdinWrite()?

but one thing i really miss is button_down and button_up 'events', if you get these from wiiuse.....

maybe i should setup a c compiler and try it myself :huh2:

Redspawn thanks glad your having fun. So am I Posted Image. Its not that the dll is to complex for autoit, just a little to complex for me. Theres some really smart people around here that could handle it, but for me It was so much easier using all the macros and functions from the library in c and then just pipe the data to autoit. this also helped take a load off of autoit since a separate process is not handling the wiimote. Just last night I got the stdinwrite working on the c app side of this project. Was having trouble there for a while but got it now. Check back in a few hours and Ill have the new one up. Its got IR Tracking, options to turn motion sensing on and off and toggle the rumble on. Leds and buzzer is also on the todo list

Your UP and Down buttons are not working?Posted Image

Link to comment
Share on other sites

wow, sounds like you are on the way to a fully working solution!

i totally understand your choice not to dig into the dll, your solution is working perfectly well and as you said its maybe even faster

the buttons are working fine, but it would be cool to get two events for a keypress:

A_DOWN on press and A_UP on release.

Link to comment
Share on other sites

Why is the site a html thing that leads to drop box ? :huh2:

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

wow, sounds like you are on the way to a fully working solution!

i totally understand your choice not to dig into the dll, your solution is working perfectly well and as you said its maybe even faster

the buttons are working fine, but it would be cool to get two events for a keypress:

A_DOWN on press and A_UP on release.

Oh I see what your saying. Yes I definatly have to implement the other button press macros. Right now I just using the 'IS_PRESSED" macro but there is also "IS_HELD", "IS_JUST_PRESSED", and "IS_RELEASED" still to play around with. :huh2:

Its funny but what taking the most time right now is setting up the example. I take forever doing the GUI's. After this next one im going to start going cheap on the examples up until I have a lot more to show. this way Ill get more done.

Link to comment
Share on other sites

Im re-writing the example so it includes my idea.

I can't test it though :huh2:

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

nice!

i'm curious what other macros are hidden in there, the whole IR stuff surely will open some interesting possibilities

it will be so easy to use the wiimote in autoit!

why hasn't this been done before?

i'm so excited!

and now i'll keep quiet and let you work :huh2:

Link to comment
Share on other sites

I need some values!

1st. whats the pitch when you hold the remote pointing straigt up.

2nd. whats the pitch when you hold the remote pointing straigt sideways.

3rd. whats the pitch when you hold the remote pointing straigt down.

Then the same for roll.

What do the abs values do ?

Edited by Maffe811

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

pitch + roll are between -180 and 180

when flat on table: pitch:0 roll:0

pointing up: pitch:90 roll:???

(the sensors work with gravity, if they stand "in line" with gravity they can't get an accurate reading)

pointing at me: pitch:jumps from 180 to -180 roll: (-)180 because its upside down

pointing down: pitch: -90 roll:???

roll goes from 0 to 180 on right and 0 to -180 on left

i don't know what abs values are, they are almost the same

Link to comment
Share on other sites

Im gonna ask my dad to order a remote :huh2:;)

Im addicted :alien::)

It tells me i cant subract it...

But since i dont have the remote, i dont know what i am subtracting...

:ph34r:

So if any one could test this i would be most helpfull!

#region example
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include "wiimote.au3"

Global $Form1 = GUICreate("Wii", 435, 168, 409, 187)
Global $lb_Roll = GUICtrlCreateLabel("", 84, 15, 108, 17)
Global $lb_aRoll = GUICtrlCreateLabel("", 84, 43, 116, 17)
Global $lb_Pitch = GUICtrlCreateLabel("", 291, 15, 116, 17)
Global $lb_aPitch = GUICtrlCreateLabel("", 291, 43, 116, 17)
GUICtrlCreateLabel("Pitch:", 227, 15, 46, 17)
GUICtrlCreateLabel("Abs Pitch:", 227, 43, 49, 17)
GUICtrlCreateLabel("Roll:", 34, 15, 25, 17)
GUICtrlCreateLabel("Abs Roll:", 34, 43, 49, 17)
Global $Edit1 = GUICtrlCreateEdit("", 28, 73, 385, 77)
GUISetState(@SW_SHOW)

;~ _Wii_Connect('_ButtonPressed')
_Wii_Connect('_ButtonPressed', '_Motion')

If @error Then
    GUICtrlSetData($Edit1, 'Failed to connect....' & @CRLF)
Else
    GUICtrlSetData($Edit1, 'Connected!' & @CRLF)
EndIf

Do

Until GUIGetMsg() = $GUI_EVENT_CLOSE


Func _ButtonPressed($sButton)
    Switch $sButton
        Case 'A', 'B', 'UP', 'DOWN', 'LEFT', 'RIGHT', 'MINUS', 'PLUS', 'ONE', 'TWO', 'HOME'
            GUICtrlSetData($Edit1, 'Button Pressed: ' & $sButton & @CRLF & GUICtrlRead($Edit1))
    EndSwitch
EndFunc   ;==>_ButtonPressed

Func _Motion($aOrient)
    ;0=roll 1=aroll 2=pitch 3=apitch
    If IsArray($aOrient) Then
        GUICtrlSetData($lb_Roll, $aOrient[0])
        GUICtrlSetData($lb_aRoll, $aOrient[1])
        GUICtrlSetData($lb_Pitch, $aOrient[2])
        GUICtrlSetData($lb_aPitch, $aOrient[3])
    EndIf
EndFunc   ;==>_Motion

Global $aOrient, $RollMove, $OldPitch,$NewPitch,$OldRoll,$NewRoll

Func _MotionMove()
$OldRoll = $aOrient[0];Roll
ConsoleWrite($OldRoll & @CRLF)
$OldPitch = $aOrient[2];Pitch
ConsoleWrite($OldPitch & @CRLF)
Sleep(50)
$NewRoll = $aOrient[0];Roll
ConsoleWrite($NewRoll & @CRLF)
$NewPitch = $aOrient[2];Pitch
ConsoleWrite($NewPitch & @CRLF)
#cs
    If $NewRoll <= $OldRoll then;Roll to left
        $OldRoll - $NewRoll = $RollMove;Roll by this much
        $Pos = MouseGetPos();Previous mouse pos
        $XPos = $Pos[0];Up/down pos
        $YPos = $Pos[1] - $RollMove;Left/right pos and subtracting the roll movement
        MouseMove($XPos,$YPos);Move the mouse
    EndIf

    If $NewRoll >= $OldRoll then;Roll to right
        $OldRoll + $NewRoll = $RollMove;Roll by this much
        $Pos = MouseGetPos();Previous mouse pos
        $XPos = $Pos[0];Up/down pos
        $YPos = $Pos[1] + $RollMove;Left/right pos and adding the roll movement
        MouseMove($XPos,$YPos);Move the mouse
    EndIf
#Ce
EndFunc
Edited by Maffe811

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

pitch + roll are between -180 and 180

when flat on table: pitch:0 roll:0

pointing up: pitch:90 roll:???

(the sensors work with gravity, if they stand "in line" with gravity they can't get an accurate reading)

pointing at me: pitch:jumps from 180 to -180 roll: (-)180 because its upside down

pointing down: pitch: -90 roll:???

roll goes from 0 to 180 on right and 0 to -180 on left

i don't know what abs values are, they are almost the same

Crap... I was hoping it was 0 to 360... okay, that means i have to make some sort of thingies and...

Crap... This just got a bit more complicated... Disregard my last script, it wont work...

I mean the section that i commented away...

Ill fix it tomorrow!

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

wait for Beege's demo, i think he will have all functions working in a gui.

i'm also about to order a remote since the one i'm using is just borrowed :huh2:

i was looking on the bay, the cheapest i found is 11$! (with delivery to switzerland)

i can not understand how this incredible piece of hardware can be produced for this price!

i don't know if it's ok to post a link to the offer here?

Link to comment
Share on other sites

wait for Beege's demo, i think he will have all functions working in a gui.

i'm also about to order a remote since the one i'm using is just borrowed :huh2:

i was looking on the bay, the cheapest i found is 11$! (with delivery to switzerland)

i can not understand how this incredible piece of hardware can be produced for this price!

i don't know if it's ok to post a link to the offer here?

I completely agree! how can they be so cheap. $11 for motion sensors, bluetooth, IR camera. Its nuts! Posted Image

Check out the new update and plz let me know if you have any problems with the example.

Edited by Beege
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...