Geoff Bunza geoffb
Front4.jpg
Figure 1. A Working Railcar Scanner 
 
Modelers operating their layout want to know the consist of each train in motion and in staging. Operators want to know this precisely, especially as trains are made up and distributed over their empire. Prototype railroads need to keep track of trains and cars as their revenue and billing is derived from the ton-mile they transport, and charges are paid to car owners as their equipment is used. This article describes a fully operational, model railroad car scanner. It begins with a short review of prototype car scanners which were developed in the 1960’s, deployed by AAR mandate. They were used until the 1970’s, and then abandoned, due to poor performance and lack of business integration. Superseded by newer technology in the 1990’s, car tracking is now used by railroads throughout North America.
 
We follow this with the details of a low cost, Automatic Car Identification (ACI) system for model railroads. This will include a relatively simple working scanner and controller, a very flexible identification tag that can be customized, and car lists generated and transferred to local displays, phones, PC’s, web pages, paper, and JMRI directly. The ACI is not dependent on scale (N-scale and larger), nor track power, nor train control mechanisms, nor signaling systems. It can be used on 4’x8’ empires and large club layouts.
 
Train consists can be monitored, saved, transmitted, and utilized via many different displays, viewers, and applications. The incremental cost per car is very low (less than a penny a car) with scanner costs less than $18 each. There are some interesting implications that can derived from clever labeling for new uses on model layouts.
 
Some History and Basic Equipment
 
IN the 1960’s Sylvania experimented with a rail car scanning system that it eventually tried out on the Boston and Maine railroad. The Federal Railroad Administration later evaluated the Sylvania system, as well as two others, in the hopes of recommending a nation-wide solution for tracking freight cars and locomotives across the US. The AAR Board of Directors announced in October, 1967 that the Sylvania KarTrack system would be the national standard, and that all cars be labeled with KarTrak colored bar-codes.  These were the first bar codes in widespread commercial use anywhere, and the precursor to the barcodes commonly found on most any item offered for sale today.
 
Label Format.jpg  KarTrak Labels2.jpg     KarTrakLabelLPN.jpg
 
Figure  2.  KarTrak RailCar Format                                        KarTrack  Codes                        Decoded:  LPN 52059  
 
ACI Installation.jpg
Figure  3.  KarTrak Prototype Scanner
 
The KarTrak system proved to be a failure, even though by 1973, 95% of all railcars were labeled. Labels became unreadable covered with dirt and road grime in the presence of harsh operating conditions. Freight haulers of long, ore trains kept using them longer, for captive use. The KarTrak system was phased out by 1977. The optically scanned KarTrak labels were superseded by a form of rugged, encapsulated RF ID tag, required to be in place by the end of 1994. These Automatic Equipment Identification (AEI) tags are now in widespread use on virtually all freight cars, passenger cars, and locomotives on the rails.
 
Automatic Car Identification (ACI) System for Model Railroads
 
This project describes an Automatic Car Identification (ACI) system for model railroads. This includes a relatively simple QR Code scanner and controller, a very flexible QR Code identification tag that can be customized and printed at will, and car lists generated and transferred to local displays, phones, PC’s, Arduinos, web pages, paper, and JMRI directly (see Figure 4. below). To identify or scan a car, it simply needs to roll over the scanner located below the roadbed. The rest is magic!
 
Operating Diagram2.jpg
Figure 4. The Operating ACI System
 
 
 
Video: ACI in Action
 
The ACI uses a relatively new sensor called the Tiny Code Reader (TCR) made by a company called Useful Sensors. Its function is entirely focused on reading graphic QR Codes like the one pictured in Figure 5. below:
MILW_67116_D&H_18661.jpg
Figure  5. QR Codes for “MILW 67116”           and                      “D&H 18661”
 
I have been experimenting with the TCR to see how small a QR Code could reliably be read, and under what conditions. QR Codes can contain many alphanumeric characters (over 200) and can be printed on ordinary office and home printers. The TCR has a practical limit herein of something less than 40 characters, and I have been limiting mine to 20 or less. Fewer characters means speedier decode time, and with a nominal 5 QR Codes read per second, I wanted to be able to read railcar labels with the train on the move! I have been able to print my own QR labels with a 600 DPI laser printer. I can reliably read QR Codes as small as 0.2 x 0.2 inches, but movement and light makes reading them problematic. I have been using 0.27x0.3” and 0.35x0.38” codes with much higher success. High train speed during scanning is not possible, so old Athearn Hustlers will not cut it. However, car scanning with a train on the move is entirely possible.
 
