Using the wiiChuck Adapter, you can easily connect the wii nunchuck to an arduino.
WiiChuck Adapter
The following arduino program, adapted from the wiichuck demo programmed by Tod Kurt, waits for a serial request from the Raspberry Pi and sends back the accelerometers data + two button states.
/*
* WiiChuckDemo --
*
* 2008 Tod E. Kurt, http://thingm.com/
*
*/
#include <Wire.h>
#include <nunchuck_funcs.h>
int inByte=0;
byte accx,accy,accz,zbut,cbut;
int ledPin = 13;
void setup()
{
Serial.begin(57600);
nunchuck_setpowerpins();
nunchuck_init(); // send the initilization handshake
}
void loop()
{
if( Serial.available()>0 ) {
inByte = Serial.read();
nunchuck_get_data();
accx = nunchuck_accelx();
accy = nunchuck_accely();
accz = nunchuck_accelz();
zbut = nunchuck_zbutton();
cbut = nunchuck_cbutton();
Serial.write((byte)accx);
Serial.write((byte)accy);
Serial.write((byte)accz);
Serial.write((byte)zbut);
Serial.write((byte)cbut);
}
}
In the Mathematica for the Raspberry Pi, wanted to chart the values of the three accelerometers as I record different movements with the nunchuck. (The values of the axis go somewhere between 80-220.
serial = DeviceOpen["Serial", {"/dev/ttyACM0", "BaudRate" -> 57600}];
ping := Module[{x}, DeviceWriteBuffer[serial, {"5"}];
x = DeviceReadBuffer[serial][[1 ;; 3]]]
data = Transpose@Table[ping, {i, 120}];
ListLinePlot[data, PlotStyle -> {Red, Thick, Dashed},
PlotLegends -> {"X", "Y", "Z"}]