Friday, May 21, 2010

Dual Intec Wireless Nunchuk Communication with Arduino

I saw an instructable some time ago featuring the Wii Nunchuk integrated with an arduino Microcontroller.  Having already experimented with a 3 axis accelerometer from SeeedStudio with my DFRobot Atmega1280-Mega microcontroller, I figured I would give it a shot with a pair of Intec Nunchuks I found on sale at The Source (also available here online).

Program:
Download

Arduino: 
After some research, I managed to find a program that worked for the type of nunchuk I had, as well as a helpful Google Project entry to go with it.  The creator of the program and the entry, Radek Karpowicz, would seem to be a quite skilled programmer and was generous enough to licence his program under the Creative Commons 3.0 BY-SA license.  This allows me to edit and redistribute his program, of course, giving him credit for his work.  Unfortunately, I am relatively new to arduino programming.  As such, my modifications are not ideal, however with some tweaking and patience, they work.

I recommend taking a look at Karpowicz's Google Project entry before continuing.
There is also a blog explaining in more detail a similar program's method of interfacing with a wireless nunchuk located here.
If you have a wireless nunchuk other than Nyko Kama, Datel Wireless Duo-FX or Intec's wireless nunchuk and this program does not work for you, I suggest checking out the arduino forums.  You may also wish to read the instructable on the matter (single nunchuk).

Processing:
The processing code uses several different libraries, the first of which is the serial library, the purpose of which is self explanatory.  The second is PeasyCam.  This library allows the use of the mouse to control the view angle, zoom and pan.  The library can be downloaded here.  The third library is the Robot library.  This library allows for interfacing with the keyboard and mouse controls, allowing one to control the mouse and use the nunchuk buttons as keys.  These functions are disabled by default via //comment.  Ensure you save all open projects before compiling a program that uses Robot.

The processing program displays the serial data as two vectors and displays the previous 50 vectors connected via lines.  The program also allows for each vector's connected lines' colours to be changed via the thumbstick.  This is achieved via a set of Arraylists.



Wiring:
The physical setup for a dual wireless nunchuk interface was devised by integrating Karpowicz's design, shown on his Google Project entry with a switching concept observed here, created by Johnnyonthespot.
As mentioned by Karpowicz, the SDA and SDL pins must be connected to 1.8k pullup resistors.

The interface schematic between the arduino and the nunchuk's wireless module can be seen below:
Image created using Fritzing.

Note: this interface using the I2C pins, SDA (data) and SDL (clock), of the arduino, these allow for sending and receiving using set protocols via the "wire.h" library.  On my board SDA is located on pin 20, and SCL on 21, on other boards these pin locations may be changed or nonexistent.

In this example, I used pins 6 and 7 to control the switching between the two nunchuk wireless modules instead of 22 and 24, this can easily be changed in the arduino program by changing the values for nunchuk1 and nunchuk2 to the desired pin numbers.
The transistors I used were 2N2222 and the resistors connected to the Base of each transistor have a value of 680 ohms.

Connecting Nunchuks to Arduino:
To connect the nunchuks to the arduino a bit of patience is needed.  You must first power up both nunchuks, then press the sync button for one of them (for example; the one in your right hand).  Once the serial output displays "Waiting for Duo FX Controller Device" again then you must then sync the second nunchuk.  The program will then try to connect to the second nunchuk.  This may take some time, as the setups for each of the nunchuks tend to interfere with each other.  If, after a minute or two, the setup does not complete, try turning one of the nunchuks off, closing the display window, recompile ►, then turning the nunchuk on and resynchronizing it.  After the first successful setup, the setup often goes much quicker for the setups thereafter when recompiling.

3 comments:

  1. Well done and thanks for recognizing my hard work! :)

    P.S. The descriptive content of the project is distributed under CC but code under GNU license. What does not change the fact that you can redistribute and modify it without consequences. But remember to mention about my project site.

    Thank you again and wish you good work!

    --
    Radek Karpowicz

    ReplyDelete
  2. Hi, Thanks a lot for this hard work but can i know which software are you using to draw your circuit ?

    Thanks :)

    ReplyDelete
  3. Sorry, I should have included a link to the software. It is called Fritzing. It can be downloaded from their site: fritzing.org

    ReplyDelete