STEPPER motor 57HS76 + TB6600 + Pot.

Hi all,

I bought the motor (57HS76) and the driver (TB6600) - I need to regulate the speed with the potentiometer. Since the possible minimum speed to the maximum possible .. I tried this: http://blog.hobbycomponents.com/?p=460

someone you do not know how to modify the code?

Thank you...

Sorry for my English, i am from CzechRepublic. :)

You need to post your code and tell us what it actually does and what you want it to do that is different.

Also post a link to the datasheet for your stepper motor.

You may find some useful stuff in these links Stepper Motor Basics Simple Stepper Code

If you look at the program code you will see a variable called (IIRC) millisBetweenSteps. To get variable speed you can use your potentiometer to change that value.

...R

Thank you for the links .... I need to go to regulate motor speed from the lowest to the highest I .. potentiometer connected.

/* Include the library */
#include "HCMotor.h"

/* Pins used to drive the motors */
#define DIR_PIN 8 //Connect to drive modules 'direction' input.
#define CLK_PIN 9 //Connect to drive modules 'step' or 'CLK' input.

/* Set the analogue pin the potentiometer will be connected to. */
#define POT_PIN A0

/* Set a dead area at the centre of the pot where it crosses from forward to reverse */
#define DEADZONE 20 

/* The analogue pin will return values between 0 and 1024 so divide this up between 
  forward and reverse */
#define POT_REV_MIN 0
#define POT_REV_MAX (512 - DEADZONE)
#define POT_FWD_MIN (512 + DEADZONE)
#define POT_FWD_MAX 1024


/* Create an instance of the library */
HCMotor HCMotor;



void setup() 
{
 //Serial.begin(9600);
 /* Initialise the library */
 HCMotor.Init();

 /* Attach motor 0 to digital pins 8 & 9. The first parameter specifies the 
    motor number, the second is the motor type, and the third and forth are the 
    digital pins that will control the motor */
 HCMotor.attach(0, STEPPER, CLK_PIN, DIR_PIN);

 /* Set the number of steps to continuous so the the motor is always turning whilst 
    not int he dead zone*/
 HCMotor.Steps(0,CONTINUOUS);
}


void loop() 
{
 int Speed, Pot;

 /* Read the analogue pin to determine the position of the pot. */
 Pot = analogRead(POT_PIN);

 /* Is the pot in the reverse position ? */
 if (Pot >= POT_REV_MIN && Pot <= POT_REV_MAX)
 {
   HCMotor.Direction(0, REVERSE);
   Speed = map(Pot, POT_REV_MIN, POT_REV_MAX, 10, 1024);

 /* Is the pot in the forward position ? */
 }else if (Pot >= POT_FWD_MIN && Pot <= POT_FWD_MAX)
 {
   HCMotor.Direction(0, FORWARD);
   Speed = map(Pot, POT_FWD_MIN, POT_FWD_MAX, 1024, 10);

 /* Is the pot in the dead zone ? */
 }else
 {
   Speed = 0;
 }

 /* Set the duty cycle of the clock signal in 100uS increments */
 HCMotor.DutyCycle(0, Speed);

}

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

I am not familiar with the stepper library you are using. Have you considered the AccelStepper library?

…R

Pls post your schematics: a) driver (settings) b) Arduino - driver - motor - potentiometer - power supply connections

Here is schematic:

Motor:

https://www.aliexpress.com/item/80mm-CNC-4th-Axis-Tailstock-CNC-dividing-head-Rotation-Axis-A-axis-for-Mini-CNC-router/2011334031.html

AccelStepper library - I have no experience ... still make use of it, if the drive will work according to my ideas. :)

---the motor should have 330 rev / min.

The stepper code I linked to in Reply #1 should be suitable for testing. It does not use any library.

...R

Can you tell us, what your motor does, or doesn't when you run the sketch? Plus: what power supply do you use for the motor?

"I need some simple program - speed adjustment potentiometer - rev min revolutions to the maximum ..and to allow adjustment step."

