A Home Wi-Fi Connected Garden Railway

What is your latest project?
User avatar
Soar Valley Light
Driver
Driver
Posts: 1451
Joined: Sun Dec 08, 2013 5:18 pm
Location: North West Leicestershire

Re: A Home Wi-Fi Connected Garden Railway

Post by Soar Valley Light » Sun Mar 11, 2018 5:49 pm

tom_tom_go wrote: Sun Mar 11, 2018 9:36 am Can we keep this thread on topic and let Michael go about explaining what he enjoys doing with his railway.

We are a broad church here and welcome all types.

We have an off topic section for debating, please use it.

Mod hat off, now back to the trains.
You're quite right Tom, it has been a bit of a hi-jack! Apologies to Michael.

Andrew(osaurus!)
"Smith! Why do you only come to work four days a week?
"'cause I can't manage on three gaffer!"

User avatar
RylstonLight
Trainee Fireman
Trainee Fireman
Posts: 209
Joined: Fri Oct 26, 2012 3:10 pm
Location: Pontefract West Yorkshire

Re: A Home Wi-Fi Connected Garden Railway

Post by RylstonLight » Mon Mar 12, 2018 1:45 pm

Hopefully more or less on topic, in the original post Micheal, you refer to controlling signals etc.

I have dabbled in microprocessor control (albeit Picaxe and arduino) and tested them outside. The ultimate plan was to control lighting, points and signals.I am worried about the longevity of the microprocessors (any any servos) outside. I tested one in what I thought was a sealed environment. All it controlled was a simple LED but after a few months it failed, I assume due to water ingress. Have you any ideas on this or do your plans for infrastructure control avoid getting the microprocessors damp in any way?

Andy
Andy S. at the Rylston Light Railway

User avatar
tom_tom_go
Driver
Driver
Posts: 4824
Joined: Wed Feb 23, 2011 3:08 am
Location: Kent, UK
Contact:

Re: A Home Wi-Fi Connected Garden Railway

Post by tom_tom_go » Mon Mar 12, 2018 2:07 pm

Hi,

I use an Arduino outside for R/C point and signal control and not had any problems with the weather.

The Arduino lives in an ice cream box inside a Plastikard building. I run it off batteries at the moment but would like to run a 'bus' power cable along the line to power it and any future servos or lights.

The servos have no special housing and simply screwed to the track base and protected from the elements that way.

It's all in my RWLR thread to read about.

Michael's stuff is far better than my efforts so interested in hearing more.

Tom

Southern188
Cleaner
Cleaner
Posts: 40
Joined: Thu Jan 11, 2018 8:37 am
Location: Dorset

Re: A Home Wi-Fi Connected Garden Railway

Post by Southern188 » Mon Mar 12, 2018 4:09 pm

My initial plan was to update my locos and get them working with the hand-held controller (one train at a time) similar to the way any other remote control system operates. Whilst writing the software I realised the many other things I could do with this system and my plans were continuingly being updated. So the controller can now handle more than one train at once (ideal for my long squashed oval shaped layout) and the trains can run in automatic mode (stopping for a set period at stations, speed changes, reversing, details in forthcoming post).

Location detection and automatic mode can mean more realism, not taking away the fun of manual control. One train on the main loop in auto mode, one doing auto shunting and you manually control the third train.

The PC controller, along with live video feed(s) could if enabled, allow anyone, anywhere to control the trains (like home automation systems) but that is not something I plan to do. Sitting in the lounge operating a train is something I have done but just to prove I could.

As for signalling, this is something that could be added, though I have no plans to do that at present. A couple of signals randomly going red might prove challenging for the driver.

Sorry, I can't comment on weather proofing as I haven't reached that stage yet. I do plan to have my main station "connected", lights, sounds, points but that should have a leakproof roof as I'm not building it :)

Michael

Southern188
Cleaner
Cleaner
Posts: 40
Joined: Thu Jan 11, 2018 8:37 am
Location: Dorset