There are real advantages to using QR Codes:
  1. They can be easily printed on an ordinary home or office printer, either ink jet or laser.
  2. Labels can contain alphabetic, numeric, and special characters like AT&SF 123456789
  3. They are very low cost to print in any quantity (like less than a penny a piece).
  4. Scanning reliability can be increased at higher train speeds by applying the same label more than once
  5. ACI labels can perform “interesting” model railroad functions, since we can put anything onto the label:
  6. The railcar name and number are obvious -- NYC 173210
  7. More than one label can be added per car – EOT for End of Train or FOT for Front of Train
  8. An F for Front or R for Rear can be added to an individual car label – RDG 89191F or SOU 2302111R
  9. Additional labels could be posted for routing information similar to the “thumbtacks” on cars of old
  10. Locomotives can be labeled, as well as cabooses, passenger cars, and MOW equipment
  11. Labels can be scanned and read via most cell phone cameras
  12. Labels can be made removable by using weak glues like Aleene’s Tack-It Over & Over without damage
  13. Removable, magnet-backed labels can attach to the screws of car trucks
 
I have considered these possibilities for car labels: FOT (Front of Train), EOT (End of Train), Car Front, Car Back, Running Extra, Train 25 (train number), RR & Car Number with F or R for Front or Rear (NYC 125023F), Express, and the like. The code is designed to eliminate duplicate car labels to multiple labeling for increased reading reliability with higher train speed over the scanner. Even with multiple labels, high speed and scanning do not mix. Examining the scan reports shows that an additional number per label is randomly generated, anticipating the possibility of using the scanner situated at a weigh scale. It can easily be turned off.
 
QR Codes can be printed using a free open source application called “QR Code Generator” downloadable from here: https://sourceforge.net/projects/qr-code-generator    I also include it in the downloads zip for this article. When you resize the codes for printing (after generating) make sure they are equally, proportionately resized. Changing the size ratio is not a good idea and may cause the code not to be read. I use MS Powerpoint to bring in the newly generated code, resize and label them and the print them out. Select the QR Code picture in your Powerpoint, right click on it and select “Size and Position.” Then change either the scale height or scale width and note that the other one will follow – do not force them to adjust differently. Print them out on normal 20lb or 24lb paper, non-glossy. Cut them out with a white border so the scanner can “find” them.
 
QR Codes Experiment4.jpg
Figure 6. Example printed QR Codes
 
I have successfully used Aleene’s Tack-It Over and Over glue to attach the labels to the bottom of cars. This is a similar glue used in “post-it notes.” Repeated use will wear the glue out. Simply re-apply to re-use the QR Label.
 
One of the neatest appliques for car labels I have found is to use a 4mmx1mm magnet from Supermagnetman.com:  https://supermagnetman.com/products/d1021?_pos=3&_sid=8562318e2&_ss=r
Glued to a thin piece of styrene with superglue. This forms a placard holder for a QR Code than can be attached to the steel screw holding a truck to the chassis of a car. To prevent the holder from rotating by itself, I glued a small wire from the magnet out towards the side of the cat and truck. I then filed a small groove in the side of the bushing for the truck screw. The wire is the “key” in the groove that follows the truck motion – simple, easy, and cheap! See Figure  7. below.
 
Magnetic_Label.jpg
Figure 7. Keyed Magnetic Label
 
Please take note that the label shown in Figure 8. Is not lying flat to the bottom of the car. This has a tendency towards missed label readings. It is often easier to affix the paper label to a thin piece of plastic or stiff card, and then apply it to the truck or car as appropriate. Doing this will spare you problems in the future.
 
Truck_Label.jpg
Figure 8. “Bumpy” Non-Flat Label
 
By simply adding an R and/or F to the car label we can determine car orientation on the rails. By adding an FOT (Front of Train) or EOT (End of Train) tag we can mark an note when a train is starting or ending scanning. I’m sure other train/car “flags” will be added. While I have anticipated placing the scanners below the tracks, the physical orientation does not matter. Labels could be placed on the side of cars and scanned from the side of the train just as well. Although I have not figured out how to disguise the label, or reduce its size to a point where it is inconspicuous in this manner. Colored backgrounds of labels may also be possible, but label contrast is very important for successful reading. More experimentation is warranted. The most beneficial action I’ve taken is to place 2 labels (not immediately next to one another) on a car for increased reading reliability. It also seems to allow for a bit higher train speed while scanning. Why? I don’t know. Placing more than one label on a car is fine, but experience shows they should not be immediately next to each other.
 
I have found that sufficient light is very important. Useful Sensors suggested that their camera had no infrared filtering, and so near-infrared (invisible to the naked eye) might work for illumination. After trying a couple of near-IR LEDs for illumination, I found there simply was not enough light, and I could not locate cheap, ultra bright near- infrared LEDs. I did have some cheap, 18000 mcd (millicandela) 3mm green LEDs. I built my first sensor platform with two switched LEDs for illumination, shown below in Figure  9. I later switched to 20000 mcd white LEDs. This was a personal preference. What was needed was enough light for the scanner. Both green and white works well at these light levels.
 
IMG_7562.jpg
Figure  9. Early Mock Up testing using green 3mm LEDs
 
I also developed a simple scheme to point the LED at the correct scanning area, by placing a strip of paper or thin white plastic on the track area for scanning and watching the lighted “coverage area” as I adjusted the LED manually. This is shown in Figure  10. :
 
LED_adjustS.jpg
Figure  10. LED Adjustment View
 
I started using 0.5x0.5 QR Codes printed on high gloss photo paper (thinking resolution was important). I used two switched high brightness green 3mm LEDs. To my disappointment, I could barely read a code (attached to the underside of an HO car)… with the car stopped precisely above the reader! Oh no! After many hours of trial and error, I found two LEDs were not better than one with glossy tags! Lowering the light improved the readings. Also I fiddled with the top of sensor to top of rail distance -- 2.17” -- (and hence the sensor to QR Code distance) to determine that there was a nice working depth of field of about 0.5-0.75” for the reader. The reader runs in read cycles of about 200ms, or 5 per second. I was hoping to see if the reader could scan a moving train at any speed at all. Otherwise I would have to stop each car precisely above the sensor – its position and centering should be workable, but I wanted to scan a moving train. After several frustrating trials, I decided to change from glossy paper to plain, 20 pound office paper. Unbelievably, the readings improved considerably.
 
Hardware
 
With the scanner basics confirmed, I went on to put together the rest of the system. I wanted a WiFi connection, initially to a web page list that could be read anywhere. I also wanted the ability to retain train lists and detailed car information for at least 500 cars. I eventually selected an ESP32 PICO module variant for processing and communication, low cost, high pin count, with a large 8MB program memory and 2MB working PSRAM. With all features turned on, only 66% of program storage is currently used.
 
Figure  11. and Figure 12. below show all the major components. The ESP32 PICO and the TCR are connected via a four pin I2C cable. I also used a 128x128 OLED display for local readings and debugging. This display is optional. The display can be daisy chained via the four line I2C cabling for a very easy “build.” A review of all the working ESP32 variants are discussed in the Bill of Materials (BOM) below. Once a car label is read, it can be displayed on the local OLED display, or transmitted via USB serial port to a PC, or transmitted as an updating web page via WiFi, or transferred via WiFi to an MQTT server and onto any subscriber -- like JMRI reporters. JMRI can collect and store latest car label scans, build a train consist, and retain all car labels for all railcars passing through your layout empire.
 
ACI Basic Config.jpg
Figure  11. ACI Basic Diagram
 
There are several workable options that one can choose for the processor module and the local displays. Most any I2C 3.3 Volt display will work, as long as its I2C address does not conflict with the TCR address of 12 (or 0x0C Hex). Be careful when substituting processor modules with less memory. I believe there will be additions and enhancements to come sometime later. Also be cognizant of the 3.3 Volt regulator current limitations on the processor module. The Adafruit ESP32 PICO QT PY I first used had a current capability of 600ma, which I thought was fine for both a small display and the TCR. However when I changed my display from a 128x64 to a 128x128 display, it ran very warm to the touch! It never failed, but I found out the WiFi RF current peaked around 425ma under long transmission loads. As it turned out the ESP32 PICO Dev Board M-02 was cheaper and supplied 800ma. It was an easy choice.
 
ACI Componennts.jpg
Figure  12.  BOM Options
  1. ESP32 PICO (I have used these successfully and recommend these):
ESP32-PICO-DevKitM-2 Dev Board – available from many vendors, these had them for $10 each:
Adafruit QT Py ESP32 Pico - WiFi Dev Board with I2C QWIIC connectors  $14.95 -- https://www.adafruit.com/product/5395
TinyPICO ESP32 Development Board $21.95 --  https://www.adafruit.com/product/5028
 
Here are the boards I evaluated:
ESP32 PICO
Flash
PSRAM
SRAM
QUIIC I2C
SDA/SCL
SDA1/SCL1
Current
V Reg
Price
Adafruit QT Py ESP32 Pico
8MB
2MB
 
Yes
4/33
22/19
600ma
AP2112K-3.3
14.95
Adafruit ESP32 Feather V2 MINI-02
8MB
2MB
 
Yes
21/22
 
