04-06-2015, 05:34 PM
Chuck,
Try this code as a test.
All it does is to turn the stepper motor in one direction for about 3 seconds and then reverses the direction for about 3 seconds and repeats the cycle until power is removed. Digital pin 12 is the step and 13 is the direction.
Ed
Try this code as a test.
Code:
/*
Test that turns the stepper motor in one direction for about 3 seconds and then reverses it for 3 seconds in a continuous cycle. Digital pin 12 is the step signal and 13 is the direction signal.
*/
#include <Wire.h>
//setup vars
const int stp = 12; //connect pin 12 to step
const int dir = 13; // connect pin 13 to dir
const int StepsPerRotation = 200; //Set Steps per rotation of stepper
const int TableRatio = 90; //ratio of rotary table
const int Multiplier = (StepsPerRotation * TableRatio)/360;
const int stepdelay = 1;
float Degrees = 0; //Degrees from Serial input
float ToMove = 0; //Steps to move
int Direction = 1;
int repeat = 0;
void setup()
{
pinMode(stp, OUTPUT);
pinMode(dir, OUTPUT);
}
void rotation(float tm, int d)
{
if(d == 0)
{
digitalWrite(dir, LOW);
}
else
{
digitalWrite(dir, HIGH);
}
for(int i = 0; i < tm; i++)
{
digitalWrite(stp, HIGH);
delay(stepdelay);
digitalWrite(stp, LOW);
delay(stepdelay);
}
}
void loop()
{
if(repeat == 0)
{
Degrees = 30;
}
Degrees = Degrees * Direction;
if(Degrees < 0)
{
ToMove = (Degrees*Multiplier)*-1;
rotation(ToMove,0);
}
else
{
ToMove = Degrees*Multiplier;
rotation(ToMove,1);
}
if (Direction == 1)
Direction = -1;
else
Direction = 1;
}
All it does is to turn the stepper motor in one direction for about 3 seconds and then reverses the direction for about 3 seconds and repeats the cycle until power is removed. Digital pin 12 is the step and 13 is the direction.
Ed