Re: A Home Wi-Fi Connected Garden Railway

Post by Southern188 » Tue Mar 13, 2018 8:01 pm

Bachmann Lyn Conversion

Whilst the Bachmann Lyn is G scale (1:22.5) and therefore slightly undersized for the rest of my 16mm railway, it's a nice little loco, good value for the money and runs flawlessly on my less than perfectly laid 45mm track. A minor niggle is that the cab and bunker are too high. I tend to use this first to ensure the track is ok and when I'm in the garden, working, eating or drinking wine, and just want a train to run with minimal control. A secondhand model purchased from Ebay was my first loco, later to replaced by a new one, when Bachmann bought out a much improved version a few years later.

lyn_4.jpg
lyn_4.jpg (258.87 KiB) Viewed 9261 times

It is easy to take apart (4 screws) and contains a DCC ready control PCB that sits on top of the motor drive assembly. There are two switches accessible when the front of the smoke box is opened. The original PCB has been replaced with one containing the microcontroller and associated components. Two 18650 lithium batteries are fitted in each side tank along with a 4 cell charger/protection circuit.

lyn_2.jpg
lyn_2.jpg (90.06 KiB) Viewed 9261 times

The component cost of the PCB, which is a typical of that needed for an electric loco, is £12-£18 depending on source of components. Details are:

1) The 3 connectors to the top left are the electric pick up points for the front, centre and rear wheels. These are used to charge the battery either off the track or from a section of the track that is powered, so it can be recharged during use. This also saves having a separate charger socket. The bridge rectifier ensures the polarity is irrelevant.

2) The lower left comprises a 2 way connector to the motor, power MOS FET and relay used to drive the motor. I use this rather than a separate motor driver as from experience these typically (especially type L298) lose to many volts (reduces speed), get hot and wastes battery capacity. However, I haven't looked lately so there maybe a better alternative now.

3) A 4 way connector for power from the batteries in the side tanks and the original on/off switch located in the smoke box.

4) A 5 volt step-down switched mode power supply. I love Pololu products.

5) An 8 way connector and ULN2003 driver for the relay, front lamp and smoke generator, leaving 4 outputs available for future use.

6) A Wemos D1 mini pro microcontroller. There are cheaper alternatives and clones but I have standardised on this one.

Pictures showing the assembly of the original control board and the new one.

lyn_3.jpg
lyn_3.jpg (104.07 KiB) Viewed 9261 times

lyn_1.jpg
lyn_1.jpg (139.68 KiB) Viewed 9261 times

A simplified descriptive flowchart of the software is as follows:

 Power on
 Initialisation
 Front lamp on
 Connect to wi-fi
 Connect to MQTT server
 Subscribe to messages that are applicable (speed, direction etc.)
 Download schedule (for automatic mode)
 Front lamp off (gives visual indication that everything has been setup correctly)
 Start main loop
 Check for incoming messages
   If speed, set loco speed
   If direction, set direction
   If lamp, turn lamp on or off
 If 30 second timer occurs
    Send status, speed, battery voltage, temperature and wi-fi signal strength messages
 Return to start of loop

Between the recent bad weather, I've been testing the Bachmann Lyn on my newly extended track and have been really pleased with the results, sufficiently to start this thread and share my experiences.

Michael

User avatar
tom_tom_go
Driver
Driver
Posts: 4824
Joined: Wed Feb 23, 2011 3:08 am
Location: Kent, UK
Contact:

Re: A Home Wi-Fi Connected Garden Railway

Post by tom_tom_go » Tue Mar 13, 2018 8:14 pm

Any videos of a running session with multiple locos?

Southern188
Cleaner
Cleaner
Posts: 40
Joined: Thu Jan 11, 2018 8:37 am
Location: Dorset

Re: A Home Wi-Fi Connected Garden Railway

Post by Southern188 » Wed Mar 14, 2018 8:52 am

Sorry Tom, not yet.

Michael

User avatar
tom_tom_go
Driver
Driver
Posts: 4824
Joined: Wed Feb 23, 2011 3:08 am
Location: Kent, UK
Contact:

Re: A Home Wi-Fi Connected Garden Railway

Post by tom_tom_go » Thu Mar 29, 2018 9:32 am

I have had time to read this again properly and using the track to charge the loco is a brilliant idea.

Do you have sections of the line outside that are powered so the loco can stop and charge up?

Southern188
Cleaner
Cleaner
Posts: 40
Joined: Thu Jan 11, 2018 8:37 am
Location: Dorset

Re: A Home Wi-Fi Connected Garden Railway

Post by Southern188 » Thu Mar 29, 2018 4:54 pm

Yes, I have a one 3 foot section of track powered and park the loco there to charge. It could be extended to top up the charge during normal use but I haven't found a need for that.

Michael

Southern188
Cleaner
Cleaner
Posts: 40
Joined: Thu Jan 11, 2018 8:37 am
Location: Dorset

Re: A Home Wi-Fi Connected Garden Railway

Post by Southern188 » Wed Apr 25, 2018 8:54 am

Location and Automation

I've fitted an L&B open wagon with various experimental circuits. This includes a location device, sound and eventually a camera.

I've looked at various ways of impementing location detection. Ideally GPS would have been good but it isn't accurate enough at this scale. There is also magnets and Infra-Red which is commercially available for LGB type layouts. I've tried magnets, with two sensors either side of the wagon and that sort of works but in the end I decided to opt for RFID (radio frequency identification) contactless cards.

There are two main types of contactless cards Those that operate at 125kHz are used in security and access control. Those that operate at 13.5Mhz are used in banking and concession bus passes. I've tried both but have chosen 125kHz because of the greater range and the aerial is easier to hide.

card reader.jpg
card reader.jpg (31.78 KiB) Viewed 8797 times

The cards (painted and hidden with ballast) are placed under the track and the card reader is located in the wagon with the coil underneath. As the wagon passes over the card it will register the card number and from this the location will be known. The cards can be read at a distance up to 3cms but because the train is moving, the coil has to be placed closer than this to give time for the card to be powered and to transmit it's serial number.

The location id will be sent as an MQTT message for any other device to see. The hand-held controller and PC controller will display the named location and locos will use it for automatic operation.

The components within the wagon are:
   PCB containing Wemos D1 mini microcontroller, step-up regulator and Dfplayer sound chip
   RDM6300 125Khz control board
   Lithium battery and associated charing/protection circuitry
   Loudspeaker
   Coil (underneath)

The automation schedule is programmed using a simple code. This is downloaded from a textfile on the Raspberry Pi when the loco is switched on, so it can be easily changed. A future option will enable the hand-held controller to select from a number of different schedules.

Each line of the schedule contains the following:

   location id, mode, speed, stop time, options (in binary for clarity), acceleration/de-acceleration (milliseconds per speed unit) and points
  where:
   mode = 1 (normal), 2 (timed stop), 3 (random timed stop)
   options are not used, n/u, n/u, n/u, token, whistle, lamp on, direction (0=forward, 1=reverse)

Example schedule:

0, 2, 8, 10, 00000010, 400, 0 // Auto start initial settings: wait 10 seconds, then speed = 8, lamp on, acc = 400
1, 1, 14, 0, 00000110, 400, 0 // normal, speed = 14, lamp on, whistle, forward, acc = 400,
16, 1, 16, 0, 00000010, 200, 0 // normal, speed = 16, lamp on, forward, acc = 200,
20, 1, 10, 0, 00000010, 200, 0 // normal, speed = 10, lamp on, forward, acc = 200,
66, 2, 9, 40, 00000000, 400, 0 // timed stop, stop for 40 seconds, then speed = 9, lamp off, forward, acc = 400
72, 1, 12, 0, 00000010, 400, 0 // normal, speed = 12, lamp on, forward, acc = 400
0 // Repeat from second entry

