Mark DiVecchio's O-Gauge Train Layouts

1992 Layout Page

2006 Layout Page

2009 Layout Page

P&LE Postcards by Howard Fogg 

Plasticville Buildings

Portable Layout Page

Train Clubs

Bing Track

Remote Train Control Program

YouTube Channel

OOK Radio Support

Technical Videos

3D Prints for my Layout

More RTC Videos

ADPCM - Playing clips from .mth sound files

P&LE McKees Rocks Locomotive Shop
3D Printer Project

White Tower Restaurant
3D Printer Project

RFID Train Detection

Engine and Car Operation
Hints and Tricks

RFID Tag Programmer using PN532

RTC Control Language - Scripting


More RFID Tag Videos

RTC Control Language - Signaling


WiFi Support for RTC

This Page last updated on .

I started developement of this web page in January 2022. It will be under construction for a while.

On this page, I describe the work that I've been doing to implement the use of WiFi to connect to my layout. I started on the coding around September of 2021. Major updates in March of 2024.


The Next Step - Connecting directly from RTC program to the WIU/WTIU

When I started my work on RTC, I used a wired interface to connect the PC to the TIU. Later, I learned how to use a CC1101 radio to connect directly. The radio was connected to the PC using a USB cable. Now the ultimate(?) implementation - I can get rid of the USB cable and Radio by using WiFi to connect to the TIU (the WIU or WTIU). I extended this so that now I can also connect using WiFi to my RFID tag detectors distributed over the layout.

Though connecting to the TIU via WiFi is nice, the real advantage is having a dozen or more RFID tag detectors around my layout and not having to have them wired together in series and then wired to my computer. If you look on my RFID tag detectors page, you can see the "ole" RS232 wired connection scheme.

This is based on the work that I did for the Remote Train Control (RTC) program and OOK Radio Support.

WiFi support is available in RTC 5.0.0 and later (starting about March of 2024). I don't have this posted yet so but if you would like a beta copy now, email me.


Running Setup in the RTC Program

Though the changes to the RTC Program to support WiFi were spread throughout almost every module in the program, for you, the user, the Setup window is where you tell the RTC Program to use WiFi.

You need the currently available WIU connected to a TIU or the soon (?? Mar 2024) to be available WTIU (a combination of the WIU and TIU). Of course, you need a Windows 10/11 based computer with the version 5.0.0 or later version of RTC installed. And most of all, you need a WiFi network- that means a WiFi Router.

First, install the WIU/WTIU following MTH's instructions for "Home" network. You should know your WiFi Router's SSID and password. If you don't know those, MTH gives you an installation method using the "WPS" button on the WIU. Look at their instructions. I've not yet tried the "MTH" network mode for the WIU but there is no reason that it should not work.

You should know the IP address of your computer. If you don't know this, run the program "ipconfig" from a Command Prompt. Look for "IPv4 Address" and note it. For example:  192.168.1.1  might be your computer IP address for many home router networks. Usually RTC can figure out the correct IP address to use.

Power on your router and power on the WIU & TIU or the WTIU. The WIU is fairly slow to boot up so give it a few minutes to boot and connect up to the router. Once the blue WiFi LED begins to blink, you should be ready to go.


After you start the program, press the [Setup] button. You will see this window.  To enable the RTC WiFi interface, click on the WTIU WiFi [X] Enable check box. RTC will attempt to find the WTIU on  your network. This might work if you have only 1 WTIU and your network is a typical simple home network.

If it works, you will see the WTIU in the list box, it will be selected (highlighted in black) and its IP address and Port will be inserted in the two boxes under the check box.

If that doesn't happen, continue on, otherwise you are done with setup and you can skip this section.
If no WTIU appear, click on the Host IP Address tab.
Click on the downarrow "v" on the dropdown box. RTC will have already tried to find the correct Host IP address. 
If your computer only has one Host IP address, RTC will select it automatically. If there are several, choose the Host IP connected to the network that your WTIU is on. If no Host IP addresses appear, presss the [Scan] button.