Now I can set the desired speed range.

Ucc supply for motor is 24 DC.

So you say it works now?

Not to my liking :smiley:

Unable to set full speed range (0 - max speed) and can not set up jogging.

I have modified the sketch so that it works with my favorite stepper library (AccelStepper), which you can find here:
Download AccelStepper library

And here is my sketch (Arduino pins A0 to potentiometer, 5 and 6 to motor driver):

/* Include the library */
#include <AccelStepper.h>

// Initialize motor pins (1 = setup with stepper driver)
AccelStepper stepper(1, 5, 6);  // step pin = 5, dir pin = 6

/* Set the analogue pin the potentiometer will be connected to. */
#define POT_PIN A0

/* Set a dead area at the centre of the pot where it crosses from forward to reverse */
#define DEADZONE 20

/* The analogue pin will return values between 0 and 1024 so divide this up between
   forward and reverse */
#define POT_REV_MIN 0
#define POT_REV_MAX (512 - DEADZONE)
#define POT_FWD_MIN (512 + DEADZONE)
#define POT_FWD_MAX 1024



void setup()
{
  /* Set the number of steps to continuous so the the motor is always turning whilst
     not int the dead zone*/
  stepper.setMaxSpeed(4000);
  stepper.setSpeed(0);
}


void loop()
{
  int Speed, Pot;

  /* Read the analogue pin to determine the position of the pot. */
  Pot = analogRead(POT_PIN);

  /* Is the pot in the reverse position ? */
  if (Pot >= POT_REV_MIN && Pot <= POT_REV_MAX)
  {
    Speed = map(Pot, POT_REV_MIN, POT_REV_MAX, 3000, 10);
    stepper.setSpeed(-Speed);
    stepper.runSpeed();

    /* Is the pot in the forward position ? */
  } else if (Pot >= POT_FWD_MIN && Pot <= POT_FWD_MAX)
  {
    Speed = map(Pot, POT_FWD_MIN, POT_FWD_MAX, 10, 3000);
    stepper.setSpeed(Speed);
    stepper.runSpeed();

    /* Is the pot in the dead zone ? */
  } else
  {
    Speed = 0;
  }
}

I set MaxSpeed to 4000 because this is the limit of AccelStepper. In the Speed command I only go up to 3000, but you could go up to 4000 here.

Unable to set full speed range (0 - max speed) and can not set up jogging.

What exactly do you mean by that?

How is your driver setting for microsteps?

Start with "FullStep" - in combination with the maximum speed pulses from the Arduino this is the max speed you can gain. If Arduino sends 1000 pulses/sec and you are in full step mode, your motor will turn: 1000 / 200 * 60 = 300 RPM.

If you set the driver to 1/4 microstepping, the speed will decrease to: 1000 / 200 / 4 * 60 = 75 RPM.

Ucc supply for motor is 24 DC.

.. and how many amps can it deliver?

Current is 1,2 A, this is about 330 RPM ?

I need a code that will only vary continuously speed from min. max. revolutions. With description and to change jog. ... I do not want there changing the polarity of revolutions.

Speed setting from zero to maximum (0 RPM - 300 RPM ??? )

...And I need to run was clean (infinitely adjustable) - 4800 microstep ?.

Current is 1,2 A, this is about 330 RPM ?

