Let's Make Robots!

Wireless Nunchuk picaxe interfacing

 

EDIT: problem solved

Hi,

Does anybody have any experiences of connecting wireless nunchuk to picaxe. I am working on this and can't find anybody who has tried it. Many people have succesfully made it with arduino (and many have had problems). I try to modify attached BASIC code according to arduino codes.( different nunchuks need different codes).

Could some of you multitalented arduino/picaxe gurus help me to figure out how to modify the code? Michael Dreher-a pioneer on this hack- has listed the needed steps(http://www.windmeadow.com/node/42):

1. The initialization sequence must be changed and because it takes some time before the controller is connected via the wireless connection it has to be done in a loop until it works
2. The decryption (^ 0x17 + 0x17) is then no longer needed
3. Send_zero () has to be called 3 times in a row
4. The TWI freq must be set to 400000
5. The controller type can be read to verify that you really have an Nunchuck
6. When an error occours, the controller must be reinitialized

It seems that number 1, 4, and 5 are essential on all nunchuks, need of other changes vary.

If you have any comments or could help with code, it would be very helpfull. I know very little about c languages and try to do this just through trial and error :)

 

 EDIT: This code works (should work)with any cheap copy nunchuk, wireless or not. You should synco your wireless 'chuk during pause of initialization. Some normal knock off nunchuks wont work on i2cfast mode.

Symbol joystick_x = b10
Symbol joystick_y = b11
Symbol Accel_X = b12
Symbol Accel_y = b13
Symbol Accel_z = b14
Symbol Accel_buttons = b15 ' lower 2 bits of accel & Z,C button states


Symbol nunchukaddress = 0xA4

Init:
  pause 3000
  hi2csetup i2cmaster, nunchukaddress, i2cfast, i2cbyte
  hi2cout (0xF0,0x55)
  pause 1
  hi2cout (0xFB,0x00)
  pause 1

main:

readNunchuk:
  hi2cout (0x00)
  pause 1
  hi2cin (joystick_x,joystick_y,Accel_X,Accel_Y,Accel_Z,Accel_buttons)
  pause 1

debug
  goto main

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I just got this working today on a Pic18F4550 ( not PicAxe ).  What I learned may help, though.  You need to use the universal init sequence.  It not only works for nearly all controllers, it makes sure the device enumeration is unencrypted.  See here:

http://www.wiibrew.org/wiki/Wiimote/Extension_Controllers

http://www.wiibrew.org/wiki/Wiimote/Extension_Controllers/Nunchuck

and my write up with C code: http://thelast16bits.blogspot.com/2013/02/pic18f4550-interface-to-wii-nunchuck.html

It has a lot of other great links.  Hope that helps!

Hello,
I am a French professor of Technology.
I tried your code on a PICAXE08M2. It works with original but with a wireless nunchuck, it does not work.
The Bluetooth connection is not stable between the nunchuck and its receptor.
Do you have an idea to help me make it work?
Thank you in advance,
Sorry for my english,

If you are still working on this, (sorry i haven't been here for a while) i can make some suggestions. These wireless ones seem someties quite tricky. My wireless nunchuk, bought from dx.com has worked very well and never loses sync.

Some ideas you could try:

1. Try both i2cslow and i2cfast with different cpu speeds

2. be sure that connection is well estabilished and synced before initialization happens, i have used long pause in the beginnig of the program.

3. In some arduino codes they say that writing every time three separate 0x00 before reading the nunchuk  makes it work, i can't understand why

 

Hope this helps you!

I remove those ugly old codes.

I solved the problem. I think this can be useful to somebody. I couldn't find any cases somebody doing this with picaxe i had to work it out myself. Problems were that i didn't at first realize that picaxe needs 8-bit not 7-bit address. Another problem was that i tried first hicout 0xa4, (0xF0) etc. in initialization but i realized i have to just write them like they are in code above. Third issue was that picaxe automatically changes the last bit of address when reading i2c device which was confusing when translating the code from other platforms. Hard enough for a history teacher with no experience of programming.

these cheap nunchuk fakes are quite funny. You can get a i2c interfaced 3-axis accelometer as cheap as $3.88. And wireless ones are something 12$. BUT they won't work with same commands as original ones.