In this example, my computer is connected to two networks. I need to pick the correct one.

Once you select a Host IP address, RTC will remember your selection.
In the dropdown, the correct Host IP address has been chosen.
Then click on the TIU/WTIU Ports tab. Here we are going to pick the WTIU to use.

First you need to enable the WTIU WiFi if it is not already enabled. Check on the WTIU WiFi [X]Enable checkbox.

If you don't see any WTIU listed, press the [Scan] button.
All of the available WTIU will show up in the list box. If there is only one, RTC will select it automatically. If there are many, select the correct one.

The WTIU identifies itself as "mthdcs-XXXX" where the "XXXX" is a four digit hex number. The ".local" just indicates that it is my local WiFi network.

Once you select the WTIU, RTC will remember your selection.

When you are done, press [Hide & Save].

Once setup is complete, you can run RTC normally.

Back at the main RTC window, you should see the red WiFi indicator and the red WTIU indicator. This means you are not connected via WiFi yet. Press the [Connect] button.
Now the WiFi and WTIU indicators both turn green followed by the TIU and AIU spinners turning green. This indicates that RTC is connected and ready to go.

Press the [Read] button to fill the Engine List with all of the engines on your layout, then select an engine and press the [Startup] button.

You can learn about the RTC program on this web page:
http://www.silogic.com/trains/RTC_Running.html

Videos to show you how to get started are here:
http://www.silogic.com/trains/RTC_Running.html#get

Download the program from here (but V5.0.0 may not be there yet). Email me if you want to beta test it.
http://www.silogic.com/trains/RTC_Running.html#RTC_Download



WiFi based RFID Detectors

The other major WiFi change was moving my RFID detectors from RS-232 based wired connections to WiFi based connections.

These detectors functionally operate the same as the wired version. You can look at this page for operational details. http://www.silogic.com/trains/RFID.html


 The ESP8266

Mike Hewett always seems to be acknowledged on my web pages and he deserves it. Mike learned about the ESP8266 based NodeMCU board and started to use it in his projects. After I saw his success and how easy it was to use, I started to rewrite my RTCNFCIRQ program to use that device.

The ESP8266 is a small powerful computer connected to a WiFi Radio. They are available from many sources on the Internet. Watch out for knock-offs.


My Ideas

I figured that could replace the wired serial connections for my RFID tag detectors (which send tag information to the RTC program). Read about the current wired solution here: http://www.silogic.com/trains/RFID.html


Here is a photo of an ESP8266. I've been using the version with the CH340 USB chip. These are around $5 each as of Feb of 2024.






Ported the RTCNFCIRQ sketch to the ESP8266 - RTCNFCWiFi

The current version of the RTCNFCIRQ sketch runs on a Seeeduino/Infiduino. This porting effort moved the sketch to run on an ESP8266 and the sketch is now called RTCNFCWiFi.

These detectors functionally operate the same as the wired version. You can look at this page for operational details. http://www.silogic.com/trains/RFID.html

Here are a few photos of an ESP8266 wired to a PN532 RFID detector. The black antenna is placed under the track (it was originally red but I painted it black, like the Rolling Stones). This only requires connection to power. The assembly here is not critical. I've used up to 12 inches of wire between the ESP8266 and PN532. The 6 inch coax cable between the PN532 and the antenna should not be extended. I tried longer cables but the performance suffered greatly.


Again I have to thank Mike Hewett for reminding me of wirewrap.

My original test bed connections were done with what is call "Dupont" wires. These are nothing more than wires with push on connectors on each end. Nice and easy to use but prone to coming loose. Good for prototyping. Mike showed me some of his work using wirewrap. When I started in the computer design business in 1970, wirewrap was still common and acceptable even for production work. Look here : National Advanced Systems.
Mike used a hand wirewrap tool but I had a couple very old Gardner-Denver wirewrap guns. I dug them out and replaced the long dead rechargable battery with 2 D cells and I was off. I used the small green proto board from MPJA.com as a base.

