Turntable VIII: Microstepped

Trying to get the turntable to rotate more slowly while remaining smooth turned out to be a challenge. When slowed down, it began ticking like a clock with enough torque that it would likely have flicked an engine off the deck. My brother-in-law and I spent a couple of hours last night trying to figure out a solution, to no avail. After that I stayed up way too late digging through Arduino forums, trying to figure out how to add a microstepping sequence to break up the “tick-tock” movement into much smaller waves. I went to bed thinking all that research was for nothing.

When I woke up this morning, though, I had the sudden idea that maybe the Adafruit motor shield has a library with a microstepping sequence already loaded. This would save us from having to make calculations and then pull in (or invent) strings of compatible code from other sources. So, after a quick reread on Adafruit’s informational website I verified that, indeed, the Adafruit is already programmed to run a microstep sequence.

Lo and behold, all I did was replace instances of “Single” with “Microstep,” uploaded the code to the Arduino, and suddenly the turntable is slow moving and smooth.

Here’s a video of the turntable moving slowly and smoothly.

I think we can adjust the code further to give the turntable a more realistic appearance by accelerating and decelerating the deck every time it moves. For now, though, I am happy with how it functions, so am posting the code here in case anyone else can make use of it:

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

#define DCC_ADDRESS 6 //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(“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.
Dcc.pin(0, 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”);

//loop(): If the DCC function detects a signal, it will call notifyDccAccTurnoutOutput on its own.
void loop()
if (firstloop) { Serial.print(“First Loop\n”); firstloop = false;}
Dcc.process(); //Calling this method makes the DCC shield check for new communications. It must be frequent or a message may be missed.
//myMotor->step(200, FORWARD, DOUBLE); //Move 180 degrees in the specified direction.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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