Sunday, 26 May 2019

Pennstadt/Valdorf and Arduinos

I have added an Auhagen level crossing (Schrankenlage) to the reverse loop as a means of getting from one side to the other. As I have been a programmer for more years than I care to mention, I thought that I could automate it using an Arduino. My son-in-law bought me a set when I retired but I have never seemed to have a reason to pull it out and have a go. This project seemed ideal for it but the box is buried in our storage room. I therefore went to my friendly Amazon account and bought an Elegoo Arduino starter set. This comes with an amazing set of accessories and all for £25. I soon got onto messing around with the Servo and the light dependent resistor (LDR) projects. Once I had both cracked, I worked on putting them together. 

Firstly, here is the level crossing in situ.

The kit comes with holes ready for wires to raise the arms so that wasn't difficult. However, one of the pivot pins broke off so I had to drill the arm out to accept a brass rod. Once they were operating, it was a case of working  out how this all would work. The reverse look only accepts trains in one direction. They comes out of staging, travel around the oval and traverse the reverse loop to enable them to go back into staging. Hence, I only have to manage trains going in one direction.

One LDR is buried into one of the approach tracks, just sitting level with the surface of the track. This is connected to an analog input to the Arduino (using a potentiometer layout if that means anything). This means that the LDR gives a reading of between 0 and 1023 depending upon the amount of light falling on it. This is mapped onto a range of 0 - 179. Originally, I then split the range into 0 - 90 and 91 - 179 with 0-90 being lit and 91-179 being darkness. 

Once the LDR goes dark (a train is over it), the gates lower. When the LDR goes light, the Arduino waits for 5 seconds - to give the train time to cross the level crossing - and the gates raise. The action is all achieved by having two servos attached to the digital outputs of the Arduino.

This works very well and, given that I have never used the C language before, was quite easy to do.  Here is a little demo of the gates before I installed them onto the layout.

The crossing gates are now fitted into place with an Arduino under the table. As I didn't want to use the Arduino that came with the starter pack - it uses jump leads so the connections are not too secure - I obtained a set of three Arduino Pro-Mini versions. This requires that all the leads be soldered in place, which was quite easy - using a flux pen made it easier. Once wired up, the Pro-mini has a mini USB socket for programing.  Here is a run showing it in operation. You may notice a couple of problems!

Firstly, the LDR is mounted too close to the crossing so the gates haven't quite cosed when the loco crosses. This is simply changed by moving the LDR another 6 inches further away on the curve. The second problem is more difficult to fix. It appears that the LDR is very sensitive and is seeing a change of light across the defined threshold when the coaches are passing over it. Fixing this will be an interesting bit of coding as I am going to have to recognise the spurious reactions. I think that it is a case of counting the reactions and if the light threshold is broken for too short a time, then the gates will not move. I am new to C programming (I have been using other, higher level languages since 1976 so I have some learning to do).

If you are interested, the code is available as a PDF - HERE

Saturday, 25 May 2019

Huge progress on the Pennstadt to Valdorf DBB line

I have concentrated on my railway for the last few weeks and have ignored all my other hobbies. This means that I have made some serious progress on all aspects of the layout. I have had one major disaster and one technological triumph (almost!).

Generally speaking, I have been getting on with making the Faller buildings. The main one of which is the Butchers/Bakers (Bakerei- Meztgerei). If you recall, I made this previously but, amazingly, got the N scale instead of the Spur HO version. I have now taken delivery of the HO version and it is completed.

I had some Preiser sitting people for the outside part but the figures on the inside are all these really cheap 50 to a packet of EBay figures from China. They are a bit tiny but it isn't noticeable once the walls are shut up. I have a 1m strip of warm yellow LEDs. There are two good things about these. One is that they are quite bright and the second is that they don't require resistors in the line. They can be cut down just to one LED. I wire them all up to a single 5V supply (A wallwart). I now have all of my buildings it in this fashion, all connected to a Marklin on off switch, as you will see later.

The next item to be completed is the Auhagen level crossing. This is a nice little kit that comes with the gates and a nice keeper's shack. This is perfect for fitting across my reverse loop providing access from the main station/town area across to what will become the fun fair. I was wondering about motorising the gates when someone suggested that I should have bought the Faller version which, I think, comes with a motor. However, I wanted some more logic than that. I went down the route of using an Arduino. I will cover this project in my next blog post.

