Nema23+tb6600 what code do i need to change

hi,i want to use the accellstepper bounce sketch to run a nema23 stepper motor with a tb6600 to drive it,i understand that the sketch must be altered to stepper mode 1?,so what in the bounce sketch do i need to alter for it to work?,i want to use the accellstepper bounce example,i am using ide ver 1.8.18.

Post the sketch to which you refer, and its source.

`type or paste code here`


thats a screenshot of the code,its the accellstepper example bounce sketch from ide18.18 untouched,i did try to paste the code but for some reason it dont give the option when i right click,several yt vids ive seen say the bounce code needs a couple of lines adding for it to work with a tb6600,its not clear what code they refer to tho!,i just need to know what code to add ok.

// 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; // 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.moveTo(500);
}

void loop()
{
    // If at the end of travel go to the other end
    if (stepper.distanceToGo() == 0)
      stepper.moveTo(-stepper.currentPosition());

    stepper.run();
}

hope that helps?.

You may find this documentation for AccelStepper to be useful

I think that for the TB6600 which is a step/dir driver you want the setup to look like this

//Example using a driver that accepts step/direction input. An enable pin is not used so enable = true (the default) need not be specified.
// Define pin connections
const int dirPin = 4;
const int stepPin = 5;
// Creates an instance
AccelStepper myStepper(AccelStepper::DRIVER, stepPin, dirPin);

this is text copyied from the dronebots webpage"A good demonstration sketch is the Bounce sketch from the
AccelStepper example sketches.

You will need to modify one line in the sketch (and all of the demo sketches) to setup the stepper
object correctly.
Modify the AccelStepper line as follows to use it with the hardware that we already wired up:
AccelStepper stepper(1,7,6);

This line sets up AccelStepper in “mode 1”, which is the correct mode for using microstep driver
modules. The “7” and “6” refer to the Arduino pins used for the direction (DIR) and pulse (PUL)
connections", Its this i need explaining as i dont see what lines of code to change in the bounce sketch ok..

DroneBotWorkShop has no mistakes. Follow it verbatim.

Open the "bounce.ino" sketch
IDE >> FILES >> EXAMPLES >> ACCELSTEPPER >> bounce.ino

Find this line:

AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

As you noted, change it to:

AccelStepper stepper(1, 7, 6); // mode, dir, pul

great now how do i add a pot for speed control,i can use A0 pin i assume but what about the code?,thanks in advance.

What about it?

VCC, GND and wiper to A0. Change speed when A0 changes.

Try this simple mod, compiles but untested.

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper(1, 7, 6); // mode, dir, pul

void setup()
{  
  // Change these to suit your stepper if you want
  stepper.setMaxSpeed(100);
  stepper.setAcceleration(20);
  stepper.moveTo(500);
}

void loop()
{
    int speedVal = map(analogRead(A0),0,1023,10,1000);
    stepper.setMaxSpeed(speedVal);
    
    // If at the end of travel go to the other end
    if (stepper.distanceToGo() == 0)
      stepper.moveTo(-stepper.currentPosition());

    stepper.run();
}

I think the OP is using dir, pul on 7, 6.

Fixed, look right?

Tank for the codes.

so what code do i need for bounce to work with my tb6600 with a speed control pot then,it seems a bit sort of mixed up with the replys,i changed the code for the tb6600 as instructed(not tested yet tho) the adding the pot part is not clear,thanks Paul.

anyone?.

  1. Do not bump your topic.
  2. You are not trying suggestions, why should anyone else try?

Did you try the AccelStepper ProportionalControl example? If you can get that to work, then the connections should be working.

// 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; // (3, 5, 6); // mode, dir, pul

void setup()
{  
  // Change these to suit your stepper if you want
  stepper.setMaxSpeed(100);
  stepper.setAcceleration(20);
  stepper.moveTo(500);
}

void loop()
{
    // If at the end of travel go to the other end
    if (stepper.distanceToGo() == 0)
      stepper.moveTo(-stepper.currentPosition());

    stepper.run();
}
And now for my nest issue i have uploaded the above code to a nano,, I have an led+dropping resistor between gnd and pin 5 the led goes thru a cycle of blinking slowly then speeding up so its like fully on then it just repeats,its as if its reading the pulse not direction,any ideas?.