Thanks for your post. Despite some complexity to your
project, positioning the turntable using Accelstepper library is very doable.
Unfortunately, because there are many factors involved, without the whole
program(sketch) in its entirety it will be very difficult to give an effective
response.
Because you have the basic setup working and based on the information you have given FWIW I offer a couple of observations which may or may not be influencing the issue.
1. The ‘while’ run loop is busy. Even though you tested without it, lcd.read()
could still be an issue. There are other ways to minimise or elliminate
potential stepping issues.
2. The PKP246MD15A2 motor (NEMA 42) is rated at 1.5 A/Phase.
The DM556 driver lowest current
setting is: Peak 2.1A / RMS 1.5A
Your dip switch settings should be:
1=ON, 2=OFF, 3=OFF, 4=ON, 5=OFF, 6=ON, 7=OFF, 8=ON.
Excessive current can magnetically
saturate the motor's core, which can reduce the effective torque.
Check if the motor is getting hot
after running for some time.
3. The PKP246MD15A2 motor is rated at 116 oz-in max holding
torque that’s only ≈ 167 grams of force at a 50 cm radius.
EXAMPLE Torque calculation:
Assuming you are direct driving a 1 metre diameter turntable accomodating 40
tracks which has a certain mass and then add the mass of a train engine giving,
lets say a conservative total of 1000gms at 50cm then allow for 25% motor and
transmission losses you end up with a force of ~ 100gms pushing a 1000gm mass. Even
though your acceleration is low at 30 m/s/s the motor may still be unable to
handle it and there could be the potential for missed steps during the
acceleration phase. Check for missed steps by running a dedicated step counting
function or sketch.
4. Also, keep in mind the maximum speed (stepping rate) for an UNO/Red board is only ~4000 steps/sec.
Thanks Andris,
I can see one issue straight away. I’ve attached an image of one of my DM556 drivers and you will see the dip switch settings are different. I suspect your driver should have the same settings as mine printed on your driver, it would explain why you are getting 3200 steps/rev when you try to set it for 6400.
I have included a test program (adapted roughly from the 'Bounce' example) to independantly check your setup for missed steps, it’s pretty self explanatory. It will also verify the step resolution setting of your driver. The serial monitor output will only show the step count coming from the driver. It won’t tell you if there is a missed step, that can only be detected by observing the turntable reaching each of its targets and returning accurately to the starting point ie ‘step 0’.
I have tested this program successfully with an identical
setup, red board mcu, nema 42 motor, DM556 driver.
To get an accurate picture of what is happening try it with different settings,
speed, acceleration, steps/rev, etc… and observe for missed steps which can be
caused by mechanical, motor driver fault, noise on the ground plane (more on
that later) and software issues. While you verify your setup I’ll have a look
at your code which, BTW does not appear to be attached.
Yes, a button tripping an ‘interrupt’ can be used to stop
the turntable at any time, if you would like help with that let me know.
```
#include <AccelStepper.h>
// Define pin connections
const int stepPin = 2; // Connect to STEP on DM556D
const int dirPin = 3; // Connect to DIR on DM556D
// Create stepper instance
// AccelStepper::DRIVER means Step/Dir interface (1 = step, 2 = direction)
AccelStepper stepper(AccelStepper::DRIVER, stepPin, dirPin);
// Motor parameters
const int stepsPerRev = 3200;
const int stepsPerTrack = 80;
// Track Target positions
const long track1 = stepsPerTrack; // 80 steps
const long track10 = stepsPerTrack * 10; // 800 steps
const long track19 = stepsPerTrack * 19; // 1520 steps
const long track31 = stepsPerTrack * 31; // 2480 steps
const long track40 = stepsPerTrack * 40; // 3200 steps
// Step count variables
long track1_StepCount = 0;
long track10_StepCount = 0;
long track19_StepCount = 0;
long track31_StepCount = 0;
long track40_StepCount = 0;
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("=== AccelStepper Bounce Test ===");
Serial.println("Starting position: 0");
// Configure stepper
stepper.setMaxSpeed(100);
stepper.setAcceleration(50);
stepper.setCurrentPosition(0);
// Bounce Cycle 1: 0 -> track1 -> 0
Serial.println("\n--- Bounce 1: Track 1 ---");
stepper.moveTo(track1);
runToTargetAndCount(track1_StepCount);
stepper.moveTo(0);
runToTargetAndCount(track1_StepCount);
// Bounce Cycle 2: 0 -> track10 -> 0
Serial.println("\n--- Bounce 2: Track 10 ---");
stepper.moveTo(track10);
runToTargetAndCount(track10_StepCount);
stepper.moveTo(0);
runToTargetAndCount(track10_StepCount);
// Bounce Cycle 3: 0 -> track19 -> 0
Serial.println("\n--- Bounce 3: Track 19 ---");
stepper.moveTo(track19);
runToTargetAndCount(track19_StepCount);
stepper.moveTo(0);
runToTargetAndCount(track19_StepCount);
// Bounce Cycle 4: 0 -> track31 -> 0
Serial.println("\n--- Bounce 4: Track 31 ---");
stepper.moveTo(track31);
runToTargetAndCount(track31_StepCount);
stepper.moveTo(0);
runToTargetAndCount(track31_StepCount);
// Bounce Cycle 5: 0 -> track40 -> 0
Serial.println("\n--- Bounce 5: Track 40 ---");
stepper.moveTo(track40);
runToTargetAndCount(track40_StepCount);
stepper.moveTo(0);
runToTargetAndCount(track40_StepCount);
// Report results
Serial.println("\n========== RESULTS ==========");
Serial.print("Track 1 Total Steps: "); Serial.println(track1_StepCount);
Serial.print("Track 10 Total Steps: "); Serial.println(track10_StepCount);
Serial.print("Track 19 Total Steps: "); Serial.println(track19_StepCount);
Serial.print("Track 31 Total Steps: "); Serial.println(track31_StepCount);
Serial.print("Track 40 Total Steps: "); Serial.println(track40_StepCount);
Serial.println("=============================");
Serial.println("\nTest Complete!");
}
void loop() {
// Nothing runs in loop
}
// Function to run motor to target and count steps
void runToTargetAndCount(long &stepCounter) {
long startPos = stepper.currentPosition();
while (stepper.distanceToGo() != 0) {
stepper.run();
}
long endPos = stepper.currentPosition();
long stepsTaken = abs(endPos - startPos);
stepCounter += stepsTaken;
Serial.print("Target: "); Serial.print(stepper.targetPosition());
Serial.print(" | Steps taken: "); Serial.print(stepsTaken);
Serial.print(" | Current position: "); Serial.println(endPos);
}
```