While this mount works, and is relatively easy to put in place, I asked fellow modeler, good friend (and national treasure), Dave Merrill to see if a self-aligning, and self-positioning mount could be designed to make this even more simple. After quick iteration Dave redesigned my mount to produce an easy, elegant solution, shown in Figure 20. It replaces a few ties on either side of the scanner, and is very easy to install. It self aligns the TCR between the rails. It can be glued, screwed or spiked in place. The 3D CAD files are also included in the download. A 2mm screw is used to fix the TCR in place. The PLA plastic will take the screw as is, to form the threads. A 2-56 screw will do the job too.
Figure 21. New TCR Mount in Use with White LED
I encourage modelers more talented in this area than me to present a better solution. I very much suspect there are even better solutions to be invented.
Loading and Configuring the ESP32 Processor
No programming is needed to make your ACI scanner operational, but you do need to give it some operating information and load your processor. All the files are provided in the article download found here:
The modeler will need to learn to download the code (sketch) to the ESP32 and edit any variations he wants to make.
Loading an ESP32 requires a bit more work, described in Production\Additional_Materials\Additional_Documentation\Starting Arduino Editor & ESP32 PICO.pdf in the accompanying download package.
When you are done setting up the Arduino editor software, put the entire contents unmodified of the\Production\Additional_Materials\Arduino\Sketches folder from the download link into your …\Documents\Arduino\ directory. Put the entire contents unmodified of the \Production\Additional_Materials\Arduino\libraries folder from the download link into your …\Documents\Arduino\libraries directory. Put the entire contents unmodified of the\Production\Additional_Materials\Arduino\tools folder from the download link into your …\Documents\Arduino\tools directory. Find the QR_Reader_Server_128Disp_2_15_MQTT.ino file in the QR_Reader_Server_128Disp_2_15_MQTT folder you added, open, compile, and load it into your ESP32. It is still possible to program ESP32 PICO after it is connected to your ACI scanner.
To use ACI, you should change the Wifi ssid and password in QR_Reader_Server_128Disp_2_15_MQTT.ino to whatever you want to use. QR_Reader_Server_128Disp_2_15_MQTT uses your own local WiFi.
Playing Wifi, JMRI, and MQTT reconfiguration games is beyond the scope of this article, but I may add more detail later, if needed. I hope the information presented in this article will point modelers in the right direction.
On ESP32 File System Load
One means of generating Car/Train reports is through web pages to any browser. To load the HTML used by the ESP32 you will need to load a file set into the internal file system called SPIFFS in your ESP32. You will need to use the Arduino 1.8.19 version of the Arduino editor (IDE) to do this, as the file transfer mechanism is not available as yet in the newer Arduino 2.3.2 IDE. First, verify that you have downloaded and setup your Arduino 1.8.19 IDE (described previously). Make sure you copied in whole the ESP32FS folder and its contents from the article zip: Additional_Materials\Arduino\tools to your folder …\Documents\Arduino\tools folder.
Open the Arduino IDE, select the correct Board from menu: Tools->Board->ESP32 Arduino->ESP32 Dev Module. Once you have the correct board selected make sure under menu pick Tools and check that you have these options selected:
Board: ESP32 Dev Module
Flash Size: “8MB (64Mb)
Partition Scheme: “8M with spiffs (3MB APP/1.5MB SPIFFS)”
PSRAM: Enabled
Port: ß Make sure this is correctly selected
Next, select from the Tools menu pick ESP32 Sketch Data Upload
And a window should open with Select FS for QR_Reader_Server… / data folder
In the selection bar select SPIFFS and the select OK
In the messages at the bottom of the window you should see SPIFFS Image Uploaded with the last message
->Hard resetting via RTS pin…
Operating with Automatic Car Identification
Once built, operating ACI is pretty easy. ACI needs a 5 Volt DC source connected to its +5V and GND. You can also power the ESP32 Board via the USB connection. The local OLED display should power up quickly and display Car Reports. If you have the Serial Monitor enabled through the ESP32 USB connection, messages should begin appearing after power up.
Before power is connected to the ACI module, set up your WiFi connection to the net with the ssid and the appropriate network password. If you know your local router’s IP Address, and Gateway, you have the option to specify a static local IP Address for your ACI scanner by uncommenting line 10 and specify the static IP Address in line 95. Select using the Serial Monitor in the Arduino IDE and watch for:
Connecting to WiFi..
Connecting to WiFi..
192.168.1.177
Client ACI-10C:8B:95:B7:94:E8 contacting MQTT broker
The IP Address displayed -- 192.168.1.177 – is the address of your ACI Scanner. Enter this address
in your browser URL address and watch for the car IDs read from the scanner. If you have set up a local OLED display, it should power up with the words “Car Reports” and then display ear car ID read with a scaled random number (which I was imagining might be a car weight).
To use MQTT transmission correctly your must provide the IPAddress or host ID of the MQTT broker in line 97
and the topic on which to publish the ACI data in line 98 like “trains/track/reporter/1” which is consistent with the MQTT naming convention in JMRI. Reporter #1 must be set up in the JMRI Reporter Table as MR1. Any number may be used. Each ACI scanner should correspond to a unique JMRI Reporter.
MQTT brokers must be running and ready
before JMRI and the ACI Scanners are powered on. I used the Mosquitto MQTT broker freely available online at
https://mosquitto.org/download/ and also included in the Additional Materials in this article’s download zip. If you install mosquito on your PC you will need to add the config file
mosquitto.conf included in the Mosquitto MQTT Broker folder in the download zip to where ever you installed mosquito (likely C:\Program Files\mosquitto ). The mosquito MQTT Broker is started from a windows command line:
- Open a window with the command prompt
- Change directory to the folder where you loaded mosquito (likely C:\Program Files\mosquitto )
- type mosquito.exe -c mosquito.conf
And a widow should open indicating something like: mosquito version 2.0.14 running
The first space in the QR Label (like NYC 201229) will be deleted by the ACI system and transmitted to the MQTT broker as the first parameter, which JMRI will search for and create a unique ID in the IDTag Table, like NYC201229
Together with Where seen (the Reporter ID – MR1) and When seen (the date-time stamp)
What the modeler wants to do next in JMRI is up to them.
If you have set up a connection to an MQTT server, a successful connection will be indicated like:
Connecting to WiFi..Connecting to WiFi..192.168.1.177Client ACI-10C:8B:95:B7:94:E8 contacting MQTT brokerACI broker connected
If no MQTT broker is found after 10 attempts, you will see:
Client ACI-10C:8B:95:B7:94:E8 contacting MQTT broker
Client ACI-10C:8B:95:B7:94:E8 contacting MQTT broker
Client ACI-10C:8B:95:B7:94:E8 contacting MQTT broker
Failed MQTT Connection state -2
and MQTT communication will not be re-attempted until reset or the next power cycling.
Assuming you have mounted the ACI scanner below your roadbed, and opened up a “scanning window” between the rails, generate an appropriate car label, like UP 7328812, resize it appropriately, and attach it to the underside of a test car. Place the car on the track near the ACI scanner, and slowly roll it over the powered scanner. The LED will light the underbody of the car, regardless of the ambient lighting in the room, and the scanner should read the car label, and publish it via all enabled communications lines – local display, USB serial port, HTTP web service, and via the MQTT broker. You may need to aim the LED better if you forgot this step before. Manually move the car over the scanner faster and faster until it will not read at all to get an idea of the speed acceptable for scanning. Try putting two of exactly the same tag on one car and see if it improves your ability to read the car. The small blue LED on the top of the TCR will turn green when the TCR successfully scans a QR code. You can leave it directly above the TCR and it will repeatedly read the same code over and over again.
You can set line 29 in the sketch from:
bool displayall = false; // Set this true to recognize every ACI read
to
bool displayall = true; // Set this true to recognize every ACI read
to eliminate multiple reads of the same label.
Line 30:
#define MaxCarsInTrain 200
Is set to remember a maximum of 200 cars internally. I have set this higher (500) but see no reason for the higher number at present. When it hits the maximum it will flush the table and start over.
I am anticipating more changes are likely to be made, and be suggested sometime in the future, which is why I opted for more memory in the processor module. Realize that inventive minds, with new labels, could tune the ACI read to become something more than a car counter for their railroads in time. Just consider the added information to supplement your railroad operations. For me, this is actually more integral to: SMA45 Intelligence On Board – Ideas for Model Railroading Beyond Mobile DCC Control
than it is to what most modelers would consider “Operations.”
Please let us know what you do with your own ACI Scanner… and Have Fun! 😊
As always, appropriate comments and suggestions are always welcome.
Have fun! 😊
Best regards,
Geoff Bunza