#include <Arduino.h>
#include "FastAccelStepper.h"
#define dirPinStepper 5
// #define enablePinStepper 6 // Uncomment if you use an enable pin
#define stepPinStepper 9
FastAccelStepperEngine engine = FastAccelStepperEngine();
FastAccelStepper *stepper = NULL;
void setup() {
engine.init();
stepper = engine.stepperConnectToPin(stepPinStepper);
if (stepper) {
stepper->setDirectionPin(dirPinStepper);
// stepper->setEnablePin(enablePinStepper); // Uncomment if you use an enable pin
stepper->setSpeedInHz(500); // 500 steps/s
stepper->setAcceleration(100); // 100 steps/s²
stepper->move(1000); // Move 1000 steps
}
}
void loop() {
}
//Above is the "usageExample" code from the fastAccelStepper library
Hello! I am trying to get the Fastaccelstepper library to work with the arduino UNO and a TMC2209 Stepper driver
The wiring is as follows:
on the TMC2209:
Vin/GND- 12 volt power supply
VIO/GND- 5 volts and ground on the arduino pins
Step- pin 8 arduino
Dir- pin 7 arduino
Enable and grounds are connected.
This setup WORKS other code libraries i'm testing, so I know issue is not the hardware. Of all the examples Ive seen online, no one has actually used an arduino uno for this library. Should I just get an ESP board instead? even though the documentation example code "usageExample" (which is what I'm using) does say that it supports arduino?
Not sure if you have yet, but I would suggest taking a look at the FastAccelStepper GitHub page. I did a project a while back with the same driver and library (but not using the UNO). It helped immensely. UNO is listed as compatible. Runs on the ATmega328P.
Here are some of the details I saw from a quick read:
Supported are avr (ATmega 168/328/P, ATmega2560, ATmega32u4)
Step Signal - avr atmega168/328/p: only Pin 9 and 10
Would also suggest looking at Direction Signal and Enable Signal. Make sure the optional parameters are set correctly to your needs as both default to their own settings if not changed. Enable Signal defaults to low, so your setup seams ok there.
So, yeah.. your setup seams like it should work. Without more info, I'd say start with trying step signal on pin 9/10?
#include "FastAccelStepper.h"
#include "AVRStepperPins.h" // Only required for AVR controllers
#define dirPinStepper 5
#define enablePinStepper 6
#define stepPinStepper 9
// If using an AVR device use the definitons provided in AVRStepperPins
// stepPinStepper1A
//
// or even shorter (for 2560 the correct pin on the chosen timer is selected):
// stepPinStepperA
FastAccelStepperEngine engine = FastAccelStepperEngine();
FastAccelStepper *stepper = NULL;
void setup() {
engine.init();
stepper = engine.stepperConnectToPin(stepPinStepper);
if (stepper) {
stepper->setDirectionPin(dirPinStepper);
stepper->setEnablePin(enablePinStepper);
stepper->setAutoEnable(true);
stepper->setSpeedInHz(7750); // 500 steps/s
stepper->setAcceleration(5000); // 100 steps/s²
stepper->move(100000);
}
}
void loop() {
}
Okay! This is the example taken from github with speed and acceleration changed. I updated the code so that i'm using pins 5 and 9 for direction and step respectively and it works! unfortunately, the fastest I can set the speed is about 7750 steps/sec before it starts humming unpleasantly (im assuming it means it is losing steps?) i understand the stealthchop vs spreadcycle configurations might allow me to go faster, I'm going to configure that next.
AVR ATMega 168/168P/328/328P - allows up to 50000 generated steps per second for single stepper operation.
Hard to say what's going on with the humming. I know when pushing my steppers to the max they would produce some loud coil whine.
As far as missing steps.. when I tested my steppers, I folded over a piece of tape on the shaft like a flag at the tip. Helped to identify position and rotation. Easy way to tell if you experiencing losing steps if it stops at unexpected positions after rerunning the code.
I'd suggest -
Checking the stepper motors spec sheet
Making sure your power supply is able to provide enough amperage
Reading the entirety of the library reference from GitHub
There are lots of websites that can be a big help with calculations and such. Just google "stepper motor calculator".
(*Edited per guidelines) I used allaboutcircuits calculator for my project.
From my little experience with projects involving stepper motors, I can tell you things can get complicated quickly. The more upfront information you have, the easier it will be to setup. Ergo.. also easier to diagnose the most common issues.
Edit: Before I forget to mention... again.
I could have sworn one of my project issues was the TMC2209 micro stepping settings combined with my acceleration settings. Caused some unexpected results. Something to look into.
If you find you need more fine tuned controls of the drivers, I'd suggest reading up on controlling and setting up through its UART port.
Your speed limitation is because you are using a stepper motor. All stepper motors have good low speed torque but dramatically fall off with rpm, and eventually stall.