Hi y'all,
I'm hoping I placed this post in the correct place. For my first arduino project I'm driving a NEMA17 stepper motor with the TMC2100 "silent stepper" driver. I'm using a 12v 2250 milliampere adapter to power the driver and put a 47 microfarad capacitor between the + and - alas I just noticed it is 10V. The Arduino board is powered using a "powerbar" with two usb ports.
Sorry for my failed attempt to create a clear electronic scheme.
I'm not the most fervent programmer, but I've been trying to get the board to bootup when powered and to tell the stepperdriver to accelerate smoothly from stillness, rotate very slowly and come to a full stop with a chance of slowly accelerating in the opposite direction. Repeat. I'm using an inverted and offset cosine to fade in the speed when it gets to it's minimum and maximum. There's probably a much more efficient and consistent way of getting this program to work, but here's my attempt:
#include "AccelStepper.h"
// Define a stepper and the pins it will use
AccelStepper stepper(4,5);
int StepSpeed; // scaled version of stepper speed in steps per second(?)), uses a cosine to vary in speed
int Counter; // counts the amount of updates before adding to the index of the cosine; The time it takes to progress the cosine
int Index; // drives the cosine that varies the stepperspeed (Scale)
int WavDir; // direction of rotation
int Mod; // introduces an extra modulation in speed for extra unpredictability
int ModCounter; // counts amount of updates before adding to the index of the extra mod
int ModIndex; // index that in turn drives another cosine to extra modulate the speed, maybe this should be a sine wave instead,
bool WavDirEva;
void setup()
{
int speed = 1000;
stepper.setMaxSpeed(speed);
stepper.setAcceleration(100);
stepper.setSpeed(1000);
Serial.begin(9600);
Counter = 0;
StepSpeed = 0;
Index = 0;
Mod = 0;
ModIndex = random(0,628);
WavDir = random(-1,1);
if (WavDir== 0) {WavDir = 1;}
WavDirEva = false;
}
void loop()
{
Counter = Counter + 1;
if (Counter >= Mod) // after this many updates changes speed by adding 1 index
{
StepSpeed = ((( cos ( Index / 100.0 ) * -0.5 ) + 0.5 ) * 1000 ) * WavDir; // cosine because it starts at the most outward amplitude, making it more smooth around both extremes
// the * -1 + 1 makes the cos start at 0 and climb up to, perhaps better to multiply the StepSpeed with the mod rather than add it. So that the mod can have a random beginning point without losing the "fade in"
Index = Index + 1;
Counter = 0;
if (Index == 628){ //6,28 = (2*pi) almost a full cos cycle.
Index = 0;
}
// Serial.println(StepSpeed);
}
ModCounter = ModCounter + 1; //introduces an extra modulation for stepperspeed.
if (ModCounter == 10000)
{
ModIndex = ModIndex + 1;
Mod = (((cos(ModIndex/100.0)*-0.5)+0.5)*1000)+1500; // Maximum should be 1000 steps p/s. So compensate in StepSpeed
ModCounter = 0;
if(ModIndex == 628)
{
ModIndex = 0;
}
// Serial.println(Mod);
if (StepSpeed != 0 && WavDirEva == true)
{
WavDirEva = false;
}
if (StepSpeed == 0 && WavDirEva == false) // somewhere here something is still wrong, causing too often a negative stepspeed
{
WavDir = random(-1,1);
if (WavDir== 0)
{
WavDir = 1;
}
// Serial.println(WavDir);
WavDirEva = true;
}
Serial.println(StepSpeed);
Serial.println(Mod);
Serial.println(WavDirEva);
}
stepper.move(StepSpeed);
stepper.run();
}
Here's what I'm trying to achieve: it worked for a while, but after connecting 3 times or so the board started only flashing the blue power light causing the motor to only pulse a bit synchronous to the power light. This happened with two different boards. Did I fry them? They don't show up in the serial ports anymore.
Help is very much appreciated!
Jorick