Hack cheap wii nunchuck to build accelerometer.

Hi. I v manage to hack a cheap wii nunchuck (5$ included shipment) found on ebay , to build a 3 axes accelerometer. When i open it i v found inside a LIS3L02AE The final "product" is this.... You can find details how is builded in http://www.grobot.gr/phpBB3/viewtopic.php?f=7&t=456&st=0&sk=t&sd=a&start=10 and because is in Greek try a trancelated version ;) http://translate.google.gr/translate?js=y&prev=_t&hl=el&ie=UTF-8&layout=1&eotf=1&u=http%3A%2F%2Fwww.grobot.gr%2FphpBB3%2Fviewtopic.php%3Ff%3D7%26t%3D456%26st%3D0%26sk%3Dt%26sd%3Da%26start%3D10&sl=el&tl=en is the best i can do :-[ In the new "product" there are 5 out pins. VDD(3,3V),GND and also VoutX,VoutY,VoutZ The problem is that Now i v got a working accelerometer but i cant find a code to operate it. Anyone can help ??? Thnx in advance

Here are a couple of projects that used the Wii Nun chuck. They should have available libraries that will help. http://www.windmeadow.com/node/42 http://hackaday.com/2009/03/30/arduino-wii-nunchuck-servos/

Thnx digimike for your reply...but..as far as i understand all wii nunchuck libraries and sketches use i2c protocol. That means that connection cables are VDD , GND , CLOCK and DATA. In my case my ouyput pins , as mentioned in my 1st post , are VDD(3,3V),GND and also VoutX,VoutY,VoutZ so i think (i m not sure) that wont work in my case..right ?

I'm not sure it's worth all that trouble. You can get 3-Axis Accelerometers NEW from Mouser for about $5 US and you can get 2 Axis ones for around $3.00 US.

Id you have a nunchuck... it's easier to leave it assembled... (unless it was broken but the accelerometer was still good.

Granted... that SPECIFIC part is actually listed as Obsolete from ST MICRO... so maybe that is the only way to get that particular one right now.

Thnx pwillard ;)

(unless it was broken but the accelerometer was still good This is my case... so i build it.... Any idea where can i find a general purpose code for my case ???

"General purpose" is a simple sketch that just reads three analogue channels and prints the result. 15-20 lines at most.

Groove >>>>General purpose" is a simple sketch that just reads three analogue channels and prints the result. 15-20 lines at most. Thnx for your reply. You mean something like..

int xpin = 3;                // x-axis of the accelerometer
int ypin = 2;                // y-axis
int zpin = 1;                // z-axis (only on 3-axis models)

void setup()
{
 Serial.begin(19200); 
}

void loop()
{
 Serial.print(analogRead(xpin)*0.0049);
 Serial.print(" ");
 Serial.print(analogRead(ypin)*0.0049);
 Serial.print(" ");
 Serial.print(analogRead(zpin)*0.0049);
 Serial.println();
 delay(100);
}

The above just prints the Volts in every accelerometer output.

I need something more "general purpose" ;) to calculate the angle in each axis for example.

I need something more "general purpose"

That code is as general as you can get. I think you're looking for something LESS general purpose - more specific in nature - that does something that YOU want.

PaulS >>>> That code is as general as you can get. I think you’re looking for something LESS general purpose - more specific in nature - that does something that YOU want.

I know :)… i was kidding :wink:
The truth is that i need something to calculate the angles that my accelerometer is.

Sorry if my "joke"wasnt so clear… :-[

i need something to calculate the angles that my accelerometer is

High School trigonometry: Assume your accelerometer is perfectly horizontal. X and Y axes measure zero, Z axis measures 1g. Rotate the device 5 degrees about the X axis. X axis still reads zero, Y axis a little more (or a little less depending on which way you rotated) and Z reads a little less than 1g. Carry on rotating until Y axis reads +/- 1g, X axis still reads zero, and now Z axis reads zero. OK, which common trigonometric function would describe this behaviour?

(Hint: it isn't "tangent", and ignore X 'cos it was always zero)

:-[ :-[ :-[ Sorry... i cant remeber :-[ :-[ :-[ I m too old for this.... Can you pls be more specific ??? Thnx

If the tilt angle is 5 degrees to the horizontal (I'm old-school, I leave radians* to the young 'uns), then the component of the acceleration due to gravity is now given by sin (5). That's quite a small value, and falls within the small angle sine approximation. (from my earlier post, sin (0) = 0, sin (90) = 1) Does that help?

*Don't forget to work in radians when using C trig functions, but I'm a good deal older than C. ;D

Groove>>>>Does that help?

:-[ No :-[ I feel a bit dummy... :P

I v tested my accelerator to see the outpout Volt acording the movment For example when is in horizontal position and i turn it 90 degres to the left the voltage goes from 1,56V to 0,93. That giving me 1,56-0,93=0,63 so the 90 degrees are 0,63/90=0,007 V/dgree right ??? This way i can calculate the angle at least in this type of movment. Right ???

so the 90 degrees are 0,63/90=0,007 V/dgree right ???

No, it isn’t that simple.
The accelerometer measures acceleration, so in turning from 0 to 90 degrees, the acceleration due to gravity has gone from 0 (horizontal) to +1g.
However, the relationship isn’t linear, it is a function of the sine of the angle of tilt.
sin(0) = 0
sin (90) = 1.
So, at 45 degrees, your output voltage should be sin(45) = 0.7 * 0.63 V = 0.445V, plus the 0g offset1 of 1.56V = 2.005V.

1Note: You don’t say what the accelerometer device is, but usually for cheap devices the 0g offset is simply half the supply voltage, which I’m guessing is 3.3V.

Groove>>>>1Note: You don’t say what the accelerometer device is, but usually for cheap devices the 0g offset is simply half the supply voltage, which I’m guessing is 3.3V.
Right… :wink:

Im still dont get it…i quit :-[

Im still dont get it...i quit

Quit? Why? What is it that you don't get?

Does my 2V prediction @ 45 degrees actually work? What about -45 degrees (tilt the opposite way), which should give 1.56 - 0.445V = 1.115V?

Groove .......you r the best ;)

Groove>>Does my 2V prediction @ 45 degrees actually work? What about -45 degrees (tilt the opposite way), which should give 1.56 - 0.445V = 1.115V?

Yes...Yes..and...Yes.. :)

And i finaly got it !!!

http://www.ies.co.jp/math/java/trig/sinBox/sinBox.html

I belive that is the same also in y axis...Right ??

Many many ......thnx for the valuable lesson. ;)

I belive that is the same also in y axis...Right ??

Correct ... and Z too. :)

Once again....thnx a lot :)

Hi,

Could someone help me? I also bought cheap nunchuck from China and it would not work. Would like to use my Arduino together with the nunchuck to measure how many degrees my motorhome is tilted and show this on my display I made myself Nunchuck adapter and connects to the analog inputs 2.3.4.5 as displayed on: http://todbot.com/blog/2008/02/18/wiichuck-wii-nunchuck-adapter-available/

If I use the original Nunchuck I can get the value but do not know how I can get this in degrees. Since I saw that you were after the same thing it would help me a lot if you could post your solution here I would be very grateful this is code i use today http://todbot.com/arduino/sketches/WiichuckDemo.zip