Stepper motors are driven by steps or pulses (that's why they are named stepper motors). The current determines the torque at a given speed, but you can't drive a stepper by just controlling the current and the current needs to be pulsed and each pulse causes the stepper go one step (in full step mode).

Did you read Robin2's two links about steppers?

Your motor needs far more current than 1,2A. The datasheet talks about 3A! Normally it will already turn at that value but you won't get the torque that is possible with your motor.

So again: 1. please set the driver settings to "full step" = 1/1 mode (dip switch settings) 2. set the current limit to a value close to the power supply's limit - if you can go with another power supply which can deliver 3A or more (at 24V), you could e.g. set the current limit to 2.5 or 3A - but not more!! 3. Run either Robin2's simple stepper sketch, which needs no library or go with the one which I posted - but you will need the AccelStepper library for that sketch. Don't forget to adjust the step/dir pins to the ones which you are using.

When the stepper works after having used the AccelStepper library sketch, you can play with adjusting the microstepping. But: microstepping gives you a smoother run (and noise) of the stepper motor, but it will decrease the maximum speed. Look at the example in my previous post.

Thank you for your message.

Yes, contributions from Robin2 I read.

Motor current limit - for example I have set for me.

so: 1. I set to full step. 2. I'll try to set a second more. 3. I tried to run a third "stepper sketch" - everything worked as it should.

..I am trying to modify existing code to remove the inverted motor ... need only one continuous direction, adjustable potentiometer ... and I can not.

Kaniiisek: ..I am trying to modify existing code to remove the inverted motor ...

What existing code?

Do you mean the code that "worked as it should"? It is usually easier to develop a successful solution starting from something that works.

In any case please post the latest version that you are having trouble with.

...R

I do not have much programming experience, so I try to modify existing code .... I just need to control the motor via a potentiometer for setting parameters ... and I still did not work.

Could I trouble you for a demonstration of a simple code with a potentiometer without reversing?

Kaniiisek: Could I trouble you for a demonstration of a simple code with a potentiometer without reversing?

I wonder how many hours of thinking you have really put into trying to solve this.

Following is a version of the second example in my Simple Stepper Code with some extra code (marked // NEW) to take an input from a pot and alter the speed.

// testing a stepper motor with a Pololu A4988 driver board or equivalent

// this version uses millis() to manage timing rather than delay()
// and the movement is determined by a pair of momentary push switches
// press one and it turns CW, press the other and it turns CCW

// updated 17 Oct 2016 to include input from a potentiometer on A0
//   potentiometer should vary millisBetweenSteps from 1050 to 27
//     NOT TESTED

byte directionPin = 9;
byte stepPin = 8;

byte buttonCWpin = 10;
byte buttonCCWpin = 11;

boolean buttonCWpressed = false;
boolean buttonCCWpressed = false;

byte ledPin = 13;

unsigned long curMillis;
unsigned long prevStepMillis = 0;
unsigned long millisBetweenSteps = 25; // milliseconds

byte potPin = A0; // NEW
int potval;       // NEW
unsigned long slowMillisBetweenSteps = 1050;  // NEW

void setup() {

  Serial.begin(9600);
  Serial.println("Starting Stepper Demo with millis()");

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
  pinMode(buttonCWpin, INPUT_PULLUP);
  pinMode(buttonCCWpin, INPUT_PULLUP);
  millisBetweenSteps = slowMillisBetweenSteps;   // NEW
}

void loop() {

 curMillis = millis();
 readButtons();
 readPotentiometer(); // NEW
 updateInterval(); // NEW
 actOnButtons();

}

void readButtons() {

 buttonCCWpressed = false;
 buttonCWpressed = false;

 if (digitalRead(buttonCWpin) == LOW) {
 buttonCWpressed = true;
 }
 if (digitalRead(buttonCCWpin) == LOW) {
 buttonCCWpressed = true;
 }
}

void actOnButtons() {
 if (buttonCWpressed == true) {
 digitalWrite(directionPin, LOW);
 singleStep();
 }
 if (buttonCCWpressed == true) {
 digitalWrite(directionPin, HIGH);
 singleStep();
 }
}

void singleStep() {
 if (curMillis - prevStepMillis >= millisBetweenSteps) {
 prevStepMillis += millisBetweenSteps;
 digitalWrite(stepPin, HIGH);
 digitalWrite(stepPin, LOW);
 }
}

void readPotentiometer() {     // NEW
    potVal = analogRead(potPin);
}

void updateInterval() {        // NEW
    millisBetweenSteps = slowMillisBetweenSteps - potVal;
}

...R