Wii Nunchuck

May 6, 2009 at 8:50pm

Wii Nunchuck

Ok, hello

new to max, fairly proficient at Arduino

trying to get Wii Nunchuck to control sound in max.

arduino part is working fine. here’s my code.

#include 
#include "nunchuck_funcs.h"

int loop_cnt=0;

byte accx,accy,accz, zbut,cbut,joyy, joyx;

void setup()
{
    Serial.begin(19200);
    nunchuck_setpowerpins();
    nunchuck_init(); // send the initilization handshake

    Serial.print("Wii Gonna Fug It Upn");

}

  void loop()
{
  if( loop_cnt > 50 ) { // every 100 msecs get new data
        loop_cnt = 0;

        nunchuck_get_data();

        accx  = nunchuck_accelx(); // ranges from approx 70 - 182
        accy  = nunchuck_accely(); // ranges from approx 65 - 173
        accz  = nunchuck_accelz(); // ranges from approx 65 - 173
        zbut = nunchuck_zbutton();
        cbut = nunchuck_cbutton();
        joyy = nunchuck_joyy();
        joyx = nunchuck_joyx();   

        Serial.print((byte)accx,DEC);
        Serial.print(" ");
        Serial.print((byte)accy,DEC);
        Serial.print(" ");
        Serial.print((byte)accz,DEC);
        Serial.print(" ");
        Serial.print((byte)zbut,DEC);
        Serial.print(" ");
        Serial.print((byte)cbut,DEC);
        Serial.print(" ");
        Serial.print((byte)joyy,DEC);
        Serial.print(" ");
        Serial.println((byte)joyx,DEC);

    }

  loop_cnt++;
    delay(1);
}

works great. I get numbers like this in the monitor:

79 129 140 0 0 133 120
79 129 139 0 0 133 120
79 129 140 0 0 133 120
79 129 140 0 0 133 119
79 129 140 0 0 133 120
79 129 139 0 0 133 120
79 129 140 0 0 133 120
79 129 140 0 0 133 120
79 129 139 0 0 133 119
79 129 140 0 0 133 120
79 129 140 0 0 133 120
79 129 140 0 0 133 119
79 129 140 0 0 133 119

how the heck do i use these numbers? I have tried to use the various arduino/max libraries, but none of them work, I think because the nunchuck sends serial data and serial clock to arduino.

Please help. I must say, I don’t even understand at this point how to make max read the serial. I just know it isn’t working with the patches i’ve found.

#43701
May 8, 2009 at 4:47pm

hi there –
the standard way to get wiimote data into max is to use the aka.wiimote object:

http://www.iamas.ac.jp/~aka/max/

#156940
May 8, 2009 at 5:45pm

not wiimote. wii nunchuck via arduino.

#156941
May 8, 2009 at 6:29pm

Ok I got it, for anyone curious:

arduino code:

#include 
#include "nunchuck_funcs.h"

int loop_cnt=0;

byte accx,accy,accz, zbut,cbut,joyy, joyx;

void setup()
{
    Serial.begin(115200);
    nunchuck_setpowerpins();
    nunchuck_init(); // send the initilization handshake

    //Serial.print("Wii Gonna Fug It Upn");

}

  void loop()
{
  if( loop_cnt > 50 ) { // every 100 msecs get new data
        loop_cnt = 0;

        nunchuck_get_data();

        accx  = nunchuck_accelx(); // ranges from approx 70 - 182
        accy  = nunchuck_accely(); // ranges from approx 65 - 173
        accz  = nunchuck_accelz(); // ranges from approx 65 - 173
        zbut = nunchuck_zbutton();
        cbut = nunchuck_cbutton();
        joyy = nunchuck_joyy();
        joyx = nunchuck_joyx();   

        Serial.print(accx, DEC);
        Serial.print(",");
        Serial.print(accy,DEC);
        Serial.print(",");
        Serial.print(accz,DEC);
        Serial.print(",");
        Serial.print((byte)zbut,DEC);
        Serial.print(",");
        Serial.print((byte)cbut,DEC);
        Serial.print(",");
        Serial.print(joyx,DEC);
        Serial.print(",");
        Serial.println(joyy,DEC);

    }

  loop_cnt++;
    delay(1);
}

Max patch (4.6.3)

