Rotate a 3D cube using a WiiChuck

Hello there,

I've managed to get my hands on a WiiChuck Adapter(“WiiChuck” Wii Nunchuck Adapter Available – todbot blog) and a Wii nunchuck.

I've used the sample code:

/*
 * WiiChuckDemo -- 
 *
 * 2008 Tod E. Kurt, http://thingm.com/
 *
 */

#include <Wire.h>
#include "nunchuck_funcs.h"

int loop_cnt=0;

byte accx,accy,accz,zbut,cbut;
int ledPin = 13;


void setup()
{
    Serial.begin(19200);
    nunchuck_setpowerpins();
    nunchuck_init(); // send the initilization handshake
    
    Serial.print("WiiChuckDemo ready\n");
}

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

        nunchuck_get_data();
        nunchuck_print_data();
        /*
        accx  = nunchuck_accelx(); // ranges from approx 70 - 182
        accy  = nunchuck_accely(); // ranges from approx 65 - 173
        accz  = nunchuck_accelz();
        zbut = nunchuck_zbutton();
        cbut = nunchuck_cbutton(); 
        //Serial.print((byte)nunchuck_roll(),DEC);
        //Serial.print("\n");
        //minX = 27,maxX = 185;//minX = 55,maxX = 213;//minX=48,maxX=233
        //minY = 96,maxY = 246;minY = 64, maxY = 255;
        /*    
        Serial.print("accx: "); Serial.print((byte)accx,DEC);
        Serial.print("\taccy: "); Serial.print((byte)accy,DEC);
        Serial.print("\taccz: "); Serial.print((byte)accz,DEC);
        Serial.print("\tzbut: "); Serial.print((byte)zbut,DEC);
        Serial.print("\tcbut: "); Serial.println((byte)cbut,DEC);
        //*/
    }
    loop_cnt++;
    delay(1);
}

I can print accelerometer values, but don't know how to convert these reading into rotationX,rotationY,rotationZ values I could use to spin a 3D cube in Processing for example.

Any ideas ?

Thanks,
George

Not sure about this, but accelerometer values are not X, Y, Z coordination. They are accelerations and vectors, but they can be used to find an angle.
Gyroscope is rotation.

Not sure, like I said. Maybe a multi-axis can do it.
Im currently reading the link...
Nunchuck is 3 axis alright.

Read this:

http://arduino.cc/en/Reference/Map

Hi sxdemon,

Thanks for the idea.
I could use that, but I don't know exactly how the the values map.
I imagined the values will be from 0 to 1023(like what analogRead() returns), but it seems like they could go to 255.

Also, I tried storing read values in a large array over time, while rotating the nunchuck, then getting the minimum and maximum values. The more 'samples' I took, the wider the ranges were, towards 255.

e.g.

minX = 27,maxX = 185;
then
minX = 55,maxX = 213;
then
minX=48,maxX=233

minY = 96,maxY = 246;
then
minY = 64, maxY = 255;

I'm a bit confused by the values.

If the device measures acceleration it almost certainly uses a signed data representation, so where is your zero point?
Simple test: hold the device horizontal.
Now your x and y axes should read roughly zero, and your z axis should read a bout 1g

@Groove

If I hold the device horizontal, I get these acceloremeter values:

x:47
y:170~180
z:217~220

y and z tend to change a bit even if I try to hold my hand still, while x barely changes, regardless of movement, this is using a nunchuck_print_data() call after nunchuck_get_data()

Sorry, I'm posting from my phone, and the browser doesn't let me scroll inside Code boxes, so I can't see all your code, so I can't comment further at the moment.

@Groove

The values in the code box were:
x:47
y:170~180
z:217~220

even horizontally you will probably get data. (since there is always some sort of acceleration or unbalanced mouvement)
as far as I know, the only way to get a Y value of 0 is a free fall ;D

try sending characters instead of numbers. i have done it and works fine. yet i have made a computer moues from Nunchuck. but rotating a cube should be a cakewalk. convert each movement of nunchuck in a specific character and send that alone to avoid synchronization issues. Have a look at my mouse code that has the nunchuk code also here: hardikpandya.com