Wi-Fi G scale train control without Central Unit
This section describes how to build a standalone controller for WiFi control of G scal (or smaller) trains.
It is fully DIGITAL but uses no Digital Central module. The decoder contains both the WiFi component AND the actual logic controller that drives 2 motors and a maximum of 5 Auxiliary outputs (NPN channels) and in addition, FWD and RVS driving lights AND cabin lights all controlled separately (F0,F1..F5 and Cabin buttons).
The ESP8266 chip is very versatile and has WiFi on board, but is also programmable with the Arduino SDK and "understands Arduino Speak"... :-)
You will need the correct drivers for the ESP8266, of course. These can be found on GitHub as generic 8266 and need to be installed ising the Device Manager in the Arduino SDK.
The decoder must receive the WiFi data at programming time , and needs the following :
(the examples are from the actual code below)
SSID for the WiFi router or Access Point (ex. "TRAINWEB")
WPA2 password (ex "trainweb")
NO DHCP is used
Define a fixed IP address (ex 192.168.0.140)
Router IP (ex 192.168.0.1)
Mask 255.255.255.0
Locomotive Name (ex "Taurus Black")
The decoder also has a potentiometer on board which allows to set the delay when accellerating and decellerating.
The interface with ¨PC, tablet, smartphone, iOS device is completely in HTML so is universal.
Just go to your browser, open a new tab and type http://xxx.yyy.zzz.aaa (the loco's address)
NOTE : if you minimize the size of the printed circuit board by not using the adapter plate on the ESP8266-012, and use a small H bridge controller such as the L293 chip, and use an UN2003 darlington array for the outputs, you can make this so small it will fit in an H0 / 00 scale loco.
NOTE 2 : the decoder will accept inputs between 12 and 24 Volt , bot DC and AC and the polarity does NOT matter !
It is fully DIGITAL but uses no Digital Central module. The decoder contains both the WiFi component AND the actual logic controller that drives 2 motors and a maximum of 5 Auxiliary outputs (NPN channels) and in addition, FWD and RVS driving lights AND cabin lights all controlled separately (F0,F1..F5 and Cabin buttons).
The ESP8266 chip is very versatile and has WiFi on board, but is also programmable with the Arduino SDK and "understands Arduino Speak"... :-)
You will need the correct drivers for the ESP8266, of course. These can be found on GitHub as generic 8266 and need to be installed ising the Device Manager in the Arduino SDK.
The decoder must receive the WiFi data at programming time , and needs the following :
(the examples are from the actual code below)
SSID for the WiFi router or Access Point (ex. "TRAINWEB")
WPA2 password (ex "trainweb")
NO DHCP is used
Define a fixed IP address (ex 192.168.0.140)
Router IP (ex 192.168.0.1)
Mask 255.255.255.0
Locomotive Name (ex "Taurus Black")
The decoder also has a potentiometer on board which allows to set the delay when accellerating and decellerating.
The interface with ¨PC, tablet, smartphone, iOS device is completely in HTML so is universal.
Just go to your browser, open a new tab and type http://xxx.yyy.zzz.aaa (the loco's address)
NOTE : if you minimize the size of the printed circuit board by not using the adapter plate on the ESP8266-012, and use a small H bridge controller such as the L293 chip, and use an UN2003 darlington array for the outputs, you can make this so small it will fit in an H0 / 00 scale loco.
NOTE 2 : the decoder will accept inputs between 12 and 24 Volt , bot DC and AC and the polarity does NOT matter !
Build Pictures
The pictures below show the home made programming board that I have designed for the ESP8266 boards, with a ESP01 and ESP12 model on it (the rectangular board with the USB connection at the bottom).
Also, there are some pictures of the L298N dual H bridge board that is used to power the motors, ans dome of the actual build of the PCB boards and the "works" built in to an LGB train. Notice the difference between the 01 and 12 boards and the different base PCBs they are mounted on, giving more function outputs to the 12 version. Also note that I have not designed a custom PCB for this prototype, as I have no way of etching PCBs at this time. I use standard 2,54 pitch perfboard and wire up the connections.
In the case of the LCE train (3 tier ICE in white) the connections between the motorized head and tail section and the center section is established by using an Ethernet Cat 5 cable with 8 wires in twisted pair. Just enough to deliver signals between the main motorized head section (where the decoder print sits) and the trailing section, which has only a motor, a L298print and some LEDs. The connections between the 2 are :
- Ground
- PM for L298N
- FWD signal for L298N
- RVS signal for L298N
- 18-24V PLUS for LEDs
- FWD wire for LEDs
- RVS wire for LEDs
- 1 free wire, potentially for AUX1
Note that the LEDs I used in the LCE (ICE) train are special ones. They have 3 wires and have Red and White components in one single LED bulb.
The type to be used is the "Common Anode" where the central wire is the PLUS wire, that connects to 12..24V and in each of the other wires you put a resistor (depending on the input voltage) of between 1K (12V) and 2K2(24V). By connecting these to ground, the corresponding color will light up. The outputs on the PCB are NPN switched so they switch to ground, which is perfect. If you use "common Cathode" type LEDs you will need to use PNP transistors with an adapted schema. Also note that if you would connect BOTH negative wires to ground, only the RED LED will ight up, as it "forward voltage" is lower than the white part, and so the white will never reach its required voltage. AVOID using a single resistor in the (+) wire.
Of course, you can also use separate white and red LEDs , as your lmocomotive allows and requires... Example : I have a Piko Taurus model, which from the factory has white LEDs only, but there are holes drilled in which you can easily fit 5mm red LEDs so that it has separate driving (white) and tail (red) lights which you can then control by the ESP8266.
Also, there are some pictures of the L298N dual H bridge board that is used to power the motors, ans dome of the actual build of the PCB boards and the "works" built in to an LGB train. Notice the difference between the 01 and 12 boards and the different base PCBs they are mounted on, giving more function outputs to the 12 version. Also note that I have not designed a custom PCB for this prototype, as I have no way of etching PCBs at this time. I use standard 2,54 pitch perfboard and wire up the connections.
In the case of the LCE train (3 tier ICE in white) the connections between the motorized head and tail section and the center section is established by using an Ethernet Cat 5 cable with 8 wires in twisted pair. Just enough to deliver signals between the main motorized head section (where the decoder print sits) and the trailing section, which has only a motor, a L298print and some LEDs. The connections between the 2 are :
- Ground
- PM for L298N
- FWD signal for L298N
- RVS signal for L298N
- 18-24V PLUS for LEDs
- FWD wire for LEDs
- RVS wire for LEDs
- 1 free wire, potentially for AUX1
Note that the LEDs I used in the LCE (ICE) train are special ones. They have 3 wires and have Red and White components in one single LED bulb.
The type to be used is the "Common Anode" where the central wire is the PLUS wire, that connects to 12..24V and in each of the other wires you put a resistor (depending on the input voltage) of between 1K (12V) and 2K2(24V). By connecting these to ground, the corresponding color will light up. The outputs on the PCB are NPN switched so they switch to ground, which is perfect. If you use "common Cathode" type LEDs you will need to use PNP transistors with an adapted schema. Also note that if you would connect BOTH negative wires to ground, only the RED LED will ight up, as it "forward voltage" is lower than the white part, and so the white will never reach its required voltage. AVOID using a single resistor in the (+) wire.
Of course, you can also use separate white and red LEDs , as your lmocomotive allows and requires... Example : I have a Piko Taurus model, which from the factory has white LEDs only, but there are holes drilled in which you can easily fit 5mm red LEDs so that it has separate driving (white) and tail (red) lights which you can then control by the ESP8266.
Schematics
|
|
Source Code
There are 2 versions available.
* The full scale program for an ESP8266-012 board with all possible channels.
* The sized down one with ESP8266-01 which only has 4 channels on pins. This requires some additional switching on the outputs to sync the lights, adding 2 PNP transistors with 20K resistors in base to the FWD and RVS signals on the controller instead of having them n separate channels. Lights are always on in this case but thy do switch directions. (the LCE train in the videos below is using this type of decoder)
* The full scale program for an ESP8266-012 board with all possible channels.
* The sized down one with ESP8266-01 which only has 4 channels on pins. This requires some additional switching on the outputs to sync the lights, adding 2 PNP transistors with 20K resistors in base to the FWD and RVS signals on the controller instead of having them n separate channels. Lights are always on in this case but thy do switch directions. (the LCE train in the videos below is using this type of decoder)
esp012-8266-g-scale.ino | |
File Size: | 16 kb |
File Type: | ino |
esp012-8266-g-scale-esp01.ino | |
File Size: | 11 kb |
File Type: | ino |