Shop OBEX P1 Docs P2 Docs Learn Events
Wii Nunchuck interface object — Parallax Forums

Wii Nunchuck interface object

JoJo Posts: 55
edited 2009-09-09 17:15 in Propeller 1
The Wii Nunchuck is a neat (and cheap) controller. 3-axis accelerometer, joystick and 2 buttons,
all neatly packaged in a convenient case. The interface is i2c and decoding isn't too complex,
though it has some weird conventions.
I looked around and didn't see any prebuild objects for accessing it from the propeller, neither on
OBEX nor on these forums, so attached is a simple object to talk to it. This object depends on (but
does not include) the i2cObject (obex.parallax.com/objects/217/)

I've connected mine to Propeller pins 28,29; these are the same pins the propeller uses to talk
to its EEPROM and so already have the pull up resistors (besides, reusing those pins just leaves
more pins free to do other stuff). If you're breaking open the Nunchuck cable, pin 28 (SCL) connects
to the yellow wire, pin 29 (SDA) connects to the green wire. However, feel free to connect it to
any other pins (but remember to make the appropriate changes to the pins used to run the i2c
protocol in the Nunchuck object)

You can also very easily make a small double sided PCB that inserts into the nunchuck controller and
gives access to all the pins:

______ 
| 1 2 3  |
|          |
| 6 5 4  |
|_-----_|




1 - green - data
2 - nothing
3 - red - 3.3+v
4 - yellow - clock
5 - nothing
6 - white - ground

--
Jo
«1

