Ashi Valkoinen

Working signalling system using SBrick and TLC products

Recommended Posts

Hello all, 

I'm glad to introduce my project I spent approx one year to work on. Those who follow my railway MOC model topic here, on Eurobricks, should be familiar with my work, and could know I do own a big station with additional storage yard (fig.1.) to store all my long, 1:45 scaled railway models.

27138110_c168ca0033eb2496091d84fd72fcab4

Fig.1.: My train station in BlueBrick layout software 

1. Why and what?

My station displays a renovated mainline station - not a dedicated one, just a station, which looks quite average on refurbished Hungarian double-track lines. A modern station comes with working light signals - and this need started my project. I owned two completed mainline signals back in 2013 (fig.2.), using polarity reversal bricks to switch four pairs of modified PF ledlights (modification allowed that only one of the ledlights turned on, depending on the applied voltage's polarity, this modification was nicely described be Viktor Péter Kovács in RailBricks #9). These signals were operated by hand, both turning them free and red after trains, which could cause a lot of error, leaving them accidentally free after a train passed. Also my station needed 5 entry signals, 11 exit signals and one shunting signal for my storage yard. It is easy to see, that without some automatisation these can't be handled light by light. It is important, that my project is about making a system which handles my station, giving play experience by setting routes and managing train traffic, but it is not about automatisation of the trains. Train drivers should drive their own trains (9V, PF, PU, custom) according to the appearing signal aspects set by the "station driver".

27138120_43b80f9306e4c76e77123bc3297eb2c

Fig.2.: My old signals - both of them powered with two pairs of PF ledlights. 

2. The real life prototypes

Before continuing, I need to explain the Hungarian signalling system in short - and also the logic behind it, and the difficulties it causes. Excluding any branchline special signals, focusing on mainline block signalling, there are two types of signals - main signals (red-white-red pole, they give a speed order to pass and forecast for next main signal) and repeat signals (yellow-white-yellow pole, forecasting only if the corresponding main signal is free or not, these are used where the tracks' curvature doesn't give enough distance to note the signal aspect of main signals). Three colours are used - green, yellow and red. 

  • Red always means to stop, giving no forecast of the next main signal.
  • Yellow allows to pass at the maximum speed permitted for the train by other conditions (track, vehicle), forecasting next main signal will be red.
  • Blinking yellow allows to pass at the maximum speed permitted for the train, forecasting next main signal will be allowing passing by 40 km/h (speed for normal switches in turning direction).
  • Green indicated to pass at the maximum speed permitted for the train, the next main signal will be also allowing passing by maximum speed permitted for the train (so it forecasts next main signal being yellow, blinking yellow or green)
  • Yellow-yellow (two lights) allows to pass with the maximum speed of 40 km/h (implying some switches in turning direction will be ahead), next main signal is expected to be stop.
  • Yellow-blinking yellow allows to pass with the maximum speed of 40 km/h, next main signal will allow also passing by 40 km/h.
  • Yellow-green allows to pass with the maximum speed of 40 km/h, next signal will allow maximum speed to pass by.

As you look at my track configuration, you may see, that all these variations mentioned above should be considered when putting ledlights to my signals. Fig.3. shows my station with installed signals and the secured neighbouring blocks. This signalling logic also means, that I should know if zero, one or two sections are free after a main signal, including the route (turning on points, or not).

27138116_07a79ca475187ef697546f223adab2d

Fig.3.: Shematic track layout of my station including the neighbouring signalling blocks, too.

3. System components

Why are the neighbouring openline tracks considered? When I allow a train to leave my station (setting a free exit signal for it) it should mean that at least the first section is free and no other train is there. So I should have control over that section - detecting trains entering and leaving them from both direction. Train detection was also needed to turn the signals automatically back to red when a train passed, reducing the chance of accidentally leaving them free by manual operation.

I chose the products of SBrick mixed with LEGO-elements. SBrick offer very nice, Bluetooth-controlled light hubs (SBrick Light), which can control 24 independent channels or 8 RGB channels, changing light colours. Since I didn't need the RGB-option (different colours are at different points in the real signals), I could use all the 24 channels of each hub (and since my signals needed 3 or 4 lights each and I have 24 of them, it was quite useful). The other SBrick product, the "+" smart brick can handle inputs and outputs - only for the Power Functions era. But besides train motors, technic motors, ledlights the PF-era had two types of sensors and I used the distance/moiton sensors to detect trains. These were never really put into commercial, the WeDo 1.0 elements were available for schools for education purposes. Fortunately Bricklink and eBay had them...

And all these inputs (distance sensors) and outputs (SBrick light ledlights, PF M-motors to set points) are connected through the surface called SBrick Pro. I connect to the SBrick hubs with my PC, running the code simply from browser. You can write all your code on this surface, using some Scratch-based language (before this project I never did any programming). You can add scripts to different events (like if the distance sensors' values change, on stratup, pressing virtual buttons you added to your "remote control"), writing texts, and of course, managing the outputs. Each physical ledlight, motor or sensor is paired in the code with different variables (like strings describing the signal aspect, number values for distance sensor measurement, logical variables to store occupation of segments, etc).

And yes, it took one year to write the code from zero (as I said, I never wrote any code before I started this project), collect the physical elements and building them into my layout. It was tested at five events this year, these events brought a lot of problems (and I had no option to test it before events since my layout is 11+ meters), but for the last event, our lugs annual exhibition at Martonvásár city (Hungary) finally it worked 2×10 hours at opening days without any major issue, so now I can finally proudly present it (fig.4.).

27138112_5095c34653de1f5212af15a07bcc64f

Fig.4.: The remote control created in SBrick Pro for my station.

I used the following components:

  • 4 SBrick+ hubs + 2 WeDo 1.0 sensor on each
  • 2 SBrick hubs + 5 PF M-motors on them
  • 6 SBrick Light hubs + 88 SBrick leglights on them for different signals
  • some PF extension wires
  • 3 9V speed regulator to power SBrick+ and SBrick hubs from 230V AC.

4. How does it work?
a) Setting a route

Routes can be set selecting the big metallic buttons on the remote control surface (one button for each neighbouring openline section and one for each station track), while direction is selected with the top corner buttons (from left to right, or from right to left). If the route can be set (no occupied segment is involved and it is not conflicting any other existing route), the program:

  • set the points via SBrick and PF M-motor,
  • it virtually locks the points (no other routes can be set including the locked points),
  • and after this sets the corresponding signals free.
  • The buttons of sections involved in the locked route stay red. 

Removing a route (if you don't want it or the train already passed it) can be done with the bright blue buttons next to each route displayed the bottom left corner. Removing a route can't be accidental, for safety it requires "two-hand operation", keeping spacebar pressed while saying okay to the warning message. After this is done, a counter start giving safety time before the route and the switch locks get cleared.

b) Motion sensors

Sensors of WeDo 1.0 can detect objects in front of them from approx. 15-20 cm. For the largest distance they have a value of 10, while if you put something very close (<1,5 cm) it gives the value of 0. Since they are mostly placed 2 cm from the tracks (to make sure wide steams can also pass), a value of 3 is set at treshold value, if the value given by the sensor goes below this value it is counted as detection.

For first, the code checks if a train is expected to be there. All sensors check one position, but trains could arrive from both direction, the sensors can't decide, which direction the train came from. The program evaluates the logic variables - direction set for the section, is any route set for the involved sensor and the neighbouring signal aspects - if it finds out that the train shouldn't be passing the sensor, gives a high pitch warning on the PC, and also resets any free signals back to red which would possibly let a train to the section where an another train violated the red signal. If the train is expected to be in front of the sensor, the signal belonging to the route and direction will fall back to red. After the train passes the sensor, there is a safety checking - seven detection cycles ran with timing, all should find the sensor value above treshold before saying the train really passed. If the automated looping mode is turned on (letting trains go through the station), after the train passed the sensor and clearence timer is also out, the cleared section's signal will automatically set free. 

All routes can be resetted in once with the bottom right bright blue button. This is necessary if some errors pop up, or someone passes a red signal - in this case to clear the error message reset must be performed. A reset has also a clearence time, and all sections' must be checked if they are occupied or not and this information is asked by the software. Setting a section clear is also a "two-hand operation" to avoid making a section accidentally free while there is a train on it.

5. Experiences
a) Problems

