Go Down

Topic: would you like a program challenge? (Read 3035 times) previous topic - next topic

matelot

This may be a little cheeky but I am trying to program an uno to run a small section of a garden railway, the sort that people sit astride the carriages behind small steam engines.
I want to control four sequential signals. Two of which are four aspect, that is they have four lights, red, yellow, double yellow and green. One has three aspect - red yellow and green and one has two aspect, red and green. By using diodes I could use just two yellow lights and have one or both light as required from two outputs.

There are five switches that the trains trigger as they pass.

The lights go to red when first turned on, if relays are used on the outputs the first relay could be de-energised to light the red lights and energised to light the yellow. When the system is reset everything finishes with all on green, this could be done by one pass of a train and not a separate switch.

When a train passes the first switch the first signal (four aspect) goes red. When it passes the second switch the second signal goes to red and the first to yellow. This sequence continues until the train passes the fifth switch, because the third signal is three aspect and the forth two it would mean that the fifth switch turns the second signal and both the third and the four signals to green.

A second train could enter the system when the first train is beyond the second switch and the first signal has gone to yellow.

If anyone is interested in a challenge I would welcome the input. Can you do it in fewer ports from the uno than the eighteen it first looks as if it requires? remember a relay on the output could save at least one output to each signal.

Thanks for at least reading this far,
Bob.

dc42

As described, whenever a signal is red, the one behind it is yellow. So one of the yellow lights in each signal can be driven from the same pin as the red light in the following section. Similarly, the second yellow light in the first 2 signals can be driven from the same pin as the red signal 2 sections ahead. You can use diode gates to ensure that both yellows are lit when required. Not only does this save 5 pins, it simplifies the wiring.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

matelot

#2
Apr 01, 2013, 09:54 pm Last Edit: Apr 01, 2013, 09:58 pm by matelot Reason: 1
One of my first thoughts but actually wrong.
If a second train follows the first is would put the first signal to red whilst the first train was between the second and third signals and the second signal would be red, two reds. I could have a train in each section - four reds.
I mentioned the use of a diode for the two yellows in the second paragraph.

Erdin

First of all, you should not make it harder for yourself.
So if you use an Arduino Mega2560, you can have all the inputs and outputs. That makes it a lot easier.
With long wires, I prefer relays with optocouplers and also inputs with optocouplers.

To me it seems that it is harder to understand what you want than the actual programming....

Sembazuru

#4
Apr 01, 2013, 10:06 pm Last Edit: Apr 01, 2013, 10:16 pm by Sembazuru Reason: 1
Without much consideration, I would probably use two pins and 3 external chips. This would allow me to only have 4 wires going from the control circuit (with the Arduino) to each of the signal displays and a central switch hub. This allows the connection to be made with simple 4-wire modular wiring. The magic solution to this: I2C. Thus the four wires would be Power, Ground, SDA, and SCL. MicroChip makes a couple of nice I/O expanders that communicate via I2C, 16bit and 8bit versions are available. Because these chips are GPIO, you use the same chip on your light outputs as you do for your switch inputs. For this application, 8bit would probably be sufficient which would be MicroChip's MCP23008. (See http://octopart.com/mcp23008-e%2Fp-microchip-468105 for availability, pricing, and data sheet for the through-hole version). I don't know the line length limitations of an Arduino's I2C so depending on how long the runs are you may need to have an I2C line driver. Then because all the switches and lights are individually addressable, the logic for what light turns on based on which switches being activated is all in your program. Makes it flexible for changing things, or adding future lights and switches. (Note, these chips only provide the lower 3 bits for addressing, so the maximum you could have on one I2C bus at a time is 8.)

Just some thinking out loud for your consideration.

Edit: "for" => "four"... homonyms...
http://www.catb.org/jargon/html/I/I-didn-t-change-anything-.html

matelot

yes optocouplers would be fine. the present switches are sensors that pull the voltage to zero with optocouplers this wouldn't matter for the inputs they could be any direction if fed from optocouplers.
Is the 2560 language the same as the uno? can I programme in one and port it?
I dont have a 2560.

matelot

#6
Apr 01, 2013, 10:15 pm Last Edit: Apr 01, 2013, 10:23 pm by matelot Reason: 1
sembazuru,
Are you saying have a chip at each set of signals?
The idea of four wires sounds good.
The furthest signal is about 200 yards from the place I want to put the central hub which is near the third signal (about 10 yards).
The switches are close to each signal head.

dc42


