Direct control of a stepper motor using a rotary encoder and the accelstepper library

  Рет қаралды 34,498

Curious Scientist

Curious Scientist

Күн бұрын

Пікірлер: 116
@isidoromaich7226
@isidoromaich7226 4 жыл бұрын
I don't have this driver but hey I learned something new and it was fun to employ the quarantine time with something useful. Thanks!
@CuriousScientist
@CuriousScientist 4 жыл бұрын
It is worth buying it. It is cheap and can run larger motors such as the NEMA23. It is fun and easy to use it. Unfortunately, I am still working during these times, otherwise I would have cranked up the number of videos. I am glad that you found it useful!
@mountainsprings3303
@mountainsprings3303 Жыл бұрын
Great Video and the code was well explained. Thanks.
@CuriousScientist
@CuriousScientist Жыл бұрын
Thanks! Glad that you found my explanation good!
@AllanWallsPhotography
@AllanWallsPhotography 3 жыл бұрын
Thanks for this thorough and detailed presentation; it has been enormously helpful. I am trying to control a very small stepper (DVD sled drive), using a rotary encoder, as a fine positioning device (I am a macro photographer). Your system will work perfectly for my purpose, but the micro stepper driver you are using exceeds the current rating of my bipolar motors (5v, 200mA/phase). Do you know if there is a way to reduce the current from the TB6600, below its minimum setting? I am not skilled or experienced in electronics, and have had no luck trying other drivers (A4988, L298N, and others).
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Hi! I am glad to see that my video is useful! Thank you for your kind comments! I have similar tiny motors and they indeed run hot as hell, I can even smell it. I had quite a succes with the EasyDriver circuit. It gives very low current (you can adjust it with the onboard potentiometer), and you can run it at lower voltages. L298N is technically not a stepper motor driver but a PWM-based DC motor driver. You can just wire it in a way that you can drive a stepper motors with it. I would stay away from that. Visit my website and you can find my email there in the contact info. I can send you some extra information if you want. BTW, later this year I will publish a video which is pretty much in line with your field: stepper motor driven focus assistant which can provide nearly automatic process of taking pictures for focus stacking. I just need to buy a few gadgets and find some time to do it.
@AllanWallsPhotography
@AllanWallsPhotography 3 жыл бұрын
@@CuriousScientist Thank you! That is useful information and I will try the easy driver. I have tried the A4988, which also has an onboard variable resistor and uses the step/dir pins, but for some reason I can't get it to work. If I still can't get the control I need, I'll get in touch. Thanks for your time!
@uyegidgg
@uyegidgg Жыл бұрын
Thanks!
@CuriousScientist
@CuriousScientist Жыл бұрын
Thanks for the generous support! I hope my tips make it worth!
@RaphaelOE.
@RaphaelOE. 3 жыл бұрын
Can you make a Video about TMC 2208 or 2209 Stepper drivers, about load funktion and how to use this? That would be realy helpful!
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Hi! To be able to make a video on the mentioned drivers, I would first need them. I am sorry, but I cannot invest money just to make a video to fulfill a request. I hope you understand it.
@usearsive
@usearsive 2 жыл бұрын
Hi Would you please share the wirring diagram of project. Thank you again for sharing the project, very useful
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Hi! I believe that I explained the whole thing in the video as well as indicated the connections in my source code.
@jdurhamify
@jdurhamify 4 жыл бұрын
I noticed that some stepper drivers are closed loop that have feedback connections build in like CL57T; do you know what the difference is between using a blind stepper controller like the one you have and connecting the encoder to arduino board to handle feedback versus connecting encoder directly to a close-loop driver? Unclear to me if there is any advantages between the two.
@CuriousScientist
@CuriousScientist 4 жыл бұрын
Hi! The closed loop one is more precise. You can do quicker and more precise movements without worrying about losing any steps. For my demonstration, the stepper motor gets the command to step X steps, but nothing ensures that it will really make those X steps. For a closed loop system, we always get the feedback from the encoder, so we can be sure that the step happened. So I would say that the precision is the best advantage. But for simple applications, it is not really necessary to invest in such systems.
@proservices6067
@proservices6067 4 жыл бұрын
I have reproduced your circuit with few changes: 1 - i used a different type of encoder (80mm pulser handwheel 100ppr rotary encoder) 2 - did not use a LCD display to print position, but i used serial instead Of course everything related to LCD been stripped from code. As a motor, i used a Nema23 close loop motor and driver, with a microstep set to 800. My problem is that i have observed a very weird behavior . After i turn the encoder for a period of time and i reach around 4090 (either positive or negative, doesnt matter), the motor stops responding to any command from encoder and is doing a "reverse movement" if i can call it like that ... a movement in oposite direction of the last state of the encoder, and i think is around the same ammount of pulses that i have input to reach the position 4090. If i set the microstepping to 400, then position of this behavior change to around 2048 . I have did not check for other ratios in microstepping. Code seems ok, i cannot find any problem, but i cannot explain this behavior. Can you do a check and see if you get same behavior on your circuit ? Best regards.
@CuriousScientist
@CuriousScientist 4 жыл бұрын
What type do you use for the variable that stores the value of the clicks from the rotary encoder? It sounds like an overflow. Try to store the values in a long or double and see if it helps.
@proservices6067
@proservices6067 4 жыл бұрын
@@CuriousScientist I have double check the code and cannot find any problem. Indeed sounds like an overflow, but why i don't understand, is why when this happens, the motor start to run in opposite direction to last movement, and i cannot count because is too fast, but is like is doing same amount of steps that have sent to it. Will try to rewrite some parts of the code and see what will get out of this. I have found all this interesting, because i could use the code to implement for a small milling machine, replace the mechanical handles with rotary encoders and close stepper system to do the movements.
@CuriousScientist
@CuriousScientist 4 жыл бұрын
I will also work on this later this week because it bothers me. I haven't encountered this problem yet, but I will use it for somewhat similar things as you, so I can imagine that sooner or later I will meet the problem. Moving the milling machine's table is a very good implementation of this setup! It makes it more convenient and maybe more precise too. My plan is to use this kind of system for moving the focus ring of a camera. It is good when you want to make macro photos and you need focus stacking. Then this system can be used to make it more precise (equal steps) or even automatic (pre-program the step size and the end of the stepping sequence). If you haven't subscribed yet, please do so, so you will see the updates regarding these projects.
@proservices6067
@proservices6067 4 жыл бұрын
@@CuriousScientist In fact my project is will include some more things, limit switches, emergency shutdown, an automatic programmable feeder with some auto loop between 2 pre set points and some I2C display to navigate thru menu and set things up. Not sure if Arduino would handle all this, if not will try set this up with ESP or Blackpill ... will see that later when i will finish all parts of the programming code and put everything together. Right now i divided everything in different stages and working on each one by one. Will let you know if i find the problem with all this story or maybe you find it first. Subscribed here and will check on laters. Good job on the code by the way. PS: i wonder if the problem doesnt come from accelstepper library ... what version you using ?
@CuriousScientist
@CuriousScientist 4 жыл бұрын
Thank you! Sounds like a complex project, I really like it! Actually, Arduino (or 2, see my recent videos for that) could handle all of those things easily. Switches and encoders can be handled via interrupts so they don't take the resources continuously. The only issue can be the smooth stepping of the motor and updating the display at the same time. But if the motor goes slow enough, it is solvable. I haven't yet checked the library itself. I have the 1.61.0 installed. I will actually look into the library in more details because at this moment I could not make it work with the blue pill (stm32f103c8t6) and stm32duino, so I want to see if I can make it work. It would be nice because the blue pill is much more powerful and I will need more than 2 interrupt pins as well. If there's any useful progress, I will publish it.
@lensofrasta
@lensofrasta 3 жыл бұрын
could you do a tutorial with stepper motor control over nrf24l01
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Sure, if you buy me all the parts. Sorry, but I cannot fulfill requests for free especially if I don't have the parts.
@lensofrasta
@lensofrasta 3 жыл бұрын
@@CuriousScientist sure,would you be able to reach out to me, p.rana@mindfulunion.net I got the transmitter to send the rotary encoder data to the receiver, but I can’t seem to move the stepper with this data
@controlledsteppers99
@controlledsteppers99 10 ай бұрын
Hi - is there a way to vary the number of steps per revolution of the encoder by pressing the button - say increment x amt each time pressed and show a number on the LCD to correspond? Thank you
@CuriousScientist
@CuriousScientist 10 ай бұрын
Hi! Sure, it is possible. Just have to introduce a multiplication factor.
@KW-ei3pi
@KW-ei3pi Жыл бұрын
Very nice. Thank you! When explaining the code in line 3, AccelStepper Stepper (1, 9, 8) you didn't explain what the number 1 does. Nine and eight are pins, but what is the "1" for? Thanks very much!
@CuriousScientist
@CuriousScientist Жыл бұрын
Read the documentation of the library, it is clearly written there. It is the motor interface type. If it is set to 1, it means that a driver is used.
@ernsteliden6719
@ernsteliden6719 3 жыл бұрын
Hello and thanks for yet a good video. What if I would like to use the encoder to set a distance and then send it there by pushing the switch or an other switch?
@CuriousScientist
@CuriousScientist 3 жыл бұрын
If you check my other videos, I also implemented that option.
@ernsteliden6719
@ernsteliden6719 3 жыл бұрын
@@CuriousScientist Thank you for you quick answer. Could you link your video about that specific setup. There are so many, I can't find it.😜 Thank you very much. And keep up the excellent work.
@CuriousScientist
@CuriousScientist 3 жыл бұрын
If I am able to provide all these resources for free, you should make the effort to search for 4-5 minutes. :P kzbin.info/www/bejne/a4XTf6pmd9Oke7M Cheers!
@ernsteliden6719
@ernsteliden6719 3 жыл бұрын
@@CuriousScientist Haha.. 😝 Yes, you are absolutely right. I'm a bit embarrassed that I didn't find it. To my defense I think the video you've linked to is one of few I did not watch. Thank you very very much.👍👍
@haryabdulrachman2763
@haryabdulrachman2763 2 жыл бұрын
Thanks a lot for this nice tutorial. Do you have tutorial about closed loop stepper motor?
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Hi and you're welcome! Not yet. Actually, a package with a huge NEMA23 motor with a CL57Y driver is sitting on my desk, unopened. I am just busy with other tasks, but it is on my list., so once I have a bit more free time, you can expect a video about it.
@haryabdulrachman2763
@haryabdulrachman2763 2 жыл бұрын
@@CuriousScientist Ok sir, thanks. Can't wait for it.
@AllanWallsPhotography
@AllanWallsPhotography 3 жыл бұрын
Could this same setup with modified code be used to control two small steppers using two A3967 driver boards and two encoders? Would the two drivers need separate power supplies, and if so, does it matter which one I power the Uno from? And lastly, should the GND pins of the Arduino and both drivers share a common ground to the power supply? Sorry for the long question! Thanks.
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Hi Allan! Yes, you technically just duplicate everything and you can control two different motors. You can drive two drivers with one single power supply as long as the power supply can provide enough power to support both of them. The Uno has so tiny consumption that it really doesn't matter which driver's 5 V output you use. And finally, yes, every shares the same ground. By the way, yesterday evening, after work I received two floppy drives. I can demonstrate the above issues in a video this weekend. :)
@AllanWallsPhotography
@AllanWallsPhotography 3 жыл бұрын
@@CuriousScientist Wonderful! Thank you so much. After stitching to the A3967, I have discovered that two of the other drivers I have been using were defective (or I broke them), but now everything is working as it should. I should have my prototype assembled this weekend. Thanks again for your help with this!
@CuriousScientist
@CuriousScientist 3 жыл бұрын
This is great news, Allan! I am glad that you made it work! Let's keep each other updated.
@andreklarenbeek369
@andreklarenbeek369 Жыл бұрын
could you also use a hand wheel encoder, instead of the rotary encoder ?
@CuriousScientist
@CuriousScientist Жыл бұрын
Sure, it is the exact same principle. I have some stepper motor videos where I used such an encoder wheel. You can use the code I wrote as a starting point.
@UReasonIt
@UReasonIt 4 жыл бұрын
Hello. Very good video. I have some of these stepper drivers and have found them to be problematic sometimes. I took one apart and they use theTB67S109AFTG driver and not the TB6600 chip. Any you find that have 1/32nd micro-stepping are not the 6600 :(. It seems from my finding that the enable pin on the TB67S109AFTG is quite slow to respond, but if you keep it "HIGH" then it seems to work fine and not loose steps.
@CuriousScientist
@CuriousScientist 4 жыл бұрын
Hi Scott! Yes, this is a commonly discussed issue. The Chinese copies have some problems, but if you are using it within the "normal" range, it will serve you. While this thing cost around $10, a proper driver with similar characteristics cost 2-3x more.
@UReasonIt
@UReasonIt 4 жыл бұрын
@@CuriousScientist Yes, I hope they work ok in my CNC. I have found you can find the TB6560 at or near the same price. I may get a few to try.
@hishambary7822
@hishambary7822 3 жыл бұрын
Thanks so much for the tutorial!! It really helped me out when i was in a pinch!! I do have a question though, If i wanted to increase the rotation of the stepper to turn faster with every rotary click of the encoder? How would i go about doing that? I'm currently running a linear stage where the stepper is 1.8deg/step so about 200steps/rev and every revolution moves the stage by only 2mm. Im trying to get it to move about 1mm every click of the encoder. If you have any suggestions on how to do it, that would be a great help!! Thanks again for the awesome tutorial!
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Hi! It is just simple mathematics... But your question does not really make sense to me. First, you want to step the stepper faster with every click. But then you say that you want to move 1 mm every click. So, which one? You just need to match the travel of the lead screw with the clicks or steps /revolution of the rotary encoder and you get the number that you need. For the first issue, you need to have a variable which is used as a multiplier for a default speed value and you increase its value by every click. If you want to move 1 mm with every click of the encoder, you just need to tell the accelstepper library that upon a click it should move 100 steps (move(100)). It is very simple.
@KarmasStreetstyles
@KarmasStreetstyles 8 ай бұрын
Hello. first of all, Great video. Really helped me a lot. one question i have is its compatability with esp 32. I have replaced the code to define the IN pins for the stepper motor, but it stilll doesnt work. Not sure whats wrong. Any help would be appreciated.
@CuriousScientist
@CuriousScientist 8 ай бұрын
Hi! What do you mean by IN pins?
@KarmasStreetstyles
@KarmasStreetstyles 8 ай бұрын
@@CuriousScientist the IN labeled pin on the motor driver ( ULN2003APG )
@CuriousScientist
@CuriousScientist 8 ай бұрын
I don't know if you noticed, but this project is made for another type of driver.
@KarmasStreetstyles
@KarmasStreetstyles 8 ай бұрын
@@CuriousScientist aha! So the cannot be run with the my driver motor. Is there a way to modify it to make it work? Thank you
@CuriousScientist
@CuriousScientist 8 ай бұрын
If I remember correctly, the accelstepper has the possibility to work with these drivers. Check the documentation of the accelstepper library.
@rubenbroeckx6972
@rubenbroeckx6972 Жыл бұрын
Is it possible to do this with a potentiometer instead of the rorary encoder
@CuriousScientist
@CuriousScientist Жыл бұрын
Sure, but then you will be limited by the physical range of the potentiometer and the resolution of the ADC.
@rubenbroeckx6972
@rubenbroeckx6972 Жыл бұрын
@@CuriousScientist Thankyou, i tried it but the motor keeps moving when the potentiometer is not. i think this is becouse of the unstable resistance value of the potmeter. Do you know if there something to do about this?
@CuriousScientist
@CuriousScientist Жыл бұрын
Use a rotary encoder... ;) Also, you can calculate the average of multiple ADC readings. Then you'd get more stable values.
@marcpaulocruz4431
@marcpaulocruz4431 Жыл бұрын
How will I know what am I going to set as the max acceleration and max speed?
@CuriousScientist
@CuriousScientist Жыл бұрын
Well, you should know what parameters you want to achieve.
@marcpaulocruz4431
@marcpaulocruz4431 Жыл бұрын
@@CuriousScientist will this still work if I use a different kind of motor driver?
@CuriousScientist
@CuriousScientist Жыл бұрын
As long as the driver is step and direction-controlled, yes.
@marcpaulocruz4431
@marcpaulocruz4431 Жыл бұрын
@@CuriousScientist got it working. Thanks!
@CuriousScientist
@CuriousScientist Жыл бұрын
Glad to hear it. Have fun! Cheers!
@cgmarch2359
@cgmarch2359 3 жыл бұрын
The button press func in video is wrong.. on your site seems correct. I am putting this in case is going to confuse others
@CuriousScientist
@CuriousScientist 3 жыл бұрын
What is wrong with the code? I have the same code in the video and on my site as well.
@kalebgross3730
@kalebgross3730 8 ай бұрын
hey im trying to get your code to work but i amunable to read the encoder position or the clicks, on a serial monitor, i would like to do this to make shure that i am able to read the encoder position and click. if you could help me out that would be great
@CuriousScientist
@CuriousScientist 8 ай бұрын
Hi! Send the variable to the serial monitor using the print() function.
@kalebgross3730
@kalebgross3730 8 ай бұрын
@@CuriousScientist sorry i should of been more spefic, thats not the problem the problem is i first of all don't know what variable to read, and then when i do try and run the code the motor dosent move, i have everything setup as how you have it. it just dosent work
@kalebgross3730
@kalebgross3730 8 ай бұрын
@@CuriousScientist i even tried to just read the buttoncounter but even that dosent work
@kalebgross3730
@kalebgross3730 8 ай бұрын
​@@CuriousScientist hey one last thing I sent you a message on your website. Feel free not to answer it. It's the same question as I originally posted. But thanks for the fast response time
@CuriousScientist
@CuriousScientist 8 ай бұрын
My code works, you can see it in the video. If it doesn't work on your side, you might have changed something and made a mistake.
@pepopepez105
@pepopepez105 2 жыл бұрын
Hello, I have a similar problem, I am trying to amplify the rotation of the motor in relation to the encoder, I am using a Chinese hbs860h closed loop, I map the read variable of the encoder with the map function but it does not quite work well, if I select 800 steps per revolution In the controller the displacement is very short but very precise when moving the encoder slowly and if I select 200 steps per revolution it is closer to the speed I am looking for but when going slowly it moves in jumps, how could I adjust this? could move fast and precise.
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Hi! Probably your speed in the code does not match the microstepping you set on the driver. That can mess up the things with the speed. Also, why would you need to map the encoder values? That does not make too much ense when using a rotary encoder.
@pepopepez105
@pepopepez105 2 жыл бұрын
@@CuriousScientist I am a novice at this and it occurred to me that with map I could get the adjustment of the encoder variable to the widest movement I need in the axis, any help is welcome I only intend to emulate the movement of the encoder in the motor axis but with a major tour
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Why don't you add some multiplication factor for the steps? Like: 1 encoder click is 10 steps. That is faster and easier to implement.
@pepopepez105
@pepopepez105 2 жыл бұрын
@@CuriousScientist I'm using the AccelStepper library with moveTo encoder I'm a novice, could you give me an example line I understand what you're saying but right now I wouldn't know how to implement it
@pepopepez105
@pepopepez105 2 жыл бұрын
amm in the interrupt of the encoder using the library? and runToPosition?
@uyegidgg
@uyegidgg Жыл бұрын
Is there a way to code it so the speed on the lcd only updates when the rotary encoder is being turned
@CuriousScientist
@CuriousScientist Жыл бұрын
Yes, there is!
@uyegidgg
@uyegidgg Жыл бұрын
@@CuriousScientist I have been trying to figure it out but its not working, I am just learning arduino and I'm sure its something simple. Would you mind sharing how to do it. Thanks
@CuriousScientist
@CuriousScientist Жыл бұрын
Only update the display when the new value is different than the old value. Or create a flag that changes when the encoder is moved, update the display, and then reset the flag afterwards. The flag is just a boolean value.
@uyegidgg
@uyegidgg Жыл бұрын
@@CuriousScientist Yes, I have been trying to only update the display when the value is different but I don't know where in the sketch to put it or if I am coding it properly
@CuriousScientist
@CuriousScientist Жыл бұрын
Have you tried anything at all, or are you expecting me to provide a code for free?
@jrmichel
@jrmichel 3 жыл бұрын
I´m confused with the wiring pins. the code and the video doesn´t match.Thank you
@CuriousScientist
@CuriousScientist 3 жыл бұрын
If you want to use my source code, simply use the pins defined in the code. It is fairly simple.
@mos123az
@mos123az 3 жыл бұрын
Thanks for this thorough and detailed presentation...but tray to us the code you provided !!not the one in the video
@CuriousScientist
@CuriousScientist 3 жыл бұрын
You're welcome! Sorry but I don't understand what you mean.
@epsody
@epsody 4 жыл бұрын
The code in the video and the code given in the link do not match.
@CuriousScientist
@CuriousScientist 4 жыл бұрын
Sorry, for some reason, I uploaded the wrong code. Now it should be OK. I started to work on a similar version with buttons instead of a rotary encoder, and for some reason, I copied that (unfinished) code. Unfortunately, I cannot really understand your question. What do you mean by broadcasting?
@epsody
@epsody 4 жыл бұрын
@@CuriousScientist Thankyou SiCu 👍
@CuriousScientist
@CuriousScientist 4 жыл бұрын
You are welcome!
@ottoertl1866
@ottoertl1866 Жыл бұрын
this is great.. works fine. but the stepper motor gets very warm...
@CuriousScientist
@CuriousScientist Жыл бұрын
Then you need to adjust the current...
@osmanozan9008
@osmanozan9008 4 жыл бұрын
The page you provided the code does not work
@CuriousScientist
@CuriousScientist 4 жыл бұрын
What do you mean? The code works, you can see it on the video. I think you flipped the DIR and PUL pins. :)
@osmanozan9008
@osmanozan9008 4 жыл бұрын
Your code page link does not work sorry :)
@CuriousScientist
@CuriousScientist 4 жыл бұрын
I checked it and it works, clicking the link opens the PasteBin page. I think that the problem is not on my side. Try a different browser or something.
@osmanozan9008
@osmanozan9008 4 жыл бұрын
Thank you very much Curious Scientist. by the way your video very good.
@CuriousScientist
@CuriousScientist 4 жыл бұрын
Thank you! I am glad if you found it useful!
@sarthaknaik8863
@sarthaknaik8863 3 жыл бұрын
Can you drop any contact or any social where i can contact you? I need help!
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Hi! You can ask the question here, so others can also learn from it. I have 2 contact details shared, you just have to look more carefully. But keep in mind that I am not a free support service.
TB6600 and Arduino - Wiring and demonstration
15:39
Curious Scientist
Рет қаралды 101 М.
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 25 МЛН
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 53 МЛН
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 18 МЛН
Stepper motor control with buttons and rotary encoder
29:54
Curious Scientist
Рет қаралды 17 М.
How to use a Rotary Encoder with an Arduino - CODE EXPLAINED!
21:11
Constant Angular Acceleration of a Stepper Motor with Arduino
25:57
Hacking a weird TV censoring device
20:59
Ben Eater
Рет қаралды 3,3 МЛН
Stepper motor PID control using a TMC2209 and AS5600
45:25
Curious Scientist
Рет қаралды 15 М.
Big Stepper Motors with Arduino
29:43
DroneBot Workshop
Рет қаралды 1,2 МЛН
Homing with the AccelStepper library and a limit switch
17:09
Curious Scientist
Рет қаралды 64 М.
BELAJAR ARDUINO #99 - Stepper Motor Dan Driver TB6600
23:10
Life Tech
Рет қаралды 15 М.
Players push long pins through a cardboard box attempting to pop the balloon!
00:31