Is I2C the best way to go

Hi ,
I have a project in mind and am trying to ascertain the best way to go about it . I think it will be by
I2C but I would be grateful for advice if there is a better more logical way.

The project is this
I have a model railway layout .
The layout has 8 points ( turnouts) operated by a servo .
There are six possible routes the train can take depending on how the 8 points are set
The aim is to have six momentary push button switches , each one selecting a different route and
setting the points accordingly.

The simple way would be use an arduino with 6 or more PWM outputs that will drive a servo to operate a
point mechanism but this has a fault , The points are spread out over the layout meaning I would need
long cables to each servo and these will pick up interference so I know I need to put a small cheap
arduino ( maybe a nano or pro micro) local to each servo and connect them all up with some kind of bus
to the master arduino which has the switches for selecting the routes

The bus only really needs to be one way ( Master to Slave). The slave arduinos on the bus dont really
need to send any info back to the master only to recieve and act on the messages from the master.

Would I2C be the best bus to use and if so can anyone point me to a sketch that shows how to connect 2 or more arduinos together using I2C , particularly how to give the arduinos an I2C address
The bus wouldnt be more than 8 feet long

Cheers
Don

Maybe I2C would work, but likely not.

I was curious about nearly the same thing. Take a read through this post Options for Remote I/O - Project Guidance - Arduino Forum

I would suggest trying to use CAT-5 cable from the central Arduino to each remote servo. If you can find it, use shielded CAT-5 if the environs are extremely noisy electrically. Much less expensive than hanging additional MCU's out there just to occasionally rotate a servo.

I2c is intended for communication between chips on the same circuit board. A few hundred millimetres perhaps. Longer is possible but not easy. Even if it did work, it would be at least as sensitive to interference as servo signals over the same distance.

You might look into 1-wire switches and 1-wire/2-wire in general.

Why are you using servos for setting points?
This are very much two-way controls, so a simple solenoid switch would do much better than a servo. Also no worries about picking up interference along the way as they're current controlled.

Thanks for your reply

first reason is its far more realistic to have a point move slowly ( like they do in real life )which the servo will do nicely and also if I am using servo's for semaphore signals as well I can make them bounce at the end of their travel again like happens in the real world

2nd reason is that I already have 24 servo's and about 15 arduino nano's that are sat around doing nothing

Don

PaulRB:
I2c is intended for communication between chips on the same circuit board. A few hundred millimetres perhaps. Longer is possible but not easy. Even if it did work, it would be at least as sensitive to interference as servo signals over the same distance.

This is the reason I asked , info is so confusing . When I googled I2C bus length the answer at the top of the page was from the Embedded systems academy who said "This depends on the load of the bus and the speed you run at. In typical applications, the length is a few meters (9-12ft)." But I also read on the microchip site
"I2C is an Inter-IC bus, designed to connect IC's on the same PCB, or at least in the same device" which is as you said . Having said that the I2C temperature sensors on my laser cutter are at the end of 2 meter cables so
they can reach the coolant tank . I just dont know which to believe

Due_unto:
I would suggest trying to use CAT-5 cable from the central Arduino to each remote servo. If you can find it, use shielded CAT-5 if the environs are extremely noisy electrically. Much less expensive than hanging additional MCU's out there just to occasionally rotate a servo.

One of my reasons for not thinking along those lines was because I want to keep the number of cables to a minimum and was thinking that a 2 wire I2C bus along the length of the board would be all I need . Because the layout is DCC the track is live at all times so I could just connect to the track nearest the arduino and regulate that to 5v to power everything locally at each point.

In actual fact most of the equipment on my layout is connected by CAN bus and I could use that , but that means putting a can shield on every arduino ( expensive) .

My other thought was to use a pic chip with built in CAN capabilty but am even less familiar with programming pics than I am arduinos

Don

I2C is meant for inter-IC communications, and mostly used within a PCB or to connect two PCBs at short distances. With some tricks you can indeed extend it to a few meters, maybe 10 meters even. Lower the bus speed, stronger pull-up resistors and shielded cables help a lot.

However your railway environment is noisy. Long current carrying wires (your tracks), brushed motors (in the trains), those servos. That again is bad for I2C communications.

DonRecardo:
The simple way would be use an arduino with 6 or more PWM outputs that will drive a servo to operate a
point mechanism but this has a fault ,

You don't need PWM only pins for servo control.
The Servo library works on any of the digital output pins.
Tom... :slight_smile:

Come to think of it: as long as your rails and central Arduino share the ground line, a single wire should be enough to control a servo. Electric noise may still be an issue, though.

wvmarle:
Come to think of it: as long as your rails and central Arduino share the ground line, a single wire should be enough to control a servo. Electric noise may still be an issue, though.

Direction of trains in a dc layout is determined by the polarity of the rails. So one moment the left track is positive, when changing direction the other one is positive. Will it still work?

It's usually switched using a dpdt switch / relay or a h-bridge. DCC is again another story.

Infrared?

RS232/422/485 would be my choice.

[edit]
My reply might have caused some confusion; it applies to serial communication using a uart.
[/edit]

RS232/422/485 would be my choice.

I have just finished testing the idea with MAX232 (RS232 signal can travel upto 150 ft without buffering); but, it does not work as the SDA/SCL could both be bi-directional and we have to connect the gates back-to-back; things get totally messed! Input signal comes back to input; it surely causes signal congestion.

DonRecardo:
The simple way would be use an arduino with 6 or more PWM outputs that will drive a servo to operate a
point mechanism but this has a fault , The points are spread out over the layout meaning I would need
long cables to each servo and these will pick up interference so I know I need...

What is the distance between the control Arduino and the servos. Did you actually try the simple way.
The servo control wire is driven by a low impedance (~25ohm) Arduino output pin (not PWM), so noise pickup is unlikely.
Try Cat-6 (ethernet) wire, and use two pairs per servo.
One pair for signal and ground, and one pair for 6volt and ground.
You might have to terminate the signal wire at the servo end if the cable is very long.
Try a ~330ohm resistor between signal and ground.
Leo..

I don't really understand what you're trying to say there.

RS232 is very much a one one one thing. RS485 (use the MAX485 chip) is designed for multiple drops.

If you want only one direction maybe using UART is a good option? Only GND + Tx line - one wire less than I2C.

GolamMostafa:
I have just finished testing the idea with MAX232 (RS232 signal can travel upto 150 ft without buffering); but, it does not work as the SDA/SCL could both be bi-directional and we have to connect the gates back-to-back; things get totally messed! Input signal comes back to input; it surely causes signal congestion.

I've edited my original reply; it was never intended as a layer for I2C but to use with an ordinary uart.

wvmarle:
I don't really understand what you're trying to say there.

RS232 is very much a one one one thing. RS485 (use the MAX485 chip) is designed for multiple drops.

You can hook plenty rs232 receivers on one rs232 transmitter. It will be one way communication, but might be sufficient. Alternatively, one can daisy chain.