Interfacing to Wii Nunchuck


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429

    Default Interfacing to Wii Nunchuck

    I'm trying to interface a Wii Nunchuck to a PIC using PBP.

    From the info on this page (http://wiibrew.org/wiki/Wiimote/Exte...ollers#Nunchuk), I have written what I think should work, but not having much joy.

    Code:
    'init nunchuck: write $55 to $A400F0 and $00 to $A400FB
    
    I2CWRITE i2c_clock_pin,i2c_data_pin,$A4,$00F0,[$55],fail
    pause 10
    i2CWRITE i2c_clock_pin,i2c_data_pin,$A4,$00FB,[$00],fail
    pause 10
    
    
    'read 6 bytes from $A40008
    
    I2CREAD i2c_clock_pin,i2c_data_pin,$A4,$0008,[STR datain/6]
    However each time I read the 6 bytes i get one of three sets of bytes back (each time I read I get the next set, and then it loops back to the 1st set).

    Code:
    80,FF,7F,7F,7F,7F
    FF,FF,7F,7F,7F,7F
    FB,FF,7F,BF,DF,EF
    Does anyone have any ideas? Has anyone successfully used a nunchuck in PBP?
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  2. #2
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Ok, I worked it out. The main problem is I needed to use:

    Code:
    DEFINE I2C_HOLD 1
    And then the following code works:

    Code:
    init:
    
    i2cwrite i2c_clock_pin,i2c_data_pin,$A4,$F0,[$55]
    pause 1
    i2cwrite i2c_clock_pin,i2c_data_pin,$A4,$FB,[$00]
    pause 1
    
    main:
    
    i2cwrite i2c_clock_pin,i2c_data_pin,$A4,[$00]
    pause 1
    i2cread i2c_clock_pin,i2c_data_pin,$A4,[STR datain/6]
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Nice

    Wondering what you are building for the WII ?

  4. #4
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by RFsolution View Post
    Nice

    Wondering what you are building for the WII ?
    I'm using the nunchuck for the 3-axis accelerometer. Next step is to interface a Wii Motion Plus too for the 3-axis gyroscope. I'm going to combine the two for a full 6 degrees of freedom sensor. The trickiest part of this will be the Kalman filter which involves some pretty heavy maths.

    I'm doing all this because eventually i want to design and build one of these:
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  5. #5
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kamikaze47 View Post
    I'm doing all this because eventually i want to design and build one of these:
    Oh man.... I WANT one!


    steve

  6. #6
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Byte_Butcher View Post
    Oh man.... I WANT one!
    That was exactly my reaction. They are selling kits, but they are hugely expensive. I figured it would be more fun to design one from scratch anyway. I think i'll start with a 4 rotor version.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  7. #7
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kamikaze47 View Post
    That was exactly my reaction. They are selling kits, but they are hugely expensive.
    Expensive AND out of stock.

    Please keep use posted on your progress! (Photos, video, working code, )



    steve

  8. #8
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Byte_Butcher View Post
    Please keep use posted on your progress! (Photos, video, working code, )
    Will do, but it's going to be slow work.

    The Kalman Filter to combine the accelerometer and gyroscope data into useful tilt measurements is what i'm researching at the moment. It's going to be tricky in PBP without floating point math.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  9. #9
    Join Date
    Mar 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: Interfacing to Wii Nunchuck

    I just started messing with the Wii Nunchuk and WMP to do a project similar to the MultiWii on RCGroups. I am just in the beginning stages of the project and was wondering if you would share any code for talking with the Nunchuk? My plan is to finish up the soldering of the connections tonight and hopefully if all goes well I'll be talking with the Nunchuk. I'm going to try and convert code from these sites http://nunchuckmouse.blogspot.com/ and http://www.musclera.com/wii-nunchuk-demonstration/ to PBP in order to accomplish this. It seems pretty basic but I've never messed with I2C. I figure if you have a heads up on how to do this any help would be greatly appreciated.
    Currently I have a 18F2550 CDC/USB connection talking to a VB6 program that I use to send command to turn on and off relays, LED's and move servos around so I'm hoping I can just expand my program to receive the I2C info once I get it to talk and send data down I plan to move forward converting the Arduino code to PBP.
    I also just bought a BTM-182 module from sparkfun to start messing with designing my own controller instead of using an RC remote. If anyone has experience using these or other bluetooth modules help there is appreciated also.
    I am a Mechanical Engineer for a company called Lite Machines, I do all of the tool and die and fixture design stuff and dabble in programming. Check out http://www.litemachines.com we make UAV's for the military so all of this is not out of reach for me just that I'm limited on time and thought maybe we could get a thread started like this one http://www.rcgroups.com/forums/showthread.php?t=1332876.

    Thanks,
    Larry

  10. #10
    Join Date
    Mar 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: Interfacing to Wii Nunchuck

    BTW- This is not in anyway work related. Just something I thought I could do at home that might also get my 9 year old son involved in electronics also.

    Thanks,
    Larry

  11. #11
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default Re: Interfacing to Wii Nunchuck

    Hi;

    I made this program one year ago. This program aquires receive the data from Nunchuck and then acording to some "if", some data is sent to the serial port.
    Maybe you can see how it works, and use it with some modification.

    Try to find the label "Nunchuck" at the end of the program, that is the routine that receive the data from the nunchuck.


    Code

    Code:
    '****************************************************************
    '*  Name    : NUNCHUCK RF.BAS                                   *
    '*  Author  : [Hugo Oliveira]                                   *
    '*  Notice  : Copyright (c) 2010                                *
    '*          : All Rights Reserved                               *
    '*  Date    : 09-07-2010                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : BreadBoard                                        *
    '*          : PIC16F628A                                        *
    '****************************************************************
    include "modedefs.bas"
    DEFINE OSC 4
    DEFINE I2C_HOLD 1
    
    @ DEVICE pic16F628A, INTOSC_OSC_NOCLKOUT
    @ DEVICE pic16F628A, WDT_OFF
    @ DEVICE pic16F628A, PWRT_OFF
    @ DEVICE pic16F628A, MCLR_OFF
    @ DEVICE pic16F628A, BOD_OFF
    @ DEVICE pic16F628A, LVP_OFF
    @ DEVICE pic16F628A, CPD_OFF
    @ DEVICE pic16F628A, PROTECT_OFF
    
    
    '                               VARIÁVEIS
    ' ====================================================================
    Jx var byte
    Jy var byte
    Ax var Byte
    Ay var byte
    BE var bit
    BD var bit
    buffer var byte[6]
    
    '                       REGISTOS PINOUT 1 = IN; 0 = OUT
    ' ====================================================================
             '76543210
    TRISA  = %00000000 
    TRISB  = %00000010
    CMCON = 7  
    VRCON = 0  
    '                              NOMES PINOUT
    ' ====================================================================
    LED    VAR PORTA.1
    TX     Var PORTB.2
    RX     VAR PORTB.1
    SDA    var PORTB.4
    SCL    var PORTB.5
    '                              DEFENIÇÕES
    ' ====================================================================
    DEFINE DEBUG_REG PORTB  
    DEFINE DEBUG_BIT 2
    DEFINE DEBUG_BAUD 19200
    DEFINE DEBUG_MODE 0
    
    '                             INICIO PROGRAMA
    ' ====================================================================
    Start:
     HIGH LED
     PAUSE 500
     LOW LED
     PAUSE 500
     HIGH LED
     PAUSE 500
     LOW LED
     PAUSE 500
     HIGH LED
     
    Main:
    
     GOSUB NUNCHUCK
    '                             JoyStick Eixo X
    ' ====================================================================
      if JX>70 and JX<=100 then
       'SEROUT TX,T9600,["%TE"]
       DEBUG "%TE"
       pause 20
      endif
      
       if JX>0 and JX<=70 then
       'SEROUT TX,T9600,["%TE1"]
       DEBUG "%TE1"
       pause 20 
      endif 
      
      if Jx>180 and Jx<210 then
       'SEROUT TX,T9600,["%TD"]
       DEBUG "%TD"
       pause 20
      endif 
      
      if Jx>=210 then
       'SEROUT TX,T9600,["%TD1"] 
       DEBUG "%TD1"
       pause 20
      endif
    '                             JoyStick Eixo Y
    ' ====================================================================  
      if JY>70 and JY<=100 then
       'SEROUT TX,T9600,["%TB"]
       DEBUG "%TB"
       pause 20 
      endif
      
      if JY>0 and JY<=70 then
       'SEROUT TX,T9600,["%TB1"]
       DEBUG "%TB1"
       pause 20 
      endif  
      
      if Jy>180 and Jy<210 then
       'SEROUT TX,T9600,["%TC"]
       DEBUG "%TC" 
       pause 20
      endif
      
      if Jy>=210 then
       'SEROUT TX,T9600,["%TC1"]
       DEBUG "%TC1" 
       pause 20
      endif    
    '                             Axis -  Eixo X
    ' ====================================================================
      if Ax<100 then
       'SEROUT TX,T9600,["%TE2"]
       DEBUG "%TE2"
       pause 20 
      endif
      
     if Ax>140 then
       'SEROUT TX,T9600,["%TD2"]
       DEBUG "%TD2" 
       pause 20
      endif
    '                             Axis -  Eixo Y
    ' ====================================================================  
      if Ay<110 then
       'SEROUT TX,T9600,["%TB2"]
       DEBUG "%TB2" 
       pause 20
      endif
      
      if Ay>140 then
       'SEROUT TX,T9600,["%TC2"]
       DEBUG "%TC2" 
       pause 20
      endif
    '                             Botões
    ' ====================================================================    
      IF BE = 0 then
       'SEROUT TX,T9600,["%RL1"]
       DEBUG "%RL1" 
       pause 80
      endif
    
      IF BD = 0 then
       'SEROUT TX,T9600,["%RD1"]
       DEBUG "%RD1" 
       pause 80
      endif    
    goto Main
    '                      SUB ROTINA - LEITURA DADOS NUNCHUK
    ' ====================================================================
    NUNCHUCK:
     i2cwrite sda,scl,$A4,$40,[$00]
      pause 10
     i2cwrite sda,scl,$A4,[$00]
      pause 10
     i2cread sda,scl,$A5,[STR buffer\6]
      pause 10
      
     Jx=(buffer[0] ^ $17)+ $17 
     Jy=(buffer[1] ^ $17)+ $17
     Ax=(buffer[2] ^ $17)+ $17
     Ay=(buffer[3] ^ $17)+ $17
     buffer[5]=((buffer[5] ^ $17)+ $17 )
    
     if (buffer[5] & $01) <> 0 then
       BE=1
      else
       BE=0
     endif
     
     if (buffer[5] & $02) <> 0 then
       BD=1
      else
       BD=0
     endif
     
    RETURN
    END
    Thanks and Regards;
    Gadelhas

  12. #12
    Join Date
    Mar 2010
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: Interfacing to Wii Nunchuck

    Thanks Gadelhas,
    I finished wiring up the Wii components last night and will hopefully get a chance to play with the I2C this weekend. I looked through your code and it seems as straight forward as I thought. I will post here or start a new thread once I get this project going.

    Larry

  13. #13
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default Re: Interfacing to Wii Nunchuck

    ok, post your results when you have them!
    Thanks and Regards;
    Gadelhas

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts