USB powered duinos and grounding

Probably yet another Dumb N00b question, but here goes... if I have say 2 Leos configured as follows:

each is in its own small enclosure
each is plugged into a port on (the same) host computer
each is emulating various HID functions, one being an add-on to the other
I want them to talk to each other over I2C

do I have grounding issues? Can I just bring 2 wires from one box to the other for I2C, or do I also need to bring a 3rd wire for ground? I was assuming that they would share vcc and ground via their USB power from the host, but assumptions can be fatal so I thought I'd ask.

Yes they will be connected through the host so there's not much point connecting them externally. If anything, you are likely to produce ground loops that way.

Depending on the distance, you might want to consider external pull-ups though.

I would disagree wi the conclusion. I would run a ground wire, it is good practice and there is no danger of any harm or ill effects through ground loops like this.

(sigh) as I continue to display my ignorance... is it good, bad, or pointless to connect the +5vdc of two Arduinos which are connected to the same powered USB hub (as well as their grounds as discussed above)?

I ask because I am having issues with interference on my i2c bus, and wondering if one of my +5v levels is wavering and causing the bogus values I'm seeing. I thought if I ganged both duinos' +5 together, like stacking
batteries, I would get more amperage capacity and the voltage might not dip under load, which I'm beginning to suspect might be my i2c problem (have yet to get the scope out of mothballs and take a look).

Breadboard is the 830 tie point kind. I'm using one of its 4 power rails for the i2c bus (every i2c device is plugged into these bus strips, one strip for SCL and one for SDA). Another power rail is powered by duino-1 (i2c bus master); a third is powered by duino-2 (i2c slave). Fourth rail is empty.

duino-1 is powering some 5mm leds, a pot, some switches and push buttons. duino-2 is powering the other i2c slaves.

Ground on duino-1 is connected to ground on duino-2. Both duinos are USB powered, on the same (powered) USB hub.

since adding the fourth i2c device (Adafruit 7seg 4digit LED backpack) I am now getting corrupted data when reading the 3rd i2c device. The corruption is small (noise in the lowest 3 bits) but enough to mess things up.

I am really not an EE, don't even play one on TV, so I am not sure what to do about interference/noise on this bus. I did a bit of googling and read something about segment LED displays being multiplexed and causing dips in +5 that could affect reference voltage levels and cause bogus digital value readings. could this be my problem?

if so -- I ganged my +5vdc from both duinos would I have a more robust vcc?

Do not connect 5V together.
Have you got pull up resistors on the two signal lines of the bus? Two 4K7 resistors should do.

Thanks grumpy mike... if you say do not connect the two +5 outs from the duinos, I believe you, but can you explain to this ignoramus why it would be a bad idea?

I tried putting fixed value pullup resistors on the SDA having read that this might help, but it had no effect. I did not try pulling up the clock yet. I put a 10K pot between +5 and SDA and tried various settings, only to find that at some extreme rotations the bus master duino would hang :slight_smile: oops.

What I have tried that does fix it, at least well enough to get the whole apparatus working again, is to reposition the LED display so that it is powered off the bus master, not off the 2nd duino. In other words, the LED 7segment display is now getting its +5 from duino 1, bus master; the wiichuck is getting its +5 from duino 2, fellow i2c slave.

This has reduced the noise to least significant bit, i.e. a jitter of 1 in the axis value being read from the chuck. This is acceptable. I will however try pullups on both the SCL and SDA and see if that makes it possible to power all the slaves off the slave duino. But see question below...

As far as my dumb non-EE brain can conceptualise it, I'm starting to think that interpretation of the clock and data on the i2c bus requires a reference +5, and if that reference jitters or dips, then pulses on the bus may not be correctly interpreted. Am I even close? Or is it that the pulses generated on the bus are based on local +5 and if that dips, then the pulses are "stunted" or malformed and don't get read properly?

