Hey I thought I'd share my code to control the quadstep motor board from an Arduino Mega using Max MSP - both codes are below.
My question - is it possible to control the acceleration and velocity of the stepper motors? The motors move very 'digitally'.
not really sure how to do it with the quadstep.h library.
Any thoughts would be great!
Hope at least my code is useful to someone using the max and the quadstep board.
/*
SparkFun Electronics 2011
Aaron Weiss, aaron at sparkfun dot com
Beer-ware License: You can do whatever you want with this sketch.
If we meet someday, you can buy me a beer.
QuadSetpper Example Sketch. For use with an Arduino Mega2560 and
a 1.8 degree bipolar stepper motor.
You must connect the STP pin for each motor as shown below.
For rest of the pins, you choose where they go.
Motor1 STP pin: mega pin 11
Motor2 STP pin: meag pin 5
Motor3 STP pin: meag pin 6
Motor4 STP pin: mega pin 46
Library Usage:
motor_pins(x,y,z,l,m,n)
x: motor channel number
y: enable pin assignment
z: direction pin assignment
l: MS1 pin assignment
m: MS2 pin assignment
n: MS3 pin assignment
motor_go(x,y,z,l)
x: motor channel number
y: step size: 1, 2, 4, 8, or 16
z: increments for given step size
for full step: 1 increment = 1.8deg
for half step: 1 increment = 0.9deg and so on
negaitve numbers rotate in the opposite direction
l: torque/speed (0-10), 0 is high speed/low torque/low current
10 is low speed/high torque/high current (2.0A max)
stall(x)
x: motor channel number
*/
// include the motor library
#include <quadstep.h>
// create an instance of the class motor
quadstep quadstep;
#include <string.h>
boolean stringComplete = false; // whether the string is complete
char strDelimiter []= ", ";
char* p;
int motor = 0, stpSize = 0, steps = 0, torque = 0;
char str[] = "0001, 0001, 2000, 0008";
int i=0;
void setup() {
Serial.begin(9600);
// assign the pin connections
quadstep.motor_pins(1,A1,36,A8,A9,A10); //ch 1
quadstep.motor_pins(2,10,9,8,7,4); //ch 2
quadstep.motor_pins(3,22,23,24,25,26); //ch 3
quadstep.motor_pins(4,27,28,29,30,31); //ch 4
}
void loop() {
if (stringComplete) {
if (p = strtok(str, strDelimiter)) {
Serial.print("motor = ");
Serial.println(p);
motor = atoi(p);
}
if ( p = strtok(NULL, strDelimiter)) {
Serial.print("stpSize = ");
Serial.println(p);
stpSize = atoi(p);
}
if ( p = strtok(NULL, strDelimiter)) {
Serial.print("steps = ");
Serial.println(p);
steps = atoi(p);
}
if ( p = strtok(NULL, strDelimiter )) {
Serial.print("torque = ");
Serial.println(p);
torque = atoi(p);
}
quadstep.motor_go(motor,stpSize,steps,torque);
// clear the string:
//char str[] = "0000, 0000, 0000, 0000";
stringComplete = false;
}
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while(Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
str[i] = inChar;
i++;
if (inChar == '\n') {
stringComplete = true;
// Serial.println("GOG");
// Serial.println(str);
i=0;
}
}
}
Here is the Max MSP code too!
----------begin_max5_patcher----------
1804.3oc0atziSqCE.d8L+JrhzU5dk5T4G4I6FwJVbWwh6B.gRacaCjFWrcm
Y.D+2u9QZmPII0kIwsfPsMNING+4iOublue6MAyXOQEAfWAdG3la99s2bioI
cC2Te7MAaxeZdYtvbYAanBQ9JZvD64jzmjl1QS.oS.HXbh5y8msrnhNmsqxb
I35Fq1sonpjJEG0Hambeqn5VWxpjhhuQMsAmBqa1dkxutkZk7f.vGpO01b47
0EUq9HmNWZOaHNRcm.THQ+Ujta.3jovC2SwByHfM6S2kjDz3QWkuw7DBtmWj
WFnOwOt8V8GSbjVUzGUc6u.KIXFnHnMdfZkG3yjGyxqVELADTnIeOngjAmFq
9WT7DPrgRD7zHEqR6.OQCKdly1rgpjwegOL9W1QOC.AaCP3C.ZKmJTOmbYAq
polQB9vvWOjm.f0ezq9TJYZTHJNUooiM2PLYZFx1MXXGji3GxIjzshQGbjzr
ooDBIL7b.WSsM2AG1efC7VMAFa3gyr1ixbka3rjCz1ctgFXKY61LixCNHkbU
OJo7ORqxmURaRiVAmpohM61bZSbpG5gKDdll8zl6lTa86Yf1wZ+TyrPH5rV1
u+FrdQ5zLI7ph8uLeImCTIlNBDBaEpJ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