Wednesday, April 28, 2010

Interfacing Arduino with wiimote (and later the nunchuck)

Interfacing Arduino with wiimote (and later the nunchuck)

I was toying with the idea of interfacing wiimote to my arduino as my replacement for accelerometer and gyroscope which comes in this package the

IMU Combo Board - 3 Degrees of Freedom - ADXL203/ADXRS614

which cost USD$124 which is equivalent to SGD$162.44. 
FYI, my wiimote cost me sgd$69 (left over from last year FYP project) and nunchuck sgd$25 (which I got from the shop at clementi city vibe where my student yenyu working part time).
Shall not elaborate about the wiimote and nunchuck...There are plenty of resources in the Internet.

I found out that the pin outs for the wii expansion port (WEP) from the Internet, thanks to the people that are willing to share the data! The drawing are for interfacing the IEEE1394 to the WEP.
Connect pin1 of WEP to Aref on arduino
pin2 of WEP to A5
pin5 to A4
pin6 to ground

I also found out that, it is not necessary to buy a nunchuck, cut out the connector part and used it with the wiimote. That, will render the nunchuck useless (to the Wii ofcourse, later you guys will find out more about my experiment with wiimote and why I have to use the nunchuck instead...........)
The replacement is a IEEE1394 male to male cable for sgd$7 from simlim square.

The pin out on the IEEE1394 and the WEP are carefully map out....

This is how it is going to look like, when they are connected...
Below are the code for sending and receiving data between arduino and pc. Similar code can be found at wiimeadows too! thanks to them for discovering the pattern of data send and receive out of the wiimote. 

below are the ASCII art for the data flow of the devices that are hooked up together.
arduino ---wired--->wiimote--bluetooth-->PC
arduino <---wired---wiimote<--bluetooth--PC

Some way, some how, when I open my hyperterminal to observe the data output, I only receive my debug message which is "serial init finished". This means my serial connection of 119200 is setup correctly, but no generated data is observed. No subsequent data is collected both from the arduino through the wiimote to the pc (need to use 3rd party wiimote driver, such as wiimote library on the windows OS), nor the pc through the wiimote to arduino (through hyper terminal). 

Used my multimeter to check the VCC and the gnd pin of IEEE1394 pin out, all seems to be correct. Just that no data is observed from the transferring between the devices.
Rewire the IEEE1394 again, with more meticulous effort put in... the result is still the same............................................

Fustrated, because if I can't get the accelerometer readings from the wiimote to arduino, my hypotheses of using it as my sensor would be false!!!!!!

I was contemplating to cut my nunchuck to retrieve the WEP PROPRIETARY connector..........because, I could still use the nunchuck on the wii (As if I got one, hahahah). If  In the end, I  decided to mutilate the nunchuck. Plug in the connector to the wiimote and the exposed end to the arduino.... No eureka moment.......... the data output is the same as the IEEE1394 cable........Very fustrated................................because of my hypotheses would failed..........................

But, which part went wrong?????? I am still finding the cause of it..........There are success stories on the Internet that used the similar setup.......

Before the last straw to be thrown, I tried to hooked up the nunchuck to the arduino instead. 
with the code attached below

Atlas.... some readings from the accelerometer on the from the nunchuck.......


nigel said...

sir you never fail to amaze me. any idea why the wiimote doesnt work while the nunchuck works?

sjteo said...

my best shot is at the I2C master and slave pairing of


Look at wiimote as if it is relaying data for both ends and I need to figure out what went wrong actually with my setup.

Because I only need the

the fats can be trimmed

YEN YU said...

Huh, so much data contained in the nunchuck ah? So every angle has an individual address?! Waliew, lol.

sjteo said...

@yen yu
the x,y,z axis data is a float but can be scaled to 0-255.

the joystick button gives -x x +x and -y y +y.

the other 2 button is just boolean

Fiie said...

Kaiser Sodrohu said...

Have you considered using PIC? My FYP is the same thing and I'm using Microchip PIC instead of Arduino. So far, I got the data sent, but the Driver WiimoteLib reads it as Wiimote acceleration values instead of Nunchuk's.

sjteo said...

entaro tassadar executor Sodrohu
how is the new land after aiur.

I am exploring a simpler device for a 3axis data acquisition. Thats y i choose to use a nun chuck.

I have not tried to use a PIC. The particular reason is i wanted to build on a board with 6 analog in, 4 pwm and some (no need too many) Digital I/O.

when it comes to extend with other analog data source reading it will be a breeze. Same as applied to the output for controlling dc or servo motors.

Kaiser Sodrohu said...

Some questions:
1. Are you running the Arduino in slave or master mode?

2. Do you know the equivalent of the AREF pin for PIC?

sjteo said...

arduino is slave mode.

2. Are you referring on getting 3.3v on Aref of arduino for ADC that is equivalent on PIC?

different pic have a different resolution. the pic18 i have got a 10bit resolution.

below are the methods i tried to put 3.3v on PIC18 for ADC
a. use voltage divider method. POT with 5v source. Tune the POT to get 3.3v

b. TTL logic converter from sparkfun. USD1.95 each. This one gives a steady 3.3v.

you need code below to make portA on PIC as an input

'Set PORTA to all input
TRISA = %11111111

'Set up ADCON1
ADCON1 = %10000010