Sadly, these have doubled in price since pre-COVID times. After having tested many different detectors these are still the best functioning detectors when placed under 3-rail track.

Cost:
ESP8266                                     $5.00
Tag Reader from Elechouse        $34.50 (as of Feb 2024)  If you buy 10, they are $29.00 each.

https://www.elechouse.com/product/pn532-nfc-rfid-module-w-external-antenna-updated-version/



The ESP8266 has enough pins to control two tag readers. I have 13 tag readers on my layout controled by 8 ESP8266.

Signal Name ESP8266
Pin
Elechouse PN532 RFID Module #0
Pin
Elechouse PN532 RFID Module #1
Pin
VDD/VCC 3V VDD/VCC VDD/VCC
GND G GND GND
MOSI D7 MOSI MOSI
MISO D6 MISO MISO
S Clock D5 SCL SCL
IRQ #0 D2 IRQ --
SS #0 D0 SS --
IRQ #1 D3 -- IRQ
SS #1 D1 -- SS


Powering the Tag Detectors

The ESP8266 can be powered by 4.5 - 20 VDC applied between the VIN pin and ground. The ESP8266 will regulate that down to 3.3 VDC for itself and for the PN532. You can use any method you want to get the voltage to the VIN pin. I used an AC to DC converter getting power from the closest 3-rail track. I have also used a dedicated power supply.


RTCNFCWiFi source code and pre-compiled binary

I'll try to keep this zip file up to date but if you are going to seriously work with it, email me to be sure you have the latest version.

RTCNFCWiFi            V4.5 - This is an ESP8266 NodeMCU based sketch using WiFi to connect RFID tag detectors to the RTC program.

Right now, this sketch is one ZIP file. You can download it here.

The ZIP file has a precompiled *.bin file which can be downloaded into the ESP8266.You must use a USB connection to load this sketch into the ESP8266 the first time, after that, you can use the Over The Air (OTA) connection - note that you don't have to use the OTA connection, you can use the USB connection all the time.

Getting it into the ESP8266 is fairly easy- here is how to do the first time which requires a USB connection:

    1. Connect the ESP8266 to your PC using a USB cable.
    2. Drivers for the ESP8266 should automatically load
    3. Note the COMx port that the ESP8266 connects as or use Device Manager to locate the port number..
    4. Extract the above ZIP file into a folder (just create a new folder somewhere).
    5. Open a command window at the folder where you put the files
    6. Using notepad, edit the file USB.bat. Change the serial port number (from "COM3") to the serial port number where the ESP8266 connected.
    7. Run the USB.bat file or manually type in the following command after changing the serial port number:
        .\esptool.exe  --baud 115200 --port COM3  write_flash --flash_mode qio 0x00000 RTCNFCWiFi.ino.nodemcu.bin
