Hello all,
im trying to get a Stepper Motor (Nema 17, TMC2208 Driver) to move to a position provided by DCS-BIOS. With the following code the stepper kinda jitters while the input number is changing, and moves about 45° (in the correct direction) when the input number switches from 0 to 65535 or the other way round. Heres the code (keep in mind i have almost no idea what im doing ;)).
The Stepper should move to any position, as directed by the unsigned Integer, so the 12oclock position is 0, the 6 oclock positions is 32.767, etc.
(I think) i used the map() to "translate" the input into the range of the stepper (200 steps per full rotation).
Sounds reasonable. Does your driver have some sort of microstepping enabled? if microstepping is involved, maybe you need map your 45° to 360° with 8* the steps?
There is nothing connected to the MS1 and MS2 pins on the driver board, so microstepping should be disabled. In prior tests the stepper moved to the correct positions with 200 steps as a reference
...slightly modified to match your code like this:
// Bounce.pde
// -*- mode: C++ -*-
//
// Make a single stepper bounce from one limit to another
//
// Copyright (C) 2012 Mike McCauley
// $Id: Random.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper(1,3,4) ; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
void setup()
{
// Change these to suit your stepper if you want
stepper.setMaxSpeed(100);
stepper.setAcceleration(20);
stepper.setCurrentPosition(-100);
stepper.moveTo(100);
}
void loop()
{
// If at the end of travel go to the other end
if (stepper.distanceToGo() == 0)
stepper.moveTo(-stepper.currentPosition());
stepper.run();
}
...make your indicator bounce smoothly between extremes?
Turns out you where right after all! Apparently for some reason microstepping is enabled. Ive set the map() to output 1600, and now it works! Well, almost. No i have the problem that, when the Value goes from 65535 to 0, the stepper does a 359° turn to match the new position, instead of continuing the turn. Any tips how to combat that?
It works! i put in -800 and 800 as xxx and yyy.
My next challenge will be to make it more accurate, as it stands now the needle drifts quite alot at lower speeds. Either ill get my Hall sensor to work to continously re-zero it, or ill get an (expensive) closed loop stepper after all.
Thank you very much, as i said i have 0 coding experience, i wouldve never figured it out on my own.