Shop OBEX P1 Docs P2 Docs Learn Events
Wii Controller Objects (Nunchuck, Classic Controller, MotionPlus) — Parallax Forums

Wii Controller Objects (Nunchuck, Classic Controller, MotionPlus)

DogPDogP Posts: 168
edited 2013-03-27 08:37 in Propeller 1
Hey,

Here's some Wii Controller Objects for the Propeller (in Spin). They allow you to connect the Wii extension controllers (ones that plug into the Wii Remote) to the Propeller (Nunchuck, Classic Controller, MotionPlus). The devices are I2C, so the easiest way to connect them is to pins 28 and 29 of a Prop board that already has an I2C EEPROM (otherwise you can use any pins and make sure you add the pullup resistor on the SDA line), and of course connect to VCC and GND. The sample programs output the data to the serial port. This format isn't the best since the field width varies, so it's hard to watch as you go, but you can view the data in Excel as comma seperated values, or output in a fixed width format (I didn't see a fixed width output for signed decimal in the serial object I used and didn't feel like messing with it). I figure the code shows how to use it and anyone else will see it work with that demo then implement it into their own code anyway.

This code is based on a Wii nunchuck example project by John Abshier, which was based on code originally by Jo
«1

Comments

  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-20 21:20
    neat ! Here is the TV version.
    My motion plus shows up on 0xA0...
    Nunchuck on 0xA4

    Any Ideas ?

    Here is a scanner for i2c bus

    Earl

    Post Edited (Ole Man Earl) : 6/20/2009 9:28:05 PM GMT
  • Clock LoopClock Loop Posts: 2,069
    edited 2009-06-20 22:58
    These devices need to be combined with Phills 3D Red/Blue video interface somehow...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    TERMS OF USE: MIT License

    "Permission is hereby granted, free of charge, to any pers...........................
    ..............................OMITTED FOR FORUM...............................................
    .................. OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. "
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-20 23:05
    Ok, it's working now on 0xA6 and changing to 0xA4
    If the ranges go outside about 8400, the thing quits with values 8407,8203,8124
    then I need to reload or rerun the program.
    Earl
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-20 23:29
    Or with a heads up camera
    or my OSD
    or
  • RaymanRayman Posts: 14,826
    edited 2009-06-20 23:31
    This is good stuff... I have a few adapters that I piggybacked on another PCB board I did. I'll give them away free at the expo...

    Hope to find time to try this out with my new PSM board!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-20 23:35
    I think I found my problem. On the proto board I am using VDD and VSS near P24. I think I have some noise on it. I am going to try a decoupling cap near the source.
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-20 23:53
    Also, I find after initializing, 0xA0 shows up in my i2c bus scan.

    Yup, it was noise..

    And dog, feel free to use any of my mods!

    Post Edited (Ole Man Earl) : 6/21/2009 12:26:42 AM GMT
  • DogPDogP Posts: 168
    edited 2009-06-21 03:13
    Good to hear it's working for you. But yeah, I noticed my MotionPlus ACKs on 0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0xA0, 0xA1, 0xA6, 0xA7, 0xF1, 0xF3, 0xF5, 0xF7, 0xF9, 0xFB, 0xFD, and 0xFF before initialization, and then all those plus 0xA2 after init (using i2cObject's devicePresent function). I'm assuming it'll be used for compatibility with passing through future devices or something. The ACKs seem to change if I've got a controller plugged into the passthrough port as well.

    BTW, you can see the Nunchuck and Classic Controller in action here: . They're hooked to the propeller, which is also emulating the controller to the Nintendo Virtual Boy. The first part (with the nunchuck) is one of my homebrew demo apps, and the second part (with the Classic Controller) is a commercial game (Red alarm). I'm outputting it to my projector rather than the headset since it's easier to get a video of (although my camera had some problems which made some video glitches and choppy audio). I haven't done a video for anything with the MotionPlus yet... I'll have to make a demo app that shows off 3 axis rotation.

    DogP
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-21 03:34
    Yes, and great work also. Here is my latest spin for the nunchuck as well as the motion plus with output going to the TV
    Earl

    next to combine them for a 6DOF demo !
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-21 03:51
    Now if we can take the Accel X,Y,Z and the Gyro X,Y,Z and put then thru a Kalman filter, wow, what a 6DOF you would have for $35 !
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-21 04:31
    Another atabbb....

    here goes
    Earl
  • DogPDogP Posts: 168
    edited 2009-06-21 07:15
    Yeah, I was thinking about combining the two and doing a full 6DOF driver, but that only works if it's a rigid body... and a MotionPlus and Nunchuck together aren't :/ (although they can be with a little duct tape :P ). Of course a very practical use would taking the circuitry out and mounting it to a rigid body in a robot, aircraft, etc... but I haven't had a need to do that yet... so until then, it's someone else's job [noparse];)[/noparse] . Good to see someone else interested in it though... any suggestions before I submit them to the obex?

    DogP
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2009-06-21 12:33
    There is one thing that most neglect to do when they make an object: PUT YOUR OBJECT IN THE OBEX! If you leave it in the forum, the tread will die on comments an it will go off the starting page where it will never be seen agian. There are so many great objects written out there that are lost because they don't get posted in the OBEX. Phil's "talk" and "3D Graphics" objects, for example. These are great objects that no one ever sees!! Objects are written but then they the person who created it will wait for them to be perfect before they post them; and then they end up never being posted!!! Post these great objects!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Toys are microcontroled.
    Robots are microcontroled.
    I am microcontroled.



    If it's not Parallax then don't even bother. :-)

    Propeller SRAM TV driver winner: ==NOT COMPLEATED:·2 1/2·WEEKS UNTIL ENDING TIME==
  • DogPDogP Posts: 168
    edited 2009-06-21 16:40
    Heh, yeah... I know what you mean... I always check the obex first when I want to do something, then search the forum. A lot of times I find what I'm looking for on the forum (as I did with the original nunchuck code). That's why I planned on putting it in the obex.

    I just figured a couple days on the forum to get some feedback would be good since I've never put anything on there, so if I'm doing something wrong, I'd rather fix it before posting. I saw someone get ripped for not using document comments, which I never used before, since I'm mostly a C programmer where there's just one type of comment. I also didn't know if there was a certain convention for varous things like constants and other things (in C, typically #define'd constants are ALL_CAPS). But yeah, I think I did most things right (from looking at other code and reading the manual), but if not, I'd like to change now, and get any immediate feedback that anyone has, and maybe make any quick changes before posting.

    DogP
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-21 18:47
    DogP,
    How about we get a team together to develop a 6DOF with Kalman filtered output on a circuit board with a prop and a place to mount the nunchuck and motion plus boards ? Would not be hard to do. I can design the circuit board, and some of the software. Just think of it. A <$50 6DOF that is accurate over time ! The autopilot and UAV guys will go bananas over it.
    Earl
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2009-06-21 19:22
    Your right about that! The autopilot guys would love the gyro as a steadying system in thier aircraft, and the Hydra guys would come up with an interface to the nunchuck and classic controller. (or perhaps a new motion controlled Hydra) smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Toys are microcontroled.
    Robots are microcontroled.
    I am microcontroled.



    If it's not Parallax then don't even bother. :-)

    Propeller SRAM TV driver winner: ==NOT COMPLEATED:·1 1/2·WEEKS UNTIL ENDING TIME==
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-21 20:59
    DogP
    Don't wait that long...most of the stuff in the Obj's are not perfect and could use some work. That's the purpose of the Obj's. Post it and they will come !
  • DogPDogP Posts: 168
    edited 2009-06-22 04:00
    Sounds good... I'll upload it to the obex shortly. The 6DOF board sounds fun, but I've got lots of other projects I'd like to do that I have a specific purpose in mind for. Of course I'd be glad to help out if there's something you need, but I'm not really interested in taking on a project that isn't a high priority to me. A low cost development module with all types of tracking would be pretty sweet though (accelerometers, gyros, compass, GPS). Er... I guess I should get a compass module since I've got the rest hooked up to a prop. I really don't know a whole lot about them, but I think it'd work better/easier than gyros for absolute positioning (like rotational head tracking), although I guess I could use a gyro w/ IR for long term accuracy, or even IR for all rotation tracking.

    DogP
  • DogPDogP Posts: 168
    edited 2009-06-22 15:57
    Just wanted to say they're up in the obex now.

    DogP
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-22 17:53
    DogP'
    Great on the Obex !

    I will take on the project of a 6DOF wii with Kalman filter and a PCB to mount then on.
    This won't be real quick as I am flying out to the Expo on Friday.

    First is to combine the nunchuck and motion plus into one program and display on TV. I have made some progress on this one but the gyro wont work at the same time as the nunchuck.
    Here is the progress I made so far.....help someone ?

    Post Edited (Ole Man Earl) : 6/22/2009 7:28:32 PM GMT
  • TimmooreTimmoore Posts: 1,031
    edited 2009-06-22 18:35
    The problem is that both numchuck and motion plus are I2C and when activated are both on address A4 so accessing either will cause the other to activate making them fight over the bus.
    There are a couple of choices I can see.
    1. Connect them to the prop with separate pins, i.e. have 2 I2C buses then they will not conflict.
    2. Activate and deactivate the devices before and after accessing them. You have the activate code - http://abstrakraft.org/cwiid/wiki/MotionPlus describes the deactivate for motion plus to be write $55 to $a400f0. There might be a similar command for the numchuck - might be the same.
    3. Try connecting numchuck to the motion plus extension socket. It could be when the motion plus is activated the expansion socket is deactivated, then you only need to activate/deactivate the motion plus via 2.
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-22 19:28
    see my combo code above...ALMOST works...deactivate etc...close but gyro numbers are not quite right.
  • DogPDogP Posts: 168
    edited 2009-06-22 20:47
    I assume there's a way to get the nunchuck data on the pass-through, but I never got around to trying to figure it out (I'm sure someone will figure it out and post it online somewhere eventually though, if it's not already). I figured the easiest way would be to run 2 I2C buses, since like Tim said, they're the same address, so they'd conflict unless you constantly deactivate and reactivate.

    DogP
  • TimmooreTimmoore Posts: 1,031
    edited 2009-06-22 20:50
    So the motion plus is giving incorrect results but the numchuck is working?
    There is some hints (see https://docs.google.com/Doc?id=dds4pks_606fmcd6zwt&hl=en) that the motion plus can take some time to initialize.
    You might want to put a long delay (several seconds) from enabling motion plus to reading and see if this corrects the problem. If yes then reduce the timeout until it fails
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-22 22:12
    I have gathered the Nunchuck is on i2c address $A4 and the Motion plus is also after it is initialized. Your right, there is a way to read nunchuck data from the pass thru port. I just haven't figured it out yet.
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-23 21:37
    Wait a minute. The Wii game reads the values of the Motion plus AND the nunchuck both on address $A4 without long delays. I agree that the initial initializing takes several seconds.
    Surely we can also read both quickly for the 6DOF !
    The nunchuck and motion plus individually give correct data. Can't seem to put them in one program to get both. What happens is the nunchuck data is fine but the motion plus is all over the place. Yes, like they are fighting for the i2c bus, except for the fact the nunchuck data is correct so I don't thing they are competing for the bus. The motion plus data must be on a different address when the nunchuck is plugged in ??
  • DogPDogP Posts: 168
    edited 2009-06-23 22:36
    Are you talking about when the nunchuck is plugged into the pass-through port of the MotionPlus, or when they're both connected to the one bus (through their main connector that goes into the Wiimote)? If they're both connected to the main port, IIRC the normal init sequence of the nunchuck is the disable sequence of the MotionPlus, which sends the MP back to $A6, and would no longer conflict.

    I don't think the "pass-through" is truly a pass-through... IIRC the pins aren't shared between the front and back (the Wiimote communicates to the MP, which communicates to the pass-through peripheral). I'm going completely by memory though, so you should verify. I'm guessing there's a command or memory location to talk to the pass-through (I don't have any MP games or I'd log them on my Logic Analyzer when they talk to an extension). What I do know though is with the MP plugged in with a nunchuck, the nunchuck doesn't work on old games (so it must not just pass it through).

    DogP
  • Ole Man EarlOle Man Earl Posts: 262
    edited 2009-06-24 01:27
    I realize the front and back i2c ports of the MP are not connected. The nunchuck DOES work with old games because, as you pointed out, the nunchuck init is the MP disable which puts the MP back on $A6 BUT the disable sequence of the MP also puts the rear nunchuch i2c back on $A4 THRU the MP via MP's firmware. It is quite a scheme worked out so that older games WILL work with the ne MP/nunchuck combo.
    That said, the NEW games that take advantage of the MP and NC connected to the back of the MP must access something in the MP to get the acceleration data while also having access to the MP gyro data in the first six bytes. I will do a program to dump the MP data and see what bytes are changing relative to the NC movement.
    Once we have that figured out, THEN we can write a 6DOF program for the Parallax Propeller that will open the prop to many new programs and applications !
    I realize this it not a forum for the Wii, BUT a collaboration of ideas to get inexpensive hardware to work with the prop for more prop applications.

    OK, I think I have run out of all the big words I can look up in the dictionary.......

    I hope we all can figure this out. Any other efforts along this line I have seen are thru linux and bluetooth, not i2c.
  • DogPDogP Posts: 168
    edited 2009-06-24 04:33
    Huh? Really??? None of my old games work with the nunchuck passed through the MP. I tried Wii Sports Boxing, and it tells me to connect a nunchuck, and although I can plug it in directly to get past the screen, then remove the nunchuck and plug in the MP with the nunchuck, none of the nunchuck controls work. I also tried Link's Crossbow Training, which wouldn't detect the Nunchuck through the MP at all, and detected when I removed the nunchuck and wouldn't even allow me to continue with it plugged through the MP. So your games work as if there was no MP??? I wonder if mine's broken :/.

    But yeah... there's not many people working this from the I2C side... luckily it's easy to figure out how to use it over I2C from how people interface through the Wiimote in Linux or over Bluetooth to a PC.

    DogP
Sign In or Register to comment.