Make a donation

Donators get access to the extended part of the site + bonus: Arduino Train DNT application.
For experiments and regular updating of the site, I need funds. I also have another project that you will like. If you are interested it, support me via donations.

About Line Apps

Designed by a modeler for modelers

My railway layout controlled via URB

Much more than the Android Apps Line

My applications are not just the remote control of locomotives and junctions on the layout. This is an attempt to change the paradigm of control by model railways, that is, to introduce automation elements and script algorithms into management. The ultimate goal of the project – give the modelers people, in reality, the same incredible opportunities as in modern computer simulations, such as MSTS, Train Simulator, Trainz and others.

There are two unique possibilities in Apps Junior and DUO (DNT) - the AWS modes and SCRIPT buttons. In the future, using to URB, I will gradually add new features to the project itself and to the Applications.

Applications are made with the most concise and user-friendly interface. Using protocol version 2 and changing sketches to URB units, you can reconfigure almost all the elements of the application interface to your other individual layout devices, for example to use the buttons of junctions control that are not used in your layout to execute other commands.

The DEMO application is made to demonstrate the capabilities of the project and is basic in the section for beginners (you can also use Junior and DUO (DNT) applications, since their command system is also based on Protocol 2). The application Arduino Train for Kids 2, made to involve your children in the fascinating world of model railway. You can see how it use on the site Instructables. I have some more interesting ideas, and in the future I will add new gaming applications for the URB project.
All applications are made in such a way that it is possible to control a railway under the control of URB by any of them without sketches changed, only the possibilities to control the layout will be different.

  Arduino Train Demo Arduino Train for Kids 2 Arduino Train Junior Arduino Train DUO Arduino Train DNT
Two players mode or independed control 2 different routes      
Dependent behavior of the loco's states control elements
Smooth thrust (12 speeds)      
Slider Algorithm™ (improved Slider Control)
Set default turnouts position button    
Whistle sound button  
Feedback mode (AWS)    
Speed indicate    
Online indicate turnout positions      
Number of controlled junctions 0 0/1 4 15 25
Number channels of Lights 0 1 1 9 + random 4 + random
Number channels of Gears 0 0/1 0/1 3 2
Multi-window Interface        
Scripts buttons      
Sensors toggle (disable/enable layout sensors)        
Save settings        
URB ready
Android version 5.0 > 5.0 > 5.0 > 5.0 > 5.0 >
 
URB freeware

Freeware Apps

All previous versions of applications that support the Protocol version 1 are obsolete and you can freely share them. The users of versions of Arduino Train Junior, ArduinoTrain BtControl Pro and Arduino Train PRO still can use the documentation using the old version my site.

Now available Demo application supporting the new protocol and the application Train for Kids for children with protocol support 1. These applications support the changing direction of the train, five locomotive speeds and have an emergency stop button. In the application for children, there is also a horn and a button for turning on the locomotive's spotlight. Instructions and sketches for the Demo application can be downloaded from the section for beginners. Description of my amusing project for your children using the Arduino Train for Kids application is available on the website create.arduino.cc

Junior Train App features

Arduino Train Junior

This application perfectly fits under the Starter Sets for Model Railroading. It not only replaces the wired remote from the kit, but also adds many new features, making the game more fun. This application controls four turnouts and reset them to their original position and have the sound of horn. And you can use any sensors for Arduino, since in the application there is a AWS mode.

This application uses most of the capabilities of URB units. You can use several locomotives and add railway signals to your game. Feedback between the application and your layout will allow you to implement the mechanism of automatic train stop before the deadlock. Also, by changing sketches you can add your own control algorithms.

App has a universal button to control your device on the layout. Changing its functions in the sketch can include lighting houses on your railway or move the drawbridge. You can even assign a script to this button to run your trains automatically.
A basic example of a layout and sketches for this application.

  • Loco control: Speed 0 — "a00z", Speed 1 — "a02z", Speed 2 — "a04z", Speed 3 — "a06z", Speed 4 — "a08z", Speed 5 — "a10z", Speed 6 — "a12z", Forward — "adfz", Backward — "adbz", Stop — "adsz", Release — "adrz".

    Junctions positions (Turnouts): Switch A Throw — "ja1z", Switch A Branch — "ja0z", Switch B Throw — "jb1z", Switch B Branch — "jb0z", Switch C Throw — "jc1z", Switch C Branch — "jc0z", Switch D Throw — "jd1z", Switch D Branch — "jd0z", Reset all junctions to default positions — "j00z".

    Universal Button: ON — "la1z", OFF — "la0z".

