Jump to content
 

Arduino to work like a NX panel


Gareth 73
 Share

Recommended Posts

Hi

I'm fairly new to using the arduino boards but have worked out how to operate multiple servos in different ways depending on which button is pressed.

But (and yes I know this is sad) I want to operate part of my layout as a NX panel with a layout similar to a panel I used to operate at Saltley PSB before we transferred to westcad. It won't have any need for track circuits but will be integrated with the signalling and will not have any input to driving the trains.

The problem I have is I don't know how to code the action of pressing button A then either button B,C,etc to then action the appropriate set of route commands to the servos on the points. Also wether it is possible to have route cancelling though not imperative.

While I've spent ages searching on the web I can't find or perhaps recognise might be better, a suitable set of commands to adapt.

Any help or pointers in the right direction would be gratefully received and sorry  if this has been covered before I could find it.

Thanks

Gareth

Link to post
Share on other sites

I know a little bit about Arduino programming but I have no idea what an NX panel is or how it works. If you can explain then I may be able to make some suggestions about the code.

 

...R

Link to post
Share on other sites

Ok a NX panel is eNtry eXit which means u decide where u want to start signalling the train(entrance) to where u want to go(exit).

So using a simple junction ud would start at signal A(1st button) and choose either signal B (2nd button) mainline or signal C (3rd button) branch

When the route A to B or A to C has been selected the system then has to set the points as needed e.g. normal position for mainline or reverse to go to branch.

In the set up I want there would be a maximum of 4 routes that could be selected from a signal so route A to B, A to C, A to D, or A to E.  Each route would entail a different mix of normal and reverse for the points. 

Hope this clarifies things abit

 

Link to post
Share on other sites

It seems to me that you need at least three separate concepts to implement that.

  • You need some means to keep a record of the things that need to be done to set a route - for example lists of the turnouts and their directions and maybe signals and their settings. 
  • You need the means to associate a pair of successive button presses with a particular route.
  • You need the means to know the present state of all the things - for example each turnout and signal

 

Could you be persuaded to do this part on a PC using Python (or any other PC programming language that you prefer) and then the PC just sends to the Arduino the list of turnout settings that needs to be made - that's how I do it.

 

Of course it can be programmed entirely on an Arduino but the way you need to handle data in the small memory of an Arduino will probably make things more complicated. Especially if you want to check whether the resources for a route are available before you set a route - for example a turnout may already be is use for a route for a different train.

 

Whether partly on a PC or entirely on an Arduino the key thing is to define data elements that make the management of the system understandable in 6 months time. For example a turnout might need to record its ID, its current setting, whether it is in use by a train or available to be allocated and whether changing it depends on the state of some signal. If it is in use then there needs to be a means to mark it as available when the current "user" is finished with it, and some means for the new "user" to mark it as in-use

 

...R

Edited by Robin2
Link to post
Share on other sites

7 hours ago, Robin2 said:

It seems to me that you need at least three separate concepts to implement that.

  • You need some means to keep a record of the things that need to be done to set a route - for example lists of the turnouts and their directions and maybe signals and their settings. 
  • You need the means to associate a pair of successive button presses with a particular route.
  • You need the means to know the present state of all the things - for example each turnout and signal

Thanks for the reply while I accept that arduino is computer based I was hoping to avoid more computers in the running of the layout. I've already got a sketch that will set the routes with 1 individual button per route. I lack the commands to make the sketch work with 2 buttons where each button might be associated with multiple routes (i understand the "and (&&)" function to get it to work but this requires the entrance button to be held while the exit button is pressed which is not quite what I want)

As the junction is loosely based on Water Orton from Saltley North panel it goes from a 4 track to 2 track mainline and 2 track branch. 

I don't think it matters that the system doesn't know the current state of points because if it sends the servo a command to move to a state it's already in then it's ready to go.

The signalling will be automatically worked by microswitches on the servos sending the data wire from the correct advance signal back to the protecting signal and held at danger after passage of train  possibly through a second arduino board.

 

Edited by Gareth 73
Link to post
Share on other sites

