TB Arduino example code Now that you have wired up the driver and set the dip switches, it is time to connect the Arduino to the computer and upload some code. For this specific example, you do not need to install any libraries. This sketch controls both the speed, the number of revolutions and the spinning direction of the stepper motor. You can open the code in a new window by clicking on the button in the top right corner.
|Published (Last):||27 July 2008|
|PDF File Size:||11.92 Mb|
|ePub File Size:||14.5 Mb|
|Price:||Free* [*Free Regsitration Required]|
TB Arduino example code Now that you have wired up the driver and set the dip switches, it is time to connect the Arduino to the computer and upload some code. For this specific example, you do not need to install any libraries. This sketch controls both the speed, the number of revolutions and the spinning direction of the stepper motor.
You can open the code in a new window by clicking on the button in the top right corner. I connected them to Arduino pin 3 and 2. The statement define is used to give a name to a constant value. The compiler will replace any references to this constant with the defined value when the program is compiled. So everywhere you mention dirPin, the compiler will replace it with the value 2 when the program is compiled.
I also defined a stepsPerRevolution constant. Change this value if your setup is different. Next we let the motor spin 5 revolutions in each directions with a high speed. So how do you control the speed, spinning direction and number of revolutions? For this we use the function digitalWrite. Control number of steps or revolutions: In this example sketch, the for loops control the number of steps the stepper motor will take.
The code within the for loop results in 1 micro step of the stepper motor. Because the code in the loop is executed times stepsPerRevolution , this results in 1 revolution. In the last two loops, the code within the for loop is executed times, which results in micro steps or 5 revolutions. Note that you can change the second term in the for loop to whatever number of steps you want. Control speed: The speed of the stepper motor is determined by the frequency of the pulses we send to the STEP pin.
The higher the frequency, the faster the motor runs. You can control the frequency of the pulses by changing delayMicroseconds in the code. The shorter the delay, the higher the frequency, the faster the motor runs. One of the advantages is that it supports acceleration and deceleration, but it has a lot of other nice functions too. You can download the latest version of this library here or click the button below.
The Library Manager will open and update the list of installed libraries. Select the latest version and then click Install. In the following example, the motor will run back and forth with a speed of steps per second and an acceleration of steps per second squared. If you are using a different setting, play around with the speed and acceleration settings. The motorinterface type must be set to 1 when using a step and direction driver. You can find the other interface types here.
Motor interface type must be set to 1 when using a driver: define dirPin 2 define stepPin 3 define motorInterfaceType 1 Next, you need to create a new instance of the AccelStepper class with the appropriate motor interface type and connections. The name that you give to the stepper motor will be used later to set the speed, position and acceleration for that particular motor.
You can create multiple instances of the AccelStepper class with different names and pins. This allows you to easily control 2 or more stepper motors at the same time. For this we use the function setMaxSpeed and setAcceleration.
The function stepper. I hope you found it useful and informative. If you did, please share it with a friend who also likes electronics and making things! I would love to know what projects you plan on building or have already built with this driver.
If you have any questions, suggestions or if you think that things are missing in this tutorial, please leave a comment down below. Note that comments are held for moderation to prevent spam.
TB6560 Stepper Motor Driver with Arduino Tutorial
If the checkbox is invisible, the corresponding document cannot be downloaded in batch. Related Links Frequently Asked Questions Notes The Part Number column shows representative part numbers only, which may not be available for sale in the precise form shown. Each Part Number constitutes a product family which may contain multiple associated product configurations. Information is subject to change at any time without notice.
ECG tb6560 User Manual