Comments

  • RaymanRayman Posts: 14,849
    edited 2008-09-16 20:07
    Sweet! I see it on Amazon.com for $19.99. This is a cool idea...
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2008-09-17 01:32
    Joao -

    Among other things that I would like to do, one of them is to create this interface. Now I can scratch that off my list and add "play with the prebuilt method". I have a Nunchuck sitting here next to my prop, I just need to find time in the day to do it. For those that don't have a Nunchuck, I recommend picking up a used one at a game store for $10 to $15. Those should be good enough to start playing with. This is certainly a great interface object for various applications.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.

    www.brilldea.com·- Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto fo SunSPOT, BitScope
    www.sxmicro.com - a blog·exploring the SX micro
    www.tdswieter.com
  • JoJo Posts: 55
    edited 2008-09-18 19:41
    You're welcome smile.gif
    Going to have to drop this into OBEX as soon as I have some time.
    If anyone has any suggestions on how to make it better or anything, feel free to drop me a line or reply to this subject.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ---
    Jo
  • RaymanRayman Posts: 14,849
    edited 2008-11-07 13:28
    There's a $4 adapter for the Nunchuck around...· Or, looks like you can just integrate it into your own PCB easily:

    http://store.fungizmos.com/index.php?main_page=product_info&cPath=69&products_id=212

    I've also noticed that there's an NES gamepad that works the same way (I2C):

    http://www.amazon.com/Wii-Classic-Controller-nintendo/dp/B000IN0BSU

    This looks to be a really cool way to integrate a controller into a design.· And, it can use the existing I2C bus, thereby not using any pins...
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-11-07 14:51
    @Ray:

    Nice find! Ordered a few of those myself.

    OBC


    Edit: I got free shipping on those Wii PCB's (US) because they were the only thing I ordered.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with a Propeller Protoboard?
    Check out: Introduction to the Proboard & Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card connected? - PropDOS

    Post Edited (Oldbitcollector) : 11/8/2008 2:48:35 AM GMT
  • cimplexcimplex Posts: 11
    edited 2008-11-08 00:00
    Just picked up a new one at WalMart for $19.95.
  • JamesxJamesx Posts: 132
    edited 2008-11-08 01:37
    OK, so suppose you now have the Wii controller as an input to a Propeller. What are the first three or four cool things you might try doing with it?

    Jim
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-11-08 02:44
    Just picked up both controllers for $14 each at the local Gamestop.

    The Wii Classic controller looks awesome.. Now to wait for those breakout boards.

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with a Propeller Protoboard?
    Check out: Introduction to the Proboard & Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card connected? - PropDOS
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-11-08 03:02
    Jamesx said...
    OK, so suppose you now have the Wii controller as an input to a Propeller. What are the first three or four cool things you might try doing with it?

    Jim


    Using it an an interface for this game would be cool..
    www.youtube.com/watch?v=V8d_aJwikfk - {Master of the Lamp}
    (Of course porting the entire game to the Prop even better.)

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with a Propeller Protoboard?
    Check out: Introduction to the Proboard & Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card connected? - PropDOS
  • J. A. StreichJ. A. Streich Posts: 158
    edited 2008-11-08 18:26
    Jamesx said...
    OK, so suppose you now have the Wii controller as an input to a Propeller. What are the first three or four cool things you might try doing with it?

    Jim

    Ideas that come to my head:

    1. Wii Nunchuch and XBee for wireless control of bot(s)
    2. Wii Nunchuch as pointing device to control a cursor on a screen.
    3. Two Wii Nunchuchs for prop pong.

    The first idea I've been thinking about for a while, actually.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-11-10 19:32
    Got my Wii adapters in today.. tiny!

    I'm looking forward to playing with these tonight.
    Thanks again Ray for spotting this.

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with a Propeller Protoboard?
    Check out: Introduction to the Proboard & Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card connected? - PropDOS
    450 x 300 - 83K
  • sylvie369sylvie369 Posts: 1,622
    edited 2008-11-10 19:57
    Mine arrived today too, just when I got home from buying one of the controllers. I can't wait to try it out tonight. Thanks for pointing this out.

    Later:

    Man, I love the Propeller. About 45 minutes worth of tinkering, and it's up and running, thanks to that object you wrote.
    This is so cool.

    Post Edited (sylvie369) : 11/11/2008 12:11:08 AM GMT
    2973 x 1859 - 2M
  • Steve NelickSteve Nelick Posts: 25
    edited 2008-11-19 03:09
    In the Nunchuk.spin object, what do the values of accelX, accelY, and accelZ mean?

    I see how to use the joystick (joyX and joyY), and I see how to read the buttons (buttonC and buttonZ), but I'm having trouble interpreting the accelX, accelY, and accelZ.

    If I hold the Wii Nunchuk in my hand and rotate my wrist left and right, the accelX value goes from about -200 to +200 And, if I rotate my wrist forward and back the accelY value goes from -200 to +200. The accelZ value keeps changing, but I don't see a pattern there.

    Do these X, Y, and Z values somehow compute into a point in a 3-D coordinate space?

    Do you think that the Wii System uses the actual values X, Y, and Z, or does it somehow use the changes in the values of X,Y, and Z to track the game player's motion when waving the controller?
  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2008-11-19 03:36
    The accelX, Y, Z are measures of accelerations in different directions. I haven't hooked up a nun-check or used the object yet, but it sounds like from you findings that if you move left or right (not necessarily rotate) you get X acceleration. zfront and back is y acceleration. Therefore up and down is Z acceleration.

    These values by themselves are not coordinates in 3D space. If you knew your position however and then knew your acceleration you could calculate velocity and thus distance from that known position. Make sense? This isn't easy to do because there are all sorts of errors that could accumulate that need to be accounted for.

    In the Wii and in your code there should be processing algorithms. There probably isn't a "This value of accelX = this action". You coudl do that, nothing wrong with it. But more of a algorithm for detecting changes and how much change is what is used to detect motion.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto for SunSPOT, BitScope
    www.tdswieter.com
  • Steve NelickSteve Nelick Posts: 25
    edited 2008-11-19 15:39
    Well Timothy, after reading your note I realized that using the accelerometer readings wasn't going to be as easy as I had hoped. So, I GOOGLED accelerometers and I see that Parallax has a course that covers accelerometers: Smart Sensors and Applications. I looked in some boxes of stuff I have from Parallax, and I found a Parallax Memsic 2125 accelerometer, and a Parallax Hitachi HM55B compass. I think I have everything I need to take the Parallax course. For a minute I thought that maybe I already had the Parallax course, but when I went thru some more boxes, what I have is Tracy Allen's Applied Sensors course, which covers a different sey of sensors.

    I'm going to start with the Smart Sensors and Applications course, and then go back to learning about Wii Nunchuk controller.
  • JoJo Posts: 55
    edited 2008-11-19 16:46
    The X, Y, Z acceleration sensors can be used to determine the orientation of the nunchuck in space and in what direction it is moving.

    The theory part first: as we live on earth, there is a constant 1G gravitational field accelerating us down all the time. So, if the nunchuck is being held still
    (so that there are no extra acceleration forces) regardless of orientation, the dot product all the acceleration sensors will be constant (and represents
    1g in the sensor units).
    The direction of the resulting vector indicates which way the nunchuck is being held.

    The formulae:
    X := accelX()
    Y := accelY()
    Z := accelZ()
    acceleration := X*Y+Y*Z+Z*X
    Generally acceleration is constant *unless* the nunchuck is being moved in some direction, in which cases it increases when it is accelerated/decelerated.

    The orientation can then be figured out:
    roll := atan2(X, Z)
    pitch := acos(Y/acceleration)

    NOTE that the nunchuck cannot detect yaw (rotation on the horizontal plane).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ---
    Jo
  • Jay KickliterJay Kickliter Posts: 446
    edited 2008-12-11 20:43
    I download the object, and using this code:

    PUB init
       i2cObject.Init(i2cSDA, i2cSCL, false)
       uart.start(31, 30, 0, 9600)
       mainLoop
    
    PUB mainLoop
        repeat
          readNunchuck
          uart.dec(joyX)
          uart.tx(COMMA)
          uart.dec(joyY)
          uart.tx(COMMA)
          uart.dec(accelX)
          uart.tx(COMMA)
          uart.dec(accelY)
          uart.tx(COMMA)
          uart.dec(accelZ)
          uart.tx(COMMA)
          uart.dec(buttonC)
          uart.tx(COMMA)
          uart.dec(buttonZ)
          uart.tx(CR)            
    
    



    In the serial terminal I'm getting:

    255,255,1023,1023,1023,0,0

    Over and over again.

    I have the greed wire hooked up to pin 29, yellow to 28, white to GND, and red to 3.3, as per the instructions.

    Any ideas why the values aren't changing, no matter what I do with the Nunchuck?
  • John AbshierJohn Abshier Posts: 1,116
    edited 2008-12-11 21:00
    The thing I see is that all bits are 1s for returned analog values and all 0s for the buttons. I don't know what that tells one. Are you sure you have set i2cSDA and i2cSCL to the correct values?

    John Abshier
  • Jay KickliterJay Kickliter Posts: 446
    edited 2008-12-11 21:35
    Checked and double checked. Even tried adding additional pull-up resistors. I'm attaching a photo, maybe someone can spot something I can't.
    1024 x 768 - 1M
  • BeanBean Posts: 8,129
    edited 2008-12-11 22:06
    I don't know if this is the problem. But in SX/B the default speed of the I2C is too fast for the nunchuk and you get something like that for the data.
    Try slowing down the I2C speed and see if that helps. In SX/B you must you 1/2 the default speed.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    "The welfare of the people in particular has always been the alibi of tyrants." ~ Camus
    www.iElectronicDesigns.com

    ·
  • Jay KickliterJay Kickliter Posts: 446
    edited 2008-12-11 22:23
    Tried slowing it down, but that didn't help any. I did realize that I bought an off-brand nunchuck. Made by intec. I would image they'd be compatible. Maybe they have different i2c address?

    Edit. I found the address scanning function in the i2c demo. It shows addresses $A0 and $A4 acknowledging, I tried using both address. Still nothing.

    Post Edited (Jay Kickliter) : 12/11/2008 10:44:36 PM GMT
  • BaggersBaggers Posts: 3,019
    edited 2008-12-12 00:35
    Jay, I was getting the same duff data too, when I tried, don't have time to look into it yet, maybe over xmas hols [noparse]:D[/noparse] so if you find out before hand let me know.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • Jay KickliterJay Kickliter Posts: 446
    edited 2008-12-12 13:07
    Baggers, are you using Nintendo's Nunchuck or a generic one like me? I didn't realize mine was generic when I bought it, and don't want to cut another cable just to find out it is a sofware problem, not hardware.
  • BaggersBaggers Posts: 3,019
    edited 2008-12-12 16:03
    Jay, I pretty sure it was Nintendo Nunchuck, but couldn't be 100% sure now, as you're questioning it, it was in a nintendo looking box, I got it when I got my Wii, about a year ago.
    like I say, though, I'm pretty sure it's a real nintendo one, is there a definitive way to confirm it?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • Jay KickliterJay Kickliter Posts: 446
    edited 2008-12-12 17:19
    I don't know for sure. But the one I bought has blue sides, and in small print on the box it says it's made Intec.
  • BaggersBaggers Posts: 3,019
    edited 2008-12-12 18:27
    then this one is a proper nintendo one then [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • soshimososhimo Posts: 215
    edited 2008-12-20 04:09
    I too just got my adapter board (as well as my propeller). My project will consist of reading the accelerometer data and move a servo assigned to that axis a number of degrees equal to the amount of acceleration. The idea is to use continuous rotation servos so I can get 360 degrees of freedom from each axis but my prototype currently consists of a single hobby servo that has not been modified for continuous rotation. I've attached a picture of my circuit laid out on protoboard with my wii chuck and servo. Notice the wii chuck adapter - best 4 bucks I've every spent (well, best 12 bucks was for the propeller but this was a close second).

    One final note. Joao, thank you so much for this contribution. I was not looking forward to the work required just to see if my POC is sound and you just saved me tons of work. Thanks again!

    Post Edited (soshimo) : 12/20/2008 4:20:04 AM GMT
    640 x 480 - 544K
  • soshimososhimo Posts: 215
    edited 2008-12-20 12:59
    I posted a YouTube video of the code in action. My next goal is to create a head (probably out of legos because it's easy and it's what I have) that I can then rotate on x/y axis using the Wii Nunchuck joystick and the servos.
  • BaggersBaggers Posts: 3,019
    edited 2008-12-20 15:54
    Cool vid soshimo [noparse]:)[/noparse]
    Can't wait to get mine working too.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • Cluso99Cluso99 Posts: 18,069
    edited 2008-12-20 16:12
    Nice video smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Prop Tools under Development or Completed (Index)
    http://forums.parallax.com/showthread.php?p=753439

    cruising][noparse][[/noparse]url=http://www.bluemagic.biz]cruising[noparse][[/noparse]/url][/url]

    This is a [noparse][[/noparse]b]bold[noparse][[/noparse]/b] test.
Sign In or Register to comment.