Communication other than I2C between two arduinos

I have few devices on I2C and one of them is LCD16X2 that is located about 6m (20ft) away. Read tons about I2C's limitations over 2M distance and some solutions like those listed here.

I only need to send integers to display on LCD. If I use second Arduino close to the LCD, is there another simple communication mechanism between two arduinos without using additional adapters? Communication needs to be only in one direction and sending two integers 0 to 100.

thank you

You could use UART serial with a robust comm protocol. Might not even need RS-232, but you'll have to do testing to be sure.

You might also look into using wireless communication (i.e. NRF modules, XBees, or 433MHz radios)

Why don't you try I2C? It might work, it might not, but it's worth a try.
Try pullup resistors at both ends of the cable (eg, 4.7K or 5.6K), then just set the I2C clock slow enough that you get reliable communication. You might be surprised at what is possible.

Note: to set I2C speed, have this in your setup():

  TWSR &= 0xFC;
  TWBR = 30; // set this number to what speed you want from the chart below:

  //Measured speed on a 16MHz Arduino:
  //TWBR:    Speed (khz)
  //160       48
  // 80       91
  // 40      167
  // 30      286
  // 20      286
  // 10      410

John_S:
Why don't you try I2C? It might work, it might not, but it's worth a try.
Try pullup resistors at both ends of the cable (eg, 4.7K or 5.6K), then just set the I2C clock slow enough that you get reliable communication. You might be surprised at what is possible.

Note: to set I2C speed, have this in your setup():

Thank you, John. I already have it set up with I2C and it was working as a prototype (on a bench with short cable) but it freezes the whole I2C as soon as i plug in the LCD with long cable (other devices on I2C work fine when LCD is not plugged in). Because so many people had problem with this (I have read I2C over distance is hit or miss), I just wanted to find a quick solution but will try to fix I2C itself first.

Couple quick questions:

  1. I am running SDA/SCL through this shielded wire. Should I swap it for CAT6?

  2. LCD power leads are fed from separate PSU that is next to LCD (I only run SDA/SCL cables back). Grounds are connected from both PSUs. Is this going to be an issue? Pull ups are also going to be connected to different PSUs on both ends. I am guessing this should be fine but wanted to make sure.

  1. Today we tell new users that the maximum length for I2C is 50 cm.
    There has been someone who has used CAT6 cable for I2C for 6 meters. However, you better stay with the maximum of 50 cm.
    The I2C bus is called a "bus", but it was not designed to go through a cable. I was designed to be used on the same pcb board. That means that any cable is wrong. Seperate wires hanging free in the air is the best :wink:
    The Wire.setClock() can lower the speed to 50kHz, but not much lower. It is for example not possible to have 1kHz.
Wire.begin();
Wire.setClock(50000);

With a software I2C library you can go lower. Then only the Master needs the software I2C, because the Master sets the SCL clock signal.
Crosstalk between SDA and SCL is much worse than a long cable. Crosstalk can not be avoided with a lower clock speed.
When looking at the picture of your cable, I think that the opposite wires are green and black, or red and white. Those can be used for the SDA and SCL. With the right pullup resistors you might get to 2 meters. When, for example, you have SDA and SCL on the green and white wires (next to each other), then 50 cm is already too long.
I write this here to give some information, it will not help to use I2C over 6 meters.

  1. The I2C bus has three wires: SDA, SCL, GND.
    A ground problem is always an issue. A problem with a signal is just one problem, but a ground problem can mess up everything.

I think that Power_Broker gave the right answer, try Serial with a low speed or wireless.
For long cables with twisted pair wires (Cat5, Cat6) is the RS-485 the perfect solution.
The special chips that are mentioned in the link that you gave turn the I2C signals into something for twisted pair wires.

I have I2C running on about 25 to 30m of cable with no problems. It is running at about 60kHz with 1k Ohm pull up resistors. Higher value resistors were a problem. Set the frequency as low as you can and see.

Can you tell what kind of cable and which wires are used for what ?

A 1k pullup resistor is not according to the I2C standard. I will not advise someone to fix one problem with another problem :o

"but it freezes the whole I2C as soon as i plug in the LCD with long cable (other devices on I2C work fine when LCD is not plugged in"

I would think that shows the I2C works at that distance, so you might concentrate on finding out why connecting the LCD causes the system to fail.

Koepel:

  1. Today we tell new users that the maximum length for I2C is 50 cm.

Recently I have had no problem using I2C with the standard Wire library over 2 metres of poor quality cable with a few joins in it - and without any external pullup resistor. This 50cm seems to be myth.

When you think about it, why should the cable distance for I2C be any shorter than for TTL serial?

...R

Koepel:
Can you tell what kind of cable and which wires are used for what ?

A 1k pullup resistor is not according to the I2C standard. I will not advise someone to fix one problem with another problem :o

I am using 2 pair telephone cable, one pair has 0V and 5V and the other has SCL and SDA. I confess the micro-controller is a PIC but I don't think that matters. The point is it works. I suggest it would be better to have a pair each for SCL and SDA with the spare wire connected to 0V.

As for 1k Ohm resistors, I don't actually know what the spec is for I2C, but I think any micro-controller will drive 1kOhm without difficulty. In any case, if 1kOhm works for 25m of cable a higher value should be OK for shorter cable.

This is hobby electronics, I strongly think people should try stuff, maybe it will work, maybe it won't. If it's for your own use what does it matter?

I already have it set up with I2C and it was working as a prototype (on a bench with short cable) but it freezes the whole I2C as soon as i plug in the LCD with long cable

Do you mean that with it running you plug in the long cable or do you mean you switch it off, connect the long cable then when you switch it on it does not work? I'd expect the former to cause a problem.