Hi Gareth.

 

It's not sad at all that you want an NX panel, it's on the list for many people

However, I'm curious as to why you are approaching this with an Arduino? An alternative could be a Raspberry pi. These can run JMRI and, when set up, can do all the NX routing for you.

 

You may also find the Model Electronics Railway Group of interest if one likes to tinker and build.

  • Agree 1
Link to post
Share on other sites

3 hours ago, Gareth 73 said:

I've already got a sketch that will set the routes with 1 individual button per route. I lack the commands to make the sketch work with 2 buttons where each button might be associated with multiple routes

You need some means to identify the start of a route selection process - maybe have a special button that starts the process. Then, once you know you are at the start of the process you need to record the "numbers" of the next two buttons that are pressed. When the two buttons have been pressed then you need to select the route that is associated with that pair.

 

I suggested "numbers" because if you assign a number with a power of two (1,2,4,8,16 etc) to each button then the sum of those numbers for any two buttons will be unique which makes it easy to identify the route.

 

...R

Link to post
Share on other sites

5 hours ago, Marcus-Jay said:

Hi Gareth.

 

It's not sad at all that you want an NX panel, it's on the list for many people

However, I'm curious as to why you are approaching this with an Arduino? An alternative could be a Raspberry pi. These can run JMRI and, when set up, can do all the NX routing for you.

 

You may also find the Model Electronics Railway Group of interest if one likes to tinker and build.

1st  Only reason I'm using arduino is it's the 1st 1 I got after looking for a servo controller type thing. I will have a look in to what you've suggested. Thanks

 

2nd ok Robin I get what you are saying could you tell me how you write a sketch that records the button presses and then how do i action on that result 

Thanks for you help

 

 

Link to post
Share on other sites

4 hours ago, Gareth 73 said:

2nd ok Robin I get what you are saying could you tell me how you write a sketch that records the button presses and then how do i action on that result 

 

That could be a very big question - have any Arduino programming experience?

 

...R

Link to post
Share on other sites

9 hours ago, Robin2 said:

That could be a very big question - have any Arduino programming experience?

 

...R

Very little. The last time I had anything to do with programming was 30 years ago in school when I built an automated train system for a project, and that was on a BBC master computer that you more or less had to tell it it was a computer before you could do anything.

With the arduino I've got my head around assigning pins and getting combined inputs (using &&)  to move multiple servos in appropriate directions to set routes.

But didn't want  to have to hold the entrance button down while the exit was chosen.

If the arduino is not suitable and the programme would be to difficult I'll leave the NX idea and just use the arduino as a servo controller on a basic route setting panel. Then in the future perhaps look into the pi.

Thanks for taking the time to reply

Link to post
Share on other sites

4 hours ago, Gareth 73 said:

you more or less had to tell it it was a computer before you could do anything.

Sounds primitive - just like an Arduino :)

 

If you can already select routes then adding the extra ability to select them with two buttons should not be too difficult. I suggest you write a short separate program just to learn how to take inputs from two buttons and produce a single result number - shown on the Arduino Serial monitor. The program should be something like this pseudo code

 

button1State =  digitalRead(button1Pin)
button2State = 
// etc

if (buttonCount < 2)
   if (button1State == LOW)  // assumes low when pressed
       buttonTotal += 1
       buttonCount ++
   else if button2State == LOW)
     buttonTotal += 2
     buttonCount ++
  else if button3State == LOW)
     buttonTotal += 4
     buttonCount ++
  }
}

if (buttonCount == 2) {
    if (buttonTotal == X) 
       // route 1
    else if buttonTotal == Y
       // route 2
     etc
     
    buttonCount = 0
    buttonTotal = 0
}

 

...R

Edited by Robin2
Link to post
Share on other sites

I would not suggest using a Pi , pi’s are not great for direct IO as the operating system complicates everything 

 

an NX “ style “ operation is quite a simple sketch , you could forget the push /pull NX buttons used on the prototype and just use simple push buttons , each with an associated led 

 

