Forums > MaxMSP

### Arduino Stepper control through Max Msp Kinect

Sep 10 2012 | 3:24 pm

hi

i trying to find out what is the best solution to control two stepper motors with arduino and max msp.
i tried maxuino but i wont work.
i am using an max msp 6, arduino uno, two easy driver boards and two steppers (https://www.sparkfun.com/products/9238).
Servo control is not a problem but in this setup that isnt the solution.
So it would be very nice if someone could share his solution to control steppers with Max.

I tried the Serialfunction with this code below but it was not working.. So if anyone could point me in the right direction
( http://bildr.org/2011/06/easydriver/ )

//////////////////////////////////////////////////////////////////
//Using the easy stepper with your arduino
//use rotate and/or rotateDeg to controll stepper motor
//speed is any number from .01 -> 1 with 1 being fastest –
//Slower Speed == Stronger movement
/////////////////////////////////////////////////////////////////

#define DIR_PIN 2
#define STEP_PIN 3

void setup() {
pinMode(DIR_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
}

void loop(){

//rotate a specific number of degrees
rotateDeg(360, 1);
delay(1000);

rotateDeg(-360, .1); //reverse
delay(1000);

//rotate a specific number of microsteps (8 microsteps per step)
//a 200 step stepper would take 1600 micro steps for one full revolution
rotate(1600, .5);
delay(1000);

rotate(-1600, .25); //reverse
delay(1000);
}

void rotate(int steps, float speed){
//rotate a specific number of microsteps (8 microsteps per step) – (negitive for reverse movement)
//speed is any number from .01 -> 1 with 1 being fastest – Slower is stronger
int dir = (steps > 0)? HIGH:LOW;
steps = abs(steps);

digitalWrite(DIR_PIN,dir);

float usDelay = (1/speed) * 70;

for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(usDelay);

digitalWrite(STEP_PIN, LOW);
delayMicroseconds(usDelay);
}
}

void rotateDeg(float deg, float speed){
//rotate a specific number of degrees (negitive for reverse movement)
//speed is any number from .01 -> 1 with 1 being fastest – Slower is stronger
int dir = (deg > 0)? HIGH:LOW;
digitalWrite(DIR_PIN,dir);

int steps = abs(deg)*(1/0.225);
float usDelay = (1/speed) * 70;

for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(usDelay);

digitalWrite(STEP_PIN, LOW);
delayMicroseconds(usDelay);
}
}

Sep 10 2012 | 4:55 pm

i remember i once found help here:
http://cycling74.com/forums/topic.php?id=8503

worked with maxuino in these days…

Sep 10 2012 | 5:55 pm

I’ve never used an easy board before, but this should be enough to get you started with taking steps in one direction :

``` #define DIR_PIN 2 #define STEP_PIN 3```

void setup() {
pinMode(DIR_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
//being serial communication
Serial.begin(9600);
}

void loop(){
//create variable to hold the number of steps
int steps =0;
// if there's serial information in the buffer
// save that in the steps variable
if(Serial.available()>0){
}
//rotate a specific number of degrees
rotate(steps*8, 1);
//wait for a moment
delay(5);
}

void rotate(int steps, float speed){
//rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement)
//speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
int dir = (steps > 0)? HIGH:LOW;
steps = abs(steps);

digitalWrite(DIR_PIN,dir);

float usDelay = (1/speed) * 70;

for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(usDelay);

digitalWrite(STEP_PIN, LOW);
delayMicroseconds(usDelay);
}
}

``````-- Pasted Max  Patch, click to expand. --

```
```
Sep 11 2012 | 11:25 am

thank you so much scott!
now i will try to change the code.
@tobias
maxuino will einfach nicht funktionieren habe wirklich alles probiert und es an verschiedenen rechner ausprobiert und es will einfach nicht …
keine ahnung was ich falsch mache aber ich bin am verzweifeln und versuche jetzt den "umweg" über serial read zu gehen. obwohl ich natürlich maxuino vorziehen würde, da ich was code angeht ein vollkommener neuling bin und max mir mit den nodes schon sehr zusagt. also falls du mir irgendwie mit maxuino weiterhelfen könntest wäre ich dir verdammt dankbar!

Sep 11 2012 | 11:48 am

hey, when i used maxuino with steppers the stepper libraries where non existing back then, and i think i used something as a l293 motor driver..
i just had a quick look on the maxuino-webpage –

— This version of maxuino has stepper capability, but only if you also use our stepperFirmata variant. If you use the Firmata that is shipped with the Arduino IDE it will work just fine for everything except it will not run stepper motors.

did you upload the stepperFirmata or just Standart Firmata?

Sep 11 2012 | 11:54 am

hey tobias

i tried both but it wont work. at the moment i am trying to figure out how to change scotts code to make a direction change but later i will give maxuino another try…

Sep 11 2012 | 12:46 pm

ok, you most probably also did:

– "Dont forget you need to add stepperDriver to your arduino libraries folder and restart Arduino IDE to get this Firmata to work."

and

– "set the modes for each of the pins you will use. […] the digital pins are on the right and have 7 modes:

Digital input
Digital output
PWM output
Servo
Stepper Motor Step
Stepper Motor Direction

[attachment=203189,4388]

###### Attachments:
1. Screenshot20120911at20.38.00.png

Sep 11 2012 | 2:05 pm

yea you are right i tried that.
i just discovered that the stepper driver is not yellow is this perhaps the problem? but i copied the StepperDriver into the arduino libaries and also in the arduino libraries folder in the document section. which is the correct one?

i also discovered a strange thing i made a picture to explain it.. perhaps someone can understand it…

edit: i know its not the right PIN configuration but thats the only way to move the stepper. with the right DIR and STEP Pin configuration its not working

[attachment=203200,4391] [attachment=203200,4392]

###### Attachments:
1. stepperproblem.jpg

Sep 11 2012 | 7:22 pm

so i reinstalled everything and the problem is still there. i uploaded the stepperfirmata from maxuino and set the right pin configuration.
the rx led on the arduino board is blinking when i move the STEP Pin in max so its getting information but the stepper is not moving :(

there is an example code from the maxuino stepper driver which is:

#include

const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution for your motor
StepperDriver myStepper; //initialize for one stepper

void setup() {
myStepper.setStep(stepsPerRevolution, 12,10);
myStepper.setSpeed(8); //with 1/8th stepping turned on, 1 rpm * 8 = 8
myStepper.step(stepsPerRevolution*8); //with 1/8 stepping turned on, one full revolution needs to be multiplied x 8
}

void loop() {
// step one revolution in one direction:

if (myStepper.update() == 1){ //here we check to see if the motor has finished the last step command and at the same time call the update for the motor to keep running
delay(1000); //when a full revolution is complete, wait 1second and do another full rev.
myStepper.step(stepsPerRevolution*8);
}
}

this example code is working. so i think the problem is in the max patch?

Apr 28 2013 | 1:10 pm

hey scott,
it’s work nicely BUT i would like to turn the stepper in other direction
i don’t know how send negative value to arduino …
i found a bad solution, is to map the max value to have negative value in arduino!
it’s work but i think there is better solution

#define DIR_PIN 2
#define STEP_PIN 3
int value;

void setup() {
pinMode(DIR_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
//being serial communication
Serial.begin(9600);
}

void loop(){
//create variable to hold the number of steps
int steps =0;
// if there’s serial information in the buffer
// save that in the steps variable
if(Serial.available()>0){
value = map(steps,127,255,0,255); //donc tt ce qui est en dessous de 127 est négatif!!
//all above 127 is negative
}
//rotate a specific number of degrees
rotate(steps*8, 1);
//wait for a moment
delay(5);
}

void rotate(int steps, float speed){
//rotate a specific number of microsteps (8 microsteps per step) – (negitive for reverse movement)
//speed is any number from .01 -> 1 with 1 being fastest – Slower is stronger
int dir = (value > 0)? HIGH:LOW;
steps = abs(steps);

digitalWrite(DIR_PIN,dir);

float usDelay = (1/speed) * 70;

for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(usDelay);

digitalWrite(STEP_PIN, LOW);
delayMicroseconds(usDelay);
}
}

do you have a better idea?
thank’s

Jul 29 2013 | 8:50 pm

Did you ever figure this out?

Aug 19 2013 | 7:42 pm

I’m finding a lot of these same issues, it would be great to hear about how you resolved this. Thanks

Feb 03 2014 | 6:45 pm

hello hope all is good !!!

just wondering if you guys sorted this out..

thanks

Viewing 13 posts - 1 through 13 (of 13 total)

Forums > MaxMSP