Master Controller for BVE5 Trainsim and other train driving games

Public Chat
Similar projects worth following
A master controller is what you use to drive a train. It is comprised of 3 levers: reverser, throttle, brakes, some switches, buttons and a speed gauge. It is built in a teabox using arduinos and 3d printed parts.

The main game that I had in mind when building this is BVE5. It has completely separate input and output interfaces. This project implements an arbiter that talks to the Arduino and provides input and output interfaces via windows named pipes, and input/output plugins for the game that interact with the Mascon via the arbiter.

Another game that it can interface with is Subway Simulator. It lacks any API, so I had to implement a nasty hack. It's a closed loop system. Current speed, brake and throttle lever positions are taken by making game screenshots, they are compared to the actual lever positions, and input keypresses are generated to compensate for differences. It works remarkably well.

Part 1. Hardware


The first idea was to implement a physical speed gauge for BVE5 train simulator. Fortunately I had a few dirt cheap stepper motors 28BYJ-48, a fake Arduino Nano, a fake CNC shield and some fake drivers.

The drivers are made for bipolar steppers, whereas 28BYJ-48 are unipolar. Luckily there's a remedy for that and it's well documented by a number of kind people.

Thus the first step was made: a speedometer for BVE5.

BVE5 Speedometer

This was a good beginning.


I took a nice donor RC remote with a couple of sticks and some switches. A train controller needs some fixed positions, for example 5. The RC sticks already have a mechanism for some clickiness in them, but they are to smooth. I filed some big notches and made a harder spring from a large paperclip. This can't compete with a real train controller, but it's enough for a child's toy.

There are two more analog inputs: brake lever and a reverser lever. The reverser is not really analog, but it was easier to implement it using a potentiometer.

Digital inputs are 2 toggle switches for various things, and two buttons, mostly for tooting. Trains toot a lot.


The project is housed in a reasonably sized wooden tea box.

Pictured here are the throttle stick, a brake pot and everybody's favourite controller.

Speedometer revisited

There's a problem of resetting to 0 when the game starts. I contemplated an idea of zero setting, and even considered a complete overkill of using a BLDC servo from one of my earlier projects. Then I read somewhere that these steppers have a friction clutch because they're used in air conditioning systems. So they don't have to have any end switch, you just spin them and they slip, and that's how they can be reset. 

I implemented the same thing. There's a little screw in the face plate that doesn't let the needle to go past zero, and that's it!


Such a versatile controller is useless without clamps, so it has got clamps. I found fantastic parametric clamps by [akaJes] and updated them so that they fit  snugly with my teabox.

The clamps really made the box usable:

For the cables:

The box from the inside:


Simple tactile switches in a harness. It's easily my favourite mechanical bit. They are really fun to press.

Now the box needs some means of closing. After some deliberation I decided to simply make angles that would kind of squeeze it together. It works surprisingly well. Also, face plates to cover the rest of the box.


Like so. 

Here's what it looks like now. Pardon the dirty table.

There's also a multipurpose LED. In BVE5 it indicates closed doors/clear to go.

Part 2. Software.

Coming soon...

  • Game support difficulties

    svofski09/08/2019 at 20:54 1 comment

    Train games are in a pretty sorry state in general. 

    Found a great game that my son likes, it's called Metro Simulator 2019. It's in an active development phase and I'd like to connect my controls to it. Asked the devs about the API and was a bit surprised to get a rather harsh negative reponse, not now and never. A bit disgruntled by such shortsightedness on their part.

    Previously I supported Subway Simulator 3D. It is a kind of game where you can't even count on an answer about what would be an absolute blocker bug in a sane world. Forget about asking for an enhancement. However I found a relatively simple solution for interfacing with it. They draw train state in a fixed location on the screen. So I made an adapter that takes a screenshot and scans the dials. It's not a polished product but just a quick hack and here's what it looks like:

    The magenta is debug graphics that shows what the program is seeing, or rather paying attention to. We have a speed gauge, from which it's easy to tell the current speed and send this information to my physical speed gauge. 

    More interesting are the brake lever position (here incorrectly labeled BP, Brake Pressure) and the throttle called "1000 AMP" (you guess about the correctness). The game only takes relative commands: throttle + / -, and brake + / -. No sticks. However by reading the current position of the lever displayed on this nice indicator I create a closed loop control that corrects the error by sending throttle up/down and brake up/down keypresses. When the program is uncertain about what it sees it stops sending updates until the gauges appear back gain. This works surprisingly well.

    A bonus feature, I scan the state of the semaphore and blink my light accordingly. This game has no reverse control (yes, this advanced), so my reverser acts as an emergency brake.

    Back to Metro Simulator 2019. Here I don't have the luxury of a static display that's always on screen. The trains have very elaborate and realistic control surfaces that display a ton of information about speed and the current state of controls. Unfortunately, this info is a part of 3d cockpit and can be anywhere on screen, or even completely off screen when you look away.

    I guess I have three possible paths here:

      * reverse engineer the relevant game dlls and just rip the data such as speed and lever position from the train model

      * implement a more advanced machine vision scanner that would work in most cases

      * forget about physical speed display and simply emulate joystick inputs, which this game seems to support (unverified)

    Here's what the relevant part of the instrument panel look like when in game. The most interesting parts are highlighted with perfect Pentium circles.

    Realistically, the cockpit is almost always visible anyway so machine vision is not necessarily a terrible idea. I like it because it's not invasive and will probably survive many game updates. I think it shouldn't be very difficult to train a HOG classifier for a speed gauge, which has a distinctive look. Things like current state of the main lever are on a screen to the right. Maybe its edges can be found with relative ease once the position of speedometer is found.

    Another option is to just emulate joystick input. This game has joystick support so although I won't get physical speed gauge, the input would still work. Kinda meh but it's the most doable solution considering time constraints.

View project log

Enjoy this project?



temple2010 wrote 11/14/2020 at 16:13 point

Интересно, а как вы получаете данные скорости из игры?

  Are you sure? yes | no

svofski wrote 11/14/2020 at 16:31 point

Поддержано две игры: BVE5 и Subway Simulator.

BVE5 имеет API, но оно немного странное. Контроллер на всех общий.  Но чтобы получить данные о скорости, состоянии дверей итд подключается дополнительный плагин к каждому поезду в отдельности. Это крайне удобно. BVE5 вообще шедевр архитектуры ПО. Но там хотя бы есть API.

Из Subway Simulator я данные получаю, делая скриншот 30 раз в секунду и сканирую в нем положение стрелок. Как ни странно это работает совсем неплохо. Хотел прикрутить еще к  Metro Simulator, но разработчики как-то наотрез ответили, что никакого API нет и не планируется.

  Are you sure? yes | no

Mike Szczys wrote 08/27/2019 at 10:04 point

This is delightful! First train controller I've seen, usually it's flight sims and this a really cool change. Thanks for including so much detail on how you developed it!

  Are you sure? yes | no

svofski wrote 08/27/2019 at 21:15 point

Thanks! I would like to add a little bit more detail when I have time: CAD files and the sources. Though the main value here is probably inspiration.  Repeatability of things built around random tea boxes is pretty low.

  Are you sure? yes | no

Does this project spark your interest?

Become a member to follow this project and never miss any updates