Shop OBEX P1 Docs P2 Docs Learn Events
Wii nunchuck help — Parallax Forums

Wii nunchuck help

I was wondering how I would get the data from the nunchuck? their are four pins:
Red 3 volt
Green Data analog in 4
yellow wier clock / analog in 5
white wire ground

I was wondering if i would do the usual serin feature?
thanks for the help!!

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-06-15 20:32
    Can't remember if the nunchuck uses spi or I2C data. Sparkfun makes a breakout board so you dont have to cut the cable. There are several hacks using the arduino you might be able to get some info from and I saw a program for the PC that reads the wiimote and nunchuck using bluetooth.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • BeanBean Posts: 8,129
    edited 2009-06-15 21:53
    Andy,
    The Nunchuk uses I2C, but it's rather picky about the speed. I've not tried the nunchuk on the Basic stamp, but I HAVE used it the the SX. On the SX you must slow down the standard I2C speed by about half.

    If I get a chance, I'll try to get it working on the BS2.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
  • sylvie369sylvie369 Posts: 1,622
    edited 2009-06-15 22:49
    There's a Nunchuck object in the Sensors section of the Propeller Object Exchange:

    http://obex.parallax.com/objects/436/

    that might give you some useful information.
  • BeanBean Posts: 8,129
    edited 2009-06-16 11:32
    Andy has asked for the SX/B code. I figured I'd post it in the thread for all to enjoy.

    DEVICE SX28, OSC4MHZ
    FREQ 4_000_000
     
    ' Nunchuk connections
    ' White wire  = Vss
    ' Red wire    = Vdd
    ' Green wire  = SDA (RA.0)
    ' Yellow wire = SCL (RA.1)
     
    LEDS   PIN RB OUTPUT ' RB.0 and RB.1 show status of Nunchuk buttons
     
    SDA    PIN RA.0 INPUT PULLUP
    SCL    PIN RA.1 INPUT PULLUP
     
    ACK    CON 0
    NAK    CON 1
     
    temp    VAR BYTE
    nunData VAR BYTE (6)
     
    ' NunChuk variables
    stickX  VAR BYTE
    stickY  VAR BYTE
    buttonZ VAR BIT
    buttonC VAR BIT
    AxisX   VAR BYTE
    AxisY   VAR BYTE
    AxisZ   VAR BYTE
     
    ' Subs and functions
    I2C_START    SUB 0
    I2C_STOP     SUB 0
    I2C_SEND     SUB 1
    I2C_RECV     FUNC 1,1
     
    PROGRAM Start
     
    Start:
    
     
      ' Initialize Nunchuk
      I2C_Start
      I2C_Send $A4
      I2C_Send $40
      I2C_Send $00
      I2C_Stop
      DO
    
     
        ' Request data from nunchuk
        I2C_Start
        I2C_Send $A4
        I2C_Send $00
        I2C_Stop
        PAUSEUS 200
     
        ' Receive data from nunchuk
        I2C_Start
        I2C_Send $A5
        PAUSEUS 20 ' If you omit this the first bit can read as a 1 even if it is a zero at fast clock speeds
        FOR temp = 0 TO 4
          nunData(temp) = I2C_Recv ACK
        NEXT
        nunData(5) = I2C_Recv NAK
        I2C_Stop
     
        ' Translate nunchuk data
        FOR temp = 0 TO 5
          nunData(temp) = nunData(temp) XOR $17
          nunData(temp) = nunData(temp) + $17
        NEXT
     
        ' Put data into variables
        stickX = nunData(0) - 128
        stickY = nunData(1) - 128
        axisX = nunData(2) - 128
        axisY = nunData(3) - 128
        axisZ = nunData(4) - 128
        temp = nunData(5)
        buttonZ = ~temp.0
        buttonC = ~temp.1
    
      ' Show variables using signed values
      LEDs = temp
      BREAK
      
      WATCH stickX,8,SDEC
      WATCH stickY,8,SDEC
      WATCH axisX,8,SDEC
      WATCH axisY,8,SDEC
      WATCH axisZ,8,SDEC
      WATCH buttonZ
      WATCH buttonC
     
      LOOP
    END
     
    I2CSPEED 0.50 ' The nunchuk needs slow I2C communication
    
    SUB I2C_START
      I2CSTART SDA
    ENDSUB
    
    SUB I2C_STOP
      I2CSTOP SDA
    ENDSUB
     
    SUB I2C_SEND
      I2CSEND SDA, __PARAM1
    ENDSUB
    
    FUNC I2C_RECV
      __PARAM5 = __PARAM1
      I2CRECV SDA, __PARAM1, __PARAM5.0
      RETURN __PARAM1
    ENDFUNC
     
    


    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
Sign In or Register to comment.