DUO Train App all screens

Arduino Train DUO

The multi windows Application with advanced settings and features. The foremost program from the Line Apps Arduino Train. It implements all the functions of the URB, and in the future, new ones will be added to this program. You can use several Android devices for controls your trains and layout. Also, the buyer of this application is given Gerber-file for produce last version PCB URB unit – link and password is shown in Settings panel App.

The Arduino code snippet system, which allows you to collect a sketch from specialized modules, has been developed for this application and the DNT application. Methods and examples of collecting sketches and their structure, together with sample snippets for layout elements, are given in the section PRO sketches library. Also, all developments published in the closed part of the site for donators are supported only by the DUO and DNT applications.

Protocol V.2

Open system of commands for interaction between the management console and all the devices of your layout

Device Type or Player commands channel ID or the function First symbol Second symbol Third symbol
Trains for player A Speed 0 a 0 0
  Speed 1 a 0 1
  Speed 2 a 0 2
  Speed 3 a 0 3
  Speed 4 a 0 4
  Speed 5 a 0 5
  Speed 6 a 0 6
  Speed 7 a 0 7
  Speed 8 a 0 8
  Speed 9 a 0 9
  Speed 10 a 1 0
  Speed 11 a 1 1
  Speed 12 a 1 2
  Direction Forward a d f
  Direction Backward a d b
  Stop a d s
  Release a d r
Trains for player B Speed 0 b 0 0
  ¦ ¦ ¦ ¦
  Speed 12 b 1 2
  Direction Forward b d f
  Direction Backward b d b
  Stop b d s
  Release b d r
Junctions (1-25) Switch A j a 0 - branch / 1 - throw
  Switch B j b 0 - branch / 1 - throw
  ¦ ¦ ¦ ¦
  Switch Y j y 0 - branch / 1 - throw
Lights Channel 1 l a 0 - OFF / 1 - ON
  Channel 2 l b 0 - OFF / 1 - ON
  ¦ ¦ ¦ ¦
  Channel 9 l i 0 - OFF / 1 - ON
Gears Gear 1 g a 0 - OFF / 1 - ON
  Gear 2 g b 0 - OFF / 1 - ON
  Gear 3 g c 0 - OFF / 1 - ON
Feedback Junction A a 0 - branch / 1 - throw  
  ¦ ¦ ¦  
  Junction Y y 0 - branch / 1 - throw  

The protocol commands consist of only four characters, the last character is always "z". The first symbol is the device type, the second symbol is the device identifier (number), the third symbol is the device status. A few examples: the command to set the speed of the locomotive is equal to 11 for player A has the form — "a11z", switching of the junction D to the position straight — "jd1z".

An interesting point, there are a lot of good materials on the Internet about the design on the basis of Arduino. Much smaller programs for Android using Bluetooth for control. And, apart from simple examples, there are practically no posts how to tie together Android and Arduino.
The problem in the rules of data transmission. For this purpose, a number of good protocols have been invented, for example the FIRMATA, which is included in the Arduino IDE collection of examples, but it is for this project that it is possible to make the protocol simpler and more flexible. In railway model, there is not a lot of data flow and the speed of passing the team is also not very important. Therefore, you can use a very simpliest URB protocol. And you can change this protocol and expand it yourself. If you have a turntable on the layout, then adding a set of commands starting with the "t" (Turntable) symbol, you can control the railtable position in degrees multiple of ten — "t34z" (rotate the railtable to the position of 340 degrees). I will also gradually add new commands to this protocol.

This type of command is parsing by a sketch, which is based on the example of Serial Event from Arduino IDE. For testing and adjusting your layout devices you can type these commands directly into the terminal of Arduino IDE.

Feedback

A unique opportunity this project

Currently, two feedback options are supported: automatic train stop before deadlock and displaying in the application the real position of junctions on the layout. The first possibility is called AWS and will expand in the future.

Feedback possible to extend the use of layout sensors to control trains. Add line state information to the application interface. And gradually will be new features to the project. URB was originally designed for this possibility and the re-equipment of the layout hardware for the use of feedback is not required.

Next possibility – indicate turnouts positions

The motor switching of the junction in railway modeling gives a lot of unobvious opportunities and gives rise to several problems. For example, the position of the junction can be uniquely associated with traffic light signals and, as a result, get a ready signal system. But at the same time, most of the modellers make bulky and complex panels, and their upgrade will very complicity. This problem is further aggravated by the fact that the position of the arrows is not always known after the layout is turned on.