The points field is for future use. The loco will send the points field as a message at each location. The ESP8266 controlling the points will receive this message and adjust the points accordingly.

The token option is again for future use. I'm looking forward to implementing this.

Following widespread testing, I've realised that using a wagon for location is much easier than installing it in each loco. The coil assembly is also less noticeable under a wagon. The wagon will eventually be covered so that the electronics aren't visible and I am also going to include the circuitry in a coach.

Here's a video of a loco under automatic control on an extension that is currently under construction. There are 3 cards on this section, the one on the curve slows the loco as it approaches the station and one at the station brings the loco to a halt. The loco will start again after the appropriate delay.

https://youtu.be/Vxh79lHODzM

Must stop hummimg when I take a video!


Michael

User avatar
gregh
Trainee Driver
Trainee Driver
Posts: 566
Joined: Sun Apr 01, 2018 5:44 am
Location: Sydney, Australia
Contact:

Re: A Home Wi-Fi Connected Garden Railway

Post by gregh » Wed Apr 25, 2018 11:05 am

I am just flabbergasted at your skills.
It's always great to read about a project that is 'pushing the boundaries', even if way beyond my skills or needs.

Just to add a little about using servos etc outside. I use Picaxe outside, usually in a small clip lock food container, which is then inside a building. Plenty of vaseline on the picaxe pins. Servos are in buildings or even in small signalling 'cupboards. No problems in 15 years, but we don't get snow here.
Greg from downunder.
The Sandstone & Termite's website: https://members.optusnet.com.au/satr/satr.htm

Southern188
Cleaner
Cleaner
Posts: 40
Joined: Thu Jan 11, 2018 8:37 am
Location: Dorset

Re: A Home Wi-Fi Connected Garden Railway

Post by Southern188 » Tue Aug 14, 2018 10:04 am

Belated thanks to Greg for his comments. Here's an update.

Thanks to Virgin Media there has been a change to the wi-fi system. After they dug up the road I waited a year before signing up but whilst the speed is fast the router is not very good. The original wi-fi was a repeater in the summerhouse but the VM router cuts out occassionally so everything now runs off a completely separate network using the original BT router.

The good weather means that trains are running most days and the system is proving very reliable, though there has been the odd problem. The auto mode is great especially when Al fresco dining, gardening or just relaxing watching the trains go by.

I have a new hand-held remote control. I realised that if something happened to the original it's not something I could buy from Ebay. Also, the PCB push button on the original were proving unreliable. The new one is in the same type of case but now has proper case mounted buttons and two rotary controllers so I can easily control 2 trains at once. This meant that I needed more I/O lines so I have updated the micro-controller to an ESP32. This incorporated battery management so the electronics is now the ESP32, LCD display and battery only.

I have a new loco (Accucraft Yeo) which has been updated and my first points working controlled from an ESP8266. The remaining 3 points will be connected over the winter.
P1000456.JPG
P1000456.JPG (268.37 KiB) Viewed 8441 times
P1000472-001.JPG
P1000472-001.JPG (300.7 KiB) Viewed 8441 times

There is an interesting article on page 38 of the August 2018 edition of Garden Rail. It's wierdly entitled 'Wireless DCC, "learning the lessons of leaves on the line"' and it's by Dagnall Clutterbuck. It's how he has used ESP8266 modules in his outdoor railway. Like myself he is using MQTT but his locos are DCC controlled. I'm not alone :) .

Michael

User avatar
FWLR
Driver
Driver
Posts: 4262
Joined: Sat Aug 05, 2017 9:45 am
Location: Preston, Lancashire, UK

Re: A Home Wi-Fi Connected Garden Railway

Post by FWLR » Wed Aug 15, 2018 7:56 am

Nice looking loco that Yeo.

The electric board underneath, would it not be susceptible to all the muck the world throws at it…

Southern188
Cleaner
Cleaner
Posts: 40
Joined: Thu Jan 11, 2018 8:37 am
Location: Dorset

