Model Railway Signal Lights  

Page 2 / 2
  RSS

John40131
(@john40131)
Eminent Member
Joined: 6 months ago
Posts: 36
2019-10-14 3:46 pm  

Hi Skynet,  You are not the only one struggling with Logic this logic is a nightmare as the Crossover requires a lot of witing and polarity switching, also I have just installed a Scissor crossing which requires 4 relays DPDT to change the polarity of Frogs considered using an Arduino but have to switch relays and I have a lot of 12v DPDT miniture , luckily I can simulate in NI Multisim, I also have a copy of Proteus which not used yet so simulate ...But I will look at all comments to help me..also the signals have 3 colour aspects plus on "Y" points on LH lines have a 5 LED white direction Left or Right as Picture ... High on sketch is when LED's are on..so switches from Red , to Yellow, to Green, and white array for direction when yellow or Green..noy sure how to change to ON - OFF in a sketch is it that simple..

Hi Pugwash, the guy who I copied this sketch from did change to a 74HC595 so maybe have a look at that..

The help is much appreciated...and I will again look through all links and comments..

Regards John

DSC 0741

 

 


ReplyQuote
Pugwash
(@pugwash)
Honorable Member
Joined: 6 months ago
Posts: 561
2019-10-14 4:25 pm  

@john40131

The following video shows random numbers being sent in pairs to two daisy-chained 74hc595 ICs.

And the following is the code that controls this process. I have also used the millis() function to give you an idea of how this would be implemented.

// pushData function based on code from Carlyn Maw,Tom Igoe
// Modified for multiple 74hc595 chips by SteveC 2019

// Uses two daisy chained 74hc595 chips to
// make a 16 LED random display.

// WARNING: the 74hc595 cannot cope with more than 20mA on
// each output pin and not more than 80mA total. therefore
// if connecting LEDs direct to chip outputs use higher
// value resistors. I use green LEDs with 2K to 3K resistors.

//Pin connected to ST_CP of 74HC595 (pin 12)
int latchPin = 8;
//Pin connected to SH_CP of 74HC595 (pin 11)
int clockPin = 12;
////Pin connected to DS of 74HC595 (pin 14)
int dataPin = 11;

// variables required for the millis() funtion
unsigned long currentTime;
unsigned long lastTime;
unsigned long tDelay = 2000;

void setup() {

  // for debugging
  Serial.begin(9600);
  Serial.println("74hc595_random_display.ino");
  
  //set pins to output  
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pushData(0,0);// turn all LEDs off
  delay(500);
}

void loop() {

  currentTime = millis(); //get the current time in milliseconds
    
    if(currentTime >= lastTime + tDelay){  
        byte randomNumber1 = random(0, 255); //create a random number between 0 and 255
        byte randomNumber2 = random(0, 255); //create another random number between 0 and 255
        pushData(randomNumber1, randomNumber2); //send both random nmbers to the 74hc595 IC
        lastTime = currentTime; // reset lastTime variable
    }
}


void pushData(byte fstByte, byte scndByte){ //controls the values of the 74hc595 chip  
  
  digitalWrite(latchPin, LOW); // pull latch pin low to accept data
  shiftOut(dataPin, clockPin, LSBFIRST, fstByte); // push the firstbyte into chip 1  
  shiftOut(dataPin, clockPin, LSBFIRST, scndByte); // push the second byte into chip 1, which pushes the first byte into chip 2  
  digitalWrite(latchPin, HIGH); // pull latch pin high to stop accepting data  
    
}

I hope this gives you a better insight into this method of LED control!

SteveC - Oh Lord, please don't let me be misunderstood! (Eric Burdon and the Animals)


ReplyQuote
Pugwash
(@pugwash)
Honorable Member
Joined: 6 months ago
Posts: 561
2019-10-14 5:51 pm  

@john40131

Furthermore, please don't think I am advocating daisy-chaining N 74hc595s to solve your problem. It could be done but it would be a programming nightmare.

Just using 6 digital pins you could control up to 64 LEDs or anything else that needs a digital HI/LO signal. This would involve 8x 74hc595s and an 8-channel Multiplexer (CMOS 405x for example). Much easier to control in a program.

SteveC - Oh Lord, please don't let me be misunderstood! (Eric Burdon and the Animals)


ReplyQuote
stven
(@stven)
Trusted Member
Joined: 6 months ago
Posts: 64
2019-10-14 8:31 pm  

I have always felt that a lucky guess would serve me just as well as struggling to discover the true answer when it comes to complex problems of logic. Many questions are binary such that you have even odds of guessing correctly.

There are many roads eventually leading to the destination. Perhaps some of the longer ones have more scenic views...


ReplyQuote
John40131
(@john40131)
Eminent Member
Joined: 6 months ago
Posts: 36
2019-10-15 1:14 pm  

@pugwash

I will have a look at that, but like you say could be a nightmare to work out and program so I think I will keep it simple for the moment and progress, on my other post regarding using servos I am able to simulate what I want to do in Ni Multisim but this just takes up so much time but at least I can get my head around wiring..... this link is the guy who setup "Newcastle Central" signals and he used the 74HC757 ...

John


ReplyQuote
Pugwash
(@pugwash)
Honorable Member
Joined: 6 months ago
Posts: 561
2019-10-20 1:01 pm  

@john40131

A word of caution about using the 74hc595.

This IC is by no means an LED driver, it is only low current tolerant. The maximum current from each output pin should not exceed 20mA and when adding the current on all 8 pins together, the current should not exceed 80mA. In the little demos, I have posted above, the current is limited to 6mA per output pin. Enough for green LEDs but not enough for red ones.

That out of the way, I have discovered a webpage with a very good explanation of how these ICs work.