I used this setup on five different events from this year's April. At the first three events there were too much false error detections - these were related to bugs in the code. Sometimes the routine for checking a train started twice or more times thus leading to "redrunning" errors. To find out, where my code runs into a bug, I started to write some values on the remote and also making error codes and messages for different events to spot out my errors. Later I left this parts in, since now these error messages clearly can point out, where and what happened in a case of redpass.

The varying width of different trains and setting sensor cycle time was also hard to do - I must deal with 12 wide steams (with rods) and sometimes 6 wide short sets. The steam engines always crashed into my sensors, so I put them more far away from the tracks, resulting in non-detection of 6 wide trains. And if the sensor doesn't catch a train at all, it will go on error at the next sensors, since it won't expect the train to be there, if the previous one haven't counted it before.

The code issues have been solved, but I don't now what to do with different widths - at least at our own events we have train varyings between 8 and 10 studs of width, there are no oversized models and no original LEGO set trains.

Also setting too frequent sensor value writing to variables lead to out of memory error, while setting it less frequent brought the possibility of missing short and fast trains.

b) Play experience

It is really nice to manage the traffic! When it finally started to work properly (at the fifth event), it was really cool to leave it in automated mode (it lets trains going through the station, and if a section get's free, it lets the next train) or set an ending or starting route for arriving and departing trains. The best part was BSBT 2022 in Schkeuditz, most of the participants really liked, that they need to drive their own trains according to the appearing signal aspects and not only following an another train as close as possible. :P

I also created a loop-operation mode for myself if I'm not collaborating with someone else to create a layout. In this case the two group of block signals are logically connected, forming a third section between themselves (fig.5.), creating a double track loop, with four sections of each (three openline, one station section).

27138118_ac967b79975a52f66a6f9bb02bed2ed

Fig.5.: My Stadler KISS EMU on the outer loop, between two block signals. The inner loop's block signal gives one green, indicating that the following two sections are clear. You can note the SBrick Light hub and SBrick+ blocks in the middle, the WeDo 1.0 sensors on the sides of track, between the signals of the group.

c) System components

