How to test a TB6600 Stepper Motor Driver Controller and stepper motor. I made this as i am making my own CNC machines and software to control them. So needed to work out how the TB6600 worked. To control motor type in commands in Serial Monitor, Set speed and steps follow instruction in Serial. Apr 08, 2019 Arduino Uno Nema 23, DM542T Driver, Control. Arduino Forum Using Arduino Motors, Mechanics. I am working on a project which requires precise control of a stepper motor and I am starting to encounter problems as I begin developing the proper code. // initialize the serial port: Serial.begin(9600).
Arduino sketch to allow control of stepper motor using the serial connection and an Adafruit Motor Shield V2 Based on http://forum.arduino.cc/index.php/topic,44526.0.html Enter the number of steps for the motor to take on the serial monitor, negative for forward,and end with a semicolon.
ArduinoSerialStepper.ino
/* |
Sketch to allow control of stepper motor using the serial connection |
and an Adafruit Motor Shield V2 |
Based on http://forum.arduino.cc/index.php/topic,44526.0.html |
Enter the number of steps for the motor to take on the serial monitor, |
negative for forward,and end with a semicolon. |
James Ritchie - github.com/JamesRitchie |
*/ |
#include<Wire.h> |
#include<Adafruit_MotorShield.h> |
//Shield and motor objects |
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); |
Adafruit_StepperMotor *motor = AFMS.getStepper(200,2); |
boolean packetEnded = false; |
boolean backward = false; |
int steps = 0; |
voidsetup() { |
Serial.begin(9600); |
//Initialize shield and set motor speed to 100rpm |
AFMS.begin(); |
motor->setSpeed(100); |
} |
voidloop() { |
while(Serial.available() > 0){ |
//Read each character, check if negative, end of command or |
//digit, and adjust step value accordingly |
char aChar = Serial.read(); |
if(aChar '-'){ |
backward = true; |
} |
elseif(aChar ';'){ |
packetEnded = true; |
} |
elseif(aChar >= '0' && aChar <= '9'){ |
steps *= 10; |
steps += aChar -'0'; |
} |
} |
if(packetEnded){ |
//Perform steps |
if(backward){ |
Serial.print(steps); |
Serial.println(' Steps Backward'); |
motor->step(steps, BACKWARD, SINGLE); |
} |
else{ |
Serial.print(steps); |
Serial.println(' Steps Forward'); |
motor->step(steps, FORWARD, SINGLE); |
} |
//Reset control values. |
steps = 0; |
backward = false; |
packetEnded = false; |
} |
} |
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment