stepper control with VMA333 driver

hey folks, could use some code help here. I've got everything working great. Only problem is that I don't know how to change this code to do what I want.

so I've got a stepper motor working with a force sensor. Stepper is connected to the VMA333 stepper driver, which is controlled by an Uno. everything works great. stable operation, power is great, etc etc.

the only example code from Velleman is this:

void setup() {
pinMode(3,OUTPUT);
pinMode(A0,OUTPUT);

// Set pin 9's PWM frequency to 3906 Hz (31250/8 = 3906)
// Note that the base frequency for pins 3, 9, 10, and 11 is 31250 Hz
//setPwmFrequency(9, 8);

// Set pin 6's PWM frequency to 62500 Hz (62500/1 = 62500)
// Note that the base frequency for pins 5 and 6 is 62500 Hz
//setPwmFrequency(6, 1);

// Set pin 10's PWM frequency to 31 Hz (31250/1024 = 31)
//setPwmFrequency(10, 1024);
;
}

void loop() {
  analogWrite(3,200);
  digitalWrite(A0,HIGH);
  delay(1000);
  digitalWrite(A0,LOW);
  delay(1000);
}

This code makes the stepper move back and forth forever. how far it moves is controlled by the delay. Basically the stepper moves for as long as the delay.

I modified the code to get it to work with a force sensor. This code works. You press the sensor, the stepper moves in one direction for the length of the delay, then moves back to it's original position, then waits until you press the sensor again.

int pressurePin = A5;
int force;
int LEDpin = 13;
int stepperPin = A0;
int clockPin = 3;
int stepperDelay = 1500;

void setup() {
pinMode(clockPin,OUTPUT);
pinMode(stepperPin,OUTPUT);
pinMode(LEDpin, OUTPUT);
Serial.begin(9600);
analogWrite(3,128);
}

void loop() {
  force = analogRead(pressurePin);
  Serial.println(force);
  
if(force >= 500){
  digitalWrite(LEDpin, HIGH);
  analogWrite(3,200);
  digitalWrite(A0,HIGH);
  delay(stepperDelay);
  digitalWrite(A0,LOW);
  
  delay(stepperDelay);
  analogWrite(3,0);
  delay(1500);
}
else
{
  digitalWrite(LEDpin, LOW);
  analogWrite(3,0);
  //delay(1500);
}
}

So the problem is, I need to it do the same thing, but at higher rpm's. The way this code is setup, there's no speed control. I can't figure out what the second number in the analogWrite is doing, but it's not speed. Zero makes it do nothing, i.e. stay still, and any other number makes it move.

All of the stepper libraries I've seen have it setup so that there's a function or variable to control rpm's and number of steps. However, due to the way the VMA333 is wired, I can't figure out how to use the libraries. The standard arduino stepper library uses pins 8-11 to control the stepper, however this board uses two control pins. Digital 3 controls "pulse" and A0 controls "direction", according to the data sheet, but it seems to do the opposite.

any ideas how I can achieve what I want, either by A: modifying my existing code to change the speed the motor moves, or B: using a stepper library with this stepper driver?

fwiw, here's the data sheet for the chip, and for the stepper driver board .

I have it wired exactly like it says to in that pdf.

sardonicmath:
So the problem is, I need to it do the same thing, but at higher rpm's.

Change the value of the variable stepperDelay to a smaller value.

...R
Stepper Motor Basics
Simple Stepper Code

Robin2:
Change the value of the variable stepperDelay to a smaller value.

...R
Stepper Motor Basics
Simple Stepper Code

that doesn't work. it makes the stepper not move as far. no speed control. the stepperDelay controls how long the motor is on. there is no control for how far it goes, other than how long the motor is on. it moves at the same speed no matter what I do. If I set the delay for 1000, it moves about 1/4 turn. 1500 does about a 1/3 turn. and so on. I need it to do the 1/3 turn in less time than it currently takes to do the 1/4 turn.

it basically works like this:

  1. read force sensor
  2. if force sensor is being pressed:
  • A. turn LED on.
  • B. turn stepper on in one direction for length of time specified in stepperDelay
  • C. turn stepper on in other direction for length of time specified in stepperDelay
  • D: wait for 1500 before checking sensor again
  1. if force sensor is not being pressed:
  • A. turn LED off
  • B: do nothing with stepper

