Picaxe 18M2-basic LED program

PJ.

New Member
Hi to all the Einsteins. New to this lark so may stick to designing houses and extensions!
I have a basic program on a 18M2 for sequencing 4 LEDs . The program works fine, I don't have an issue with the programming part using the flow diagram method. I have a second (similar) pic with the same program but need to somehow trigger it from the 'master' pic after its (master) sequence starts. Tried making pins 'high' and 'low' for milliseconds etc to try to trigger it but it's all just erratic and doesn't work. The master pic sequence starts with an IR sensor that momentarily makes a pin low to start the program running. It's a basic 'red' 'Amber' 'double amber' 'green' sequence.

But so far no one has managed to tell me how to interface this simple set up so that one pic starts after the master says so. Am I missing something here? Surely it just needs a high pin to start the sequence?
All the best
PJ
 
Last edited:

newplumber

Senior Member
Hi PJ
If you post your code then someone waaay smarter then me can help you out
and please tell what picaxe chips you are working with like using 2 picaxe 18m2s?
so may stick to designing houses and extensions!
you have to be more stubborn then the picaxe and you will win guaranteed :)
 

premelec

Senior Member
@PJ Depending on time delay you can stand a very simple way would be to apply V+ to the second PICAXE using a pin from the first - please post your code so we might see what the problem is [and schematic if necessary].
 

PJ.

New Member
Hi Premelec
I did originally try your method as you describe (well at least in my head anyway). I made an OUT pin high on the master pic and connected it to an available IN pin on the 'slave' but the results are not good. I shall try post a schematic as suggested by yourself and new plumber. I know this is only basic stuff but when you can't solve it.......:mad:
Many thanks for your response!
 

hippy

Technical Support
Staff member
A belated welcome to the PICAXE forum.

What you are trying to do seems reasonable and it should work how you expected so there is possibly some minor issue in what you have done or how you are doing it.

If you can post details of what you have so far, and how things are connected and to where, it should be possible to determine what the issue is and should hopefully be fairly trivial to resolve.

One thing to note, as you are using multiple PICAXE devices, is that the 0V (GND) of each PICAXE or board needs to be connected together. If you just have two boards, each with their own battery, with just one wire between them, things will not behave exactly as expected.
 

PJ.

New Member
Hi Hippy
Thanks for this. Yes the ground is common from a regulated 5v supply. The pcbs and circuits work fine in isolation. Ive attached the flow diagram for the master pic. The 'slave' pic (I don't like that word so I'm going to call it 'secondary') has the same program on it but needs to be controlled by each change of the led sequence from the master. Hope this makes sense?? Would just short bursts of voltage in milliseconds from a OUT pin on the master to a IN pin on the secondary pic work? :confused:

Thanks again
 

Attachments

lbenson

Senior Member
+1 to hippy for the suggestion that the grounds be common--that is, wired together if, for instance, the picaxes are on separate project boards. [Hmmm, you posted while I was typing.]

Not specific to your problem, but it is also advised that you include an in-line current-limiting resistor (e.g., 1K) if you connect an output pin to an input pin. This is to prevent in inadvertent occurrence of the input pin being set to "output" low while the other pin is output high, which could result in one or both pins being "burned out" with excess current.
 

PJ.

New Member
+1 to hippy for the suggestion that the grounds be common--that is, wired together if, for instance, the picaxes are on separate project boards. [Hmmm, you posted while I was typing.]

Not specific to your problem, but it is also advised that you include an in-line current-limiting resistor (e.g., 1K) if you connect an output pin to an input pin. This is to prevent in inadvertent occurrence of the input pin being set to "output" low while the other pin is output high, which could result in one or both pins being "burned out" with excess current.
Thanks Ibenson. That's interesting. I shall build this into the pcb as you say to give it that protection.
Many thanks again!
 

hippy

Technical Support
Staff member
"Primary" and "secondary" are good substitutes if one doesn't like the "master" and "slave" terminology, but if wanting to retain the notion of which is commanding the other then "master" and "servant" may be another compromise.

The flowchart is a little complicated so it may be best to start with something simpler.

On the primary you could wait for an IR command then trigger the secondary, have the secondary wait for that trigger and then just flash a LED.

Iron-out any issues with that then expand it so the system grows towards what you ultimately want, one step at a time.
 

PJ.