Re: A Home Wi-Fi Connected Garden Railway

Post by Southern188 » Wed Aug 15, 2018 10:26 pm

Yes Rod, a nice looking loco, Accucraft have done a good job. The electronics have been in the same position in my Lew, which has been running for 4 years. No problems with muck so far.

Michael

User avatar
tom_tom_go
Driver
Driver
Posts: 4824
Joined: Wed Feb 23, 2011 3:08 am
Location: Kent, UK
Contact:

Re: A Home Wi-Fi Connected Garden Railway

Post by tom_tom_go » Thu Aug 16, 2018 11:51 am

I think isloating this setup from your home network is a good idea anyway.

User avatar
FWLR
Driver
Driver
Posts: 4262
Joined: Sat Aug 05, 2017 9:45 am
Location: Preston, Lancashire, UK

Re: A Home Wi-Fi Connected Garden Railway

Post by FWLR » Fri Aug 17, 2018 8:51 am

Thats great to hear Michael. Do you have anymore videos of it running please.

Southern188
Cleaner
Cleaner
Posts: 40
Joined: Thu Jan 11, 2018 8:37 am
Location: Dorset

Re: A Home Wi-Fi Connected Garden Railway

Post by Southern188 » Fri Jun 12, 2020 8:42 am

It's been a while so I thought I would update this thread with the latest developments on my railway.

My railway has expanded, and there are now 13 items controlled by ESP8266 and ESP32 processors. There are 7 locos (1 steam), 2 wagons (sound and location), a railway station (sound, lights and 6 points), 2 handheld remote controllers and one central controller.

The main change has been the removal of the wi-fi network! Whilst it worked well it had it's disadvantages, required external power for the router, 15 seconds startup for router and each device and was difficult to run my locos elsewhere.

I now use ESP-Now, a peer to peer protocol developed by the manufactures of the ESP range of processors for direct wireless communication. It effectively works like a 2.4Ghz wireless keyboard communciations with a computer. In practise it works well, all devices can communicate with each other and has the advantage of being instantaneous and is low power. If I had known about this protocol earlier I probably wouldn't have gone down the wi-fi network route, but it has been fun and that's what hobbies are all about :) .

The automation mode continues to be an nice option to use and can now control 6 points, following the addition of a points controller. The addition of a LGB KGF field loco and an Accucraft Baguley Diesel to the fleet means that these can be setup to run automatically whilst the main locos are operating.

https://youtu.be/1BOpqjPOD0E

Lockdown projects have seen the addition of an electronic token system which allows multiple locos to operate without them running into each other, a doubled headed option and several new buildings.

https://youtu.be/a-R3EhYzYSA


Michael
Last edited by Southern188 on Fri Jun 12, 2020 10:16 am, edited 1 time in total.

User avatar
ge_rik
Administrator
Administrator
Posts: 6497
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: A Home Wi-Fi Connected Garden Railway

Post by ge_rik » Fri Jun 12, 2020 9:00 am

Sounds intriguing. I've tried doing a web search for more info but not found much so far. Can you recommend a good source?

Rik
------------------------
Peckforton Light Railway - Blog Facebook Youtube

User avatar
philipy
Moderator
Moderator
Posts: 5033
Joined: Sun Jan 30, 2011 3:00 pm
Location: South Northants

Re: A Home Wi-Fi Connected Garden Railway

Post by philipy » Fri Jun 12, 2020 9:31 am

Rik,
I suspect that "EPS" should read "ESP"?
https://www.espressif.com/en/products/s ... w/overview
Philip

Southern188
Cleaner
Cleaner
Posts: 40
Joined: Thu Jan 11, 2018 8:37 am
Location: Dorset

Re: A Home Wi-Fi Connected Garden Railway

Post by Southern188 » Fri Jun 12, 2020 10:18 am

Thanks Philip, yes that's the correct link and I've corrected the typo.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests