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.