sardonicmath:
that doesn't work. it makes the stepper not move as far. no speed control

Try the code in the link I gave you - it is conceptually much simpler.

...R

Robin2:
Try the code in the link I gave you - it is conceptually much simpler.

...R

how would I change the wiring to work with that code?

sardonicmath:
how would I change the wiring to work with that code?

IIRC the driver has Ena + and - and Dir + and - and Step + and - (don't have time to reload the user manual now).

Connect the negative connections to Arduino GND and connect the Dir + to the direction pin in the program and the Step + to the step pin in the program.

OR, if you already have them connected differently just change the program to match your pin connections.

Some drivers require you to set the Enable pin so you may need to experiment by connecting it to GND or 5v (I'm assuming you don't need to control it with your program).

...R

Robin2:
IIRC the driver has Ena + and - and Dir + and - and Step + and - (don't have time to reload the user manual now).

Connect the negative connections to Arduino GND and connect the Dir + to the direction pin in the program and the Step + to the step pin in the program.

OR, if you already have them connected differently just change the program to match your pin connections.

Some drivers require you to set the Enable pin so you may need to experiment by connecting it to GND or 5v (I'm assuming you don't need to control it with your program).

...R

it has CLK+ and -, EN+ and -, and CW+ and -. The manual says that the CW is direction and the CLK is pulse, but the code seems to work the opposite way. Setting the CLK (on D3) to high makes it go one way, setting it to low makes it go the other way. CW is being set to "128" on A0 in their example. I've changed the variable to a million things and it doesn't seem to do anything at all unless I change it to 0, in which cast it does nothing.

Robin2:
IIRC the driver has Ena + and - and Dir + and - and Step + and - (don't have time to reload the user manual now).

Connect the negative connections to Arduino GND and connect the Dir + to the direction pin in the program and the Step + to the step pin in the program.

OR, if you already have them connected differently just change the program to match your pin connections.

Some drivers require you to set the Enable pin so you may need to experiment by connecting it to GND or 5v (I'm assuming you don't need to control it with your program).

...R

ok, i got it working. although whether I have the "direction" pin connected or not changes nothing. how do i control the speed and distance the motor moves with that code?

sardonicmath:
ok, i got it working. although whether I have the "direction" pin connected or not changes nothing. how do i control the speed and distance the motor moves with that code?

Please post the actual program that you have uploaded to your Arduino and ALSO post a photo of a pencil drawing showing exactly how you have everything connected.

The value of the variable millisBetweenSteps controls the speed. I had hoped that would have been self evident maybe you can suggest a better name for the variable?

...R

Robin2:
Please post the actual program that you have uploaded to your Arduino and ALSO post a photo of a pencil drawing showing exactly how you have everything connected.

The value of the variable millisBetweenSteps controls the speed. I had hoped that would have been self evident maybe you can suggest a better name for the variable?

...R

i did figure that out right after I posted the comment. i put that variable down to 1 and it's almost as fast as I need it. Probably the gearbox reduction making it too slow. I did notice that the way you have your code set up, slowing the motor down makes the operation very, very, not smooth, which is not an issue i've run into with the various libraries.

sardonicmath:
I did notice that the way you have your code set up, slowing the motor down makes the operation very, very, not smooth, which is not an issue i've run into with the various libraries.

If you want smoother movement at low speeds you need to use microstepping.

...R

Robin2:
If you want smoother movement at low speeds you need to use microstepping.

...R

What is it with the people on this board answering questions in the most obtuse way possible? I used to use this forum alot back around 2007/2008 and folks were way more helpful and with way less attitude. It's like people on here now actively try to obfuscate the answer in any way they can. is it an ego thing? I don't get it.

"Hey how do I make this green?"

"I believe green does not convey the proper gravitas, perhaps you should consider orange."

"Ok how do I make it orange?"

"But what IS orange, really? Do you know the history of the development of the paintbrush? Perhaps you should look it up."

"FFS, how do I make it a color?"

Your code runs the stepper much rougher at low speeds than any other code I've used, no matter what type of steps were run with the other code.

sardonicmath:

If you want smoother movement at low speeds you need to use microstepping.

What is it with the people on this board answering questions in the most obtuse way possible?

I don't see anything obtuse in what I said - it is a simple statement of fact.

If you need more explanation then please let me know what you are having difficulty with.

...R