Saturday, 10 August 2019

Getting obsessive about little things

The last week or so has been full of silly things that really count for very little but take up a lot of time.

Push Pull fun

First off, I was getting to grips with my new cab control, push-pull passenger train. The problem is that the cab coach has a decoder installed to control the lights on the face of the coach. The loco headlights change, of course, with the direction of the train. This means that, when I reverse the direction of the train, only the loco lights change. I then have to change the direction of the cab coach lights and, quite often, I forget.

The answer would be for me to create a consist where the controller manages the lights on the train. However, whenever I built the consist - which wasn't easy because I couldn't find the manual so kept getting it wrong - the lights on the cab were always the same colour as on the loco. I tried about 10 times and finally went on to the ESU forum and asked the question.

Three days later, I had still not received an answer so had to tackle the problem again. I sat down with the train and the controller and one hour later I had cracked the problem.

I turned the loco around physically!

It is now sorted! When the loco has white lights, the cab has red and vice versa. (BTW, I never did get an answer! I did get told off for placing the question in the German forum but I didn't get an answer there either!).


Arduino Stress and Fun Fairs

I am currently building a fun fair to go into the empty area on the left hand side of the railway. I have a roundabout (Faller Polyp) and a Ferris wheel. I have motorised the Polyp (well, thought I had) and am building the other two little concessions that come with it. The plan is to motorise the roundabout and fit it with music. It will also be decorated with an LED light show. All of this is to be managed through a range of Arduino processors. I have mentioned my activities before but I should explain that, although I have been programming since 1975, I have never used the C language so have had to change my mindset a little. I thought that I was getting somewhere as I already had an Arduino Nano controlling the level crossing and had demonstrated the roundabout working with music.

Aside: an Arduino normally comes as a development kit. Plug the board into a computer, using USB, and the board gets powered. In addition, the PC connects to the Arduino through a COM port (or the equivalent on a Mac or Linux). This connection provides a pathway for the code to be installed on the board. In addition, there can be feedback of data from the board to a "serial monitor" window. 

OK, on to the fun and games. The fun fair needs a decent, independent, power supply(PS). I am fitting 12VDC motors into the Faller kits, replacing their 16VAC ones which are hard to drive and need a specialised PS.  I already had a Chinese 12V PS but it has a problem - the 240VAC input is is the same line of connectors as the 12V so extreme care is needed. To avoid any issues, I planned to place it inside a box. Because it was to be closed, I decided to fit a computer fan. These are 12VDC and I thought it would be easy to fit one in. However....

12VDC but fixed - that means that they only operate at or near 12V so anything less and they sit and stare at you. I built the box and everything worked fine. However, the fan made a distinct hum which I felt would become annoying if heard constantly from underneath the layout. The plan moved on. If I put an Arduino in the mix and have this read a thermistor (a heat sensitive resistor) I can turn the fan on as the temperature rose and and off as it descended. Days later, it was all working except the fan. I realised that the problem was that I was using the fairground code to run this. This speeds the motor up, runs it for a period of time and the slows it down. Off to Amazon to find a new fan. This time, |I bought one that advertised PWM as an ability. PWM is Pulse Width Modulation. This means interrupting the 12V for a length (very small) of time which, even though the voltage stays at 12V, the average voltage is less so the motor runs slower. I fitted this and, again, nothing. I checked against my roundabout and that still worked fine. It seems that the PWM  fan requires a special sort of power and data link which I couldn't be bothered to mess around with so decided that I could live with simple on and off depending on temperature. Still nothing!

After hours of messing about fruitlessly, I realised that I had a ground on the Arduino (from the computer) and another ground on the L298N (the L298N is the power board that uprates the power available from the Arduino to a level that can drive a motor). This isn't good practice so I ran a ground from the Arduino to the ground on the L298N and - bingo - everything worked. For some reason, without the proper ground, the L298N was only outputting around 7 volts. With the ground sorted, it was outputting 11.95V and off went the fan. As an aside, suddenly the funfair ride was spinning fast. It seems that it was getting 7 volts when I thought that it had 12!

The last messing about was getting all of this to work on a Nano. Nanos are fully working Arduino boards but the are designed for sitting stand alone with power, not connected to a PC. They are very cheap at 3 for around £10.00 on Amazon. They have a micro USB connector for programming but all the connections must be soldered rather than using the jumper leads as in the standard Uno Arduino. Yet again, I messed about for a few hours not sure if I had the software wrong or the wiring. Eventually, I ruled out the software and did a detailed review of the wiring. This sorted the problem and now have a working fan system. I need to work out a realistic cutoff as, today, it was 77 degrees in our living room so to test it, I had a cut off of 80 and pinched the thermistor to get it to rise. I guess that a cutoff around 70 would be OK in actual use.

Here is the current box, although I am going to rebuild it into a bigger box. As you can see, there are 6 12V DC outputs available.

This is the Chinese power supply. It isn't intended to be used in a public location.


Here are the importand component parts. The fan is obvious. The item in the middle is the L298N. This takes control signals from the Arduino and provides higher power at 12V DC. It also has PWM inputs so the speed can be controlled, provided that the motor can use it. The Amazon purchased 12V DC motor in the roundabout does so I can slow it down and speed it up. This isn't needed for the fan. The item to the right is the Arduino Nano placed on some printed circuit board. The L298N has a 5V output so I power the Arduino from that. All nicely arranged.


Tomorrow, I build a new box and then that is that. Back to building the funfair. My next job is to get a couple of shift registers working with 16 LEDs to provide the light show on the roundabout. The Arduino doesn't have enough ports to drive 16 LEDs so I have to use nice little integrated bit shift circuits. Luckily, I have an Arduino development kit and there are examples with code for all little things like this, thank goodness. YouTube is a big help as well. More tomorrow.

Wednesday, 24 July 2019

Music and a fun fair


Here is a video of a new addition to my layout.



This is the Faller HO Polyp fairground ride. It comes with an AC motor, which I have discarded and replaced with an Amazon sourced 12V DC motor with gearbox.

12V DC motor

This has been hooked up to an Arduino with complex components. One is an L298N H Bridge motor controller. The other is a DF Player Mini - plays mp3s from a micro SD card.

You can see the resulting mess on the prototyping board here

UserPostedImage


Basically, there are 10 rock and roll tunes on the SD card. The Arduino picks one at random and calculates its length in seconds from an inbuilt table. It the spins the motor up gradually for 14 seconds, runs the ride for the required length and spins it down for 15 seconds. It then delays for a random period and starts all over again. The idea is to recreate the ride that my wife remembers from Raphaels Park, Romford in the 60s when she was a teenager! The L298N is there to drive the motor as the Arduino doesn't have enough oomph. The power to the L298N comes from a Chinese 12V power supply in the pink box behind. This is the source of the hum. I am currently working on a thermistor driven Arduino to go inside the box and control the fan, which is what is making all the noise! Mind you, as it is 85F in my living room at the moment, now is not a good time to work out the settings!

Sunday, 21 July 2019

Arduino, Arduino, Arduino

In case you don't know, an Arduino is a little processor board that can control physical items connected either through digital (on-off) or analogue pins on its board. Up to now, I have used an Arduino to control the level crossing. I now have three more in various stages of completion for the following tasks:

  • Indicators of  arrival in the shadow station
  • Making the "Polyp" ride operate
  • Coordinating 60's rock and roll music to the "Polyp".

Shadow Station

Because of my arthritis, I can't turn to see the trains when they reach the end of the shadow station board and control the loco from the ECOS. The simple answer was to put up some visual indicator of position for each of the shadow station tracks. The final answer was to use light dependent resistors (ldr) buried in the track to control coloured LEDs on the fascia board beside the ECOS. After a lot of messing around due to a faulty ldr, it was all resolved and in place. LDRs are very expensive - NOT. £4.99 for 70! Once I replaced the dodgy one, everything works. I now have this nice little display in front of me where each track is aligned to a coloured LED which lights up when a loco moves over it.


The white light is just to show that it is working because, when there are no locos in the shadow station, all the lights are off so it is nice to have a pilot light.




As the shadow station is dis-mountable, there is a multi-way plug attached which connects to the main board. This plug can only be inserted in one direction. Mind you, I have to remember to unplug it when taking everything down!





Although this is the one for the level crossing, it shows you how the LDR is placed in the track. It is not at all noticeable.

Making the Polyp ride operate

The Faller kit for a fairground ride is called the "Polyp". It looks like our Octopus ride. My wife remembers going on something similar in her early teens at the Funfair in Raphael's Park in Romford. I think that she remembers "The Whip" where the boys from the ride would hit the brake in one of the compartments to make it swing round. As she say, she always remembers not only the ride but the music that was played. This was all the excuse I needed. First off, I have to make the ride operate. It comes with a motor but this is a simple 16VAC motor that can be turned on and off. It needs an AC power supply, which I didn't have. I had a nice 12V Chinese PS sitting there from an earlier attempt to put under-shelf LED lighting in my old railway room. I was able to get a nice little 12V motor and gearbox from Amazon and fit it instead of the provided one.






The problem was making a "lightweight" Arduino control a motor that would pull current in excess of the Arduino's capability. The answer turned out to be an L298N Dual H Bridge Stepper Motor Driver . This sits between the Arduino and the motor and provides the extra power required. It can also be controlled for speed and direction. Here is the L298N attached to the Arduino and wired into the motor. The pink box contains the Chinese PS as the 240V connections were somewhat exposed!


The Arduino program drives the motor for a period and then keeps it still for another - random - period when the whole things starts over again. Notice that it starts up slowly and slows down nicely at the end.


Now, we have the problem of the "rock" music. That's the next step.

Coordinating 60's rock and roll music to the "Polyp".

There are so many cheap add-ons for the Arduino that you can manage almost anything that you can think of. I have a little thing called a DF PLayer Mini which is a little board that wires into the Arduino and provides music off a mini-SD card. All for £3.50 or so. This little thing can manage up to 100 folders with MP3 files inside. It can be started, stopped, make a selection, etc. The trick is to get it working! I had to mess about for a good few hours trying to get the correct include files and the matching code until I hit on the right combination. 


Currently, I am running it through a Boombar Bluetooth speaker but I have a natty little AUX driven one coming. Along with all of this, I have got hold of a set of CDs for Dion and the Belmonts, Del Shannon and Eddie Cochran. Tunes from these such as "Runaway" and "The Wanderer" should provide a great background to the fair. 

Now to tie it all in


Now, the big problem! I have to make the Arduino running the ride drive the other one running the music. Amazingly, there is an include file called Wire which does all of this. Provided I keep to a single character, I can send it from one to the other. '0' to '9' should do for the tracks, 'G' for Go and 'S' for stop should make it all workable.

The ride will decide on a random tune. Both will know how long the tune is. The ride can tell the music which track and when to start it. They will both run for the length of the tune and then the ride will tell the music to stop. The ride will then wait a random time and it will all start again.

Needless to say, it will be a bit like Christmas songs in a shop! Hence, we change the tunes by refreshing the SD card and we can turn the whole thing off on demand. This is where an LDR comes in. Sitting on the ground in the fun fair will be a police car. When the ride is active, the police car will be over the LDR. To stop the ride, just pick up the car and move it sideways to expose the LDR. Job done!


Monday, 24 June 2019

SBB on the Pennstadt - Valdorf Line

I have always liked the Krok, even when modelling US,etc. so it was inevitable that I would eventually turn to the SBB for some stock. First off, I have bought a new 39568 Krok and a 2nd hand Marklin 482 from Rails of Sheffield on EBay. Rails admitted that they couldn't test the 482 so I got £10 off the price - Not bad value at £80 - no sound but you can't have everything.




Now, I had to get some stock. First off was a pack of three 3rd class SBB coaches. Again, these came from EBay at a cost of £40. These are Roco, I belive and one even has a slider and lighting fitted. I am investigating how to get lights into the other two coaches. Here is one of them. The others are the same.



I then dashed of to my LHS and ordered 6 Roco 'aggregate' wagons - these came in at £25.00 each. The cost of all these is proving to be very acceptable.


I found these four mineral wagons on EBay for £40.00!




I have written a nice little bit of web software that provides me with trains to run. For my Open University degree, I wrote a program that provided for the routing of freight cars on US model railroads. This was great to use but it did demand that you run your trains exactly to the schedule because it needed to know the physical location of every loco, wagon and caboose. I didn't want anything so complicated with my nice little Marklin train set so I fitted up a "shadow station" with four tracks off the main board and wrote some software to propose trains to run.

This requires that I can find the exact wagons it is asking for. I then accept the train, make it up, run it and then release all the components. To make this easy, I have everything in open trays so that I can find and replace things easily.

This is the box that I built for my new SBB equipment.


This sits on top of the wardrobe until required!

The locos are in little carriers that make it easy to lift them out and put them back without damage.







The mineral wagons came in a nice polystyrene box so, rather than make the tray even bigger, I chose to leave them where they are.

There is a piece of ribbon glued to the top of each locations. This ribbon is run under each wagon. Pulling on this gets the wagon out without a lot of gripping, etc. The coaches have two ribbons and a bar between them. As you pull on the bar, the coach rotates and is easy to hold.












Finally, when packed up, it looks like this.













Here is a video of both the Krok and the 482 running on my layout.



Monday, 10 June 2019

Shadow Station Routing

Now that the shadow station board is complete and the routing set up, I can finalise the details.

This is how the whole thing looks with the shadow station board in place.


It all fits very nicely - sorry about the wonky leg! There are four tracks running the length of the board. These are fed by a three way and a standard point.



The board length is planned against the Rheingold train sitting there. So that the board wasn't unnecessarily long, this train only fits onto the middle track of the four as this is the straightest out of the three way.

To make all of this easy to manage, I have created a set of routes. This was a very simple operation on the ECOS. However, to avoid lots of confusion, I moved all of the staging point controls across to a second page so there is a clear set of operations for the main board and the staging area.

The ECOS is very clever when it comes to setting up points. I put the new three way onto the layout and started to define it. I was worried that I only had a new point operation. I need not have worried because, as soon as I added a three way image to the setting, it understood the change and managing it was extremely simple. Here is the point control/routing page from the ECOS.



New Shadow Station Board

My main layout size is just 2m x 0.9m. As I now have a few locos and a few more wagons and coaches, I need somewhere to store them when the railway is in use. I can't have any more space permanently so I have to have a detachable board for what I used to call a 'fiddle yard' and then 'staging' but now must refer to a 'shadow station'!

Originally, to enable me to move in and out of the bedroom railway area, I designed and built a board that went on the end of the 2m side. This meant that it had to squeeze in between the railway board and the wardrobe. It also meant that I couldn't reach the top end of the board as it was now over 1m away and out of reach. I fixed the support side by including a drop down leg but could never resolve the track connections.

When my wife looks at things, she can often see what I miss. I think that I get too close to the problem. She took one look and said, why don't you come off the long end of the board into the room. My response was that it would over hang the bed, but - in fact - the old design was already going that way once I had a Class 23 and four Rheingold coaches. On looking at here suggestion, it made a lot of sense. She also commented on the fact that I had extended the original board and suggested that I should build a new board which would be in one piece rather than being three bits glues together. As we were only talking about £20 worth of 5mm foam core, this made a lot of sense.

I have a lot of dedicated tools for making up foam core so the process is easy. I make all the framing from three thicknesses of foam core cut in strips 50mm wide all stuck together with 50mm double sided tape. This is extremely strong along the length. The cross members are notched into the side members and everything is hot glued into place.



The next problem is to square it all up. I do this by hot gluing the top surface on, ensuring that the boards are nice and square.



As this board is to stick out into the room on a pair of legs, It makes sense to put some walls along the sides and ends of this board to stop anything falling off the edge or careering off the end!


To finish it off nicely, I used up the remnants of my Woodlands Scenics grass mat.

Attaching it to the main board is done in two ways. I have a couple of sockets for dowels which locate the board correctly. (As you can see, I had a couple of goes to get these in the right position). There is also a flat board added (see in the right of the above picture) that slips under the existing board between it and the desk the board is rested on. One these are in place everything is very secure.


The above shot is of the board in place before I had laid the track. The near end is supported on two legs that slot into boxes in the underneath ((see later).

The board is designed to be stored between the permanent railway and the wardrobe.


Moving things around, you can now see the two sockets for the legs. In the second image, bellow, you can see that the legs are designed to fit one inside the other for storage.




The legs are constructed using a clever knife that slices a V-shaped cut in the foam core, which makes a clear and firm fold and another that slices a 5mm piece of foam out of the board leaving the paper outer coating. Three V-shaped cuts and one notch make for a very strong box section, which is how I make the legs.

The next post will conclude this by showing the track in place and how the routing is set up.

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