Hi, @Paul_KD7HB , could you give me some guidance in what part of the documents should I be looking through?
This is some example code of how to move a stepper more smoothly at a constant rpm. If you need acceleration, you ramp down the step timing, or you can use one of the stepper libraries which includes acceleration.
// Define the number of steps per revolution
uint8_t microSteps = 16;
uint32_t stepsPerRevolution = 200*microSteps; //3200
uint32_t targetRPM = 60;
uint16_t stepsPerSecond = (stepsPerRevolution*targetRPM)/60;
uint32_t usStepDelay = 1000000ul/stepsPerSecond; //312.5 us between steps
//Pin for enabling the stepper motor (needs to be LOW for the motor to work)
uint8_t enablePin = 8;
uint8_t stepPin = 7;
uint8_t dirPin = 4;
void setup()
{
// Set the enable pin to OUTPUT and initially set it LOW
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, LOW);
pinMode(dirPin, OUTPUT);
digitalWrite(dirPin, HIGH);//HIGH or LOW will set directioncw/ccw
pinMode(stepPin, OUTPUT);
digitalWrite(stepPin, LOW);
}
void loop()
{
uint32_t now = micros();
static uint32_t lastStep = 0;
if (now - lastStep >= usStepDelay)
{
lastStep = now;
digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);
}
}
I have merged your cross-posts @User24228.
Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.
Repeated cross-posting can result in a suspension from the forum.
In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
I have this code but its not working!
// Define pins
#define EN_PIN 8 // LOW: Driver enabled. HIGH: Driver disabled
#define STEP_PIN 2 // Step Pin
#define RX_PIN 6 // SoftwareSerial pins
#define TX_PIN 6 //
#include <TMC2208Stepper.h>
// Create driver that uses SoftwareSerial for communication
TMC2208Stepper driver = TMC2208Stepper(RX_PIN, TX_PIN);
void setup() {
driver.beginSerial(9600);
// Push at the start of setting up the driver resets the register to default
driver.push();
// Prepare pins
pinMode(EN_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
driver.pdn_disable(true); // Use PDN/UART pin for communication
driver.I_scale_analog(false); // Use internal voltage reference
driver.rms_current(500); // Set driver current = 500mA, 0.5 multiplier for hold current and RSENSE = 0.11.
driver.toff(2); // Enable driver in software
digitalWrite(EN_PIN, LOW); // Enable driver in hardware
}
void loop() {
digitalWrite(STEP_PIN, !digitalRead(STEP_PIN));
delay(1);
}
that is rather vauge!
what does the code do? what should it do?
have a read of how-to-get-the-best-out-of-this-forum
Is this correct?
have you badly copied / tailored their example?
they have different pins for Tx and Rx
don't use the same pin as it might confuse SofwareSerial (the Tx pin is an output and the Rx pin is an input)
Depending on your application, the step/dir mode of the 2208 might be all that you need, and it is very simple to wire and run without the serial interface.
People on the internet said that is not recommended to connect stuff to the TX pin and the RX pin, what other pins do I use?
How do I make that? is the step/dir mode good?
just pick two pins that you don't use, like 3 and 4 for example.
just don't use 0 and 1 indeed
In the code, when the delay is 1, it makes a weird noise and the motor does not move. When i put 10 it goes back and forth. Something is wrong?
Also, the code said current 500Ma, but it is actually not changing anything! Do you know why?
your TMC2208 driver has a STEP_PIN
every time there is a rising edge (LOW to HIGH) on that pin, a step is taken
The (poorly written) code
digitalWrite(STEP_PIN, !digitalRead(STEP_PIN));
is flipping the pin state. it's like you had written
if (digitalRead(STEP_PIN) == LOW)
digitalWrite(STEP_PIN, HIGH); // it was LOW, make it HIGH
else
digitalWrite(STEP_PIN, LOW); // it was HIGH, make it LOW
the delay() after this command is basically how fast you switch the pin state ➜ here it's every ms.
so the STEP_PIN does
LOW
wait 1ms
HIGH ➜ a step is taken
wait 1ms
LOW
wait 1ms
HIGH ➜ a step is taken
wait 1ms
LOW
wait 1ms
HIGH ➜ a step is taken
wait 1ms
LOW
wait 1ms
HIGH ➜ a step is taken
wait 1ms
can you share a picture of your circuit and describe how things are powered
Above you said that the pin 3 and 4 can be used, in the driver where do i connect these 2 wires?
you connect only one but you don't use the extra pin for anything else as it's "reserved" for the SoftwareSerial port
2 apparently different topics by different people are actually the same topic by 2 people working together, so I have merged them.
@User24221 and @User24228 please only use this topic for your questions about your stepper motor project, please do not create any more.
Thank you.
So google is ALWAYS worth a five minute search
I searched on youtube simply with TMC2208
Third video is this one
at 8:30 the teach tech guy mentions a website which is listed in the text below the video
Sean Sadler’s comprehensive instructable to using the 2208 in dynamic UART (mode 3): https://www.instructables.com/id/UART...
additionally the uart-mode configures the stepper-driver
with uart you can adjust
- the current
- the drive-mode
- the microstepping
for making a stepper-motor rotate in uart-mode you still use the step/dir-inputs
This means feeding the stepper-driver in his step/dir-input makes the stepper-motor rotate
even in UART-mode.
Though there might be one reason why it does not work:
damaged driver-chip.
If you have the power-supply connected to the TMC2208-driver-board and you connect or dis-connect the motorwires the chip can be damaged!
This is due to the high voltage-spikes that occur in the moment you dis-connect te wire.
The stepper-motor has coils just like an electric fence and each time a current flows through the coil and you disconnect the power-supply a high voltage-spike occurs
So if you have fiddled around with the motor-wires connecting / disconnecting the motorwires while the power-supply was switched on and connected to the driverboard you might have damaged the driver-board.
So make sure to connect the motorwires with high reliability and always switch off the power-supply before you change anything on the motorwires.
If you have a new and not yet used TMC2208 stepperdriver board
switch powersupply off.
connect all wiring
and then use a small testcode that does nothing more then creaing step-pulses at a rather low frequency to test if the motor rotates at all.
This basic test does not require any kind of uart-communication.
best regards Stefan