600ma
AP2112K-3.4
19.95
Adafruit ItsyBitsy ESP32 MINI-02
8MB
2MB
 
Yes
21/22
 
600ma
RT9080-3.3
14.95
SparkFun ESP32 Qwiic Pro Mini MINI-02
8MB
2MB
 
Yes
15/5
 
600ma
AP2112K-3.4
9.95
Digikey Espressif ESP32-PICO-DEVKITM-2
8MB
2MB
 
No
21/22
 
800ma
SGM2205
10
Espressif ESP32-PICO-DEVKIT-4.1
4MB
 
0.5MB
No
21/22
 
1000ma
AMS1117
18
Espressif ESP32-PICO-KIT-1
4MB
 
0.5MB
No
21/22
 
800ma
SGM2205
10
UM/Adafruit ESP32 TinyPICO
4MB
4MB
 
No
21/22
 
700ma
NCP167BMX330TBG
22
             
The Espressif ESP32-PICO-DEVKITM-2 Board has the most memory, lowest price, and an 800ma Voltage regulator which will easily power the QR Reader and an OLED display. The QT Py ESP32 Pico with a 600ma regulator will work, but the regulator runs very warm. In this case, I did not like “very warm.” All will work and handle a 200 car train in memory.
  1. Optional OLED displays – only I2C connected displays are recommended, for price and convenience. Try these for Adafruit, although most any I2C display with an SSD1327 driver will work. Smaller 128x64 OLED I2C displays are cheaper and will work too. Adafruit has displays with their QWIIC plug connectors which eliminates some soldering and hassle, but will cost a bit more.
  2. The Tiny Code Reader (TCR) QR Code Scanner – there is only one kind at present, available from:
Tiny Code Reader from Useful Sensors  Adafruit.com #5744   7.00
USEFUL SENSORS TINY CODE READER SEN-23352  digikey.com 1568-SEN-23352-ND  8.62
Useful Sensors Tiny Code Reader  Sparkfun.com   SEN-23352  7.00  
  1. 18000 or 20000mcd 3mm LED – white or green, like these:
 
  1. 30 Ohm 1/4 Watt resistor
Digikey CF14JT30R0TR-ND   0.10     RES 30 OHM 5% 1/4W AXIAL Resistor
Digikey 2019-RK73B2ATTD300JTR-ND   0.10    RES 30 OHM 5% 1/4W 0805  CHIP Resistor
 
Besides 5 Volt power connections to the ESP32 Dev Board M-02, all the connections are shown above. This is an easy electrical build. The only solder attachment needed is the 3mm LED to GND (short lead) and through the 30 Ohm resistor on the long lead to the 3.3 Volt pad on the TCR – see BOM Options Figure 8.
You can use the Adafruit STEMMA QT / Qwiic JST SH 4-Pin Cable  https://www.adafruit.com/product/4210
Or equivalents to make quick work of interconnecting the local display and the TCR. You can also use it to connect to the Adafruit QT Py ESP32 Pico - WiFi Dev Board with I2C QWIIC connectors if you use this processor (Figure 13.). I prefer to use the ESP32-PICO-DevKitM-2 Dev Board and the Adafruit STEMMA QT / Qwiic JST SH 4-pin cable  https://www.adafruit.com/product/4397  instead. I cut off the female connectors and solder the connections directly as pictured in Figure 9.  Five Volt power comes into the processor board via the USB connector or the +5V and GND pins.
 
qwiic cable.jpg
Figure 13. Adafruit QWIIC Cable for easy I2C connections
 
Mechanical Mounting
 
The early mock-up shown in Figure 9. and Figure 14. attached the TCR to a bottom shelf and the distance from the top of TCR to the top of rail (eventually at 2.17 inches). This was done by shimming the TCR mount which I made out of scraps of styrene strip. The TCR has components on both sides of the board and only one 2mm mounting hole. Leveling the TCR so it looked straight up, and centered between the rails was very important. My belief was that this did not represent the most likely mounting scenario for most model railroads. Rather, I assumed that the TCR would more likely be suspended below the track/railbed. Remember that a length of track would need the center set of ties removed (1 5/8 inches) so the QR labels were visible with no obstructions or shadows. I wanted a very low cost mount that did the job.
 
TinyCodeReaderMount1b.jpg  TinyCodeReaderMount1.jpg
Figure 14. Prototype Mount                                                                                              Figure 15. TCR
 
Ultimately, I decided to try my hand with a 3D printed mount, that would hold the TCR suspended by four 1/16 rods connected to a simple mount above the ties alongside the track. Amazingly, it all worked! Figure 16. Shows the 3D print of the TCR mount. It took about 18 minutes to print and has 5 holes/dimples placed to allow for drill alignment. All 3D printer files are in this article’s zip file for downloading.
 