At any rate ... I have N slaves (some of which are duinos) all connected to common SDA and SCL and a common ground; but each duino on the bus has its own local +5vdc which may vary a little with transient load and so on. I understand the pullup concept but am wondering, to whose +5vdc should I pull the shared SDA and SCL buses up with a resistor? Both duinos? (but wouldn't that be ganging the +5 out together which you advised not to do?)

Or should I "grow up" and attach a single, external power supply to the breadboard, not use USB power, and power both duinos and all other devices off one single source, eliminating any inconsistencies in my +5 level? I do have a couple of those wall-wart powered plugnplay breadboard supplies.

Both SDA & SCL need to be pulled up. All devices connected via I2C can only pull the line low, the resistors is what makes the high level.
The pullups should be at the end of the string of connected devices.

I put a 10K pot between +5 and SDA and tried various settings, only to find that at some extreme rotations the bus master duino would hang :slight_smile: oops.

oops indeed, you might just have blown one or more of the I2C devices.

Just because your botched attempt at using one pull up resistor did not see any improvement is no reason not to put pull up resistors in the correct place immediately.

As far as my dumb non-EE brain can conceptualise it, I'm starting to think that interpretation of the clock and data on the i2c bus requires a reference +5, and if that reference jitters or dips, then pulses on the bus may not be correctly interpreted. Am I even close?

No not even close. An I2C device only works by pulling down the signals, the exact value of the 5V is totally irrelevant.

I understand the pullup concept but am wondering, to whose +5vdc should I pull the shared SDA and SCL buses up with a resistor?

It doesn't matter.

if you say do not connect the two +5 outs from the duinos, I believe you, but can you explain to this ignoramus why it would be a bad idea?

Because if the two supplies were ever separate then you would cause power to be back fed into one or other power supply which is bad. Therefore even though you are powering them for the same source there is no need to common them specifically, it is very bad practice.

Hi grumpymike, I am glad to report all the i2c slaves are still alive despite my underinformed experiments :slight_smile:

Thanks for the explanations, various. So as I am now understanding it, correct me if I am still confused, if I have N power supplies (like 2 duinos and maybe a breadboard supply) feeding a multi device project, I should connect all their grounds together but NOT their +5 (or + anything). OK. will remember that.

in principle, is it better/wiser to have just one hefty P/S powering everything including the duinos?

I am not sure what CrossRoads meant by "at the end of the chain of connected devices" because afaik the i2c bus is not a daisy chain but a party line; I have all my i2c devices connected to one pair of rails on my breadboard.

given this setup, is it still true that the pullup resistors should be at one end of the rail rather than in the middle? I will assume so and put them at the far end of the rail.

I read someplace (the text was too technical and mostly went over my head so I may have misunderstood it) that i2c-equipped devices sometimes already have internal pullup resistors, and that some people disable these when stringing a lot of devices together, so as to have just one pair of pullups on the bus. I hope this is not really required, as I would find it pretty nerve-wracking to start cutting traces on my duinos etc.

RESULTS: if the offending 7seg LED i2c backpack is powered by duino-2, there is still corruption of i2c reads from the wiichuck even with two 4.7Kohm resistors in place to pull up both SDA and SCL. However, if I power the offending LED backpack from duino-1 and the resistors are in place, then the noise problem goes away entirely. I am not sure how to interpret this, but I now have a working i2c bus, no mouse creep, and an LED readout, so in practical terms this is success :slight_smile:

next experiment I guess will be to set up a heftier 5vdc supply, 1a or so, and power everything from that. as I understand it, the duinos are smart and will cease to draw power from USB if they see sufficient input voltage on VIN? so if I were to feed them both a solid +5vdc from some external supply, it would be safe for my USB ports? just making sure before I smoke anything valuable...

Just adding to the archived info here:

This article on pullups and i2c contains an amusing story plus lots of links to other resources.

in principle, is it better/wiser to have just one hefty P/S powering everything including the duinos?

Tough one. In a fixed final system yes every time. However, in a development situation the large power supply is less forgiving of mistakes. With a 1A power supply you short out a track and the power supply shuts down. With a 10A power supply you short out a track and the track melts. Also separate power supplies are naturally decoupled with one supply you have to put in decoupling components to prevent interaction between system, This is especially true if one part generates interference like a motor.

However, if I power the offending LED backpack from duino-1 and the resistors are in place, then the noise problem goes away entirely.

That is lack of decoupling between systems. See :- http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

as I understand it, the duinos are smart and will cease to draw power from USB if they see sufficient input voltage on VIN?

True for the Uno but the nano has not got that circuit.

On pullups look at this:- http://www.dsscircuits.com/index.php/articles/47-effects-of-varying-i2c-pull-up-resistors

Remember that "sufficient" voltage on the Uno Vin is above 6.6V, because the on-board 5V regulator requires at least that input voltage. If all your Arduino boards have such on-board regulators, you can use a "hefty" 7V power supply to supply all boards, and let the local regulators produce a good and decoupled 5V voltage. In case of a short or overload somewhere in a circuit, only the affected regulator will shut down, to prevent further damage, the other boards will continue working normally.

Ground loops are bad when some high-power device (motor...) causes a high current and spikes on Gnd lines. Such devices should be connected directly to their power supplies, so that the bulk current only flows over these lines. Then connect a wire from the device Gnd to the common (controller...) Gnd, which carries only the small logic currents. The same considerations also apply to a common supply for multiple boards with regulators: connect both the supply + and - to the boards and their regulators. Such paired supply cables also will reduce EMF, because then the same currents flow through the + and - wires, in opposite direction, and thus cannot cause an EM field.