Controlling tracks

Fun

The parts I have ordered for the ShiftRegister have not arrived yet, and I’ve used the time to investigate two elements that will help me control my whole setup. These are the 8588 Trenngleis (Interrupt Track) and the 8589 Schaltgleis (Switch track).

8588 Trenngleis (Interrupt Track)

The Interrupt Track controls power to a specific part of the track. In the classic (not automated setup) you would connect it to a toggle switch or a Signal (8940, which contains a toggle switch). The Interrupt Track is mainly used to control side tracks, such as stations or shunts to control multi-train setups on the same electrical loop. On the shunt, an engine could be parked (track powered off) until needed. In a station, a train can be parked on the sidetrack (which is then powered off) until another train on the main track has overtaken it. For the Shunt I would need only one 8588 but for the side track, I would need two. However, only one of the 8588 needs to be controlled by a relay.

The 8588 can be controlled with a Relay, where we open (no power) or close (power) the connection between the two connectors. This all is extremely straightforward, so where is the problem? Well, there are some considerations when automating this. One is the switch or the controller that triggers the relay, and the other is with the Elegoo Relay bank.

My first experiment was to control the relay with an extra button (code here). This works, but from time to time, there is either nothing happening or multiple switches. I encountered the problem of bouncing switches. What happens here is: if I pressed the button longer than 150 milliseconds, the Arduino thought the button had been pressed again, which resulted in the issues I saw. The solution was to use a debouncing function. A debouncing function checks if the button has been pressed again in the last 200ms and if so, it ignores that event (new code). Problem solved; now the relay switches are without any issues.

The other issue I found was that a single relay switch would switch (as expected) from optionA (see last post ) to optionB with digitalWrite(switchPin,HIGH), however when using the Elegoo relay banks, it turns out that it’s the other way around. When one uses the Elegoos digitalWrite(switchPin,HIGH) it will switch to optionA and digitalWrite(switchPin,LOW) will switch to optionB. This isn’t a big deal, but it’s good to find out now, as it means that the code for the shift register control needs to address this problem.

8589 Schaltgleis (switch track)

The switch track is pretty nifty, as it can detect not only the passing of a train but also the direction it passes over the switch. My first experiment was to understand what triggers the switch, the engines, the waggons or both. The wiring will consist of two LEDs showing the direction of the train passing through. I will also use the Arduino Serial Monitor to show the direction of the passing train (code here). It turns out that only the Engines trigger the switch, and depending on the type of train (long and short), it may trigger longer or shorter.

Two other things I need to keep in mind:

From the input of the experiments with the 8588, I learned that I would have to look at debouncing the switch. In my first experiment, the issue didn’t show up because I used a delay(500) between switching the lights on and off; however, if you comment out (//) the delay and digialWrite lines and have a look at the serial output, you will see that the switch triggers a lot when the train passes. This will be a big issue if I want to use the Switch Track to trigger other functions, such as operating a Switch Point.

The other thing to keep in mind is to choose how to implement the Switch Track into the Arduino code. There are two options. The first is to use it inside the loop and check if the switch has been pressed and the second is to use Arduino Interrupts. An Arduino Interrupt means that the Arduino processor monitors a specific PIN if it changes state, and if so, it will execute a short function. More details can be found here. The crucial differences are, that interrupts literally interrupt any other process going on and that depending on the model of Arduino/ESP, there might be only a limited number of PINs that can be used for monitoring Interrupts. They basically function like a red emergency button.

I created two versions of the code: Using the loop and using interrupts. Which is the right one to use in the later automation will need to be seen.
Another thing to consider is to use a pushdown button on Analogue Pins instead of digital pins. The main difference between an Analogue Pin and a Digital Pin is that a digital Pin has two values, HIGH and LOW. In contrast, an Analogue port shows the voltage applied to that pin in values between 0 and 1023. In the code, I used readValue=analogRead(buttonPin); then, I checked if the value was below 100, indicating it had been grounded. Analogue Pins can not be used for interrupt triggering, but will free up needed digital Pins.

Summary

Automation is about two core concepts: actions and control. I can now control Switch Points and a side track (action) and understand where a train is on track (control). I’m almost able to get started on an automated setup. As the parts will arrived soon, I will dive into using the shift register to control all the Switch Points and multiple trains on one track.

Previous
Previous

Using Bluetooth and an 74HC595 to control Märklin Switch Points

Next
Next

Using Arduino to control Märklin Z Switch Points