Reprogramming the Turntable

Tonight I began painting all of my track using Rust-Oleum Satin Espresso spray paint. I sprayed about a foot of track at a time, masking points as needed and wiping down the railheads with an old tee shirt to remove the paint while it was still wet.

However, I posted a question on Reddit earlier today asking about where I should place a coaling stage (I haven’t been able to find a picture of Hemyock’s coaling stage, although I’m sure it had one), and one of the responses suggested that I add another “slot” from my turntable, citing realism and wasted space.

It’s something I’ve been considering for a long time, but I was kind of hoping the consideration would just go away because actually adding another slot would mean reprogramming the Arduino that controls the turntable.

Well, it wasn’t too difficult. I simply reloaded the old sketch and added another DCC address to create a ~15-degree turn (18 steps of the motor) clockwise or counterclockwise. Then I loaded this into the Arduino, and bashed my head against the wall for a couple of hours wondering why it wouldn’t work. As it turns out, the NmraDcc library that I was trying to load was an updated version, which “causes the sketch to silently stop working” if certain call-back functions are used. So I loaded an older version of the library, and it worked immediately.

Here’s the new sketch:

#include <NmraDcc.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>

#define DCC_ADDRESS 7 //Change accessory address here.
NmraDcc Dcc ; //Declare DCC Shield.
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); //Declare Motor Shield.
bool firstloop = true;
//Comment: getStepper(steps, stepper#)
//Stepper# is which port the motor is connected to. If using M1 and M2, indicate port 1. If using M3 and M4 indicate port 2.
//NEMA 14 Stepper Motor has a 0.9 degree/step. 360/0.9 = 400.
Adafruit_StepperMotor *myMotor = AFMS.getStepper(400, 2);

//This function is called whenever a normal DCC Turnout Packet is received.
void notifyDccAccTurnoutOutput( uint16_t Addr, uint8_t Direction, uint8_t OutputPower )
Serial.print(“DCC Turnout Packet Received\n”);
if ((Addr == DCC_ADDRESS) && OutputPower){
Serial.print(“Move 180 degrees\n”);
myMotor->step(200, Direction, MICROSTEP); //Move 180 degrees in the specified direction.
} else if ( (Addr == (DCC_ADDRESS + 1)) && OutputPower){
Serial.print(“Move 15 degrees\n”);
myMotor->step(18, Direction, MICROSTEP); //Move ~15 degrees in the specified direction.
} else if ( (Addr == (DCC_ADDRESS + 2)) && OutputPower){
Serial.print(“Nudge 1 step\n”);
myMotor->step(1, Direction, MICROSTEP); //Move 1 step in the specified direction.
delay(200); //Wait 200 ms for debounce.

//setup(): This is executed first and only one time.
void setup()

while(!Serial); //Wait for the USB device to enumerate.
Serial.print(“Start Setup\n”);
AFMS.begin(); //Create with the default frequency 1.6KHz.
myMotor->setSpeed(0.025); //Set speed for 1/2 rotation per minute., 2, 1); //Setup external interrupt, the pin it’s associated with that we’re using, and enable the pull-up.
Dcc.init( MAN_ID_DIY, 10, CV29_ACCESSORY_DECODER, 0 );//Call the main DCC init function to enable the DCC receiver.

Serial.print(“Setup Over\n”);

Just when I thought I was completely done laying new track, here’s the new length of track with the glue still drying (and the foundation of the engine shed to ensure proper clearance):

I still need to add feeders to power this length of track, and you can see in the second photo where I added a facing bit of track on the far side of the turntable, which has no other purpose except to hold a buffer stop so engines won’t fall off. That will not be powered, for obvious reasons.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s