Direct connection of NUNCHACK

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Direct connection of NUNCHACK

Post by ziss_dm »

Hi Alex,
I have created driver for Nunchack directly connected to the i2c. It is implemented as additional i2c accelerometer. If you are interested, I can post changes here.

jimnaz
Posts: 16
Joined: Fri Jan 21, 2011 5:21 pm

Re: Direct connection of NUNCHACK

Post by jimnaz »

Please post. Sounds interesting.

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Direct connection of NUNCHACK

Post by ziss_dm »

This is the patch:

Code: Select all

*** MultiWiiV1_pre7.pde   Sun Feb 20 23:44:00 2011
--- MultiWiiV1_pre7_acc.pde   Fri Mar 11 13:29:25 2011
***************
*** 62,67 ****
--- 62,68 ----
  //#define ADXL345
  //#define BMA020
  //#define BMA180
+ #define NUNCHACK
 
  /* I2C barometer */
  //#define BMP085
***************
*** 227,233 ****
    #define SERVO
  #endif
 
! #if defined(ADXL345) || defined(BMA020) || defined(BMA180)
    #define I2C_ACC
  #endif
 
--- 228,234 ----
    #define SERVO
  #endif
 
! #if defined(ADXL345) || defined(BMA020) || defined(BMA180) || defined(NUNCHACK)
    #define I2C_ACC
  #endif
 
***************
*** 749,754 ****
--- 750,786 ----
 
  static uint8_t rawADC_WMP[6];
 
+
+ #if defined(NUNCHACK)
+ void i2c_ACC_init() {
+   i2c_rep_start(0xA4 + 0);//I2C write direction => 0
+   i2c_write(0xF0);
+   i2c_write(0x55);
+   i2c_rep_start(0xA4 + 0);//I2C write direction => 0
+   i2c_write(0xFB);
+   i2c_write(0x00);
+   delay(250);
+   accPresent = 1;
+ }
+
+ void i2c_ACC_getADC() {
+   TWBR = ((16000000L / 400000L) - 16) / 2; // change the I2C clock rate
+   i2c_rep_start(0xA4 + 0);//I2C write direction => 0
+   i2c_write(0x00);
+   i2c_rep_start(0xA4 + 1);//I2C read direction => 1
+   for(uint8_t i = 0; i < 5; i++)
+     rawADC_WMP[i]=i2c_readAck();
+   rawADC_WMP[5]= i2c_readNak();
+   accADC[PITCH] = + ( (rawADC_WMP[2]<<2) + ((rawADC_WMP[5]>>2)&0x3) );
+   accADC[ROLL]  = - ( (rawADC_WMP[3]<<2) + ((rawADC_WMP[5]>>4)&0x3) );
+   accADC[YAW]   = - ( (rawADC_WMP[4]<<2) + ((rawADC_WMP[5]>>6)&0x3) );
+ //  accADC[PITCH] = - ( (rawADC_WMP[2]<<2)        + ((rawADC_WMP[5]>>3)&0x2) );
+ //  accADC[ROLL]  =   ( (rawADC_WMP[3]<<2)        + ((rawADC_WMP[5]>>4)&0x2) );
+ //  accADC[YAW]   = - ( ((rawADC_WMP[4]&0xFE)<<2) + ((rawADC_WMP[5]>>5)&0x6) );
+ }
+ #endif
+
+
  void i2c_WMP_init(uint8_t d) {
    delay(d);
    i2c_rep_start(0xA6 + 0);//I2C write direction => 0


Short notes:
1) Uses "The New Way" of initialization http://wiibrew.org/wiki/Wiimote#The_New_Way
2) I have changed orientation to match my setup. The original orientation is commented.
3) It would not work, in case you have WMP connected, as they are using the same i2c adresses (in my setup I have i2c Gyro and NUNCHACK)

Rurek
Posts: 30
Joined: Sun Jan 30, 2011 1:28 pm

Re: Direct connection of NUNCHACK

Post by Rurek »

I think, this is the best way to use Alex's native, legacy idea - use cheap WMP+NK. BIG THING, thank you a lot!
One question - with this mod (and WMP direct I2C from ITG3205 mod) can I supply NK the "oldiest way" from Vcc pin on WMP ? Or only new way with 2,8v taken from WMP (3rd kynar?)

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Direct connection of NUNCHACK

