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 another example Ive been playing with using GDI+ for IR tracking. The glowing ball code is from one of UEZ examples. Posted Image

Posted Image

Wii IR Tracking GDI+.au3

Link to comment
Share on other sites

The newer version works fine, but LED1 is still on at startup but not checked on the gui.

--> Make sure you have deleted the previous DLL and autoitport.exe. The udf will only extract the binarys if they are missing from scriptdir. Otherwise it will use the one in the directory.

You're right.

I had lots of messages in the console window like this

[WARNING] Packet ignored. This may indicate a problem (timeout is 10 ms).

[WARNING] Received data packet when no request was made.

[WARNING] Packet ignored. This may indicate a problem (timeout is 10 ms).

Where do those messages come from?

I thought that those messages were because I had 2 instances running but I tried 2 again and didn't see those warnings.

-->They are coming from functions in the Wiiuse Lib but im suprised you are seeing them. Are you looking at the data in _Wii_checkmsg(), or maybe uncomment some of the conslewrites I have in there to see?

No, I didn't uncomment anything. It may have been related to running 2 instances at a time but I don't know how.

Is it possible to read the state of the leds?

--> did you see _Wii_GetLEDStatus()?

I just didn't see it. (That function must have the wrong shaped buttocks.)

The wiiuse site seems to be down this weekend so I can't get any information from it.

--> no its not down, just for some reason the main page http://www.wiiuse.net doesn't work. Try going to http://www.wiiuse.net/docs/public/style_emoticons/autoit/wink.gif

Thanks, I didn't realize I needed to click the "files" tab to see what functions exist.

I've ordered some IR leds but I probably won't get time to do anything with them because next weekend I am going on holiday for 2 weeks.

I've written a few things in C but nothing in C++ or C#. I've written lots of things in Delphi and many variants of basic and C like languages. I would expect to be able to get messages working between a C program and an AutoIt program though that doesn't mean I'm right. If you are prepared to share your code then I'll have a look after my holiday. I installed the free Visual Studio on my laptopo last year but I've never done anything with it. Or maybe we could work out how to use the dll straight from AutoIt.

I think the 3D effects like Johnny Lee showed would have to be written in a compiled language to get the speed but it would worth trying in AutoIt first.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

You're right.

--> Awsome. The only reason I did like that (not delete files) is because of how im working back and forth between the c app and autoit and I dont want to re-embed the binary each time I make a change to it.

No, I didn't uncomment anything. It may have been related to running 2 instances at a time but I don't know how.

--> Im really stumped by this and going to try and pinpoint it. You are writing to the console at least somewhere somewhere in the script correct?

I just didn't see it. (That function must have the wrong shaped buttocks.)

--> Posted Image

Thanks, I didn't realize I needed to click the "files" tab to see what functions exist.

--> Dont feel bad I did the same thing.

I've ordered some IR leds but I probably won't get time to do anything with them because next weekend I am going on holiday for 2 weeks.

I've written a few things in C but nothing in C++ or C#. I've written lots of things in Delphi and many variants of basic and C like languages. I would expect to be able to get messages working between a C program and an AutoIt program though that doesn't mean I'm right. If you are prepared to share your code then I'll have a look after my holiday. I installed the free Visual Studio on my laptopo last year but I've never done anything with it. Or maybe we could work out how to use the dll straight from AutoIt.

--> Sounds great! Ill shot you a pm later today, or tomarrow. with the project folder. I really need to add more comments. Did you try a TV remote for the IR? I heard you can also use candles Posted Image

I think the 3D effects like Johnny Lee showed would have to be written in a compiled language to get the speed but it would worth trying in AutoIt first.

--> Have you done anything with ? It sometimes takes the examples a while to start up (like possibly 30 seconds), but when they finally do the are really impressive when it comes to performance and actual 3D game environments.

Edited by Beege
Link to comment
Share on other sites

You're right.

--> Awsome. The only reason I did like that (not delete files) is because of how im working back and forth between the c app and autoit and I dont want to re-embed the binary each time I make a change to it.

No, I didn't uncomment anything. It may have been related to running 2 instances at a time but I don't know how.

--> Im really stumped by this and going to try and pinpoint it. You are writing to the console at least somewhere somewhere in the script correct?

I just didn't see it. (That function must have the wrong shaped buttocks.)

--> Posted Image

Thanks, I didn't realize I needed to click the "files" tab to see what functions exist.

--> Dont feel bad I did the same thing.

I've ordered some IR leds but I probably won't get time to do anything with them because next weekend I am going on holiday for 2 weeks.

I've written a few things in C but nothing in C++ or C#. I've written lots of things in Delphi and many variants of basic and C like languages. I would expect to be able to get messages working between a C program and an AutoIt program though that doesn't mean I'm right. If you are prepared to share your code then I'll have a look after my holiday. I installed the free Visual Studio on my laptopo last year but I've never done anything with it. Or maybe we could work out how to use the dll straight from AutoIt.