TCR_Mount2.jpg
Figure 16.  TCR 3D Printed Mount
 
TCR_Mount2b.jpg
Figure 17.  TCR Mounted
 
Four 1/16 holes were drilled in the four corners of the TCR mount. The fifth hole was drilled for a 2-56 screw and threads tapped for the board mount. Remember that when the LED was attached to the TCR with dropping resistor, no protrusions were allowed below the board. This was to permit an even mount in the base. Two styrene strips were chosen to fit above the track ties and below the rail tops. Four more 1/16 holes were drilled slightly wider than the 4 holes in the TCR mount to provide a little tension on the supports. You can see a slight bend in the 1/16 rods in Figure 18.
 
Suspended Mount.jpg
Figure 18. Suspended TCR Mount
 
You will find that the rods are a tight fit after you drill the support holes. I used a small reamer from MicroMark.com https://micromark.com/products/micro-size-precision-reamers-set-of-6?keyword=reamer
(See Figure 19.) to just barely allow the rods into the holes with a little effort with some smooth long nose pliers. You want the friction to hold the mount in place as you position it to the right height and center the TCR lens between the tracks. If you make the holes too large (for too loose a fit) you can use some long nose pliers to slightly crimp the styrene rod near the hole site, to create a tighter fit. Besides depth and centering, it is important that the vertical axis of the lens be perpendicular to the track, even if the track is on a grade. Once the TCR mount is set, power on the TCR and the LED should light. Put a piece of paper over the track and center the light in the middle of the cleared ties in the track as demonstrated in Figure 10. Be careful to hold the TCR board in place to not rip the LED off the board or disturb the suspended mount. You will find you can rotate the mount in place, change its height, level, and position relative to the track. This is not difficult if you take your time and are careful. It only took me three tries. 😛 Once the mount is stable and tested, it can be permanently fixed in place with a few drops of glue. If you have to remove it, you can drill out the mounting holes and re-suspend the mount anywhere.
 
Reamers.jpg
Figure 19. Reamers
 
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.
 
SelfMount1.jpg  SelfMount2.jpg
Figure 20. 3D Printed Partially Self-Aligning TCR Mount
 
NewMount.jpg
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.
 
Arduino IDE setup has been covered before several times including here: A modeler’s introduction to the Arduino,  MRH, Dec 2016 --  http://mrhpub.com/2016-12-dec/online/html5/index.html?page=1&noflash
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:
  1. Open a window with the command prompt
  2. Change directory to the folder where you loaded mosquito (likely C:\Program Files\mosquitto )
  3. 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

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 19
Geoff Bunza geoffb
Placeholder1 for Future Endeavors

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 2
ErieMan47
Wow!  This is amazing Geoff.  Once again you have hit it out of the park.  I have gotten so much good use out of your SMA DCC decoder projects, and now this.  Thank you for what you have given us.
 
In the photos at the beginning of your post you use an image of an Erie box car.  As I am sure you know, Erie was long gone by the time ACI labels started showing up.  I was relieved to see that what you are really doing is putting a QR code on the underside of the car, where it won't be seen.  😁
Dennis
Modeling the Erie RR Delaware Division in the early 1950s in HO
Reply 4
Geoff Bunza geoffb
Hi Dennis,
 
As usual I was completely oblivious to the prototype timing of the Erie's passing and KarTrack (not the first time! 😉).
Good thing this is not a KarTrack model (Yuk, Yuk!)
 
'Glad you enjoy this.
Have fun!  🙂
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 1
CandOfan
*burp* trying to swallow lots of other things at the same time! But this one will go into the queue. I'm already using esp32's and MQTT, so this should be an addition in kind for me. The sensor is a new one for me, so that's great info.

Modeling the C&O in Virginia in 1943, 1927 and 1918

Reply 3
John P
Very ingenious, but I wonder how many people will be willing to accept this, given that it requires a large pit between the rails with a bright light inside1 And it's a drawback that it doesn't function at high speed. But looking at the spec sheet on the Adafruit site, I see that they don't explain how long the code has to be visible or how fast the target can move. A CMOS camera might function by taking still pictures, rather than requiring the presence of the target for a long period, and that might make it possible to reduce the size of the pit quite a lot. The key question would be how much benefit you get from having a moving target that's visible for a reasonably long period. Might it be sufficient to have the target visible just for a brief period via a "peephole", if that's all the sensor really needs?
 