Post by ziss_dm »

Rurek:
If you have LLC, you can supply to Vcc (+5v) and connect Nunchack to the arduino and connect ITG3205 to LLC. If you don't it s better to use +2.8v from WMP and remove pullups from Nunchack.

Regards,
ziss_dm.

Rurek
Posts: 30
Joined: Sun Jan 30, 2011 1:28 pm

Re: Direct connection of NUNCHACK

Post by Rurek »

OK, the way of powering Wii sensor is clear for me...but what about Logic level on I2C bus (SCK and SDA lines), without LLC? Can Wii senors (especially your method of WMP conection, directly to ITG3205) handle logic level from Ardu?

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Direct connection of NUNCHACK

Post by ziss_dm »

You can connect low voltage devices directly to the arduino, but you have to follow the rules:
1) Disable internal pullups (or you can damage your devices)
2) Use external pullups connected to the low voltage source (3.3v or 2.8v)

This is Alex notes about pullups:
SPECIAL NOTE ABOUT THE PULL-UPS: - they are now enable by default - WARNING if you use I2C devices that don't support 5V.
- If you use a WMP alone: enable it in soft
- If you use a WMP + NK : enable it in soft
- If you use a WMP + BMP020 (5V friendly thanks to its LLC): enable it in soft
- If you use a WMP + (LLC + I2C devices): enable it in soft
- If you use a WMP + direct I2C bus connection I2C devices (not 5V friendly): disable it in soft and use external pull-ups on 3.3V. note that most breakout boards are built with pullups already available.

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Direct connection of NUNCHACK

Post by ziss_dm »

Hi,

This is patch for MultiWii1_preter7.

Regards,
ziss_dm
Attachments
MultiWii1_preter7_nunchack.pde.zip
Patched PDE
(21.98 KiB) Downloaded 252 times
MultiWii1_preter7_nunchack.patch.zip
Patch
(853 Bytes) Downloaded 258 times

juanvivo
Posts: 8
Joined: Thu Feb 24, 2011 6:03 pm

Re: Direct connection of NUNCHACK

Post by juanvivo »

I'm trying to compile this version and gives me an error.

rawADC_WMP was not declared in this scope...

i only active this small code:

/* I2C gyroscope */
#define ITG3200

pd.- I fixed it. i move the

static uint8_t rawADC_WMP[6];

line before #if defined(NUNCHACK)...

Now i have another problem. THe code is too big for my 168... I disable the LCD conf, but is insufficient. Can i disable anything more??

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Direct connection of NUNCHACK

Post by Alexinparis »

ziss_dm wrote:Hi,

This is patch for MultiWii1_preter7.

Regards,
ziss_dm


Thanks, I forgot to add it in preter.
It will be in the next one ;)

scaro
Posts: 3
Joined: Sat Mar 26, 2011 5:00 pm

Re: Direct connection of NUNCHACK

Post by scaro »

juanvivo wrote:I'm trying to compile this version and gives me an error.

rawADC_WMP was not declared in this scope...

i only active this small code:

/* I2C gyroscope */
#define ITG3200

pd.- I fixed it. i move the

static uint8_t rawADC_WMP[6];

line before #if defined(NUNCHACK)...

Now i have another problem. THe code is too big for my 168... I disable the LCD conf, but is insufficient. Can i disable anything more??


I meet excatly the same trouble with 1.7 prebis. It seems that the code doesn't support the nunchuck by default, even with the "already patched V1.7" from
Ziss_dm. Any idea to solve this?

rbirdie001
Posts: 178
Joined: Fri Apr 01, 2011 10:32 pm
Location: Czech Republic, Prague

Re: Direct connection of NUNCHACK

Post by rbirdie001 »