How 74HC595 Shift Register Works & Interface it with Arduino

This may be worth reading before you decide to go down this route!

SteveC - Oh Lord, please don't let me be misunderstood! (Eric Burdon and the Animals)


ReplyQuote
John40131
(@john40131)
Eminent Member
Joined: 6 months ago
Posts: 36
2019-10-20 6:40 pm  

@pugwash

Thanks very much for link I will have a look next couple of days, I have another Arduino Sketch senario which does work albeit a bit long winded appart from an IF senario.... have a look I posted in another link.

John


ReplyQuote
Pugwash
(@pugwash)
Honorable Member
Joined: 6 months ago
Posts: 561
2019-10-22 12:02 pm  

@john40131

I have changed my mind about how difficult it would be to program two or more daisy-chained 74HC595 chips.

The following graphic showed how the penny dropped.

Controlling i.e. manipulating, the output pins using a boolean array, which in every loop() is written to the array of 74hc595s.

I took the following code from your initial sketch to show graphically how it could be done.

void routeUpplatform3right() { // All Trains Up Via Platform 3 to Blackburn

digitalWrite(upplatform3RedLed, LOW); 
digitalWrite(upplatform3YellowLed, HIGH);
digitalWrite(upplatform3GreenLed, LOW);
digitalWrite(upplatform3WhiteLed1, HIGH);
digitalWrite(upplatform3WhiteLed2, HIGH);
digitalWrite(upplatform3WhiteLed3, LOW);

delay(mainLedDelay);

digitalWrite(upplatform3RedLed, LOW); 
digitalWrite(upplatform3YellowLed, LOW);
digitalWrite(upplatform3GreenLed, HIGH);
digitalWrite(upplatform3WhiteLed1, HIGH);
digitalWrite(upplatform3WhiteLed2, LOW);
digitalWrite(upplatform3WhiteLed3, HIGH);

delay(mainLedDelay);

digitalWrite(upplatform3RedLed, HIGH); 
digitalWrite(upplatform3YellowLed, LOW);
digitalWrite(upplatform3GreenLed, LOW);
digitalWrite(upplatform3WhiteLed1, LOW);
digitalWrite(upplatform3WhiteLed2, LOW);
digitalWrite(upplatform3WhiteLed3, LOW);

}

And this is what I came up with!!

signal demo

SteveC - Oh Lord, please don't let me be misunderstood! (Eric Burdon and the Animals)


ReplyQuote
Skynet
(@skynet)
Active Member
Joined: 2 months ago
Posts: 6
2019-10-22 1:01 pm  

Hi @pugwash @john40131 this IC Driver may help you out it large at 40 pin but it's an real led driver that you can use SPI or bitbang to load the data in a serial stream. I use them for debugging projects, to load the data into it takes about 1ms of cpu time. I have one wired up to 4 seven segment displays and 8 individual leds. I have another one with a string of leds on it and as my program progresses along I turn on a leds or off to aid in debugging. There are some arduino libraries for it and not hard to write your own. This baby could control 34 leds so 4signalheads having 5 leds each. current per led is 15ma. If you use those hc595 your gonna need ULN2803 to drive the leds.

 

When programming think about the reuse of code so you can save steps later software should make it easier to use the hardware. 

https://www.microchip.com/wwwproducts/en/MM5450   use the MM5450 it has an enable line...

http://ww1.microchip.com/downloads/en/DeviceDoc/20005651A.pd

Donnie

This post was modified 2 months ago by Skynet

ReplyQuote
Skynet
(@skynet)
Active Member
Joined: 2 months ago
Posts: 6
2019-10-22 1:23 pm  

How are the white leds wired looking at that diagram the is a red, yellow, green, white, left and right?

Does the white above the green part or the left or right diverge? or is part of it? 


ReplyQuote
Pugwash
(@pugwash)
Honorable Member
Joined: 6 months ago
Posts: 561
2019-10-22 2:28 pm  
Posted by: @skynet

How are the white leds wired looking at that diagram the is a red, yellow, green, white, left and right?

Does the white above the green part or the left or right diverge? or is part of it? 

This is a bit of a mystery! The sketch, as flawed as it is, in the first post of this thread, only details three white lights. Only after publishing a photo of the actual light gantry can we see that there are more than just three white lights. In fact, there are nine!

I am pretty sure that these white lights indicate the direction of the next point setting i.e. left or right, and that five white lights will be illuminated depending upon this setting simultaneously.

Perhaps @john40131 could clarify this, otherwise, we are debating this subject based on a false premise.

SteveC - Oh Lord, please don't let me be misunderstood! (Eric Burdon and the Animals)


ReplyQuote
John40131
(@john40131)
Eminent Member
Joined: 6 months ago
Posts: 36
2019-10-22 6:08 pm  

@pugwash

Yes you are correct, there is Red, Yellow, Green, 1 single white in the middle, 4 white to Right and 4 to Left this only lights when Yellow or Green is on and a train is going Left or Right at a " Y " set of points..

So if Yellow Left, Yellow lights for 5 seconds then Green for 5 Seconds and the middle white LED is also lit and the 4 LEDs to Left come on so wiring which I used 30swg enamel copper wire 7 wire of which one is common to all ..

John


ReplyQuote
Skynet
(@skynet)
Active Member
Joined: 2 months ago
Posts: 6
2019-10-22 8:07 pm  

@John40131 Can you draw the track diagram of rails these 6 signals protect include as an image please?

What is monitoring the tracks and switch positions to insure it is safe to display the signal for the movement?

so the signals display something and delay, display something else delay, then display another aspect repeat?

 

 


ReplyQuote
Page 2 / 2

Please Login or Register