AccelStepper and DCS-BIOS

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 ;)).

#define DCSBIOS_DEFAULT_SERIAL
#include "DcsBios.h"
#include "AccelStepper.h" 
AccelStepper stepper(1,3,4);

int val = 0;
int AltNeedle = 0;

void onPltAltimeterNeedleChange(unsigned int newValue) {
    AltNeedle = map(newValue, 0, 65535, 0, 200);
}
DcsBios::IntegerBuffer pltAltimeterNeedleBuffer(0x133c, 0xffff, 0, onPltAltimeterNeedleChange);

void setup() {
  DcsBios::setup(); 
  stepper.setMaxSpeed(1000);
  stepper.setAcceleration(1000);
  
}

void loop() {
    DcsBios::loop();
    stepper.moveTo(AltNeedle);
    stepper.run();
    
  }

Any advise would be appreciated.

http://dcs-bios.a10c.de/

This looks like you are using a driver of some sort:

And it moves both ways with some consistency, which sounds like you've got it connected properly.

What is the problem? Does it lose position? Is 45° not enough motion?

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?

AltNeedle = map(newValue, 0, 65535, 0, 200*8);

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

Would this

https://www.airspayce.com/mikem/arduino/AccelStepper/Bounce_8pde-example.html

...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?

That's great.

The other problem is trickier. I think about changing this function:

to be richer.

It needs to remember what the newValue was before, and deal with the history.

Maybe something like this completely untested code:

void onPltAltimeterNeedleChange(unsigned int newValue) {
   static unsigned int oldValue = 0;
   int change = (int)(newValue - oldValue); 
   //AltNeedle += map(change,-32767,32768,xxx,yyy);   
   AltNeedle += map(change,-32768,32767,xxx,yyy);   
   oldValue = newValue;
}

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.

Oops -- the int max and min are wrong -- Should be: -32768,32767 per:

I'll edit my code.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.