This is hobby electronics, I strongly think people should try stuff, maybe it will work, maybe it won't. If it's for your own use what does it matter?

Yes, that's what I think. Try different things. If you are going to get a product certified or are going to sell it, then design within tolerances and specifications.
I did a test with some Cat 6 cable - I had I2C working over a 75 foot (23m) cable. Is it out of spec? Yes. Did it work? Yes. Will if fail eventually? I don't know... If it does then I've learned that that is too much and will try something else.

why should the cable distance for I2C be any shorter than for TTL serial?

TTL is driven high and low with each bit. I2C is "open-drain" and pulled high by the resistors. Based on the capacitance of the cable (function of length and other factors), then the pullup forms an RC circuit on the I2C lines. If the cable capacitance or the bus frequency is too high, then the signal is a sloppy hump instead of a nice clean square wave.

I did a test with some Cat 6 cable

Characteristic impedance of cat 6 cable is 100Ohms, characteristic impedance of telephone cable is anything between 600 and 1200Ohm. While I realise this is a bit crude I think driving telephone cable with a pull up resistor is going to be more successful than driving cat 5 or cat 6.

PerryBebbington:
This is hobby electronics, I strongly think people should try stuff, maybe it will work, maybe it won't. If it's for your own use what does it matter?
Do you mean that with it running you plug in the long cable or do you mean you switch it off, connect the long cable then when you switch it on it does not work? I'd expect the former to cause a problem.

I plug/unplug in cable only when the system is off. If I turn on the system with the LCD SDA/SCL cables plugged in, I2C "freezes" as soon as Arduino sends signal to it (there are two LCDs and digital potentiometers on I2C). If I unplug the LCD (only the one that is 6m away) from SDA/SCL and start the system, then it is working fine. Again, this set up worked on a bench with short cable - the only thing changed was that now I have longer cable and separate PSU for LCD (but grounds are connected)

The point well taken about trying things - I just wanted to finish this project quickly (its for a fundraiser) and everything seems to take forever. Will report back if any of the solutions offered here work. Thank you

Hi Mvoltin,
OK, that's clear. I guess you now know that it's possible. I suggest lower value resistors. Also try 2 resistors on each wire (4 in total), one at each end of the cable. As the resistors will be in parallel they should be twice the value of 1 resistor.

PerryBebbington:
As for 1k Ohm resistors, I don't actually know what the spec is for I2C, but I think any micro-controller will drive 1kOhm without difficulty. In any case, if 1kOhm works for 25m of cable a higher value should be OK for shorter cable.

Spec is 3ma. 1k at 5v is 5ma
Many i2c LCD backpacks have a 4.7k pullup on the signals.
If those are still on the backpack, then the resistance is reduced to around 824 ohms, which wold be 6ma
The pcf8574 spec only guarantees 3ma.

This is hobby electronics, I strongly think people should try stuff, maybe it will work, maybe it won't. If it's for your own use what does it matter?

I disagree. I don't think people should just blindly try stuff with no understanding.
Doing things like exceeding a spec or abusing an API can be ok in some situations; however, I think if they are done, that they should always be done intentionally and with an understanding what might or could go wrong rather than just a random trial and error method with no concern for limits.
The reason is that depending on is being done or what is being controlled, it could have serious consequences including life threatening.
i.e. like a fire, or serious injury.

I believe trial and error methodologies lead to a poor mindset of believing that something works and is reliable when it really isn't and might be on the edge of calamity.

--- bill

Bill, you are entitled to your opinion, as I am to mine. I do think you have stretched what I said into areas I never intended. There is no clear boundary between having a clear understanding and not having a clue, and part of progressing from not having a clue to having a clear understanding is experimentation. Sometimes experimentation leads damaged parts, sometimes it leads to success. Either way it leads to learning.

"I don't think people should just blindly try stuff with no understanding."

If you ever teach a yodeling class, probably the hardest thing is to keep the students from just trying to yodel right off. You see, we build to that. - Deep Thoughts by Jack Handy

zoomkat:
If you ever teach a yodeling class,

Don't you need a HGV licence for that?

...R

PerryBebbington:
Hi Mvoltin,
OK, that's clear. I guess you now know that it's possible. I suggest lower value resistors. Also try 2 resistors on each wire (4 in total), one at each end of the cable. As the resistors will be in parallel they should be twice the value of 1 resistor.

I finally got back to this project and encountered a different problem:

Installed two 2k pullups on the far-away LCD (16x2) side. Upon turning on the system, the far-away LCD runs but the one that is close (20x4) doesn't. I notice that the 20x4 lcd gets slightly darker squares where digits are supposed to be displayed and nothing happens. It starts working again when the 16x2 LCD is disconnected.

Then I put pull-ups on the system side (closer to 20x4 lcd that is about 20 inches from the arduino) starting from 4.7k, 2k, 1k and, in every instance, 20x4 LCD starts working fine (no more darker squares) for a few seconds and displays what it supposed to but then it gets "garbled". While the far-away 16x2 LCD works fine. Again, once the 16x2 lcd gets disconnected, the 20x4 works again (with or without pull-ups).

One more difference from before is that my I2C doesn't "freeze up", they continue working (including digital POTs), it's just LCD.

I am not sure what to do next. I now have pair of 1K pullups on the far-away LCD 16x2 (about 20feet away) and pair of 1K pullups next to Arduino and this seems plenty (Digital POTs also have their built-in pull-ups enabled and Arduino's internal pull-ups are also probably enabled).

I might have misunderstood where you put the resistors but try a pair next to the Arduino and another pair at the furthest point at the same time. Try 2kOhm first.

Also, try running I2C more slowly.