Hi,
also I need to connect itg3205 WMP and Nunchack. I modified WMP board to direct connection of itg3205 and with version 1.preter7 GYRO alone worked. Then I connected nunchak in parallel to I2C and loaded MultiWii1_preter7_nunchack.pde (moved line up in the source to allow compilation). Now it shows in GUI that nunchak is present but GYRO neither ACC doesn't work. GUI looks like running but it shows crazy, sometimes negative values in cycle time and GYRO and ACC values are unreal. Lines doesn't change at any movement but even when it's not moving sometimes they shows false peaks in all ACC axes.
My WMP and nunchak boards normally works with 5V, even I2C pullups are connected to 5V and also ITG 3205 is powerd from 5V - it was always like this and I hope it's normal for this type of boards.
Do you have any idea what I'm doing wrong?
Thanks!
Attachments
conf_itg3205_NK_direct.png
itg3205_nk_parallel.jpg

rbirdie001
Posts: 178
Joined: Fri Apr 01, 2011 10:32 pm
Location: Czech Republic, Prague

Re: Direct connection of NUNCHACK

Post by rbirdie001 »

addition to previous post:
even with disconnected nunchak was MultiWii1_preter7_nunchack.pde NOT working (same strange behaviour including green nunchak detection box) but after loading original MultiWii1_preter7.pde it started to work normally (of course without nunchak detection).
Screenshot attached - curves in the middle of the window are real movements.
It seems to be some error in nunchak patch but unfortunately I'm not experienced enough to understand the code.
Can someone (thanks ziss_dm! ;) ) look at it and try to post corrected patch?
Thanks!
Roman
Attachments
conf_itg3205_only.png

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Direct connection of NUNCHACK

Post by ziss_dm »

Hi,
This one works for me...

Regards,
ziss_dm
Attachments
MultiWii1_preter7_nunchack.zip
(22.02 KiB) Downloaded 258 times

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Direct connection of NUNCHACK

Post by ziss_dm »

Hi,

rbirdie001: Couple of notes to your connection:
1) Currently you mixing 3.3v and 5v devices in i2c bus.
2) You have pull-ups to 5v on your nunchack, which is probably killing your ITG3205

Recommendations:
1) Power up nunchanck from WMP's +2.8v (see my pictures in ITG3205 thread)
2) Remove pull-ups from nunchack
3) DISABLE internal pull-ups in the sketch

Code: Select all

//#define INTERNAL_I2C_PULLUPS

rbirdie001
Posts: 178
Joined: Fri Apr 01, 2011 10:32 pm
Location: Czech Republic, Prague

Re: Direct connection of NUNCHACK

Post by rbirdie001 »

ziss_dm wrote:Hi,

rbirdie001: Couple of notes to your connection:
1) Currently you mixing 3.3v and 5v devices in i2c bus.
2) You have pull-ups to 5v on your nunchack, which is probably killing your ITG3205

Recommendations:
1) Power up nunchanck from WMP's +2.8v (see my pictures in ITG3205 thread)
2) Remove pull-ups from nunchack
3) DISABLE internal pull-ups in the sketch

Code: Select all

//#define INTERNAL_I2C_PULLUPS


Hi!
I checked voltage on my ITG3205 I2C pullups in original state and suprisingly there was 5V! It seems to be 5V device-the same as my nunchuk. I measured also power for itg3205 chip and in original config it was also 5V. From my guess it really looks like problem the nunchuk software patch. In the same wiring connection with parallel nunchuk it works witn MultiWii1_preter7.pde but not with MultiWii1_preter7_nunchuk.pde and oposite - even without wire connencted nunchuk MultiWii1_preter7_nunchuk.pde doesn't work.
There are 5V pullups at itg3205 and 5V pullups at nunchuk, Arduino internal are disabled.
Isn't the problem in the code? Original MultiWii1_preter7_nunchuk.pde didn't compile, when I moved the line static uint8_t rawADC_WMP[6]; before #if defined(NUNCHACK) as recommended by juanvivo it compiles without error but does it mean that everything is OK?
Sorry, I don't understand much programming so I'm not able to correct sketch myself.
Just for interest picture of my WMP board.
Thanks for the help.
Attachments
My WMP - backlighted board to improve visibility of tracks.
My WMP - backlighted board to improve visibility of tracks.

Rurek
Posts: 30
Joined: Sun Jan 30, 2011 1:28 pm

Re: Direct connection of NUNCHACK

Post by Rurek »