It's too bad that the infrared LEDs haven't worked out. I've played with some that I got from AliExpress which claimed an intensity of 25mW/sr, but how that compares with your visible-light LEDs I don't know.
 
Edit to clarify(??) that I'm thinking the critical issue might not be how long the target is over the sensor (which is maximized by making the pit longer) but how much it moves in the time taken for a single camera frame, most likely 1/30 second or 1/60th. If it moves much, the image might be smeared too much to get an accurate reading, and that'll be your limitation of train speed. But then again, if you have a marginal situation, it would help to get a good scan if the camera can capture several frames and so have more chance that one of them will be valid.
Reply 3
Geoff Bunza geoffb
Hi John,
 
The whole idea of experimenting with this new sensor for months was to see if the MRR application was within reach -- it is indeed. The limited specs presented by  Useful Sensors  never anticipated reading a much reduced QR Label in a moving field. The  spec'ed net read and decode is 200ms or 5 times a second, but most of that is likely processing/decode time and transmission. The image is likely captured in about .025 seconds or less (net 40 frames per sec) as they are using a low cost solid state camera -- hence the low cost -- with no options for additive lenses or variable focal length. The depth of the camera "pit" relates merely to its focal point and depth of field (which accommodates about 0.5" more above the rail head).
 
You can get a good idea of its reading rate relative to train speed by watching the accompanying video provided with the article.
 
The light provided for the scan will be turned on and off in the presence of a train, just like the prototype KarTracks scanners. That's part of the "more to come." So I suspect its distraction will be kept to a minimum. It will also sense train direction as a side effect.
 
It is pretty obvious that video sensors will play a bigger part in both interactive commercial automation, and model railroading. More expensive, faster, still cameras and videos cameras would aide this application, but not its cost, for the time being.
 
Perhaps you or other modelers will try similar, but different approaches to car scanning. For me it was the novelty, the challenge, and the answer to "why not?" that encourages my own activities, not the number of installations I will see.
 
Have fun!  🙂
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 4
thewizard1
Very cool stuff Geoff.
The only thing I have mastered in life is how to spend money
Reply 2
MikeHughes
All I can say is WOW, so cool.  After touring the G3 grain unloading facility at the PNR convention, I can see this reader being used to mimic that kind of automation.
 
Thanks @geoffb for all you do and give back to the hobby.  I am having a blast building the steam throttle, and can see building this at some point for use on my Laggan sub.
Happy NMRA Member since 2024
Reply 2
Tim Bowser NCR-Boomer
Fast scan (no pun intended) of the project notes, I slowed up at the sensor pit and frustration with inability to read the QR codes even with two LEDs providing illumination.  The two immediate takeaways both fall back to the tiny CCD camera on the sensor.  Too much light (saturation) for the camera, and in the case of the paper switch, too much light from reflection (glare).  Your best option for the QR prints would be a optically "dead flat" medium, even less than Dullcote.  Minimal reflection (sheen), maximum contrast.
 
You could try a photographic print media, such as Epson Matte Presentation Paper, 27 lbs , for a flat finish, and heavier stock to support the code block.
 
Regards,
 
Tim Bowser
Husband and 'enabler' of a semi-pro photographer 
Tim Bowser

Capitol Free-mo Participant, and
Chesapeake Speed-Mo Proponent
Reply 1
RossA
Geoff,
 
Amazing!  Looking forward to chatting with you about this project.
 
Take care.
 
Ross A
Reply 2
CandOfan
Right now, even the deep pit and bright light would be fine in places like staging areas.
 
In a real-world layout, how many places does one need to read these labels?
 
Where did the prototype read the ACI labels? My impression (could easily be wrong) was only in yards.

Modeling the C&O in Virginia in 1943, 1927 and 1918

Reply 2
CandOfan
Fast scan (no pun intended) of the project notes, I slowed up at the sensor pit and frustration with inability to read the QR codes even with two LEDs providing illumination.  The two immediate takeaways both fall back to the tiny CCD camera on the sensor.  Too much light (saturation) for the camera, and in the case of the paper switch, too much light from reflection (glare).  Your best option for the QR prints would be a optically "dead flat" medium, even less than Dullcote.  Minimal reflection (sheen), maximum contrast.
 
You could try a photographic print media, such as Epson Matte Presentation Paper, 27 lbs , for a flat finish, and heavier stock to support the code block.
 
Regards,
 
Tim Bowser
Husband and 'enabler' of a semi-pro photographer 
Possibly even better might be Epson Hot Press Bright paper. It is very high contrast, dead flat finish, and about as heavy as photo paper comes. It costs more than Matte Presentation, but given the size of the labels, I doubt that's a significant cost differential.

Modeling the C&O in Virginia in 1943, 1927 and 1918