#P window setfont "Sans Serif" 9.;
#P flonum 332 463 46 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 332 414 46 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 332 438 49 196617 change 0;
#B color 14;
#P flonum 390 463 46 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 390 414 46 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 390 438 49 196617 change 0;
#B color 14;
#P flonum 214 463 46 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 214 414 46 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 214 438 49 196617 change 0;
#B color 14;
#P flonum 156 463 46 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 156 414 46 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 156 438 49 196617 change 0;
#B color 14;
#P flonum 96 463 46 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 96 414 46 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 96 438 49 196617 change 0;
#B color 14;
#P flonum 33 463 46 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 33 414 46 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 33 438 49 196617 change 0;
#B color 14;
#P newex 137 377 170 196617 unpack i i i i i i i i i i i i i;
#P message 19 194 20 196617 13;
#P newex 65 193 31 196617 spell;
#P newex 19 167 56 196617 trigger b l;
#P newex 137 159 43 196617 delay 4;
#P button 137 185 15 0;
#P message 19 144 14 196617 r;
#P window setfont "Sans Serif" 10.;
#P comment 221 353 141 196618 Combine into one value;
#P comment 221 326 141 196618 Convert to integers;
#P window setfont "Sans Serif" 9.;
#P newex 137 351 64 196617 fromsymbol;
#P newex 137 325 40 196617 itoa;
#P newex 137 298 61 196617 zl group 78;
#P newex 137 264 67 196617 select 10 13;
#P window setfont "Sans Serif" 10.;
#P comment 203 22 90 196618 serial port select;
#P window setfont "Sans Serif" 9.;
#P user ubumenu 233 41 29 196617 0 1 1 0;
#X add a;
#X add b;
#X add c;
#X add d;
#X add e;
#X add f;
#X prefix_set 0 0  0;
#P button 315 41 15 0;
#P button 19 119 15 0;
#P newex 233 70 67 196617 prepend port;
#P window setfont "Sans Serif" 10.;
#P window linecount 2;
#P comment 102 70 101 196618 sample rate (15ms -- 100ms);
#P window setfont "Sans Serif" 9.;
#P number 61 70 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P user hslider 61 41 19 111 86 1 15 0;
#P toggle 19 42 15 0;
#P window linecount 1;
#P newex 19 96 52 196617 metro 10;
#P newex 137 236 110 196617 serial b 115200 8 1 0;
#P message 315 70 32 196617 print;
#P window setfont "Sans Serif" 10.;
#P comment 312 22 86 196618 list serial ports;
#P comment 9 22 47 196618 On/Off;
#P comment 221 267 174 196618 Ascii character 10 = CR , 13 = LF;
#P comment 221 301 141 196618 Group characters until LF;
#P window setfont "Sans Serif" 9.;
#P flonum 274 463 46 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 274 414 46 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 274 438 49 196617 change 0;
#B color 14;
#P connect 31 12 45 0;
#P connect 31 10 48 0;
#P connect 31 8 1 0;
#P connect 31 6 42 0;
#P connect 31 4 39 0;
#P connect 22 0 31 0;
#P connect 31 2 36 0;
#P connect 31 0 33 0;
#P connect 10 0 9 0;
#P connect 9 0 15 0;
#P connect 15 0 25 0;
#P connect 25 0 28 0;
#P connect 28 0 30 0;
#P connect 33 0 32 0;
#P connect 32 0 34 0;
#P fasten 11 0 12 0 66 60 66 60;
#P connect 12 0 9 1;
#P connect 28 1 29 0;
#P connect 36 0 35 0;
#P connect 35 0 37 0;
#P fasten 15 0 27 0 24 139 142 139;
#P connect 27 0 26 0;
#P fasten 14 0 8 0 238 223 142 223;
#P fasten 7 0 8 0 320 223 142 223;
#P fasten 30 0 8 0 24 223 142 223;
#P fasten 29 0 8 0 70 223 142 223;
#P connect 26 0 8 0;
#P connect 8 0 19 0;
#P fasten 19 2 20 0 198 290 142 290;
#P fasten 19 1 20 0 170 290 142 290;
#P connect 20 0 21 0;
#P connect 21 0 22 0;
#P connect 39 0 38 0;
#P connect 38 0 40 0;
#P connect 42 0 41 0;
#P connect 41 0 43 0;
#P connect 17 0 14 0;
#P connect 1 0 0 0;
#P connect 0 0 2 0;
#P connect 16 0 7 0;
#P connect 48 0 47 0;
#P connect 47 0 49 0;
#P connect 45 0 44 0;
#P connect 44 0 46 0;
#P window clipboard copycount 50;
#156942

You must be logged in to reply to this topic.