I already know it is possible to link a Wii Remote to a PC, but as it has tilt sensors, and buttons, I thought it would be a good idea if it could link to Scratch.
So can it link to Scratch?
Offline
EDIT: I've tried it. It works! Use the two programs below to connect and use the wiimote like a mouse and keyboard to control your scratch programs.
It's not very easy though.
you may have major problems getting your computer to connect to the wiimote through bluetooth like I did. Be careful.
For a windows computer: (xp. not sure about vista, 7)
http://www.wiimoteproject.com/bluetooth-and-connectivity-knowledge-center/wiimoteconnect-0-6-%28support-for-autoconnect%29/
(you'll probably need to do some reading.)
http://glovepie.org/
This program will let you use the tilt of the wiimote to control the mouse cursor.
Try the "WiiMouse Accel.PIE" script. there's others in there that may work better.
You may have to make some changes to it. and you'll want to put the scratch program in presentation mode.
Let me know if you want more help.
Last edited by AddZero (2010-04-13 15:53:26)
Offline
Could you make it work through the WeDo blocks? Since it has a tilt sensor?
Offline
johnnydean1 wrote:
Well has anyone done it?
I think some people have tried...
Offline
Yes, it's possible, I wrote how above.
EDIT: I have tried it and it works.
No sensor blocks or hacking necessary.
With the programs that I wrote about above, you can connect the wiimote, then map (or assign) the tilt of the wiimote to the mouse movement, and the buttons on the wii to keyboard buttons. like "a" key for the "a" button. You can then use those keys in your scratch program.
Those programs make your wiimote control your mouse and buttons. You can then use it to control any windows program... Including Scratch.
(If you need to use the mouse AND control with the tilt of the wiimote, we'll have to figure out another way for scratch to get those commands... that's possible but more complicated.)
So if you want to make this work, try those programs above. But this may not be easy to do, let me know if I can help.
If there's interest, I'll write a tutorial.
Last edited by AddZero (2010-04-13 15:18:50)
Offline
Does it use the tilt sensor like the scratch board
Im getting a bluetooth adaptor soon so Ill try it for myself
Offline
johnnydean1 wrote:
Does it use the tilt sensor like the scratch board
You might be able to... but read this:
Here's 3 ways of getting tilt information into scratch that I see, in order of difficulty:
1. easy. Use GlovePIE's scripting language to map (assign) the tilt to the mouse movements. (like I suggested already.)
2. harder. Use ClovePIE's scripting language to map the tilt to key presses.
but key presses are just on and off. you might be able to make it so that if it's tilted a little to the right, it barely taps the right arrow key every half a second, if it's all the way tilted it holds the key down. you can do the same for all 6 tilt directions if you want. then you write the scratch program to look for those key presses and convert them to a tilt variable, depending on how often the key is pressed.
3. hard. You might be able to write another program that tricks scratch into thinking it's a sensorboard. or perhaps GlovePIE can output to that somehow, so you could use the sensorboard blocks. (like tilt) But that might be much more complicated.
johnnydean1 wrote:
Im getting a bluetooth adaptor soon so Ill try it for myself
You may want to look at these recommendations for bluetooth adaptors for connecting to a wiimote... otherwise it will be a pain or impossible to connect:
http://wiibrew.org/wiki/List_of_Working_Bluetooth_Devices
Last edited by AddZero (2010-04-13 18:08:19)
Offline
Ok, I had to test this further. It works pretty well!
Here's the PIE script and scratch file I made to get button and tilt information for scratch:
To make this work, follow my instructions above and copy and paste this script into GlovePIE.
/*
wiimote 2 scratch by addzero
How to use:
1. Press "Run" button above.
2. Start the scratch program. (in scratch or on website.)
3. Press the "Home" on the wiimote to turn ON and OFF tilt reporting.
This presses a bunch of keyboard buttons quickly depending on the
wiimote angle. (a&d for roll, w&s for pitch The scratch program
converts this to tilt information.)
ONLY turn this on while the scratch program is active.
*/
//Key mappings:
Up = wiimote.Right
Down = wiimote.Left
Left = wiimote.Up
Right = wiimote.Down
Z = wiimote.A
X = wiimote.B
C = wiimote.Plus
V = wiimote.Minus
B = wiimote.One
N = wiimote.Two
H = Wiimote.Battery
wiimote.Led1 = true
//toggle acceleration/tilt reporting with Home button
if wiimote.Home = true
if var.accel = false then
var.accel = true
wiimote.Led4 = true
elseif var.accel=true then
var.accel = false
wiimote.Led4 = false
A=false
D=false
W=false
S=false
end if
wait .5 s
end if
//if it's on, tap the wasd keys depending on the roll and pitch
if var.accel= true
var.time = var.time + 1
if var.time > 8
var.time= 1
end if
if var.time < (wiimote.SmoothPitch / 10)
A=true
else
A=false
end if
if var.time < (wiimote.SmoothPitch / 10) * -1
D=true
else
D=false
end if
if var.time < (wiimote.SmoothRoll / 10)
W=true
else
W=false
end if
if var.time < (wiimote.SmoothRoll / 10) * -1
S=true
else
S=false
end if
end ifthe script taps the wasd keys to give tilt information.
This scratch file is designed to work with it:
http://scratch.mit.edu/projects/AddOne/987298
(side notes:
it's cool that you can press all the keys on the wiimote and they all light up, unlike the keyboard, which will only allow a few keys at a time. It should be easy to add multiple wiimote and nunchuck support. )
Let me know if you try this and it works or you need help with it.
Last edited by AddZero (2010-04-15 02:25:11)
Offline
Could you please make it run of a tilt sensor on the sensing tab.
Offline
AddZero wrote:
Ok, I had to test this further. It works pretty well!
Here's the PIE script and scratch file I made to get button and tilt information for scratch:
To make this work, follow my instructions above and copy and paste this script into GlovePIE.Code:
/* wiimote 2 scratch by addzero How to use: 1. Press "Run" button above. 2. Start the scratch program. (in scratch or on website.) 3. Press the "Home" on the wiimote to turn ON and OFF tilt reporting. This presses a bunch of keyboard buttons quickly depending on the wiimote angle. (a&d for roll, w&s for pitch The scratch program converts this to tilt information.) ONLY turn this on while the scratch program is active. */ //Key mappings: Up = wiimote.Right Down = wiimote.Left Left = wiimote.Up Right = wiimote.Down Z = wiimote.A X = wiimote.B C = wiimote.Plus V = wiimote.Minus B = wiimote.One N = wiimote.Two H = Wiimote.Battery wiimote.Led1 = true //toggle acceleration/tilt reporting with Home button if wiimote.Home = true if var.accel = false then var.accel = true wiimote.Led4 = true elseif var.accel=true then var.accel = false wiimote.Led4 = false A=false D=false W=false S=false end if wait .5 s end if //if it's on, tap the wasd keys depending on the roll and pitch if var.accel= true var.time = var.time + 1 if var.time > 8 var.time= 1 end if if var.time < (wiimote.SmoothPitch / 10) A=true else A=false end if if var.time < (wiimote.SmoothPitch / 10) * -1 D=true else D=false end if if var.time < (wiimote.SmoothRoll / 10) W=true else W=false end if if var.time < (wiimote.SmoothRoll / 10) * -1 S=true else S=false end if end ifthe script taps the wasd keys to give tilt information.
This scratch file is designed to work with it:
http://scratch.mit.edu/projects/AddOne/987298
(side notes:
it's cool that you can press all the keys on the wiimote and they all light up, unlike the keyboard, which will only allow a few keys at a time. It should be easy to add multiple wiimote and nunchuck support. )
Let me know if you try this and it works or you need help with it.
How about joysticks and gamepads? Would they work?
Offline
So did you try it with a wiimote? I noticed that you redid the graphics, cool!
johnnydean1 wrote:
Could you please make it run of a tilt sensor on the sensing tab.
I think that's beyond what I can do, but I'll look into it.
It's possible to make the tapping method work better. I left some test code in there that takes the average of the last 8 or 16 taps using a list and uses that. That's more responsive but jerks more... it could be tweaked to work smoother.
Also I toyed with the idea of sending angle information using binary, by pressing more keys, but that will be more work to work right, because not all the keys report at the same time, or skips.
markyparky56 wrote:
How about joysticks and gamepads? Would they work?
Yes, GlovePIE will work with joysticks and all sorts of things... Rock Band controllers, microphone, ps3 controllers... then you can program them to do all sorts of fun things... midi instruments, browsing the internet, voice output, gaming controllers...
you can also make the wiimote play sounds, vibrate, and turn on and off the lights. it's pretty easy to program.
Last edited by AddZero (2010-04-15 13:22:08)
Offline
AddZero wrote:
markyparky56 wrote:
How about joysticks and gamepads? Would they work?
Yes, GlovePIE will work with joysticks and all sorts of things... Rock Band controllers, microphone, ps3 controllers... then you can program them to do all sorts of fun things... midi instruments, browsing the internet, voice output, gaming controllers...
you can also make the wiimote play sounds, vibrate, and turn on and off the lights. it's pretty easy to program.
Awesome! Thanks.
Offline
Ok, here's a new version of the glovePIE script that moves the mouse depending how the wiimote is tilted, the scratch program then converts this to pitch and roll variables. (it also scales the mouse input so it can work full screen or shrunk.)
It's now very responsive.
/* * wiimote 2 scratch- MOUSE METHOD (not tapping method.) alpha2 by AddZero * * How to use: * 1. Press "Run" button above. * 2. Start the scratch program. (in scratch or on website.) * 3. Press the "Home" on the wiimote to turn ON and OFF tilt reporting. * This moves the mouse depending on the pitch and roll of the wiimote. * The scratch converts this into the pitch and roll variables. * ONLY turn this on while the scratch program is active. */ //Key mappings: Up = wiimote.Right Down = wiimote.Left Left = wiimote.Up Right = wiimote.Down Z = wiimote.A X = wiimote.B C = wiimote.Plus V = wiimote.Minus B = wiimote.One N = wiimote.Two H = Wiimote.Battery wiimote.Led1 = true //toggle acceleration/tilt reporting with Home button if wiimote.Home = true if var.accel = false then var.mouseoffsetX= mouse.CursorPosX var.mouseoffsetY= mouse.CursorPosY mouse.LeftButton = true wait 250 ms mouse.LeftButton = false wait 250 ms mouse.CursorPosX = mouse.CursorPosX + 100 //it moves the mouse 100 so scratch can figure out the mouse scale. //so it works correctly in fullscreen or shrunk as well. wait 500 ms var.accel = true wiimote.Led4 = true elseif var.accel=true then var.accel = false wiimote.Led4 = false mouse.CursorPosX = var.mouseoffsetX mouse.CursorPosY = var.mouseoffsetY end if wait .5 s end if //it moves the mouse depending on the roll and pitch if var.accel= true mouse.CursorPosX = var.mouseoffsetX + (wiimote.SmoothRoll div 2) mouse.CursorPosY = var.mouseoffsetY + (wiimote.SmoothPitch div 2) end if
Use it with this scratch project. See above posts for more information on how to make this work.
Last edited by AddZero (2010-04-16 15:23:36)
Offline
And btw I got a Blue Tooth adaptor in the post so Ill try it soon
Offline
Hey I finally got a adaptor and it works perfectly, your script is fantastic!
Offline
johnnydean1 wrote:
Hey I finally got a adaptor and it works perfectly, your script is fantastic!
Sweet! I'm glad it works!
It may be nice to get the wiimote acceleration (wiimote.RawForceX ...) instead of angle. Scratch would figure out the angle and also register shakes, thrusts and slashes.
the angle value is nice because it's calibrated, there would have to be some way of just sending the acceleration but first send the calibration or calibrate somehow.
the glovePIE wiimote example scripts will give some clues.
I'm looking forward to what you do with this!
Offline
Well I made a script like this
Key.Right = Wiimote.Down Key.Up = Wiimote.Right Key.Down = Wiimote.Left Key.Left = Wiimote.Up Key.Space = Wiimote.2
Offline
johnnydean1 wrote:
Well I made a script like this
Code:
Key.Right = Wiimote.Down Key.Up = Wiimote.Right Key.Down = Wiimote.Left Key.Left = Wiimote.Up Key.Space = Wiimote.2
Cool! that makes the buttons work!
(Do you see how the tilt to mouse works?
and how the home key turns it on and off?)
I'm curious what kind of games you make. Let me know if you want some help.
Last edited by AddZero (2010-04-17 16:32:47)
Offline
Well with that code you can control most games in Scratch
Offline
johnnydean1 wrote:
Well I made a script like this
Code:
Key.Right = Wiimote.Down Key.Up = Wiimote.Right Key.Down = Wiimote.Left Key.Left = Wiimote.Up Key.Space = Wiimote.2
Why Wiimote.right for upkey and not the obvious
up = up
down = down
etc.
Offline
If you hold it on its side (Like a X-box / PS3)
------------------------------------------------------------------------------------------
Up + |
Left Right 1 2 |
Down - |
------------------------------------------------------------------------------------------
Offline