In nearly all cases, model trains are powered by electric motors which are mounted within motor cars. These are usually the locomotives at the forward end of a train, whether they’re models of diesel or steam locomotives. For models of passenger trains that can run in either direction without being reversed, the motor cars are usually not the end cars, so that no matter the direction such a train is running, some cars are pushed and some are pulled. Trams are simpler, because they’re usually either single cars or two or three articulated cars. For example, the Toyama Light Rail system’s PORTRAMs are two-car articulated units.
What makes a motorized rail car different from your typical motor-control application is that the power to run the motor is not provided by direct connections to the motor, but is applied to the metal rails (usually nickel-silver), which are in electrical contact with some of the metal wheels on the motor car, which are in turn connected to the motor. So if a motor car is resting properly on a track (assuming the wheels and track are clean) and a voltage is applied across the rails of the track, the motor will turn and the motor car will move. Increase the voltage and the motor turns faster; reverse the polarity and the motor car reverses direction. In fact, if you pick up a motor car and turn it around to point in the opposite direction, you’re also reversing the applied polarity of the power, so the train will still move in the same direction on the track. So all you need to control the movement of the motor car are the applied voltage and its polarity, not the direction your motor car is pointing.
Motor control hardware
Usually the power to drive model trains comes from commercial power packs or throttles which have variable voltage output (usually up to 12 volts DC) and reversible polarity. More expensive units have additional features like momentum simulation, but we won’t worry about such things right now. For this project, instead of a commercial model train throttle, I will be using an Adafruit Motor Shield mounted on an Arduino Uno. This shield has four output channels, each of which can source up to 1.2 amperes of current. If connected to a fixed 12 volt DC power source, the shield can provide voltages from -12 to +12 volts to the output connections. These connections go to the rails of the track we want to power. This means a single Motor Shield could drive four separate stretches of track at the same time. And 1.2 amperes of current is way more than most N-gauge model trains will draw even at full speed, especially the PORTRAM N-gauge models I have.
The motor controller’s processor will be an Arduino Uno with one or two Motor Shields mounted on top. Since the Motor Shields communicate with their processor via the I2C pins on the Uno, I won’t be able to use I2C to communicate with the layout’s central processor as well. For that connection I will be using Ethernet over standard Cat5/Cat5e cables.
Update: I was successful in running one of the PORTRAM models on a loop of track, powering it with the Motor Shield and Arduino Uno pair of boards. Here’s a video of the PORTRAM under Arduino control.
In the back (best look starts at 0:43) you can see the Motor Shield mounted on top of the Arduino board (which is inside an orange acrylic case). The blue/white wire coming from the terminal block on the left is the connection to the two rails of the track. Because the tram’s motor runs on 12 volts at full speed, the board pair is powered by a 12 volt 5 amp switching DC power supply from Adafruit plugged into the Arduino’s barrel-jack. The Motor Shield then receives its supply voltages from the Arduino.
The Arduino code running this test, named ThrottleTest, is stored here in my GitHub repository. It’s a modified version of the Motor Shield’s DCMotorTest example code which is included with the Motor Shield’s Arduino library. The instructions for installing this library can be found here on Adafruit’s web site.
I should point out here that the top scale speed for the KATO PORTRAM models is very close to the maximum speed of the Toyama Light Rail’s trams, around 60 kilometers per hour. During this test though, the acceleration and deceleration times are shortened to about 5 seconds; on the prototype PORTRAMs, 15 seconds is more typical.
Motor control software
つづく (to be continued)