What I wanted to have was a fully lit town, especially as I have a plan for a fun fair. Hence, every building has a set of LED lights. The goods yard is lit with tall double lamps and the streets are lit by more decorative items. These are all wired up to a single switch on the fascia. As the railway is in our bedroom, I have got into the habit of putting the lights on when we turn the bed down and my wife enjoys looking at the effect. It is enhanced because of the wardobe mirrors which make it all look much larger. 

One of the nice things, when the wife is in bed looking across at the railway, is the wardrobe, sited as it is alongside one end of the railway. The doors are mirrors so  she can see the whole railway, with its lights on.

Lastly, I have caused an expensive little problem. The problem came from the placement of the semaphore signal that I had protecting the yard entry point. It worked very well. It meant that I could bring the shunter out onto the main line when required without risking a train on the main line hitting it. It was a Marklin 703891 home signal with lattice mast. It was placed right on the front of the layout and, when reaching across fitting the Faller buildings in place, I knocked it and broke the wire connection. This was OK-ish, because it still worked electronically, even if the arm didn't move. On a second occasion, I gave it a whack and broke the arm off.

I decided to replace it but with a 76491 Single colour light signal. I ordered this last Monday and DPD delivered it at 8.30 on Thursday morning. How is that for service? This is better because it fits under the track and isn't glued in solid. As the track at the front is where all the connections are fitted, the track isn't screwed down so, if I do give it a nudge, it leans nicely!

If you look carefully in the picture of the wardrobe, you can see the spot of green in the mirror.

In fact, I have got into the habit of looking in the mirror to check the status. It is easier that bending my head over to look at the actual signal.

Things are moving on too quickly so I must take a break from this. I am enjoying it too much but it is a restricted size so has limited amounts that can be done. Mind you, I have plans to build a fun fair in the area the other side of the level crossing and to add a cliff against the removable staging to hid that when fitted.

I am so glad that I chose Marklin!

Wednesday, 1 May 2019

More scenery goes down

I have never done much sceniking so I have taken lots of time to get the base works done. I have found that, once there was a basis, I could get some detail in quite successfully. I have a couple of drawers full of Woodland Scenics stuff so it was a case of using a range of their products across the board.

Having put lights into the main buildings, I then went on to put street and yard lights into the system. I had reason to move the baseboard out away from the walls - a van had come off the tracks in the tunnel. The board is designed to cope with this type of action but in the process, I pulled a lot of the lighting wiring off. I had done a bit of a kludge with the wiring to this point so it was a good excuse to crawl on the floor and rewire everything. This is not something that I take to lightly as my arthritis allows me about 1 1/2 minutes under there before I have to lay down so it took a good deal of time to do. Previously, I was soldering the connections and then covering them with heat shrink. I have found a gadget for making these connections which doesn't require that I have a soldering iron plugged in.

This is the connector:

You insert the first wire in one end and crimp it. The second wire goes in the other end and gets crimped as well. Then - and this is the good bit - the ends are heat shrunk. I have a new mini blow torch to do this.

You push the button on the back and it fires up. It is very easy to control. I heat both ends and - bingo - the wires are secured. When finished, you rotate the button and that turns off the gas.

Using these tools and fittings I was able to rewire all the lighting successfully.

I have then done a lot of work putting bushes, etc. into the areas that I had built up as hills. I wasn't happy with the edges of the hills so these bushes cover them nicely. Additionally, I bought a box of Nuch walkers that have been sprinkled around the hills.

My current task is to build an Auhagen road crossing. I intend to make it work using an Arduino board using servos. I have the prototype Arduino sketch working. I am just waiting for some more servos and some circuit board to arrive to get the whole thing working. IT is going to be fitted across the reverse loop in the middle of the board. The idea is that a photocell will detect the train and close the gates. Once back in the light, the Arduino will wait for some seconds before closing the gates. It is a simple piece of programming. It could be more complex but I want to keep everything simple nowadays.

My next blog should show the gates working and I will also be covering the software that I have written to provide train consists.