It is imposible to good work because ITG3200 needs 3,3v not 5v!!! Look to the datasheet of ITG3200....maybe ITG3205 can handle 5v, but IMHO it is impossible..
Look to thread about ITG3205, I posted today my solution, it is proven to work, but I have another WMP clone with ITG3205, the same as ziss_dm

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Direct connection of NUNCHACK

Post by ziss_dm »

Hi rbirdie001,

Could you post pictures of your connections WMP/NK/Arduino?
Maybe this could help.

Regards,
ziss_dm

schumixmd
Posts: 7
Joined: Sun Apr 10, 2011 4:13 pm

Re: Direct connection of NUNCHACK

Post by schumixmd »

Hello, I do have the same problem described by rbirdie001.

My hardware are:
1. WMP+ IN&PA-v1.6B. (dealrextreme) with ITG3105
2. Nunchuk - Wii Nunchuk-G edition V1.1 (blue color) (XL 335X)
3. Arduino Duemilanove

I have connected WMP+ to Arduino with the mod of ziss_dm, and have disabled internal pullups.
And it works fine with preter7.
Then have connected the nunchuk from 2.8v of WMP and loaded preter7_nunchuk and it doesn't work as it should work. The same strange behavior, negative numbers is cycle time and strange graphics. Also tested to feed the nunchuk from 3.3V and form 5v, but nothings changed.

