Using an Arduino Esplora for Trainz
Hi,
I'm back to Trainz after a long break.
i'm wondering if it's now possible to control Trainz from an external apps.
I'd like to have a microcontroller device connected to my pc and then have it to control some functions of TRAINZ.
As there is a commercially available train controller on the market, i think it could be possible to do the same by myself.
thanks
Jean-Francois
Hi Jean-Francois,
I have programmed an Arduino Esplora micro controller as a programmable controller for Trainz 12. It works very well and makes driving (in DCC mode) very enjoyable. This was my first Arduino project and took me about 3 days to program.
The following link shows my controller in action:
https://www.dropbox.com/s/b0y76mydtxsl7u7/IMG_2165.JPG
For general information about the Arduino Esplora, see
http://arduino.cc/en/Main/ArduinoBoardEsplora#.UxgR3dyefbQ
This is the arduino sketch (the source):
https://www.dropbox.com/s/61jo3esucmyjl62/Esplora_Trainz_Controller.ino
(Arduino software 1.5.5-r2 or later must be installed on your pc or mac to view the sketch)
The buttons of the Esplora handle the following actions:
top button - toggle map mode
left button - pause
right button - toggle forward switch (turnout). Direction depending on driving direction.
Reverse button - toggle driving direction (handled internally in Esplora)
The linear potentiometer sets the DCC throttle
The joystick can be toggled to two different states by pushing it down
First state:
left - view direction towards left
right - view direction towards right
top - Zoom in
down - Zoom out
Second state:
left - move backwards in consist
right - move forward in consist
top - view direction upwards
bottom - view direction downwards
The LCD display also shows the consumpion of a supply (for example water for a steam engine, or diesel
for a diesel engine). The supply lasts for approximately 30 minutes at full throttle. To reset the supply level to maximum, the "reset" button on the esplora needs to be pressed. This supply level is not connected to any internal supply level in Trainz, because the Esplora has no knowledge of any Trainz internals (no two way communication). But it makes driving in DCC mode much more interesting. Reset the supply level only at the corresponding refill station in Trainz.
If the supply has been used up, the engine cannot be moved any further. The LED is green, if the supply is above a 10% level, below it is red. It is blue, if the second state has been selected for the joystick.
The controller works for both PC and Mac versions of Trainz.
This solution is of course only for people who enjoy to do a bit of programming. You might have to slightly adjust the sketch depending on the keyboard you use on your computer.
Rene