Jump to content



Photo

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


  • Please log in to reply
87 replies to this topic

#1 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 18 June 2011 - 01:58 AM

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

Functions:
Spoiler

Example:
Spoiler

Download Updated 11/30/11:
Attached File  WiimoteMT.html   155bytes   2443 downloads
Previous Downloads = 279

Download Analog to Digital Package
Attached File  Wiimote ADC.html   161bytes   4281 downloads

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, 15 December 2011 - 12:17 AM.

  • Manadar likes this





#2 Maffe811

Maffe811

    Sir Longbottle

  • Active Members
  • PipPipPipPipPipPip
  • 644 posts

Posted 18 June 2011 - 11:28 AM

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...
Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.Scripts:
Spoiler

#3 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,818 posts

Posted 18 June 2011 - 01:52 PM

Probably has potential for custom presentations and suchlike.

Unfortunately, I dont have a remote here :huh2:
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#4 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 18 June 2011 - 01:54 PM

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

#5 Maffe811

Maffe811

    Sir Longbottle

  • Active Members
  • PipPipPipPipPipPip
  • 644 posts

Posted 18 June 2011 - 05:22 PM

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:
Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.Scripts:
Spoiler

#6 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 18 June 2011 - 08:43 PM

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, 20 June 2011 - 09:51 AM.


#7 RedSpawn

RedSpawn

    Seeker

  • Active Members
  • 10 posts

Posted 19 June 2011 - 04:38 PM

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?

#8 RedSpawn

RedSpawn

    Seeker

  • Active Members
  • 10 posts

Posted 19 June 2011 - 05:50 PM

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:

#9 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 19 June 2011 - 07:05 PM

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

#10 RedSpawn

RedSpawn

    Seeker

  • Active Members
  • 10 posts

Posted 19 June 2011 - 08:03 PM

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.

#11 Maffe811

Maffe811

    Sir Longbottle

  • Active Members
  • PipPipPipPipPipPip
  • 644 posts

Posted 19 June 2011 - 08:19 PM

Why is the site a html thing that leads to drop box ? :huh2:
Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.Scripts:
Spoiler

#12 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 19 June 2011 - 08:31 PM

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.

#13 Maffe811

Maffe811

    Sir Longbottle

  • Active Members
  • PipPipPipPipPipPip
  • 644 posts

Posted 19 June 2011 - 08:59 PM

Im re-writing the example so it includes my idea.
I can't test it though :huh2:
Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.Scripts:
Spoiler

#14 RedSpawn

RedSpawn

    Seeker

  • Active Members
  • 10 posts

Posted 19 June 2011 - 08:59 PM

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:

#15 Maffe811

Maffe811

    Sir Longbottle

  • Active Members
  • PipPipPipPipPipPip
  • 644 posts

Posted 19 June 2011 - 09:20 PM

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, 19 June 2011 - 09:41 PM.

Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.Scripts:
Spoiler

#16 RedSpawn

RedSpawn

    Seeker

  • Active Members
  • 10 posts

Posted 19 June 2011 - 09:47 PM

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

#17 Maffe811

Maffe811

    Sir Longbottle

  • Active Members
  • PipPipPipPipPipPip
  • 644 posts

Posted 19 June 2011 - 09:52 PM

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!
Plain Text         
#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, 19 June 2011 - 09:53 PM.

Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.Scripts:
Spoiler

#18 Maffe811

Maffe811

    Sir Longbottle

  • Active Members
  • PipPipPipPipPipPip
  • 644 posts

Posted 19 June 2011 - 09:55 PM

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!
Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.Scripts:
Spoiler

#19 RedSpawn

RedSpawn

    Seeker

  • Active Members
  • 10 posts

Posted 19 June 2011 - 10:04 PM

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?

#20 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 20 June 2011 - 12:21 AM

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, 20 June 2011 - 01:33 AM.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users