Thanks to MarkT , we changed Motorshield Rev3 with TB6600. But now we cant find an easy connection diagram to connect Uno R3 and TB6600 together. Would anyone care to direct me to proper link that I can easily connect these 2?
pwmA = 3;
pwmB = 11;
brakeA = 9;
brakeB = 8;
These are the pin numbers I am using in my program. But TB6600 has En+,En+, DIR+,DUR-, PUL+ and PUL- signs on it. Some sources say connect all negatives (EN-,DUR-,PUL-) to GND pins of Ardunio. Any pin that GND sign on it can be used? What about positives + (EN+,PUL+ and DIR+) ?
And this is my program. Not yet converted for 200 steps.
#include <Stepper.h>
const int stepsPerRevolution = 40; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on the motor shield
Stepper myStepper(stepsPerRevolution,12,13);
// give the motor control pins names:
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
int previous = 0;
void setup() {
Serial.begin(9600);
// set the PWM and brake pins so that the direction pins // can be used to control the motor:
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);
// initialize the serial port:
Serial.begin(9600);
// set the motor speed (for multiple steps only):
//myStepper.setSpeed(500);
}
void loop() {
//Get Motor up to 500 speed and turn 500 times / Total turns 2030
myStepper.setSpeed(400);
myStepper.step(30);
myStepper.setSpeed(500);
myStepper.step(2000);
//Slow Motor down and stop
myStepper.setSpeed(300);
myStepper.step(10);
myStepper.setSpeed(200);
myStepper.step(10);
myStepper.setSpeed(100);
myStepper.step(10);
delay(1000);
//Get Motor up to 500 speed and turn 500 times / Total turns 2030
myStepper.setSpeed(400);
myStepper.step(-30);
myStepper.setSpeed(500);
myStepper.step(-2000);
//Slow Motor down and stop
myStepper.setSpeed(300);
myStepper.step(-10);
myStepper.setSpeed(200);
myStepper.step(-10);
myStepper.setSpeed(100);
myStepper.step(-10);
delay(1000);
}
DenizYILDIZ:
if I am gonna use accelstepper then I need only to connect Pin 9 to DIR+ and Pin 8 to PUL+ and others to GND pins on Aurdino Uno R3?
And should I connect EN+ to anywhere on Aurdino Uno R3 board? Thanks
Those pin connections should be correct for my code. You can use any pins you like (other than 0 and 1) as long as the code matches the connections.
The accelStepper setup would be myStepper(1,stepPin,dirPin)
I'm not sure from the gobbledygook in the data sheet whether EN+ needs to be connected or whether it should be connected to 5v or GND. You will need to experiment. Start without connecting it.
Ok Robin thnx. I found this site that tells the connection between TB6600 and Raspberry Pi. And ofcourse Uno is different but the logic may be same with different pin numbers.
He connected EN+ to 5V or GND ( he said doesnt matter even Raspberry works 3.3V) And he connected DIR+ to GPIO 18 which is direction pin of Raspberry Pi. and PUL+ was connected to GPIO 23 which is pulse pin of Raspberry Pi. Others were connected to GND
Before last check, I must be sure about Ardunio Uno R3's pin numbers for direction and pulse(step) pins. As you said pin 9 is for direction and pin 8 for pulse(step).
TB6600Ardunio UNO R3
DIR+ >>>>>>>>> PIN 9
PUL+ >>>>>>>>> PIN 8
EN+ >>>>>>>>> 5V or GND (Either will be tested)
DIR- >>>>>>>> GND
PUL- >>>>>>>> GND
EN- >>>>>>>> GND
Am I right with this connection table? And how Uno R3 gets its power? Do I need extra powersupply or PIN will do that?
His code for Raspberry Pi+TB6600+Stepper motor
#!/usr/bin/python
#
# Written by Haydn Huntley (huntley@nlogn.com) on 08/16/2013.
# Feel free to use this code any way you want.
# Runs on a Raspberry Pi and drives an HY-DIV268N-5A stepper motor controller.
#
# Note: this program must be run as root in order to use the GPIO calls.
import time
import RPi.GPIO as GPIO
enablePin = 4 # Note enable is active low!
directionPin = 18
pulsePin = 23
pulseState = 0
delay = 0.000001 # 1 microsecond
def setup():
GPIO.setmode(GPIO.BCM)
GPIO.setup(enablePin, GPIO.OUT)
GPIO.setup(directionPin, GPIO.OUT)
GPIO.setup(pulsePin, GPIO.OUT)
GPIO.output(enablePin, 0)
return
def forward(steps):
global pulseState
print "forward delay=%0.3fms steps=%d" % (delay * 1000, steps)
GPIO.output(directionPin, 1)
for i in range(steps):
pulseState += 1
GPIO.output(pulsePin, pulseState % 2)
time.sleep(delay)
pulseState %= 2
return
def backwards(steps):
global pulseState
print "backwards delay=%0.3fms steps=%d" % (delay * 1000, steps)
GPIO.output(directionPin, 0)
for i in range(steps):
pulseState += 1
GPIO.output(pulsePin, pulseState % 2)
time.sleep(delay)
pulseState %= 2
return
def main():
# For the NEMA 14 12v 350mA (#324) stepper motors from AdaFruit:
# http://www.adafruit.com/products/324
# Driving it with 12v using a delay of 1 microsecond.
revolutions = 3
steps = revolutions * 200 * 16
setup()
forward(steps)
time.sleep(0.5)
backwards(steps)
GPIO.cleanup()
return
try:
main()
except:
print "something went wrong!"
GPIO.cleanup()
raise
GPIO.cleanup()
exit(0)
Then I found another code. This time driver sends pulses but no motor movement. Actually it is trying. It is trying to take a step but no spinning.
//Arduino Sketch based on easy driver
int dirpin = 8;
int steppin = 9;
int enable = 7;
void setup()
{
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
digitalWrite(enable, LOW);
}
void loop()
{
int i;
digitalWrite(dirpin, HIGH); // Set the direction.
delay(100);
for (i = 0; i<4000; i++) // Iterate for 4000 microsteps.
{
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
delayMicroseconds(400);
digitalWrite(steppin, HIGH);
delayMicroseconds(400); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.
digitalWrite(dirpin, LOW); // Change direction.
delay(100);
for (i = 0; i<4000; i++) // Iterate for 4000 microsteps
{
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
delayMicroseconds(400);
digitalWrite(steppin, HIGH);
delayMicroseconds(400); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.
}