Interfacing to Wii Nunchuck


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    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

  2. #2
    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

  3. #3
    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

  4. #4
    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