This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-04-13 04:12:55

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Wii Remote

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?


You can now reach me on Twitter @johnnydean1_

Offline

 

#2 2010-04-13 04:32:27

AddZero
Scratcher
Registered: 2007-08-11
Posts: 100+

Re: Wii Remote

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)


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#3 2010-04-13 07:27:19

midnightleopard
Scratcher
Registered: 2007-09-13
Posts: 1000+

Re: Wii Remote

interesting. I am sure you could do it with a program and some source hacking!


http://pwp.wizards.com/5103673563/Scorecards/Landscape.png

Offline

 

#4 2010-04-13 07:43:48

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Wii Remote

Could you make it work through the WeDo blocks? Since it has a tilt sensor?


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#5 2010-04-13 12:42:41

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Wii Remote

Well has anyone done it?


You can now reach me on Twitter @johnnydean1_

Offline

 

#6 2010-04-13 12:45:26

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Wii Remote

johnnydean1 wrote:

Well has anyone done it?

I think some people have tried...


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#7 2010-04-13 14:48:41

AddZero
Scratcher
Registered: 2007-08-11
Posts: 100+

Re: Wii Remote

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)


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#8 2010-04-13 16:39:16

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Wii Remote

Does it use the tilt sensor like the scratch board

Im getting a bluetooth adaptor soon so Ill try it for myself


You can now reach me on Twitter @johnnydean1_

Offline

 

#9 2010-04-13 17:54:21

AddZero
Scratcher
Registered: 2007-08-11
Posts: 100+

Re: Wii Remote

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)


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#10 2010-04-14 03:33:01

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Wii Remote

Thx


You can now reach me on Twitter @johnnydean1_

Offline

 

#11 2010-04-15 01:44:41

AddZero
Scratcher
Registered: 2007-08-11
Posts: 100+

Re: Wii Remote

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 if

the 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)


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#12 2010-04-15 03:17:45

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Wii Remote

Could you please make it run of a tilt sensor on the sensing tab.


You can now reach me on Twitter @johnnydean1_

Offline

 

#13 2010-04-15 10:09:15

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Wii Remote

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 if

the 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?


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#14 2010-04-15 13:19:32

AddZero
Scratcher
Registered: 2007-08-11
Posts: 100+

Re: Wii Remote

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)


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#15 2010-04-15 13:25:30

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Wii Remote

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.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#16 2010-04-16 13:25:38

AddZero
Scratcher
Registered: 2007-08-11
Posts: 100+

Re: Wii Remote

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.

Code:

/*
 * 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)


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#17 2010-04-16 13:43:54

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Wii Remote

kool


You can now reach me on Twitter @johnnydean1_

Offline

 

#18 2010-04-16 13:46:19

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Wii Remote

And btw I got a Blue Tooth adaptor in the post so Ill try it soon


You can now reach me on Twitter @johnnydean1_

Offline

 

#19 2010-04-17 07:50:53

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Wii Remote

Hey I finally got a adaptor and it works perfectly, your script is fantastic!


You can now reach me on Twitter @johnnydean1_

Offline

 

#20 2010-04-17 14:05:24

AddZero
Scratcher
Registered: 2007-08-11
Posts: 100+

Re: Wii Remote

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!


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#21 2010-04-17 14:34:05

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Wii Remote

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

You can now reach me on Twitter @johnnydean1_

Offline

 

#22 2010-04-17 15:59:33

AddZero
Scratcher
Registered: 2007-08-11
Posts: 100+

Re: Wii Remote

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)


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#23 2010-04-18 11:56:28

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Wii Remote

Well with that code you can control most games in Scratch


You can now reach me on Twitter @johnnydean1_

Offline

 

#24 2010-04-18 14:28:43

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Wii Remote

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.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#25 2010-04-18 14:41:57

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Wii Remote

If you hold it on its side (Like a X-box / PS3)

------------------------------------------------------------------------------------------
     Up                                  +                                            |
Left  Right                                                  1           2          |
    Down                               -                                             |
------------------------------------------------------------------------------------------


You can now reach me on Twitter @johnnydean1_

Offline

 

Board footer