Pages: [1]   Go Down
Author Topic: Multiple Nunchucks on I2C bus  (Read 1133 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi folks,

I'm currently working on a project to allow two users to share control of a vehicle (ex. one drives while the other controls cameras, sensors, etc). Thus I need two input devices, and the Wii nunchuck would be *perfect*.

I've done my homework and found the nunchuck adapter and the Wire libraries to handle the I2C communication to the Arduino.

Here's the question: In looking through the libraries (and according to everything I've found online) the nunchuck wants to be (has to be?) at address 0x52. If I have multiple nunchucks connected to the same I2C bus, what happens when I use the Wire library and send a request to the device at address 0x52? (Does one respond? Do they both respond? In sequence or in parallel? Is it like Highlander and "there can be only One"?)

 Several hours of searching yielded nothing that I could find related to multiple nunchucks or I2C bus slave address conflicts... hard to believe that when they wrote the standard they didn't anticipate this application!  smiley-wink

Anyone have any experience they'd be willing to share? (Or failing that, anyone care to take an educated guess?)

Thanks for the help!
Logged

Wuppertal/Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 895
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I did this by accident with 2 I2C-EEProms and it took  a while to find out why had bus-errors for more than half the storage or read ops.

The standard cares for this : the devices must use a unique address, no exceptions to this rule.

So two nunchucks will not work.
Eberhard
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Eberhard... that's exactly what I needed to know!
Logged

Dyess AFB, Tx
Offline Offline
Newbie
*
Karma: 0
Posts: 48
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Isn't it possible to reprogram the individual nunchuck I2C addresses?  Or is that a question of the individual I2C device?  From what I read about the protocol you could send out a general call and reprogram individual addresses.
Logged

Wuppertal/Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 895
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
Quote
Isn't it possible to reprogram the individual nunchuck I2C addresses?  Or is that a question of the individual I2C device?  From what I read about the protocol you could send out a general call and reprogram individual addresses.
Usually addresses are fixed on the hardware side. Most Phillips devices allow to choose from a range of 4 addreses to connect more than one device of the same type, but that is up to the manufacturer (hardware).

There probably is a way to change the address of the nunchuck, but Nintendo won't tell us how to do that...

Eberhard
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A bit of searching turned up a list of modifications in the 1992 revision of the standard, including "Programming of a slave address by software has been omitted. The realization of this feature was rather complicated and had not been used.".

So it looks like addressing via software may have been possible at one time, but isn't any longer. Along the same lines, a note on the general call states, "Devices which are capable of handling this general call but do not need it will not answer." My guess is that the nunchuck doesn't answer...

So... taking a different approach, has anyone implemented I2C via software on the Arduino so that it can be used on pins other than Analong In 0,1? Or am I making this overly complicated and should give up on the multiple nunchucks and fall back to old-school joysticks without fancy accelerometers?
Logged

Dyess AFB, Tx
Offline Offline
Newbie
*
Karma: 0
Posts: 48
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll have to read more on the I2C protocol.  I've only just started learning about it, but I had the impression that the master of the bus could rewrite any slave address, but then again if the slave is coded right it could ignore the change.

Maybe you could multiplex the two nunchucks.
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 64
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you could be able to use a relay to switch the SDA lines to the one you wanted to read. It'd take an extra arduino pin, but you'd be able to read two nunchucks all the same. I'm not so sure how it would work with transistors - but you could probably try shutting the SDA line off to one of them.

As for reprogramming I2C addresses, I think the only way you could do that would be to use slave devices with the address pins available and somehow manipulate them with the Arduino, or if the slave was another microcontroller that is able to reassign its address.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's an interesting question - I could see applications for this - but in your case, why not use two arduinos?  It sounds like they will be controlling separate systems.
Logged

0
Offline Offline
Faraday Member
**
Karma: 7
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the nunchuck can be powered via a digital output (and I seem to recall it can), how about just powering up the one you want to talk to, shut it down, talk to the next one, etc?

Not sure what the startup time for a nunchuck is, but it might be worth a try.

-j

Logged

Dyess AFB, Tx
Offline Offline
Newbie
*
Karma: 0
Posts: 48
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not sure that would work, according to the I2C spec the bus will only work if all devices on the bus are powered.  
Logged

0
Offline Offline
Faraday Member
**
Karma: 7
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
according to the I2C spec the bus will only work if all devices on the bus are powered.
Well, if the device is hi-Z when off, I don't see how the bus could know the difference...

-j

Logged

Dyess AFB, Tx
Offline Offline
Newbie
*
Karma: 0
Posts: 48
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From the ATMEGA168 datasheet:
Quote
21.2.2 Electrical Interconnection
As depicted in Figure 21-1, both bus lines are connected to the positive supply voltage through
pull-up resistors. The bus drivers of all TWI-compliant devices are open-drain or open-collector.
This implements a wired-AND function which is essential to the operation of the interface. A low
level on a TWI bus line is generated when one or more TWI devices output a zero. A high level
is output when all TWI devices tri-state their outputs, allowing the pull-up resistors to pull the line
high. Note that all AVR devices connected to the TWI bus must be powered in order to allow any
bus operation.

I suspect that when the device is powered off that the TWI connection is not high impedance.

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I've been looking at this application note from Phillips called "Bi-directional level shifter for I2C bus and other systems" for interfacing I2C devices at different voltage levels, but there is a page in it about isolating a powered down section. I think it's intended for devices on different levels but I would think it would still work if they were on the same level. Here's the link to it:
http://www.semiconductors.philips.com/acrobat/applicationnotes/an97055.pdf
Check out page 12. I hope that's helpful.
Cheers.
Logged

Pages: [1]   Go Up
Jump to: