Turntable Pt 3 - Control



For the actual operation of the turntable I originally wanted to use an Arduino Uno with a motor control board driving a stepper motor (if you're not familiar with Arduino here's a quick explanation).  Three good sources for Arduino stuff are ArduinoAdafruit and Sparkfun.  This is probably the cheapest way to go but I'm new to the programming so there's a learning curve involved.  I waffled on just using manual control with a gear or belt and pulley driven by a hand crank.  Still pretty cheap but the operation of the turntable will be from 2.5' away and I'm concerned about getting the tracks lined up properly.  So now I'm back to the Arduino control because you can program it to do very accurate indexing and with a stepper motor it would be repeatable.

I ended up going to the Yahoo group "Arduino for Model Railroading" (click here) to ask for help.  Several folks there were very helpful and stuck with the project for a few weeks to develop a working sketch (program).  This required a lot of going back and forth because they had the programming knowledge but I had the gear to run it on.  Suggestions would be made and then I would modify the sketch and run the program.  In the end we came up with a very cool control system for the turntable.


The system consists of an Arduino microprocessor, the Mega 2560, running a 4x4 matrix keypad, a Nokia LCD display and an EasyDriver board running a NEMA 17 stepper motor.  This is a stand-alone system and won't need to be connected to a computer to run.  The Mega and the EasyDriver both run on 5VDC and the stepper motor runs on 12VDC through the EasyDriver.  The Mega provides power for the Keypad and the LCD.

If you're not familiar with some of this stuff I'll give a quick explanation.  The Arduino Mega ($17 - $25) is a larger version of the Uno, mentioned earlier.  It's a small microprocessor that can be programmed through a USB connection to your computer.  Once it's programmed it can run independently on power from a wall-wart style power supply or even a battery.  The board has numerous pins around its perimeter for input and output connections.  The EasyDriver ($8) is a stepper motor control board that uses a "library" of commands to provide custom control of the motor.  The 4x4 matrix keypad (5 for $7.50) has 16 keys set up in 4 rows and 4 columns.  The keys are 0 - 9 and A,B, C and D.  The keys can be programmed to be anything you want; symbols, numbers, letters, anything.  The LCD ($5) is actually a display from an older style cell phone.  It doesn't do color but can display low resolution images.  You can use Photoshop to make your display as a GIF file and then use an app to change it into code that the display understands.  The NEMA 17 stepper motor ($17) is a medium size (NEMA 17 is the size) motor that has a bunch of coils mounted around the output shaft that causes it to rotate in steps.  This one uses 400 steps to make a full rotation.  I'm mounting a 20 tooth pulley on the motor and a 60 tooth pulley on the turntable shaft to give me a 3:1 ratio so it takes 1200 steps to make one full rotation.  The EasyDriver can operate in 1/8 steps so I'll be running 9600 steps per revolution to give very smooth operation.  The total investment for this control system is about $75 and that includes everything mentioned above.


The program, called a sketch, is pretty cool.  When it's first initiated the stepper begins homing in full step mode.  I've mounted an Infra-Red Beam Break detector under the turntable platform.  As the turntable bridge rotates it also rotates a small metal flag attached to the shaft beneath the layout.  When the flag interrupts the IR beam it sends a signal to the Mega board which stops the stepper and sets that point as zero.  Everything the stepper does from that point on is referenced to that point.  There are 16 tracks around the turntable pit and each track is a certain number of steps from the zero point.  They're listed in the program and that's how the stepper knows where to find a specific track.  I can punch in a "2" on the keypad, hit the # key to enter it and the bridge/stepper knows to turn 90 steps to get to that point.  If I enter 15 it'll go 975 steps.  That's full steps though.  The program knows that after the zero point is established it needs to multiply everything by 8 so that 975 steps now becomes 7800.  That's how you get the smooth operation.  The EasyDriver also uses code that automatically starts and ends every motion by slowly ramping up speed at the beginning and then ramping down to a stop.  This creates a very realistic motion for the turntable bridge, especially since my turntable will be representing an Armstrong turntable, one that was totally positioned by man power.


Prototype turntables were used to position locomotives, to turn them so they'd be headed in the right direction for whatever job they had next.  Sometimes an engine would come onto the turntable so it could be swung around 180 degrees and head back out.  To simulate this I can enter the track number on the keypad and then enter "A" and the program knows to add 600 full steps or 4800 1/8 steps to the track value.  If an engine comes onto the turntable bridge at track # 15 I can enter 15A on the keypad and the engine will be turned 180 degrees and it can go back out track #15 in the opposite direction.  Using the * key you can erase an entry for a track number if you make a mistake.  There are still 3 other keys not used yet; B, C and D.  I'm planning to use a thumbstick (small joystick) to manually drive the turntable and one of those keys will be used to initiate that.

The LCD screen is set up to display current track #, next track # and it also displays "mvng" (moving) when the bridge is in motion.

Anyone interested in using the turntable sketch for their own project can find it at the Yahoo group mentioned before, "Arduino for Model Railroading".  It's located in the "Files" section in a folder called "Turntable Indexing".  Here's a link to the folder (click here).

2 comments:

  1. Augy: the Yahoo group "Arduino for Model Railroading" doesn't seem to be accepting new members. This makes access to your Arduino turntable control sketch(es) unavailable. Is there another source for your sketch(es)? Perhaps a direct email? Thanks in advance for sharing and congratulations on such a clever and useful project! jk

    ReplyDelete
  2. JK - Look for "Turntable Pt 5 - Arduino Sketch" for the complete sketch and explanation.

    ReplyDelete

Painting Plaster Castings

 Today I painted the remaining walls of the roundhouse and thought I'd add a blurb here to share my technique for painting plaster stone...