Uno to Uno i2c problems

Hi there,

I am working on an automation project involving i2c communication between 2 arduino unos. The first has an Adafruit LCD shield mounted on it, and serves as the “master”. The “slave” arduino has an Adafruit motor shield connected, along with 2 stepper motors and a electronic pneumatic air solenoid. Essentially the master arduino is used for allowing the user to select the type of test that they would like to run, then sending that data to the slave. The slave has an incrementing counter (since this will be implemented on a cycle testing machine) that is pinged back to the master to display. The first issue that I’m having is the master seems to freeze up when connected to the slave. This doesn’t happen every time, and it can be somewhat avoided by plugging the power into the master first, then the power for the logic and motors on the slave arduino. However, sometimes doing this doesn’t work, and the master will not even run the setup code (displaying the company name and setup prompts), and will display a blank screen. None of the buttons, including the reset will work, forcing me to power cycle both arduinos. Do I need to have a pullup resistor between the 2 arduinos to prevent this problem? I was reading elsewhere in the forums that the Uno’s have a built in pullup resistor, but it might not be enough? Just FYI I have 3 12V DC wall plugs as power sources, 1 for the master arduino, 1 for the motors, and 1 for the slave.

Secondly, I am having trouble with the shot count displaying correctly. Right now it seems to count in powers of 2 (2, 4, 8, 16, 32, 64, etc), but I would like it to display the count for each cycle completed (1, 2, 3, 4, etc). I believe that this may have to do with the scaling of the shotCount at line 228 and 276, but am not sure. Both scripts are attached below.

Thanks in advance!

LCD_Menu_Script.ino.ino (9.75 KB)

Slave_Arduino_Script.ino (4.01 KB)

The sketches look quite OK, the only thing I noticed was that you don’t check the result codes of Wire.endTransmission() (sending part) and Wire.requestFrom() (receiving part). You probably should do that and handle errors.

From the above description I would guess that the problem is in the wiring. Please post a wiring diagram of your setup. How long is the I2C cable? Did you connect the grounds of the two Arduinos?

If the I2C signal length is more than a frew cm you should install external pull-ups because the internal ones are to weak for the higher capacitance. What distance is between the Arduinos and the motors/solenoids?

Extremely strange is the case where a push on the reset button doesn’t reset the master Arduino. I never experience such a behavior on an UNO.

I have the 2 arduinos wired in the following configuration (M = master, S = Slave):
M- GND -> S- GND
M- A4 -> S- A4
M- A5 -> S- A5
The grounds are common, so they should be able to establish a logic base. However, the jumper wires that I'm using for I2C communication between the 2 arduinos are 12" long... so that could be the source of the problem. When I searched the forums, a lot of people tended to say that around 4.7Kohm is a good value to start for pullup resistors between 2 unos. Would I need one resistor per line (a4, a5, and gnd)? or should I just throw them on a4 and a5, since those are the lines that actually send transmissions back and forth.

Thanks for your help!

-K

When I searched the forums, a lot of people tended to say that around 4.7Kohm is a good value to start for pullup resistors between 2 unos.

It's a good start value for a short bus. In your case I would try 3k3 provide better results. Best would be to take a look at the signals with a scope. Do you have the possibility to attach one?

However, the jumper wires that I'm using for I2C communication between the 2 arduinos are 12" long... so that could be the source of the problem.

If my knowledge of that strange American units is not completely wrong, this is about 36cm, which should be a tolerable value although rather at the upper limit.

The problem might be the motors as they tend to influence the signals on longer wires. Try to use at least shielded cabling between the UNOs and connect the shield to GND.