All this was taken into account in the development of this project by changing the sketches of a particular URB, you can program any logic of the behavior of the signals. Also in the application there is a button DEFAULT, which sets junction to the position assigned user, the same happens when the layout is initialized when the power is turned on. Since there may be more than one player in the project, this button also helps to synchronize the position of the lines during the game. Without using feedback, the DEFAULT button is very useful.

This situation changes when the feedback mode is activated. The command unit URB always notifies the application about changing the positions of junctions. Thus, even if two Android phones are used, the position of all junctions will be online displayed on each of them.

How it works

To use feedback, simply add the following code to the block parsing of the sketch the URB communicate unit.

 
if (inputString.charAt(0) =='j') {
  if (inputString.charAt(1) =='a') {
    if (inputString.charAt(1) =='1') {
      // code for set junction A to straight position
      Bluetooth.print("a1z"); // feedback command
      Serial.print("a1z");      
    }  
    if (inputString.charAt(1) =='0') {
      // code for set junction A to branch position
      Bluetooth.print("a0z"); // feedback command
      Serial.print("a0z");      
    }
  }
}

Wireless communications

Brief description of wireless technologies

Bluetooth Serial connection

Since in the project, as a management console are used Android, the choice consists of Wi-Fi and Bluetooth. Many people argue that Wi-Fi is the best way to wirelessly transfer data compared to Bluetooth. Wi-Fi is client-server tech. Since this immediately gives IP addressing, a high-speed duplex communication channels with broadcasting and long range. Also it is reliable and well-developed network software solutions, and a large selection of equipment for building networks.

But there is a very big problem in order to use Wi-Fi, you either need to rent cloud-based Internet IOT-technologies on the Internet (that is, the internet is essential for the work of your layout), or install and configure a local server for routing. I think this is too complicated and unjustified.
With the advent of the ESP-32 chip with a specialized fast Wi-Fi CPU (compared to slowed ESP8266), it appeared possible to experiment with its integrate in the project. I have another clone URB project on Wi-Fi, and in the future, perhaps I will publish it on this site. This chip is also good for Bluetoth, as can work both in Wi-Fi mode and Bluetooth. On the progress of this project-clone you can read out in the section for donators.

Bluetooth was originally conceived by developers to connect type point-to-point, and this technology works very poorly when building routing. But in our case, this one is much more convenient and simplest than Wi-Fi, it is connection software invisible – it is enough to establish a connection between two devices and you get a virtual wireless analogue of Rx-Tx cable. And this outweighs the shortcomings described above.

As result, in any of my applications, just click on the blue icon of Bluetooth and in the opened list select your bluetooth module by the MAC-address. It's simple and convenient. Of course, you must first pair your Android with yours Bluetooth-module in the standard way: Settings > Bluetooth > Find device.
I made the choice by MAC-address (like 30:18:E4:00:09:E2) so that you could explicitly separate two identical by the name of bluetooth modules. The MAC-address of any device is always unique.

URB unit

Universal Railway Bus unit is first and foremost a convenient and reliable connector, replacing the breadbord and a bunch of wires. A more important feature of URB is the integration of several blocks into a chain, and on this basis the construction of any electronics for layout and control. In other words, it is a universal controller for railway modeling electronics.

PCB Universal Railway Unit

It's just the way of the world, that without hardware, any program on Smart Phones and Tablets can not influence the reality. As you have already read about my applications, you know those it use the Arduino platform to control train models and layout devices. To connect details of Arduino with each other using a Breadboard and wires it is possible, but it is very inconvenient and unreliable. And to avoid this, I came up with a USB board.

This board uses Arduino NANO. Therefore, the dimensions of URBs are only 60x70 mm, which makes it possible to hide it even inside model building. This solution provides excellent flexibility, maintainability, simple mass production and low cost. The board is designed to avoid incorrect connection of Bluetooth modules and Arduino NANO.
To the functions of Arduino, the board (URB unit) adds the following capability:

  • Connectors for two Bluetooth HC-05 (HC-06) modules
  • Direct plug 3 servos or direct plug 3 any Arduino sensors
  • Direct plug relay block
  • Direct plug motor-driver aka L298 or similar
  • Convenient screw connections
  • 6 (7) High-Current outputs (Up to 0.5A per channel)
  • High-Voltage Outputs up to 50 V
  • Reliable data exchange between the MCU (like Raspberry Pi) using 3.3 volt logic and Arduino
  • Built-in I2C bus
  • Optional: install I2C pull-up resistors and smoothing capacitor for power supply