--> Sounds great! Ill shot you a pm later today, or tomarrow. with the project folder. I really need to add more comments. Did you try a TV remote for the IR? I heard you can also use candles Posted Image

I think the 3D effects like Johnny Lee showed would have to be written in a compiled language to get the speed but it would worth trying in AutoIt first.

--> Have you done anything with ? It sometimes takes the examples a while to start up (like possibly 30 seconds), but when they finally do the are really impressive when it comes to performance and actual 3D game environments.

Yes, au3lrrlicht2 would be a good approach.

I like the new example in post #41. There is something wrong though. If I comment out

_Release();_wii_Release

_WiiClose()

in the exit function then the program hangs, but if I leave them there then the script tries to call those functions twice and I get errors that it couldn't delete the dll etc.

The graphics seems to be offset in the gui window. I was surpised that a remote controler gives a signal but I get nothing from a gas ring on my cooker hob. I haven't tried a candle but the sun works quite well. So you could use the wii remote as a sun dial. Not sure how well it would sell though.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Yes, au3lrrlicht2 would be a good approach.

I like the new example in post #41. There is something wrong though. If I comment out

_Release();_wii_Release

_WiiClose()

in the exit function then the program hangs, but if I leave them there then the script tries to call those functions twice and I get errors that it couldn't delete the dll etc.

The graphics seems to be offset in the gui window. I was surpised that a remote controler gives a signal but I get nothing from a gas ring on my cooker hob. I haven't tried a candle but the sun works quite well. So you could use the wii remote as a sun dial. Not sure how well it would sell though.

I know something strange is going on with the registered exit functions and im not sure if it has something to do with GDI+ or the fact that im using OnEventMode in this example. they work just fine in the other example which is more confusing. Only thing I know is that (in this example) they never get called if I dont call them manually before exit, which is why I added them to the exit function. Posted Image

Edited by Beege
Link to comment
Share on other sites

Added some more updates.:

- Added 4 new functions. _Wii_Resync(), _Wii_Disconnect(), _Wii_GetIRSensitivity(), _Wii_SetIRSensitivity. see Header 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.

Be sure to vote if you like this project. Posted Image

Edited by Beege
Link to comment
Share on other sites

Another update with 3 more functions. _Wii_SetAccelThreshold(), _Wii_SetSmoothAlphaMode(), _Wii_SetSmoothAlpha(). see Header for descriptions. Posted Image
Link to comment
Share on other sites

  • 1 month later...
Link to comment
Share on other sites

You have been busy.

I wanted to buy a wii-mote.

Then i tried the wii at my GFs place, now i want a wii.

I think im gonna wish for half a wii for christmas.

But good job with this.

Would like to see a Wii-mote moves mouse test script.

Maybe browse to the tabs of your internet browser by rolling the remote side ways ?

Or turn volume up and down by rolling the remote back and forward when in a media player ?

[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 you guys are actually making a autoit script that reads the wiimote COOL!!! I have a wii just no bluetooth wait maybe its in my laptop... i will check

nope :mellow:

You can get a little USB Bluetooth on Ebay for like $2. I just bought a couple last week that work just fine. :)

Link to comment
Share on other sites

ok i was just going to get one from the dollar store.. no shipping cost! :mellow: (i walk where ever i go)

And no wait time Posted Image

Link to comment
Share on other sites

This is just amazing stuff Beege. I've been playing with it since I ran across the topic yesterday. The first thing that popped into my mind was using the Wiimote in place of the mouse (a WiiMouse?). I swiped part of the example in your main download (for the buttons) and part of the GDI example (for the IR tracking) and whipped up a little demo program. It could still use some polishing, but it works (for example, it is currently hardcoded to scale up to 1360 x 768, but should be easily automated based on @DESKTOPWIDTH x @DESKTOPHEIGHT). I run a compiled version and when it runs it minimizes itself.

#include <GUIConstantsEx.au3>
#include "Wiimote.au3"

; Wiimote key setup :
;   A       - primary mouse button (default = left)
;   B       - double click primary mouse button
;   -       - middle mouse button
;   +       - secondary mouse button (default = right)
;   HOME    - Exit program

;Set a default keyboard escape in case things go wonky
HotKeySet('{ESC}', '_Close')

; Create a default window showing Wiimote X / Y
Global $main = GUICreate("WiiMouse",110,20,1,1)
Global $lblx = GUICtrlCreateLabel("",1,1,50)
Global $lbly = GUICtrlCreateLabel("",51,1,50)

; Minimize the window to display the desktop
GUISetState(@SW_MINIMIZE)