Ziss_dm, I read that you suggest to remove pullups from nunchuk. Can you please tell how to remove them?
Here are my boards (don't look at wires)
IMG_0482.JPG

scaro
Posts: 3
Joined: Sat Mar 26, 2011 5:00 pm

Re: Direct connection of NUNCHACK

Post by scaro »

Hey guys, I'm the third one who meets troubles with nunchuck and direct connection to arduino. I've tried with the latest 1.7 preter direct nunchack connection, and doesn't work when the nunchuck is defined.(but works good with only ITG3200 defined) I think it is only a pull up resistor issue like my predecessors, but how to remove them? It must be different following the nunchuck clone, and as I haven't the same at the schumixmd's, I ask also this question. If anybody knows, it will be very nice and helpfull for me and the following others. To illustrate my issue, I attached a screenshot of the multiwiiconf 1.7 preter with and without nunchuck (defined or not defined in the sketch), and a picture of my nunchuck clone that I bough at dealextreme. I use the same setup as ziss_dm: the same WMP from dealextreme with direct connection to ITG3205, and nunchuck powered up by +2,8v from WMP.
regards.
Attachments
nunchuck.tiff
dealextreme nunchuck
(220.26 KiB) Not downloaded yet
screenshot with WMP only (//#define nunchack)
screenshot with WMP only (//#define nunchack)
Screenshot with nunchuck defined
Screenshot with nunchuck defined

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Direct connection of NUNCHACK

Post by ziss_dm »

Hi,
It should be quite easy to find pullups, just trace SDA/SCL lines. One side of the resistor should be connected to the SDA or SCL the other to the VCC.

Looking to the pictures, you posted:
R1,R2 for the blue pcb clone
R7,R8 for the green one

But double check it.

regards,
ziss_dm
Last edited by ziss_dm on Mon Apr 11, 2011 9:04 am, edited 1 time in total.

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Direct connection of NUNCHACK

Post by ziss_dm »

Hi,

rbirdie001: Could I ask you to perform small test for me? Could you please post ACC values from GUI:
1) Level normal (after calibration)
2) And inverted, preferrably also level

regards,
ziss_dm

schumixmd
Posts: 7
Joined: Sun Apr 10, 2011 4:13 pm

Re: Direct connection of NUNCHACK

Post by schumixmd »

ziss_dm wrote:Hi,
It should be quite easy to find pullups, just trace SDA/SCL lines. One side of the resistor should be connected to the SDA or SCL the other to the VCC.

Looking to the pictures, you posted:
R1,R2 for the blue pcb clone
R7,R8 for the green one

But double check it.

regards,
ziss_dm


thanks for your short reply ziss_dm.
In my case (blue clone) R1 and R2 are connected to SDA and SCL but they are not connected to VCC, instead thay are connected to GND.
Should they just to be removed?

thanks

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Direct connection of NUNCHACK

Post by ziss_dm »

Hi,
I think, it is better to remove them.

Regards,
ziss_dm

schumixmd
Posts: 7
Joined: Sun Apr 10, 2011 4:13 pm

Re: Direct connection of NUNCHACK

Post by schumixmd »

Hi,

after removing pullups from nunchuk nothing's changed. I feed nunchuk with 3.3v from arduino thru Wmp+. However .. I do not see anymore strange cycle time.
I do have
#define I2C_SPEED 100000L
#define ITG3200
#define NUNCHACK
#define INTERLEAVING_DELAY 3000

Here is how it react to Calibrate Button
preter7_nunchak_conf.jpg


There is any other suggestions or should I trow this board to trash and buy another!? :?

didlawowo
Posts: 8
Joined: Tue Apr 05, 2011 12:42 pm

Re: Direct connection of NUNCHACK

Post by didlawowo »

anyone have a simple schema about connecting Wmp clone and nunckuk clone from dealextreme (same nunchuk like schumixmd and itg3205).

my itg3205 works, when i divide signal by 3 in code source, but quadcopter don't move in GUI ...

i don't know how to connect the nunchuk (on wmp ? on direct i2d ? which pins ?)


thx in advance.

schumixmd
Posts: 7
Joined: Sun Apr 10, 2011 4:13 pm

Re: Direct connection of NUNCHACK

Post by schumixmd »

didlawowo wrote:anyone have a simple schema about connecting Wmp clone and nunckuk clone from dealextreme (same nunchuk like schumixmd and itg3205).
my itg3205 works, when i divide signal by 3 in code source, but quadcopter don't move in GUI ...
i don't know how to connect the nunchuk (on wmp ? on direct i2d ? which pins ?)
thx in advance.



Hi,

if you'll use the mod supplied by ziss_dm and will convert your WMP+ then you'll be able to use it like ITG3200 and it will work without any division very smoothly.
However I still can't make my nunchuk work. Very bad clone including PCB quality.
your quadcopter is not moving because you didn't #define Nunchuk in the sketch.

Question to ziss_dm, alexinparis and others.. maybe i misunderstood something, It is necessary to have receiver connected to Arduino in order to have Acc showing values (graphs)?

regars,
roman

schumixmd
Posts: 7
Joined: Sun Apr 10, 2011 4:13 pm

Re: Direct connection of NUNCHACK

Post by schumixmd »

Hi guys,

After playing some days with my very chinese clone of nunchuk I didn't get it work on i2c and was very disappointed, because now I must wait another month for another nunchuk. But when thinking that i can get the same nunchuk as this one (in general I am not very lucky) I decided to go to sparkfun site and see what do they sell. Have to say.. was very impressive to see that the same ADXL335 is 25$. But I noticed that there(at sparkfun) it is analog, I i had an idea :idea: to convert my nunchuk to analog.
So I found the outputs according to data sheet from sparkfun, and connected them to arduino inputs A1,A2, A3. The capacitors already are on the board, so I did not modified nothing more. In the sketch i have #define(ed) ADCACC and uploaded it to board.
This time I was more lucky, but not enough - it works, but in my opinion values are too low .. it is not sensitive enough - however .. this is my first try.. so I don't know what they should be. So.. if someone can help me change the code to make it more sensitive.
The second issue is that Z axis is always about 75. I noticed acc_1G=75 in the code, but don't know if this is a normal state of acc :? .

Here is a screen shot.
nunchuk_analog.jpg

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: Direct connection of NUNCHACK

Post by ziss_dm »

Hi schumixmd,
This is normal, ACC should always show 1g in static. (around 75 when it is flat, in your case). Just make sure that inverted it shows around -75. If not, you would have to adjust Acc_1G.

Regards,
ziss_dm

didlawowo
Posts: 8
Joined: Tue Apr 05, 2011 12:42 pm

Re: Direct connection of NUNCHACK

Post by didlawowo »

hi,
i'm reading all explication about this topic. but finally to use original or nunchuk clone in direct mode we just have to connect this with sda scl vcc and gnd on the board and active new code in 1.7 ?
what 's the advantage off this mode ?

Post Reply