your sketch needs to read the state of each button , when an input is triggered , which you have decided is an “Entrance “ , your sketch then flashes all the leds associated with a valid Exit route , on pressing an exit button, the relevant button entrance and exit   led turns solid , all other exit leds go out . The Arduino then uses IO to switch points and signals etc. 

 

your sketch has to ensure that any conflicts are detected and the relevant exit led is not flashed ( ie that exit route isn’t offered ) , there are various ways to do that , you could maintain a table of points and their status ( free, locked to a route ) so that you can tell if the point can be assigned to a intended route ) 

 

cancelling a route could be done by simply pressing the same entrance button , ie your logic knows the button is “ locked” to an active route and hence pressing it , does a route cleardown process 

 

you may find you rapidly run out of IO, ( and you will ) , so you either have to use multiple Arduino's, which complicates the code greatly, or use some IO expanders 

 

the Arduino has more then enough power and memory for straight forward layouts

 

a big layout will tend to result in a lot of code, but much of it repetitious in nature

 

tables can be used to map routes and hold status 

ie

route table ( columns , button no, pointA, pointB,PointC, exit button no) 

hence on detecting a button push you can scan the route table to determine the associated points , and the exit button , by finding all entries corresponding to the entrance button , you can determine all possible corresponding “ exit “ choices 

 

further tables can provide signal numbers etc , tables in RAM can be used to hold route status , points locked , free , etc 

 

not a trivial coding task , but not difficult if you have mastered the basics of Arduino programming 

 

 

 

Dave  

Edited by Junctionmad
Link to post
Share on other sites

Hi,

 

First of all, I'm sorry to say that you can't make a model railway panel work exactly like an NX Panel, there are functions in an NX that are there to get around some real world problems. The next bit of bad news is that niether an Arduino or JMRI are easily made to work like an NX Panel and a proper interlocking.

 

I gave up trying Arduino for a proper interlocking after 3000 lines of code (although this was mainly due to the number of inputs / outputs required), but I am getting their with JMRI.

 

