Im trying to get 2 wii nunchucks to communicate with the arduino on the I2C bus. I know that the nunchucks have the same slave address, but I wasn't sure if there was a way to create a switch between the two DATA lines of the nunchucks.
for example:
Both nunchucks are connected to the same system clock (SCL) pin on the arduino...but there is a binary switch to choose which nunchuck's data line is connected to SDL on the arduino (and will be controlled by another pin on the arduino).
I'm just getting familiar with I2C, does this seem workable?
Or is there a way to change the address of one of the slaves?
maybe somebody could explain the I2C better for me then google :0)
I think what you are trying to do would work in principle but would be difficult in practice. The data and clock lines are bi-directional and switching a live I2C module lines off and then on might put it into some weird state. If you can't figure out how to change the device address on one of the modules you might be better off using two Arduino boards each with their own controller.
I think only the Analog 5 and Analog 6 can be used for i2c. Otherwise, you could master two separate buses the way you explain. I've heard of input multiplexers, which might be able to do it, except you'd have to mangle the i2c library to manage the multiplexer AND deal with the three-state protocol of i2c.
At the price point, I'd say your best bet would be to dedicate a separate ATmega8/168 for each i2c bus, in a "co processor" arrangement. One manages the left Chuck and one manages the right Chuck. (Heh, retrolefty beat me to it on this answer.)
Another alternative would be to emulate the Wii Nunchuck by assembling your own buttons and a simpler accelerometer. The ADXL330 is available at SparkFun and Seeedstudio, and it's very convenient to interface with it directly instead of via i2c.
Another solution to use only one Arduino with two Nunchuck is to use the hardware I2C library (Wire.h) for one Nunchuck and a software I2C library for the other one.
You can use AVRlib for a software-based I2C library but you have to check if the code size of this library and the 8 MHz frequency is enough for the Arduino (with an ATmega8 or ATmega168 on it).
Remark: is there no way to change the I2C address of the nunchuck ? no "hidden" bytes to send via I2C that some Nintendo engineers could have published ?
Thanks a lot for your suggestions. It seems that software I2C may be the best bet if I am to stick with only one arduino...
Although I DO know that the wii nunchuck stores it's ID (slave address) in a flash EEPROM...There's just not much documentation on writing to the nunchuck...
I tested 2 wii nunchucks on one I2C bus by using Toshiba quad bilateral switch TC4066BP. I2C data line is switched every 100ms, alternately. 2 wii nunchucks share I2C clock line.
It seemed to work well, but I did not check the I2C data closely, so it might happen some weird state.
No you only need to switch it when you want to access it.
Switch to numchuck 1
I2C read the values
Switch to numchuck 2
I2C read the values (at same address)
good job, I'm sure it works good...I've been getting clean data with both nunchucks (with bjts). 100ms switching time? hmm...is that because of programming?
"100ms" is a temporary value, not a special value.
I want to use 2 wii nunchcks simultaneously, so I coded such a test program.
You can select wii nunchuck explicitly.