Bluetooth has is limitations, and pushing 12 different hubs to this project was quite overkill and unexpected even from the SBrick-team - but it works. For first I had many connection issues, it was really lucky moment when all the 12 hubs went online and connected to my PC, but later I found a "wizard" option, which seemed to be doing nothing, but after quitting from it all connections got resetted and all hubs went online instantly. So no more angry waiting, pairing and swearing at it.

SBrick lights are really nice, they can be powered both from internal batteries or 230V AC with power supply cable, for a use like mine the plug-in power supply is preferred. The option of programmed handling of 24 different channels is superb. SBrick hubs are now well-known over the world, they do well, the SBrick+ hubs can handle the input, unfortunately the newer sensors have no more PF-connectors, so these SBrick+ hubs work only with the rare WeDo 1.0 units, it is quite a hard limitation.

You can see my system in action in the following video:

...and I felt really honored to have a mention from @michaelgale and Enrico Lussi at their articles from BSBT 2022:

Michael Gale's article at BrickNerd

Enrico's article at BMR

6. Future plans

The system will be fully done, when the P40 switches of FXTracks will come out and I can replace all my old R40 9V points to fancy new R104 ones (fig.6.). I am too lazy to motorize all my 9V points currently, and when I competely rebuild my layout to incorporate the new points I'll do the missing motorisation progress, too.

27138114_cafd1343c85714cb067e0750a626366

Fig.6.: Comparison of my current layout using R40 switces (bottom) and the future layout with FX Tracks R104 switches (upwards). 

Your comments and critics - as always - welcome. Feel free to share your impressions! :)

Edited by Ashi Valkoinen

Share this post


Link to post
Share on other sites

Oh boy....this is technically speaking, far beyond my understanding 😁however I do appreciate the amazing work you have put into this project, to make such a complicated system work.... ! It is really next level for the hobby 🙌👌👍

Share this post


Link to post
Share on other sites

Ab-so-lu-te-ly stunning.

Crazy - and so cool.

I mean, making it technically "work" (signing up hubs, have a connection) is one thing and certainly the basis of all what you are doing.

But getting this all to work - for me, incomprehensible. This must have been and surely still is so much work ... wonderful.

Thank you very much for sharing - and particularly for the write-up. It was/is a pleasure to read and enjoy!

All the best,
Thorsten

Share this post


Link to post
Share on other sites

Way, way too advanced for me, but it's jaw-droppingly cool.

My one criticism is that it looks very, very European. I realize that we have some signals like that in NA, but the majority are still constructed as cantilevers/signal bridges over the tracks. I think you'd want to offer that as an option if you wanted to sell to NA customers. 

IMG_5080.JPG

Edited by LordsofMedieval

Share this post


Link to post
Share on other sites
14 hours ago, LordsofMedieval said:

My one criticism is that it looks very, very European. I realize that we have some signals like that in NA, but the majority are still constructed as cantilevers/signal bridges over the tracks. I think you'd want to offer that as an option if you wanted to sell to NA customers. 

Basically I didn't created this setup to sell it - it is for my own entertainment and one more play experience addition to our LUG when we have public, joint display. Andyes, it is European, since I am modelling XXI. century Hungarian railroad. We have also some signal masts where there are three or more tracks next to each other, or if for any reason traditional signal poles doesn't fit next to the track, but these masts are rare and using them on my layout wouldn't be authentic.

18 hours ago, M_slug357 said:

Sooo cool! I wish I could get my layouts up to this level!

Thank you. It is about time, dedication and unfortunately funds. I built up everything on my own, got a little support (LUGBULK-baseplates), and collected these for 13 years by now. :)

15 hours ago, Toastie said:

Ab-so-lu-te-ly stunning.

Crazy - and so cool.

I mean, making it technically "work" (signing up hubs, have a connection) is one thing and certainly the basis of all what you are doing.

But getting this all to work - for me, incomprehensible. This must have been and surely still is so much work ... wonderful.

Thank you very much for sharing - and particularly for the write-up. It was/is a pleasure to read and enjoy!

All the best,
Thorsten

It means a lot of work (now with the signalling system building my layout up before an event takes 12 hours compared to the previous 10 hours), but it pays off nicely. We can switch between being a driver or traffic manager, we can shunt or drive mainline trains, a lot of fun which pays for the hard-work part. :)

On 11/17/2022 at 8:31 PM, Selander said:

Oh boy....this is technically speaking, far beyond my understanding 😁however I do appreciate the amazing work you have put into this project, to make such a complicated system work.... ! It is really next level for the hobby 🙌👌👍

Thank you!

Share this post


Link to post
Share on other sites

Very impressive project.  Programming all this and getting it to work is an accomplishment, especially in just 1 year, especially without prior programming ability.

Share this post


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

  • Recently Browsing   0 members

    No registered users viewing this page.