Electronic – arduino – Data exchange over 5 meter cable

arduinocancommunicationdigital-communicationsi2c

I have a microcontroller which needs to communicate over a cable, which will be approx. 5m long, with another very small microcontroller. The devices will be used outdoors in various conditions. The data rate will not be very high. When you connect the small uC with the cable to the big uC, a identification string and periodic (each minute) battery updates are sent from the small uC.

I thought about I2C but I'm not sure if it is designed for such needs? CAN is also possible but I think it´s a little bit overkill for my needs. Does anyone have good ideas?

EDIT:
I want to use as few pins as possible for the cable.

Best Answer

While CAN might be a bit "overkill", it is always to prefer if you have that option. Brief comparison or CAN versus RS232/RS422/RS485:

CAN advantages:

  • Far more robust and tolerant to EMI. But in terms of the technology itself and in terms of built-in protection in a standard transceiver.
  • Will work just fine without shielded cables at lower baudrates.
  • Built-in error handling, CRC and frame synchronization. So there's no need to invent yet another obscure, custom UART-based protocol. Meaning CPUs don't have to waste time encoding/decoding, calculating CRC etc.
  • Easy to maintain and easy to re-design from point-to-point into multi-node system, should the need arise in the future.

CAN disadvantages:

  • Not really a sensible choice unless your MCU has a CAN peripheral on-chip. External CAN controllers are burdensome and a thing of the past.
  • Might have slightly higher current consumption than UART-based solutions.

The cost of CAN transceivers versus RS-xxx transceivers should be about the same (except if you pick old crap transceivers like MAX232 that need 5x 1uF decoupling caps). Signal voltage levels don't matter, there's CAN and RS-xxx transceivers for both 3.3V and 5V.

The number of wires for a semi-duplex system will be 3 in either case. In the case of CAN, you have CAN H, CAN L and signal ground. In the case of for example RS-422 you have T+, T- and signal ground. Skipping signal ground is really not recommended for either case, don't listen to people telling you otherwise.