i2c multiple arduinos + sensor loosing communication

Hey there,
i have a mega connected to 4 nanos via i2c. Each nano reads from an motorencoder and calculates the rpm and then sends it to the mega when wire.requestfrom is called. Works like a charm. Now i connected a IMU to the i2c lines. I get all the data from the IMU and the nanos. But when i start the motors every now and then the i2c commuication is broken. I already added 330 Ohm in series on the SDA and SCL line, which improved it a bit. Could it be that when i change the speed of the motors the change in current draw leads to spikes for the vcc on the nanos which then leads to wrong highs and lows in the i2c protocol? Any ideas how to make the connections more stable?

thanks

Could it be that when i change the speed of the motors the change in current draw leads to spikes for the vcc on the nanos which then leads to wrong highs and lows in the i2c protocol?

Yes, that sort of stuff is a major problem. Even the magnetic field from the spinning motor magnets can disrupt the signaling if it is near the wires.

One option is to use shielded wiring like might be found on an old USB mouse. The USB wire also has twisted pairs but making those work requires treating them as transmission lines and ensuring they have the proper termination, unfortunately, I have no clue how to do that for I2C.

Another possibility may be in the twi library. I've been using the twi library that the Wire stuff is a wrapper for (i.e. twi is a C library and Wire is the C++ wrapper for it). What I see is that sometimes the I2C slave is doing an interrupt and not able to acknowledge I2C in time. I can find no fix, so I just run the I2C command a few times until it completes, it has never taken more than twice to complete. It is an ugly workaround, but I'm not going to dig into twi anymore until I have a chance to try the I2C that Atmel did for their xMega line, I understand it is a complete overhaul. It is also possible that the Wire wrapper is already doing a retry, but I have no interest in looking.

Thanks for the reply.

ron_sutherland:
Yes, that sort of stuff is a major problem. Even the magnetic field from the spinning motor magnets can disrupt the signaling if it is near the wires.

But if i just communicate with the nanos they work, no matter if the motors are running or not.

How long are the I2C wires in total, is the IMU adding enough to be just a little too much?

The funny thing about I2C (or Inter-Integrated Circuit) is that when it is run off a board it is sort of a hack (the name actually tells how it was to be used), its intent was to stay on a single integrated circuit board. The wires that connect to the remote devices have both inductance and capacitance that can resonate with the picked up EM (like an antenna). If the wires are oscillating at a resonance perhaps change it by running them through a ferrite core, and add shielding to help reduce the pick up of EM noise. Unfortunately, the resulting system can be fragile, it may work one day and not the next (when the TV is on in the room).