The I2C bus needs resistors pulling the data line to a high potential. You can install resistors of any type on the board. I recommend 10K resistors. I also recommend the use of a smoothing capasitor 1000mf x 25V, when a URB connected to relay or servos, to avoid voltage drop when they turn on.
I2C pullup resistors
PCB URB details set

URB unit details

  1. PBS-15 (HO27): 2.54mm pitch PCB female single row 15 pin – 4 pieces (or 15 pin – 2, 6 pin – 2, 4 pin – 2).
  2. PLS-40: 2.54mm 40 pin male single row pin header connector  – 1 piece.
  3. DIP IC Sockets 16P – 1 piece.
  4. 2 Pin screw PCB terminal block connector 5.08mm pitch – 6 pieces.
  5. 3 Pin screw PCB terminal block connector 5.08mm pitch – 4 pieces.
  6. ULN2003A (DIP16 package): High-Voltage, High-Current Darlington transistor arrays – 1 piece.

URB unit accessories

Arduino NANO and optional 3.3 to 5V level converter and 2 bluetooth modules HC-06(05).

HC-05 and HC-06, in fact it, is absolutely identical bluetooth modules with identical chips. One of the chips of these modules is a microcontroller. On the HC-05 there are two additional pins for its programming. There are no such pins on HC-06 and its module is easier to use for my project.

How get URB board

All people who make the donation get access to a restricted part of the site, where there are detailed instructions and a file of the GERBER format for ordering the URB version 2.7 board from manufacturers PCB or DIY-making. Owners of the Apps Arduino Train DUO and Arduino Train DNT can download last version PCB URB 2.8 here. Also you can get FREE these instructions for version 2.4, or even get a ready board from URB project community members on Facebook.

All versions of URB units are absolutely compatible. Versions 2.7 and 2.8 are slightly more convenient to use.

If you have ideas on mass production of URB units – write to me urb@arduinorailwaycontrol.com

Sketches Arduino and Protocol 2

As the experience with the first version of the protocol showed, you do not like the big examples code. And with the new version of the protocol it was possible to achieve modularity of the code.

URB arduino sketch diagram

The basic principles remain unchanged, only a simple, understandable code, no more complex than examples Arduino IDE. Now, the parsing commands (from the application or the real console or several consoles) moved to functions. In void loop () block code, you specify only the desired logic.

In Arduino IDE a unique system of combining a common sketch from several individual files. As you have already noticed, the Arduino IDE software always creates a folder in which the sketch file of the same name is contained. This is done because all the files in this folder, when you upload sketch (firmware) to the Arduino board, are combined into a single. Thus, you can break the sketch into functions in separate files. The project now uses this method of combining files.

A bit about the starting conditions

Your layout is quite complex in terms of wakeup control. The position of junctions, the order and logic of the switching on of the lines, the state of the global settings at the power-up of the mock-up must be uniquely determined.
In this project, this problem is resolved in two ways. The first, obvious, in the void setup () block, you describe not only the purpose of the I/O pin, but also their meaning. Then you, in accordance with them, bring the layout elements to the initial state. The second way is to use the RESET function. This function resets each URB by a common command. Then the same thing happens as in the first method. The reset command in the Protocol has the syntax "000z", and is executed every time the application is successfully connected via Bluetooth.
You can also force the layout lines at any time by pressing the DEFAULT button in the Application (however, like everything else, you can override the features of this function yourself).

Now, if a motor-driver is connected to a specific URB, you simply fill the PWM array with values, like a tables. Those, here you set the dynamics of trains on a particular connected with motor-driver lines. This new feature gives you one more unique opportunity available only in this project – you can limit the maximum speed in the sketch to the section connected to the URB. For example, for Yard lines, you can set a maximum level of only 200, and for Mainlines, leave 255.

Communication station

The new sketch principle for the project, which I represent on the code of the Communication Station, because it is the largest and complex compared to local URBs. The general principle remains unchanged: upon the arrival of an external command defined by the protocol according to the rules set by you, the communication station either changes the state of its conclusions, or translates this command to the local URB. The local URB is programming according to the same principles.
So, the first block of code collects the control command, the status of all sensors and device positions on the layout. I divided it into several functions by devices names. I repeat, the Arduino file system of the sketches is very simple, if you need the above function, just add the fi le with this function to the folder with the main sketch. You can change the code in functions, directly translating the input command to other URBs, or, what seems to me more correct, to perform operations with input commands in the logic block.

After this introduction I propose to look at a working example of a sketch.