One of my first thoughts but actually wrong.
If a second train follows the first is would put the first signal to red whilst the first train was between the second and third signals and the second signal would be red, two reds. I could have a train in each section - four reds.


If you are using relays to switch the lamps, then you could still use the same pin-saving arrangement with this modification. You probably want all the lights to be red by default (when the controller is not working); so the red lights will be connected through the NC contact of the associated relay. You can then gate the power for the orange and green lights in the same signal through the NO contact of the same relay.

The idea of using a common bus and a chip at each signal is appealing, however to get I2C to work over anything like that sort of distance, I think you will have to use some sort of amplification in order to meet the rise time specification.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

matelot

#8
Apr 01, 2013, 10:46 pm Last Edit: Apr 01, 2013, 10:48 pm by matelot Reason: 1
yea dc42 thanks for the reply.
do you know how to wire and prog a I2C system? would it be much beyond basic uno programming?
I've never gone that far .

Sembazuru


sembazuru,
Are you saying have a chip at each set of signals?
The idea of four wires sounds good.
The furthest signal is about 200 yards from the place I want to put the central hub.
The switches are close to each signal head.



Yes, that is exactly it. Attached closely to each signal head (possibly even inside the housing) would be an I/O expander chip, and then in a central box for all the switch inputs would be another I/O expander chip. So you might have (please pardon the ascii graphics...)

+---------+   4-wire modular cable   +------------+   4-wire modular cable   +-------------+   4-wire modular cable   +-------------+
| Arduino |=------------------------=| Switch box |=------------------------=| Signal Head |=------------------------=| Signal Head |= (Future expansion)
+---------+                          +------------+                          +-------------+                          +-------------+
                                       |   |   |
                   Pairs of wires ->   |   |   |
                                       |   |   |
                          Switch one --+   |   +-- Switch three
                                           |
                                      Switch two


Then read from the I2C device in the Switch box, decide what the lights should be based on all the switch states and switch state history. Then write out to the I2C device in Signal Head 1, and then to Signal Head 2. Repeat this loop as fast as you can. You could even have multiple switch boxes (either for proximity reasons or if you end up with more than 8 switches in the future). You may be able to get away with a combination of star and daisy-chain topologies, but I'd research I2C bus topologies first. Don't want funny signal reflections messing things up.

If I2C doesn't work out for technical reasons, I/O expander chips are available for many different bus technologies. If you keep the pin count to 8 or below (up to 6 signals, power and ground) you can exploit the simplicity of modular connections by using either phone cables or Ethernet cables for your physical wiring. (Buy a crimper, ends and a spool of CAT3 or CAT5 cable and you can make your own custom lengths cheaply.)
http://www.catb.org/jargon/html/I/I-didn-t-change-anything-.html

matelot

#10
Apr 01, 2013, 11:01 pm Last Edit: Apr 01, 2013, 11:07 pm by matelot Reason: 1
Hmm.
At each box I would need four wires for the signal, one for the switch and a return. Are the signal heads you are suggesting capable of this?
Is the signal head addressed from the library wire.h?

dc42

Having thought it over some more, I think multidrop RS485 using async serial protocol might be better because of the long cable runs, with an attiny84 at each signal. If you use Cat 5 cable (or preferably Cat 6 for its lower resistance), then depending on the power requirement of the signals, you might be able to use 1 pair for the RS422 and the remaining 3 pairs for power. The attiny84 has enough pins to connect all 4 lights, the RS485 transceiver, and the switch.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

matelot

ok I will examine that approach can you be more help with the details?

Sembazuru


yea dc42 thanks for the reply.
do you know how to wire and prog a I2C system? would it be much beyond basic uno programming?
I've never gone that far .


I'm about to dip into I2C for the first time myself, but reading through the tutorials it seems straight-forward enough. Because it is one of the built-in protocols of the ATMega chips, there is support already there using the Wire library included with the ArduinoIDE.

Well, as dc42 says, the lengths required for this might be a bit too long for raw I2C. But, doing some Google searches I found someone reporting success with LTC4300 chips being used as I2C line drivers. Datasheet: http://datasheet.octopart.com/LTC4300A-2IMS8%23PBF-Linear-Technology-datasheet-7622793.pdf
This would definitely be something that would need to be prototyped and tested thoroughly. So... what is your R&D budget? (rhetorical question...)
http://www.catb.org/jargon/html/I/I-didn-t-change-anything-.html

matelot



This would definitely be something that would need to be prototyped and tested thoroughly. So... what is your R&D budget? (rhetorical question...)



Ha Ha small as possible.

Go Up