To use the OTA method (after the first time using USB)

    1. Extract the above ZIP file into a folder (you can use the same one you created above)..
    2. Open a command window at the folder where you put the files
    3. Using notepad, edit the file OTA8.bat. Change the IP address to the IP address of your ESP8266. You can get the IP address from RTC after you use the device for the first time (Look in the Setup window..
    4. Run the OTA8.bat file or manually type in the following command after changing the IP address:
        .\python3\3.7.2-post1\python3 -I .\espota.py -i 192.168.1.114 --auth=esp8266 -f .\RTCNFCWiFi.ino.nodemcu.bin 
If  you try to compile this yourself, I used the Arduino IDE portable version 1.8.16. You will have to download that version of the IDE, install it and then install the ESP8266 library. After that, download and manually install the following additional libraries:

    Needed for all sketches (From the Arduino IDE, use the Sketch->Include Library->Manage Libraries, find the library and hit [Install]):
ESP_DoubleReset_Detector v1.3.2 by Khoi Hoang
ESP8266TimerInterrupt v1.6.0 by Khoi Hoang

After that, download and manually install the following additional libraries into the IDE portable library folder (on my computer : C:\arduino-1.8.16\portable\sketchbook\libraries):
  
    Needed for all sketches:
        RTC_NFC by Mark DiVecchio.    Download library from here.

    Needed for RTCNFCWiFi
PN532_SPI by Adafruit Industries and Seeed Studio, modified by Mark DiVecchio
PN532_modified by Adafruit Industries and Seeed Studio, modified by Mark DiVecchio
NDEF by Adafruit Industries and Seeed Studio
    Original at   https://github.com/elechouse/PN532
    Download modified library from here.


RTC RFID Tag Detection Configuration

When you first load the ESP8266 with the program, it must connect up to the WiFi router (so we need the SSID of the router and the password) and you must tell it what detector number it is and how many tag readers are connect to it.

This is done by connecting to the ESP8266 from your phone. Tap on your WiFi icon and follow along:



After you download the RTCNFCWiFi program into the ESP8266, it will start an Access Point. If you look on your phone, you will see the new WiFi AP listed as RTCRFID. Tounch on that AP to connect to it.



The phone should connect up and you should see the RTCRFID AP "connected without internet".








Then startup a web browser such as Firefox or Chrome. Enter this IP address into the Address Bar:  192.168.4.1 . Press GO. You should see this screen which lists all of the accessible routers in the area. Here is were we enter the information that the RTCNFCWiFi program needs to communicate with your computer via the WiFi Router.

Enter:
The SSID of your router
The WiFi password of your router
The detector number of this device
The number of tag readers connected to this device.

Then click on [Setup RFID WiFi].
You should see this screen indicating that the device is rebooting and will connect up the WiFi Router.


You have to do this with all of the RFID tag detectors on your layout. Be sure that the detector numbers are unique. Then the detectors are ready for use by RTC.



WiFi based RFID Detectors on my Layout

I have 8 Detectors with 13 Tag Readers on my layout. I've hidden the 8 Detectors inside of buildings - mostly Plasticville but one 3D printed shed. The readers are mounted under my 3-rail tubular track using black double sided foam tape.

In some of these photos, you can see LED's lit up. The tag reader itself has a red power led and the ESP8266 has a blue led under control of the sketch running. My RTCRFIDWiFi sketch blinks the blue led on each tag detection. You can see these LED through the windows.

All of these ESP8266 NodeMCU devices have Over-the-Air (OTA) programming enabled. With OTA, I can update the sketch running in the device over WiFi directly from the computer running the Arduino IDE. I described how to do that a little furthur back on this web page. Sure better than my previous wired scheme where I had to walk around my layout with my notebook computer and a USB cable, plugging into each ESP8266 one at a time to reload a sketch.


Detector 1 with 1 Tag Reader Attached
(I had to make little signs so I could remember which detector was which.)
Plasticville Log Cabin

Detector 2 with 2 Tag Readers Attached
Plasticville Hobo Shack

Detector 3 with 1 Tag Reader Attached
3D printed Servo Shed - a "Make" on Thingiverse:
https://www.thingiverse.com/make:1065442 

Detector 4 with 2 Tag Readers Attached
Plasticville Manufacturing Company

Detector 5 with 2 Tag Readers Attached
Plasticville Signal Tower

Detector 6 with 2 Tag Readers attached is inside a tunnel so a photo of it would be all black!

Detector 9 with 1 Tag Reader Attached
Plasticville Cape Cod House

Detector 10 with 2 Tag Readers Attached
Plasticville Grocery Store




Updated Programs

Tag Programmer        This is the program to run on your PC used to program tags. Requires an ESP8266 and PN532 programmed with the latest RTCNFCWiFi sketch. I've updated this program to use these WiFi connected Tag Detectors. If you need this program now, email me. I'll have it posted here soon.



This site prepared and maintained by Mark DiVecchio

email :  markd@silogic.com

SD&A HOME
 
 Mark's Home Page

The DiVecchio genealogy home page
The Frazzini genealogy home page

This site will be under construction for a while.