Why not use timer interrupts? The interrupts take priority over anything else (except other interrupts) and other tasks are interrupted (they are continued after executing the interrupt service routine). That's how I got smooth movement on the 6 axis (7stepper motor) robot arm I made. You only need 1 arduino. If you need timers 0-2 for the functions they are needed for, an arduino mega has 3 extra free timers. If the extra size of the arduino mega is bad, then a mega 2560 pro (embed) is the same but smaller than both the standard mega and uno. I had the exact same problem and thats how I fixed it :). You're definitely right that a lot of channels fail to mention the hiccups that happen when using other devices on the same arduino, I also found that annoying.
@CuriousScientist4 жыл бұрын
Thanks, this sounds an excellent idea! I haven't checked the feasibility of timers yet to be honest, so I don't have any experience with them. I used the timers for some other project to generate multiple independent PWM signals on an STM32, but that's my "biggest achievement" with them, nothing too fancy. I used the presented method, because I found it easy and comfortable to implement it. I will look at the timer-approach when I have some time and I might publish a video about it if I can make it work.
@paulocella97454 жыл бұрын
I tried with interruptions, but everything gets more complicated when you have to send arduino commands to a Nextion type display. The engine always stopped, even using interrupts. The solution was also to use an exclusive arduino for the stepper motor. The nextion display needs 3 print commands to receive information and then the problem begins. If you need an engine to run smoothly and at the same time send information to a display nextion, you will have problems.
@7alfatech8603 жыл бұрын
Good suggestion. Always nice to have more than one way to fix a problem.
@CuriousScientist3 жыл бұрын
@@7alfatech860 Yes, it is good to have some alternatives!
@qcnck27764 жыл бұрын
Your setup makes a lot of sense. Arduinos are cheap enough that using one for dedicated stepper control is a good idea. BTW, I use the Wago style connectors too, and they are very convenient.
@CuriousScientist4 жыл бұрын
Thank you! Yes, it worth the "investment" to have a dedicated Arduino just for the stepper motor in a project. I love these "Wago-style" connectors. They are very convenient to use and they can carry high enough currents for my Peltier projects too.
@dondon19922 жыл бұрын
Thank you, you have a good programming knowledge which can help us, I hope you have more videos specially in arduino using stepper motor and its practical application in manufacturing.. I like the professional coding style, with detailed explanation. I will watch all you video as part of my startup project using arduino..
@CuriousScientist2 жыл бұрын
Thank you! I have nearly 200 videos and considerable part of the videos is related to stepper motors and Arduino, so you will probably find what you are looking for. There is a dedicated playlist on my channel for stepper motor related videos. Have fun!
@StevePotter3 жыл бұрын
Handy trick: Instead of using a separate program for the serial display of the slave, you can use two instantiations of the Arduino IDE. (at least with Windows 10, using v. 1.8.15, when one Arduino IDE is running, you can run another one (or more)). You just need to have both Arduinos plugged into two USB ports and choose the correct Port in each instantiation of the Arduino IDE. Then two serial windows can be used at the same time.
@CuriousScientist3 жыл бұрын
Yes, this can also work! It is just too much fiddling for me and it is also a good way to show RealTerm to other people. It is a good tool.
@sshah8762 жыл бұрын
Great teacher! Good explanation, hey one small question, can you send a stop command from master to stop the motor , “ with deceleration” … cheers..
@CuriousScientist2 жыл бұрын
Thanks! Of course you can stop the stepper with deceleration. The acceleration value is also used for decelerating the motor, so you just have to adjust that value. Try small values so the deceleration will be noticeable.
@sshah8762 жыл бұрын
@@CuriousScientist super!
@wisdomwatchtower Жыл бұрын
Great. I like it.
@CuriousScientist Жыл бұрын
Thank you!
@tayfunsertmba609723 күн бұрын
I have tested this diagram, and it seems that your wiring is incorrect. You need to ground the PUL-, DIR-, and ENA- to the GND of both Arduinos. PUL+ should connect to pin 8, and DIR+ should connect to pin 9. However, the code is correct. Thank you for inspiring me!
@CuriousScientist23 күн бұрын
Strange. If it is wrong, then how is it working in the demonstration? :)
@The1357911131516 Жыл бұрын
Very good video thanks alot. But i have a question here, isn't using two arduinos a little bit like using the runToPosition() blocking function? Meaning the motor can't change his way until the distination is reached.
@CuriousScientist Жыл бұрын
Hi! You can send a new command at any moment and override the ongoing command.
@신태진-w2g3 жыл бұрын
What if I want to add a rotary encoder to turn the stepper and an LCD to display the position, just like you did in your other video about directly controlling a stepper with rotary encoder. In that example you wired the rotary CLK and SW pin to the interrupt pins (2,3) of the arduino. If I want to do the same here, should I connect both the rotary encoder and the LCD the master arduino?
@CuriousScientist3 жыл бұрын
Hi! The issue is not that simple. The accelstepper library keeps track of the number of steps done in a variable which you can reach with the "currentPosition()" method. So, when you want to display the position, you have to fetch the info from the secondary microcontroller that runs the motor. Same for rotary encoder. You have to change the position and instruct the motor to move. So, ideally this would happen on the secondary Arduino as well. However, I figured out a workaround. Since you want to move with the rotary encoder, I assume that you want to move with fine movements with relatively slow speed. So, you use a variable on the master Arduino to store the position of the stepper motor. You change the value of this variable by turning the rotary encoder. Then, you just have to write a code that sends the updated value to the secondary Arduino and then the secondary Arduino will just perform those steps. Regarding the LCD, it is the same as the encoder. You connect it to the master Arduino and display the value of the variable that you change with the encoder. You can update the LCD and send the value to the slave Arduino at the same time. But keep in mind that this is an open loop stepper motor controlling circuit and code. Therefore, it might be possible that steps are skipped...etc. But at low speeds it works quite reliably. Later on I will make my own library for a closed loop system but I am still waiting for parts to arrive before I start the project.
@The1357911131516 Жыл бұрын
Hello. So now im using the same system with two master-slave arduinos. I have a stepper motor with TMC2209 connected to my slave arduino. And a distance sensor (vl6180), LCD-Display, and a potentiometer connected to my master arduino. Im trying to build a linear actuator with the stepper motor that holds a desired travel distance for a moving part attached to the actuator. The problem im facing here is that the motor rotates very slow. I'm using accelstepper library and i have increased the speed to very high values. This project is for my graduation and i would be extremly happy if you can help me.
@CuriousScientist Жыл бұрын
Hi! Probably something is wrong with your code.
@karthikregu69523 жыл бұрын
After boot loading and programming chip Atmega328 with Arduino is it possible run above i2c program without Arduino , yes possible run with( Atmega328 and with crystal and pf capacitor) . on plain board
@CuriousScientist3 жыл бұрын
Sorry, but I do not really understand what you mean. If you mean that we can program a bare AVR chip, then I believe it is possible. Arduino is "just" the framework that makes our job easier.
@karthikregu69523 жыл бұрын
@@CuriousScientist yes sir , thank for answering my question after programming with AVR chip , is it possible to run code with bare chip with out Arduino board
@alf30712 жыл бұрын
How can ramps board control a 3d printer with so many steppers and sensors and display with just one arduino and not have rough steppers? how do they do it?
@CuriousScientist2 жыл бұрын
Probably it is done by a better programmer than I am. :) I guess that the motors are driven in interrupts with timer peripherals instead of driven directly by the CPU. I have never used ramps boards, so I don't know how they figured it out.
@petercohen88776 ай бұрын
How to determine the port number value in RealTerm as the Slave is not connected to the PC directly during the example running? Tried 9 but the terminal screen is blank black. I have UNO Master connected directly to COM9 of my PC. The A4, A5, 5V and GND of the Master and Slave are connected respectively to each other. The USB port of the Slave is not connected to the PC to avoid problem you mentioned.
@CuriousScientist6 ай бұрын
Hi! I don't really understand the question. You just program them one by one and then use only the master for communication with the computer. Hence, you only need that one's COM port.
@petercohen88776 ай бұрын
@@CuriousScientist Is the following procedure correct? I connected the Slave UNO R4 Wifi to the PC and uploaded the slave program. Then, I disconnected the Slave UNO from the PC and connected the Master UNO R4 Wifi to the PC. After that, I uploaded the master program. Upon entering R8000 from the Arduino IDE, I saw tones of "The function is doing something..." but the motor did not turn. I want to see the outputs from the Slave. As I understand, I need to use RealTerm to do that? Motor not moving might be due to a compilation error. I copied and pasted your Slave program but I got " invalid conversion from 'const char*' to 'char' [-fpermissive]" at the line commandChar = ""; under dataProcess() during compilation. Could you please tell me how to fix this correctly?
@CuriousScientist6 ай бұрын
If you need to see both microcontrollers via a serial terminal, open one MCU in the Arduino IDE, and another in another terminal software such as RealTerm or CoolTerm...etc. Connect one board at a time to avoid mixing up the COM ports. Regarding the error code, try to change the "double quotation marks" to 'single quotation marks'.
@petercohen88776 ай бұрын
@@CuriousScientist Hello, at 41:19 of the video, you seem to have both Arduinos connected to the same PC via USB to show the outputs from both the Master and the Slave. I guess you removed the 5V connection wire between the two boards to avoid damaging the boards. So either both connected to the PC at the same time without the wire connecting the respective 5V port or Master connects to the PC and Slave connects to the Master with a cable in between the respective 5V ports? Am I correct?
@CuriousScientist6 ай бұрын
Since both are powered via USB, you should remove the 5V connection between them.
@dondon19922 жыл бұрын
Dear Curious Scientist, What if i have 3 stepper motor in one machine, For my point of view yes, need to have individual slave for each stepper motor.. do i need to use 3 arduino Slave?, just need your confirmation..Thanks
@CuriousScientist2 жыл бұрын
Hi! I don't think so. The toggling doesn't take too much effort for the MCU, therefore I think that you can control multiple steppers with the same slave. The processes which interfere with the stepping are the serial communication, printing on displays, reading sensors...etc. That's why we do these on the master, independently from the motors.
@dondon19922 жыл бұрын
@@CuriousScientist Yes, the idea is just like multi-threading which you demonstrate, i have other sensor to monitor and pushbuttons like, Emergency Stop/ Stop/Start/Reset/Auto and Manual mode/ Safety Curtain sensor, during running .. and i also need to run closely run the 3 stepper at the same time .
@CuriousScientist2 жыл бұрын
The buttons can be placed on the slave if you use interrupts and non-blocking driving of the steppers. Everything else can go to the slave.
@allesnichts82443 жыл бұрын
Why not using a STM or ESP32 which perfome much faster/better?
@CuriousScientist3 жыл бұрын
This would need multithreading and not necessarily a faster chip. Or an entirely different programming approach (using timers). The problem is not the speed of the MCU. The problem is that some external modules, for example a load cell module or a display takes several milliseconds to read or write which is too long time. If the processor is blocked for a longer time than the time between two stepping pulses, the stepper motor will skip steps. The current libraries for stepper motor control rely on polling the GPIO pins instead of using a peripheral (timer) to unload the CPU. In fact I am working on a smarter approach for controlling stepper motors, but it is progressing slowly because I have many other things to work on.
@allesnichts82443 жыл бұрын
@@CuriousScientist The goal is to avoid any delay on the communication betwee the controller and the MCU. This means a fast MCU! Of course this cannot be realised , even there is a very fast MCU, when other processes disrupt this flow. Therefore there is no way around multithreading. On the otherside,realize multitasking and your next bottleneck will be the speed of your MCU. With your approach you realize some kind of multitasking… But this can be realized more elegant with a powerful STM and some cool code.
@CuriousScientist3 жыл бұрын
Don't get me wrong, but I think you don't exactly understood what I meant. These stepper motor driver could be served (nearly) perfectly with an Arduino. There's no need for a fast CPU. The STEP pin needs to be toggled to perform a step on the stepper motor and based on the toggling frequency, the stepper motor will obtain a certain speed. Now, since the toggling is done via switching the pin on and off with a delay between them, the only time when you can perform other tasks than toggling the STEP pin is this time between the two toggling. This is a very short time, and not enough for serving other external hardware or sending data to the serial port...etc. So, this is not about the slow CPU, but it is about the available time when the CPU is not blocked. However, this toggling could be done with a timer as well and it would allow the CPU to do other tasks while the timer takes care of the motor. The timer will provide the PWM signal in the background while the CPU can take care of other tasks. The only thing when the CPU needs to "step in" is when we want to update something or we want to start/stop the timer → start/stop the motor. Wait until I write my own, timer-based library and you will understand what I am talking about.
@kymcainday6677 Жыл бұрын
Why not use ESP32 with dual core using free RTOS? The core used by WiFi will be used by the stepper only and the other core for the other tasks.
@CuriousScientist Жыл бұрын
Because I am not experienced with that system. Since the code I wrote is freely available, please feel free to port it for ESP32 if you want. I would be happy to learn from your implementation.
@christoskylar2601 Жыл бұрын
@@CuriousScientist The suggestion by @kymcainday6677 is certainly a viable option. And with the ESP32 being Arduino compatible, it is not even necessary to port the code. It will run directly on the ESP32.
@CuriousScientist Жыл бұрын
@@christoskylar2601 I would be very careful with this statement. Just because you can compile the code for ESP32, it does not mean that the code that you originally wrote for Arduino will work with ESP32 without any modifications. I know. I am constantly getting core panic errors with a code that is originally made for Arduino and I am trying to run it on ESP32.
@christoskylar2601 Жыл бұрын
@@CuriousScientist Well, I'm not having any such errors. Obviously, you need to install the ESP32 libraries and use different pins, but Arduino code runs equally well on ESP32. That's been my experience. It's my first time with ESP32 and I'm very happy to have tried it. Hopefully others will try it too.
@christoskylar2601 Жыл бұрын
I just want to add that I'm using the DOIT ESP32 Devkit V1. Maybe other models behave differently.
@paulocella97454 жыл бұрын
Good!!
@CuriousScientist4 жыл бұрын
Thank you! Cheers!
@alf30712 жыл бұрын
this sucks I wish u could control motors and sensors from one arduino , why haven't they thought of this problem? this sucks to need two arduinos for something simple as controlling a stepper while reading some sensors...
@CuriousScientist2 жыл бұрын
Probably some better programmer than I would be able to figure this out without the need for 2 MCUs. I just show an alternative way that could give a solution for the issue.
@alf30712 жыл бұрын
@@CuriousScientist it may have something to do with using the runSpeed() command of the library inside the loops doing calculations and other stuff, I will try this tomorrow
@alf30712 жыл бұрын
@@CuriousScientist It worked dude! it's still a bit slower because those calculations take some time but it's way smoother now when I put that command between calculations