Reply 3
Michael Tondee
You never cease to amaze me Amigo!
 Great project that I'm going to have to look into when I get back going on the layout again.

Michael, A.R.S. W4HIJ

Model Rail and "mad scientist" for over 50 years.

Member of "The Amigos", Co-Inventor of the A.O.S.T.

I call what I do "An artistic impression of reality" and the Island is "lost" somewhere in the Pacific Northwest, see it here...

The Blackwater Island Logging & Mining Co.

Reply 2
Geoff Bunza geoffb
@thewizard1 & MikeHughes & RossA & Michael Tondee,
 
Thank you all for you kind comments.
I hope you might enjoy building one or more of these -- not hard and really fun to see in action.

Have fun!  🙂
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 2
Geoff Bunza geoffb
Hi Tim and C&Ofan (name?),
 
Thanks for those ideas and leads on the matte paper. I will try them both out.
I am hoping that many more modelers will explore more options for scanners and lightweight video applications and come up with better approaches and ideas like yours.
 
The detector-enabled light will be an easy add, and is on the to-do list.
 
With appreciation, Have fun!  🙂
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 2
NDHolmes
Geoff, you never fail to amaze me.  I'd considered QRs for car ID a while back when trying to figure out how to track loads/empties in the loadout silo and the unload dump, and put it on the inevitable backlog of "I should look at this some day, but for now 125kHz RFID works well enough"   But yes, matte paper.  Glossy stuff is the bane of scanners everywhere.  Nothing like customers who put glossy shipping tape over their barcodes to ruin your read rates! 

I'm a little surprised the IR leds didn't work out, because that was my first thought until I got to the part where you'd already tried it. 
 
The Useful Sensors camera/barcode reader module is new.  I didn't know such a thing existed at that ridiculously cheap price point.  My initial experiments were a webcam and some throwaway python code just to get it working.  Either way, very cool project and gives me some motivation to get back to it!
Reply 1
Geoff Bunza geoffb
 
Hi,
 
Years ago, I started out by looking at still cameras for scanning, and the overhead processing at the time was not really available. The TCR uses a dedicated RPi Pico to decode the image -- way more capable than what I once examined. Even replacing the TCR might be doable with a fast SS Camera, but it is going t drive the cost up (for now). I have found that my iPhone 8Plus can read very small printed QR Codes, so I know better scans are possible.
 
Like many other tools, these will get better over time. This project started with trying to answer could this be done at all? It's not a perfect solution, but it is relatively cheap for a whole fleet of cars. I enjoy it for the entertainment value (animation of sorts) but other modelers have gotten excited for other reasons. I'm not much of an operator on my own, so I don't feel I can do justice to its use in RR operations. The reactions I've received so far from operators are all over the map, so I have no conclusions as yet. As usual for me... I'm amazed it works!  😃
 
Have fun!  🙂
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 2
Chris VanderHeide cv_acr
Where did the prototype read the ACI labels? My impression (could easily be wrong) was only in yards.
Actually probably not IN yards.
 
On the main track, but usually NEAR a yard or junction point so you can update the car's location when you see a train arriving or leaving from that point.
 
Maybe a computerized hump yard would also read the car data in order to automatically route it into a particular bowl track, but otherwise you wouldn't have them IN a yard anywhere, but a couple miles out so you just record the arrival/departure of the car passing the scanner.
Reply 4
CandOfan
I'd guess that I got those impressions from seeing readers in hump yards.

Modeling the C&O in Virginia in 1943, 1927 and 1918

Reply 1
David Husman dave1905
In a real-world layout, how many places does one need to read these labels?
 
Depends on the use case.  If you were using it for inventory control then every industry and yard track  so you would know what was placed in and taken out of every track on the layout.
For my purposes I would like a reader at every OS point (both ends of a siding or at "train order offices" and I would just read the engine and caboose.    The engine would tell you what train it was and the caboose going by would indicate a departure.  Then the dispatcher would have a screen and it would record the fast clock times each train OS'd at each station and display it on the screen.  The dispatcher wouldn't need the crews to OS, and he'd never "miss" an OS.
For my layout that would be about 12 readers in the main track.
 
However the limitations on the speed of the equipment passing the reader and the enormous gaping hole in the roadbed don't really make this seem like a viable solution.  Get it to where a QR code can be read at a scale 45 mph and the reader is only a hole a half inch in diameter and the lens is 1/8 inch below the tops of the ties or flush with the tops of the ties, without the bright lights, and it suddenly becomes much more useful.
 
Personally I think the future is in RFID for the same reasons real railroads use AEI technology instead of ACI technology.

Dave Husman

Visit my website :  https://wnbranch.com/

Blog index:  Dave Husman Blog Index

Reply 0
John P
I've been thinking about car ID for years, and I've tried to do it with bar codes and RFID. Both of those worked after a fashion, but there were practical issues I couldn't solve, like the tags being too difficult to mount accurately enough, or not enough range. But if I had a system that worked, what I'd want to do with it would be to put the readers at the entrance/exit to every yard, and at every industrial spur. Then the location of every car would be known, unless it's actually part of a moving train, which should be a temporary condition (unless it's Charlie's MTA car). I like the idea that after an operating session, car locations can be compared with a switch list and demerits issued for errors! And if a car is wrongly placed, correcting the error can be part of the next session.
Reply 1
CandOfan
 
Depends on the use case.  If you were using it for inventory control then every industry and yard track  so you would know what was placed in and taken out of every track on the layout.
For my purposes I would like a reader at every OS point (both ends of a siding or at "train order offices" and I would just read the engine and caboose.    The engine would tell you what train it was and the caboose going by would indicate a departure.  Then the dispatcher would have a screen and it would record the fast clock times each train OS'd at each station and display it on the screen.  The dispatcher wouldn't need the crews to OS, and he'd never "miss" an OS.
For my layout that would be about 12 readers in the main track.
 
However the limitations on the speed of the equipment passing the reader and the enormous gaping hole in the roadbed don't really make this seem like a viable solution.  Get it to where a QR code can be read at a scale 45 mph and the reader is only a hole a half inch in diameter and the lens is 1/8 inch below the tops of the ties or flush with the tops of the ties, without the bright lights, and it suddenly becomes much more useful.
 
Personally I think the future is in RFID for the same reasons real railroads use AEI technology instead of ACI technology.
OK, looking at it that way, I'd need about 35, and most of those would be difficult to disguise the light.
 
I was thinking of RFID too, but that seems to have a load of troubles too. Has the state of the art advanced in the past couple of years? When last I looked, it was largely impossible to distinguish between two parallel tracks, as just one example. Presumably this is not a problem on the prototype due to scale.
 
> unless it's Charlie's MTA car
 
Is he still eating sandwiches every day?

Modeling the C&O in Virginia in 1943, 1927 and 1918

Reply 1
Raphael
This is a neat project. I'm a big fan of anything with an ESP32 and some sensor.
 
One thing I did consider doing at the museum railroad a while ago was detect which train was moving using a camera, and use that info to display some educational content about "what's running now" on a nearby screen. My thought was to use either an RPi or a laptop for the computing part, and either a webcam or a quality IPsec cam with an IR illumination. I temporarily moved that project aside as instead I used OpenCV to do basic train motion detection for a display, without trying to detect which trains or cars.
Add OpenCV's cv::QRCodeDetector and you have a good solution similar to yours. Although rather than do QR, I'd have the system capture an image of a specific once and then match it again later, with the added benefit that it can "learn" in-place with the same lighting.
I personally like old-gen laptops because they are cheap and plenty on ebay, and conveniently provide computing, storage, network, and display, all in an easy to maintain package. A substitute for this application is to use any Android phone since it can have the camera on one side, and the display on the other side, and these are trivial to program in a combo of C++/Java/Kotlin or you name it. It would be a lot more compact, for sure.
 
If you want more hype, substitute an RPi for the computing power, and a USB web cam should probably do it fine as most modern hardware is quick & good (albeit lacks a focusable lens). For my own automation projects, I standardized on old-gen Lenovo laptops as I can often get then cheaper than RPis on ebay and with Linux they make wonderful automation platforms.

Ralf~
[ web site ]

Reply 1
Jim at BSME
Regarding IR Leds:
I wonder if they didn't work out because of the "glossy" paper. However, I do know in my security camera white does show very bright so that could be over powering the camera and washing out the black of the QR code. I wonder if the QR was grey and black or grey and red, QR codes do not have to black and white, at least I have seen QR codes in color.
 
Regarding the pit:
I don't see a minimum distance, but the statement "sensor focuses best 10cm to 15cm (4 inches to 6 inches)" so wonder if some distance optimization could be done with size of QR code. Of course the primary limiting factor would be focal length of the camera.
 
With all the other cameras for for the RPi or the ESP if one could implement the reader on another platform to get better read results, either distance and/or speed. Of course this product from Useful Sensors does the heavy lifting of decoding a QR code, and is inexpensive.
- Jim B.
Baltimore Society of Model Engineers, Estd. 1932
O & HO Scale model railroading
Check out BSME on: Facebook, Instagram
Reply 1
Reply