New Member
Just to clarify, the primary is a working pcb with a program on the Pic chip that controls an LED sequence- this will not change- (GREEN until, IR sensor, then RED, wait 45 seconds, then SINGLE YELLOW, wait 45 seconds, then DOUBLE YELLOW, wait 45 seconds, then return to GREEN until IR sensor is triggered again. If any yellow leds are on and the IR sensor is triggered it will return to a red led and start the cycle until green etc. The flow diagram is a simple one really. The plan is to run the Secondary picaxe chip/ pcb with the same sequence but one led colour/combination ahead of the master, ie,

Master -RED, Secondary- SINGLE YELLOW, Master-SINGLE YELLOW, Secondary- DOUBLE YELLOW, Master-DOUBLE YELLOW, Secondary- GREEN until both back to green. The secondary can only be controlled via the Primary. An IR sensor on the Secondary is only to change the led from GREEN to RED. It waits on red until the primary board's sequence is triggered by its own IR sensor and then they both interact with whats described above. Well thats the plan any way. It just means you can daisy chain the boards together and they all work in the correct sequence until all showing green leds. They work perfectly by themselves at the moment.
Regards
 

hippy

Technical Support
Staff member
It perhaps seems more complicated than it is to yourself because it's not clear what the "override switch" is or does, how this controls the secondary, or what that secondary code is.

Is that one flowchart being run on the both master and secondary boards ?

If so what is its "override switch" and "IR input" connected to ?

Also, for the master, the flowchart we have; "If any yellow leds are on and the IR sensor is triggered it will return to a red led and start the cycle until green etc" - That doesn't seem to be in the code. There are checks before the yellow single and yellow double are turned on but they check the "override switch" (C2) not the "IR input" (C1).

It's also not clear how the master command cells for turning various LED's on controls or instructs the secondary ?
 

hippy

Technical Support
Staff member
Okay; have figured out that it is trackside signalling, the sequence showing if safe to proceed into the section of track the train has just entered ...

TRACK.jpg [ Click to enlarge ]

So that makes the master code more understandable. It goes red when the train passes, should ideally go red whenever a train goes past but we can set that aside for now.

Once the train passes it then turns red, some time later, yellows and eventually green again.

[ previous misunderstanding deleted ]

The one further down the track will have been turned red when it was previously passed, will then sequence towards green as the master does.
 
Last edited:

PJ.

New Member
Hi Hippy
Apologies. Yes you are correct. I should have mentioned this from the off-my mistake. Yes it is British 4 aspect track side signalling. There is a small concurrent program running on the master at the same time that takes care of the signals when a train passes on one of the other colours apart from green but thats not relevant as you mention. The IR sensor only reverts the program back to red (danger). The 'override' is just a manual switch that holds all signals on red if desired (just a liitle gimmick) and will revert back to the green when turned 'off'. It has no other function and does not affect the program. the secondary board has the same set up with an IR sensor to show 'danger' (red) when passed on any other colour. it then waits for the signal ahead to change to red to allow a yellow signal to show on the secondary. For clarity - Master chip is 'DISTANT' signal, secondary chip is 'HOME' signal.

Hope this clears it up-Thanks again for working out what this is for-brilliant!
 

hippy

Technical Support
Staff member
It seems like it should then just be a case of setting a master output line high for a period then low after changing its own LED to signal the secondary to change its LED too. For the secondary just waiting for that once it has set its red and other colours.

Alternatively, just toggle the output line from the master and have the secondary wait until it sees a change.

Either should work.
 

PJ.

New Member
Yes this makes sense, When you say 'toggle' you do mean high then low? I'm sure I tried this but it didn't go through the colour sequence it appeared to go straight from red back to green and miss out the 2 yellow leds. What sort of duration would be required, ie milliseconds? Maybe the program was to quick to notice the change before....
 

hippy

Technical Support
Staff member
For toggling one would need a genuine TOGGLE command. That ensures the output line does change whenever it should because it is otherwise difficult to know what state it will be in to know what level to set it to. The advantage of toggling is that the state change persists for much longer than a setting high then low pulse usually will. That means a much lower chance of the secondary missing it no matter what it's doing.

Having states skipped would seem to suggest that the logic flow is somehow wrong, something is causing it to not go where things are intended to go.

One can also get odd behaviour if using the Download Serial In as an input signal. A signal on that can cause the program to restart which may make it look like it's partially following a sequence when it's actually starting again from the beginning.
 

PJ.

New Member
OK now I'm learning. Is there an equivalent method for the flow chart as I do not use the code method. Say, B7 high, wait 0.025, B7 low..?
 

PJ.

New Member
Thanks for your help. Managed to get the 2 pcbs to talk to each other using the toggle command. Tweaked the durations and it works a treat, very realistic. Thanks again!
 
Top