It can be done, but you need to be skilled in not only writing Arduino or JMRI logic, but also very skilled on interlocking logic (I'm not that skilled at either!). Lots of people I see on Facebook and elsewhere all start trying to build NX Panels etc for their Model Railways and it is not as simple as it sounds.

 

My big recommendation is write any code like relay logic, don't go into memories and variables etc. Just simple 'if and else' statements will make it work more like an interlocking.

 

Simon

Link to post
Share on other sites

On 25/07/2019 at 16:01, St. Simon said:

Hi,

 

First of all, I'm sorry to say that you can't make a model railway panel work exactly like an NX Panel, there are functions in an NX that are there to get around some real world problems. The next bit of bad news is that niether an Arduino or JMRI are easily made to work like an NX Panel and a proper interlocking.

 

I gave up trying Arduino for a proper interlocking after 3000 lines of code (although this was mainly due to the number of inputs / outputs required), but I am getting their with JMRI.

 

It can be done, but you need to be skilled in not only writing Arduino or JMRI logic, but also very skilled on interlocking logic (I'm not that skilled at either!). Lots of people I see on Facebook and elsewhere all start trying to build NX Panels etc for their Model Railways and it is not as simple as it sounds.

 

My big recommendation is write any code like relay logic, don't go into memories and variables etc. Just simple 'if and else' statements will make it work more like an interlocking.

 

Simon

Basic Entrance Exit Routing is quite straight forward and not a difficult task to code , assuming you are comfortable and competent with writing code. the complexity of real life life NX systems are mostly around safety systems which do not apply to a model railway. What we are looking to do is to emulate an NX Panel not duplicate one. 

 

The main issue with a stock Arduino is the lack of sufficient IO for anything other then the most trivial of layouts ( and hence most unlikely to any  benefit from NX complexity ) 

 

you have three ways to deal with this , route the IO through a layout bus , and use the ardunio as a “ logic  engine “ , join multiple arduinos together , by several different mechanisms, to expand the IO , but this complicates the software significantly 

 

the other is to expand the IO on a single arduino via again various means of IO expanders ( I2C , SPI ) etc. ,the added software complexity is more controlled at the cost of extra hardware . A typical circuit could use several MCP23017s ( there is an ardunio library for this ) 

the key thing is an Arduino has more then enough processing power and memory to handle basic MR NX projects 

 

the suggestion not to use “ memories or variables “ is utterly bizzare, Coding is correctly called software engineering for a reason , it’s an engineering discipline .  You should use the full capability of any coding language to the extent of your abilities. This should include , variables, lookup tables , OOP techniques , etc etc etc 

 

Remember , we are emulating the prototype not duplicating it. 

 

Howeber these are not really undertakings for a “ novice “ programmer , you need to be competent and have several reasonable projects “ under your belt” 

 

 

Edited by Junctionmad
Link to post
Share on other sites

In his Post on 15 July the OP said " I've already got a sketch that will set the routes with 1 individual button per route." That suggests to me that all that is now required is a simple system to select those routes by pressing 2 buttons rather than 1 button.

 

...R

PS ... IIRC there used to be a number attached to every Reply which made it much easier to refer to a specific earlier Post - is my memory faulty?

Edited by Robin2
Link to post
Share on other sites

Thanks for all the replies.

I haven't had much chance to do much on this project.

I don't need it to be a full blown NX panel with full interlocking etc (That would be way to much like what i do at work).

I've now got a mega board which has enough IO for all buttons, servos and route leds. I've got a sketch that works holding the entrance button down and then pressing the exit button at same time which will set all appropriate servos to normal or reverse. It doesn't matter what state the points are in before button press I won't be using track circuits or similar to hold the route. (As it probably be just me running it all I 'll try and use mental interlocking ) All I need is rather than probe and stud or individual point switches etc is just to have 2 individual push buttons per route which are push and release the entrance and then with in a set time an push and release the exit . I still haven't got head round sketch that robin put in July 16 post as not had time to mess with it. 

Thanks again all

Link to post
Share on other sites

  • 1 year later...

As both a signalling engineer and a model railway enthusiast with some Arduino experience, I found the way to go with the NX panel was to use the button press to set a software latch for the event of entrance or exit button. If you start with a latch for Entrance pressed as well then next button has to set the Exit  pressed latch as well as setting individual latches for the relevant Buttons. 

When the corresponding ENT &  EXT signal buttons have been pressed I move points by means of a relay as I have Cobalt point motors, they could feedback over the contacts so the Arduino can give point indications.

When a route is set I also set a route latch that can be used to inhibit conflicting routes.

The Arduino provides outputs to the main aspect and rout indicators of the signal as well as red/green on the NX panel and route lights.

For a simple 2 route signal into a bay platform and a through platform with input from the next signal on the through platform to give the third aspect input and 2 platform starter signals my code reached 190 lines and utilised 22 I/O pins and has 9 latches using bool functions.

My station area alone would need either a dozen Arduino Megas or huge number of I/O extenders, After the first 3 signals were created and tested I realised the folly of this method and starter to device a lever frame option using microswitches and servos in the frame to provide 'locking' of the levers.

Link to post
Share on other sites

  • RMweb Gold

I can certainly see how attractive an NX system for a model railway would be - as a teenager in the early '60s  I wondered about golf tees as buttons! - but fear that half the joy of the real thing is watching the system "strip-up" a route, as the interlocking checks everything, and then the progressive clearing of the TCs with TORRS (Train-Operated Route Release System) as the train occupies and clears each one.

 

When St Simon says it's more than tough to do, I am inclined to believe him. 

  • Thanks 1
Link to post
Share on other sites

  • RMweb Premium
9 hours ago, dorchfc said:

After the first 3 signals were created and tested I realised the folly of this method and starter to device a lever frame option using microswitches and servos in the frame to provide 'locking' of the levers.

 

I also intend to to develop a Servo Interlocked Lever Frame using the Arduino to do the Interlocking and Drive Servos for the Points, Signals and Interlock Frame. Phase 1 of this is described here: - https://www.rmweb.co.uk/community/index.php?/topic/150296-moretonhampstead-signalling/

 

 

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...