How to stepper motor control with driver TB6560 and Arduino Rotary Encoder
ฝัง
- เผยแพร่เมื่อ 19 พ.ค. 2019
- How to stepper motor control with driver TB6560 and Arduino Rotary Encoder
A rotary encoder is a type of position sensor which is used for determining the angular position of a rotating shaft.
In this tutorial, we will learn how to control a stepper motor, with driver TB6560 and rotary encoder with arduino processor. The motor is moved when detecting motion of the encoder.
Can be heavily applied in your DIY projects.
Please subscribe DIY Channel and share, motivate us to make useful videos
Thank you for watching the video - แนวปฏิบัติและการใช้ชีวิต
great!!!
Great video dear. Can u please put a link of Code in the discription? Thanks dear it helps a lot
Do the cables that were soldered to the encoder go directly to the two ports of the arduino together with the ground, or is there any protection?
Make video using all these tb6560 driver arduino uno encoder encoder disk
and potentiometer also for speed controlling
Hey. I am a subscriber to your channel. A very interesting video about creating a tablet printer. Can you drop me a sketch to control the table?
Great video,, question ,,, which part goes to the printer to get power from?
are also powered from outside
Good video Pls tell limit switch npn sensor push botton how to working pls new video
ok
@@DIYInkJet u r code is super working my epson l1800 dtg how to limit switch 2 with in push botton, out push botton, stop push botton how to add this code pls help
@@DIYInkJetneed u r code too. Please send mrfai2000@gmail.com thanks
I don't see it hooked up with a diy dtg printer,, will it communicate with the printer to print?
it is not used in dtg printer, please watch other video th-cam.com/video/jPHzJetT3Ns/w-d-xo.html
Hi. When you're going to leave the Arduino code, I'm running a little fast, thanks.
What is the major function of rotary optical encoders on HP M631 ADF ? is it responsible for motor stall ?
works correctly
hey bro awesome tutorial can you please share the Arduino code as well to study and implement
You can rewrite the code. We will share the code in the future.
@@DIYInkJet ok please do share
@@DIYInkJet please share bro. Where waiting. Tnx. Great video. Thats the video im looking for. Hope u could help us🙏🙂
@@havefun8962 please contact whatsapp: +84918219268
@@DIYInkJet hallo
I only have the microstep driver DM542-05. Does it still work?
yes no problem
@@DIYInkJet It means I tried your project. As the result, everything is the same except the driver that I mentioned above. However, it did not work.
@@DuyVu-dn8ss maybe you connected the wrong driver.
ITs the same with other driver. for example 6600?
yes
Hi . Can you tell me how i can add buttons to control the platen?
vui lòng kết nối whatsapp: +84918219268
Hi sir thk u for your awesome video. This code have some error. Can u please update new code
ok
Any one help how to add limit switch in out stop arduino codeing
Cool please sketch 🙏🙏🙏
Good job .if you can send me code Arduino pls
GOOD BROTHER GREETINGS BEFORE ALL THAT CODE I CAN USE IT WITH AN ARDUINO MEGA 2560 AND WITH A POLOLU 8825 DRIVER
use for tb6560
donde puedo obtener el código para la targete arduino
Hello
The number of turns is not the same ( motor of the printer and my stepper ) is that normal ?
i don't get problems in the futur ?
Thanks i appreciate your help
+ 1 Sebscriber
please contact whatsapp: +84918219268
Hi, you have the sketch code for downloading? Thank you
pls whatsapp (+84918219268)
@@DIYInkJet faile Arduino sensor disk???
Sent to e-mail
Syahrulanwar1992@gmail.com
Please send encoder diagram or tell which encoder you used
Is it okay to make that call even when it's plugged into the printer?
need more advanced programming to work well with the printer. please contact whatsapp +84 918219268
@@DIYInkJet unfortunately I don't know how to get in touch with you through whatsapp, I'm in Brazil and mine is +55 81 991474272 and the email: prepackembalagens@gmail.com.br I'm trying to develop something like that for me, any help will be very valuable . Thank you and stay with God!
very cool friend! how can i get the code for Arduino? sketch
Please contact whatsapp: +84 918219268
#define encoder_a 2 //keep this on and interrupt pin
#define encoder_b 3 //keep this on and interrupt pin #define motor_step 9 #define motor_direction 8 #define senzor_front 6 #define senzor_rear 7 #define load_button 4 #define eject_button 5 int home_position = 0; int load_position = 0; int pe_load = 0; void setup() { pinMode(encoder_a, INPUT); pinMode(encoder_b, INPUT); // disable pullup as we aren't using an open collector encoder digitalWrite(encoder_a, LOW); digitalWrite(encoder_b, LOW); //set up the various outputs pinMode(motor_step, OUTPUT); pinMode(motor_direction, OUTPUT); // then the senzors inputs pinMode(senzor_front, INPUT_PULLUP); pinMode(senzor_rear, INPUT_PULLUP); pinMode(load_button, INPUT_PULLUP); pinMode(eject_button, INPUT_PULLUP); } void loop() { // Control platen position of boot up and move to front if (home_position == 0) { digitalWrite(motor_direction, HIGH); TurnStepper(); if (digitalRead(senzor_front) == LOW) { home_position = 1; } } // eject platen if (digitalRead(eject_button) == LOW) { home_position = 0; } // load platen if (digitalRead(load_button) == LOW) { load_position = 1; } if (load_position == 1) { digitalWrite(motor_direction, LOW); TurnStepper(); if (digitalRead(senzor_rear) == LOW) { load_position = 0; pe_load = 1; } } } void TurnStepper() { digitalWrite(motor_step, HIGH); delayMicroseconds(40); //speed delay, the lower it is t digitalWrite(motor_step, LOW); delayMicroseconds(40); //speed delay, the lower it is the faster }
Second... Encoder A B +3.3v GND to belt drive
Quote:
#define encoder_a 2 //keep this on and interrupt pin
#define encoder_b 3 //keep this on and interrupt pin #define motor_step 4 //can be any pin #define motor_direction 5 //can be any pin volatile long motor_position, encoder; unsigned long WaitReverse = 200; //
mani raj i want to ask you..this code just works when the printer print or works begin from the printer is on..? I mean that I want this code works when the printer is printing only, when the printer is cleaning this code does not work..
hi. how have your projects been done?
Hi Interesting tutorial.. do you have the code for downloading Thanks
Please contact whatsapp: +84 918219268 or email willkaydesign@gmail.com
DIY Channel Will the stepper motor work forward and reverse?
@@woodengifts2472 yes
DIY Channel Hi I sent you an email could you send me the code please? Thanks Gary
how to stepper motor with sensor controller eye mark register ?
Please contact whatsapp +84 918219268
If I ask, would you share the codes you wrote?
If I ask, would you share the codes you wrote?
@@DIYInkJet
DO YOU SHARE THE CODES YOU WRITE?
@@DIYInkJet I USE GOOGLE TRANSLATION. NO ENGLISH.
good brother greetings that code only works for this driver tb6560 brother does not work with the pololu 8825 driver I have tried to simulate it with the 8825 driver and it does not respond the motor does not do anything it is a nema 17 of 1.8 degree
#define pha_a 2 // pin 2 on UNO is connected to phase a encoder
#define pha_b 3 // pin 3 on UNO is connected to phase b encoder
#define step_CLK 9 // pin 9 on UNO is connected to the CLK pin of TB6560
#define dir_CW 10 // pin 10 on UNO is connected to the CLK pin of TB6560
#define pin_EN 11 // pin 11 on UNO is connected to the CLK pin of TB6560
static boolean rotating=false;
volatile long motor_position,encoder;
boolean A_set = false;
boolean B_set = false;
void setup() {
pinMode(step_CLK,OUTPUT);
pinMode(dir_CW, OUTPUT);
pinMode(pin_EN, OUTPUT);
digitalWrite(pin_EN, LOW);
delay(1);
pinMode(pha_a,INPUT);
pinMode(pha_b,INPUT);
digitalWrite(pha_a, HIGH);
digitalWrite(pha_b, HIGH);
// encoder pin on interrupt 0 (pin 2)
attachInterrupt (0, encoderPinChangeA, CHANGE);
// encoder pin on interrupt 1 (pin 3)
attachInterrupt(1, encoderPinChangeB, CHANGE);
encoder = 0;
}
void encoderPinChangeA()
{
if (digitalRead(pha_a)== digitalRead (pha_b))
{
encoder--;
}
else
{
encoder--;
}
}
void encoderPinChangeB()
{
if (digitalRead(pha_a)!= digitalRead (pha_b))
{
encoder--;
}
else
{
encoder++;
}
}
void loop () {
// run when detecting notion
if ( rotating ) delay (1);
if (encoder >0)
{
digitalWrite(dir_CW, HIGH);
digitalWrite(step_CLK,HIGH);
digitalWrite(step_CLK,LOW);
_delay_us(200);
motor_position++;
encoder =0;
}
else if (encoder
Any one help me pls how to add two limit switch, in push botton, out push botton, then stop botton, pls tell me
thank you
if (digitalRead(pha_a)== digitalRead (pha_b))
{
encoder--;
}
else
{
encoder--;
}
this part is wrong, it should be
if (digitalRead(pha_a)== digitalRead (pha_b))
{
encoder--;
}
else
{
encoder++;
}
@@muhammeddogan8157 KARDEŞİM NE YAPTIN BİTİRDİNMİ PROJENİ *
Can you give me the code?
This code online download not work
Hi brother how can i get the code for Arduino? sketch
pls contact whatsapp +84 918219268
HI I have a question, can I use optical rotary encoder E38S6-600-24G instead of the one you used in your project?
Please send the code
#define encoder_a 2 //keep this on and interrupt pin
#define encoder_b 3 //keep this on and interrupt pin
#define motor_step 9
#define motor_direction 8
#define senzor_front 6
#define senzor_rear 7
#define load_button 4
#define eject_button 5
volatile long motor_position, encoder;
int home_position = 0;
int load_position = 0;
int pe_load = 0;
void setup() {
pinMode(encoder_a, INPUT);
pinMode(encoder_b, INPUT);
// disable pullup as we aren't using an open collector encoder
digitalWrite(encoder_a, LOW);
digitalWrite(encoder_b, LOW);
//set up the various outputs
pinMode(motor_step, OUTPUT);
pinMode(motor_direction, OUTPUT);
// then the senzors inputs
pinMode(senzor_front, INPUT_PULLUP);
pinMode(senzor_rear, INPUT_PULLUP);
pinMode(load_button, INPUT_PULLUP);
pinMode(eject_button, INPUT_PULLUP);
//--------------------------------------------------
// encoder pin on interrupt 0 (pin 2)
attachInterrupt(0, encoderPinChangeA, CHANGE);
// encoder pin on interrupt 1 (pin 3)
attachInterrupt(1, encoderPinChangeB, CHANGE);
encoder = 0;
// -------------------------------------------------
}
// -------------------------------------------------
void encoderPinChangeA(){
if (digitalRead(encoder_a) == digitalRead(encoder_b)){
encoder--;
}
else{
encoder++;
}
}
void encoderPinChangeB(){
if (digitalRead(encoder_a) != digitalRead(encoder_b)){
encoder--;
}
else{
encoder++;
}
}
// -------------------------------------------------
void loop() {
// Control platen position of boot up and move to front
if (home_position == 0) {
digitalWrite(motor_direction, HIGH);
TurnStepper();
if (digitalRead(senzor_front) == LOW) {
home_position = 1;
}
}
// eject platen
if (digitalRead(eject_button) == LOW) {
home_position = 0;
}
// load platen
if (digitalRead(load_button) == LOW) {
load_position = 1;
}
if (load_position == 1) {
digitalWrite(motor_direction, LOW);
TurnStepper();
if (digitalRead(senzor_rear) == LOW) {
load_position = 0;
pe_load = 1;
}
}
// -------------------------------------------------
if (encoder > 0){
digitalWrite(motor_direction, HIGH); // output direction HIGH
digitalWrite(motor_step, HIGH); // output step HIGH
digitalWrite(motor_step, LOW); // output step LOW
_delay_us(2000); // tunggu 200 microsecond
motor_position++; // posisi motor bergeser tambah satu point
encoder = 0; // reset ke 0
}
else if (encoder < 0){
digitalWrite(motor_direction, LOW); // output direction LOW
digitalWrite(motor_step, HIGH); // output step HIGH
digitalWrite(motor_step, LOW); // output step LOW
_delay_us(2000); // tunggu 200 microsecond
motor_position--; // posisi motor bergeser kurang satu point
encoder = 0; // reset ke 0
}
// -------------------------------------------------
}
void TurnStepper() {
digitalWrite(motor_step, HIGH);
delayMicroseconds(100); // speed delay, the lower it is the faster
digitalWrite(motor_step, LOW);
delayMicroseconds(100); // speed delay, the lower it is the faster
}
@@wikastana gan, saya sdh coba tapi putaran motor tetap satu arah walaupun encoder diputar bolak balik, bgtu juga putaran utk load platen sama eject platen kan seharusnya jdi beda atau berlawan putarannya tpi kok ini malah satu arah semua, apanya yg salah ya gan??
@@uwtyhulonthalo3152 groundnya sudah bener belum, cek dulu encodernya , hrsnya bisa cek koneksi dng portnya harus betul2 nyambung, dan ini sudah saya uji dan tdk ada masalah
@@uwtyhulonthalo3152 control motor yang saya gunakan TB6650
@@wikastana klo sy menggunakan driver TB6560, ok gan ntar sy periksa ulang lagi, thanks
Thumbs down!! You call this a "How To" but don't post the code?? 12 minutes of my life that I can never get back!!
Pc Arodino code not clear pls send code
#define pha_a 2 // pin 2 on UNO is connected to phase a encoder
#define pha_b 3 // pin 3 on UNO is connected to phase b encoder
#define step_CLK 9 // pin 9 on UNO is connected to the CLK pin of TB6560
#define dir_CW 10 // pin 10 on UNO is connected to the CLK pin of TB6560
#define pin_EN 11 // pin 11 on UNO is connected to the CLK pin of TB6560
static boolean rotating=false;
volatile long motor_position,encoder;
boolean A_set = false;
boolean B_set = false;
void setup() {
pinMode(step_CLK,OUTPUT);
pinMode(dir_CW, OUTPUT);
pinMode(pin_EN, OUTPUT);
digitalWrite(pin_EN, LOW);
delay(1);
pinMode(pha_a,INPUT);
pinMode(pha_b,INPUT);
digitalWrite(pha_a, HIGH);
digitalWrite(pha_b, HIGH);
// encoder pin on interrupt 0 (pin 2)
attachInterrupt (0, encoderPinChangeA, CHANGE);
// encoder pin on interrupt 1 (pin 3)
attachInterrupt(1, encoderPinChangeB, CHANGE);
encoder = 0;
}
void encoderPinChangeA()
{
if (digitalRead(pha_a)== digitalRead (pha_b))
{
encoder--;
}
else
{
encoder--;
}
}
void encoderPinChangeB()
{
if (digitalRead(pha_a)!= digitalRead (pha_b))
{
encoder--;
}
else
{
encoder++;
}
}
void loop () {
// run when detecting notion
if ( rotating ) delay (1);
if (encoder >0)
{
digitalWrite(dir_CW, HIGH);
digitalWrite(step_CLK,HIGH);
digitalWrite(step_CLK,LOW);
_delay_us(200);
motor_position++;
encoder =0;
}
else if (encoder
@@msr2363 tanks
Hi, can you tell me exactly what engine step by step it is? Thank you.
Step motor 1.8
@@DIYInkJet Yes, I imagined that, but is it Nema 17 or Nema 23?
@@otercesotercesfernandez784 Nema 17