Group Abstract Group Abstract

Message Boards Message Boards

Reading sensor data from a Wii nunchuck via Arduino to Raspberry Pi

Posted 12 years ago
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"}]
POSTED BY: Diego Zviovich
4 Replies
Attachments:
POSTED BY: Jose Calderon
Someone mentioned that using a logic level converter and the Raspberry Pi I2C bus could work without Arduino. Do you think it would?
POSTED BY: Sam Carrettie
That's really cool! Thanks for sharing!
POSTED BY: Arnoud Buzing
Diego, this is great! - Thank you for sharing. If we understood the setup correctly, the so called “WiiChuck” Wii Nunchuck Adapter was used. One can read about it at the following blog: todbot blog. Here are a few images with a greater detail of the adapter.



POSTED BY: EDITORIAL BOARD
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard