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.