; Global declarations
Global $WiiMotion[8]            ; Define the motion array
; IR screen dimensions are 1023 x 767 scale up to 1360 x 768
Global Const $xfactor = 1.33    ; Scaling factor for X
Global Const $yfactor = 1.04    ; Scaling factor for Y

;ConsoleWrite("desktop width="&@DesktopWidth&" hieght="&@DesktopHeight&@CRLF)
;ConsoleWrite("xfactor="&$xfactor&" yfactor="&$yfactor&@CRLF)

$Found = _Wii_Startup($main) ; Start up the Wiimote functions
Global $Wii = _Wii_Connect() ; Connect to the Wiimote
If @error Then
    MsgBox(1,'Error', 'Could not connnect to wiimote')
    Exit
EndIf

; Define the button and motion handlers
_Wii_SetButtonHandler($Wii, '_ButtonPressed')
_Wii_SetIRTrackingMode($Wii,1) ; Turn on IR tracking
_Wii_SetIRDotTrackingHandler($Wii, '_Motion')

; Main message handling loop
Do
    ; Check for Wiimote or GUI messages
    _Wii_CheckMsgs()
    $nMsg = GUIGetMsg()

    ; Check to see if GUI requested exit
    If $nMsg = $GUI_EVENT_CLOSE Then Exit

    ; Display Wiimote X / Y data
    GUICtrlSetData($lblx, $WiiMotion[0]&" / "&$WiiMotion[1])
    GUICtrlSetData($lbly, $WiiMotion[4]&" / "&$WiiMotion[5])

    ; If the Wiimote X / Y have changed move the mouse to where it is pointing
    If $WiiMotion[0] = 0 And $WiiMotion[1] And $WiiMotion[4] <> 0 And $WiiMotion[5] <> 0 Then
        MouseMove(Int($WiiMotion[4] * $xfactor), Int($WiiMotion[5] * $yfactor),0)
    EndIf
; Pause 5 milliseconds to allow messages to get processed
Until Not Sleep(5)

Exit

; Hotkey requested exit
Func _Close()
    Exit
EndFunc

; Convert Wiimote code to button name
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

; Wiimote button handler
Func _ButtonPressed($sButton)
    If $sButton[0] = 6 Then
        Local $but = _GetButtonString($sButton[1])
        Switch $but
            Case 'A'
                MouseClick("primary")
            Case 'B'
                MouseClick("primary",Default,Default,2)
            Case 'PLUS'
                MouseClick("secondary")
            Case 'MINUS'
                MouseClick("middle")
            Case 'UP'
            Case 'DOWN'
            Case 'LEFT'
            Case 'RIGHT'
            Case 'ONE'
            Case 'TWO'
            Case 'HOME'
                Exit
        EndSwitch
    EndIf
EndFunc   ;==&gt;_ButtonPressed

; Wiimote motion handler
Func _Motion($aMotion)
    ; Copy array if first IR dot passed to handler
    If $aMotion[0] = 0 Then $WiiMotion = $aMotion
EndFunc   ;==>_Motion

WiiMouse.au3

Link to comment
Share on other sites

  • 3 weeks later...

Quick request. This script has a tool within it called AutoItPortB.exe for which I can't see the source (it comes precompiled in the library and is extracted for use). Where did you get that from and did you write it?

The main reason is to ask if you have the source for it? I have trouble pairing due to timeouts and want to extend that which is within this autoitportb.exe file. If the tool can be customised that would be great.

Link to comment
Share on other sites

Quick request. This script has a tool within it called AutoItPortB.exe for which I can't see the source (it comes precompiled in the library and is extracted for use). Where did you get that from and did you write it?

The main reason is to ask if you have the source for it? I have trouble pairing due to timeouts and want to extend that which is within this autoitportb.exe file. If the tool can be customised that would be great.

wsherliker

Yes AutoitPortB.c was written by me. It handles sending data between the wiimote and autoit. I cant be sure you problem is due to "pairing" just yet. Have you tried manually pairing the wiimote to the pc first instead of using the _WiiAutoPair() function?

Link to comment
Share on other sites

This is just amazing stuff Beege. I've been playing with it since I ran across the topic yesterday. The first thing that popped into my mind was using the Wiimote in place of the mouse (a WiiMouse?). I swiped part of the example in your main download (for the buttons) and part of the GDI example (for the IR tracking) and whipped up a little demo program. It could still use some polishing, but it works (for example, it is currently hardcoded to scale up to 1360 x 768, but should be easily automated based on @DESKTOPWIDTH x @DESKTOPHEIGHT). I run a compiled version and when it runs it minimizes itself.

NullStmt

Thankyou! Im glad to see your having fun. More examples to come in the future. This project is going to last a while for me :mellow:

Link to comment
Share on other sites

  • 2 months later...

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