Adruino UNO
Sainsmart a4988 stepper motor driver
4-wire bi-polar stepper motor with 1.8 degree steps
I have been working on this class project and I don't have any idea on how to code the arduino to take an input signal (EOG) to control a stepper motor.
I'm having trouble getting the arduino to actually take the input and move the motor based on the EOG input. I tried to move the motor using a potentiometer, but it wasn't really effective.
Does anyone have an suggestions on how I can move forward or possibly have sample code??
Thanks in advance!
The code I used is exactly the same as www.arduino.cc/en/Tutorial/MotorKnob, except I changed the input pins to 2 and 3 for step and direction. I am just using an Agilent power supply, and supplying it with 12 volts.
The motor I am using is a SparkFun Mercury Motor, SM42BYG011-25.
mak491:
The code I used is exactly the same as www.arduino.cc/en/Tutorial/MotorKnob, except I changed the input pins to 2 and 3 for step and direction. I am just using an Agilent power supply, and supplying it with 12 volts.
The motor I am using is a SparkFun Mercury Motor, SM42BYG011-25.
Don't want to post the code you are using, then how do you expect help?
// change this to the number of steps on your motor #define STEPS 200
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 2,3);
// the previous reading from the analog input
int previous = 0;
void setup() {
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
}
void loop() {
// get the sensor value
int val = analogRead(0);
// move a number of steps equal to the change in the
// sensor reading
stepper.step(val - previous);
// remember the previous value of the sensor
previous = val;
}
Ah, that helps -
You need to use the AccelStepper library to drive the A4988, it takes step and direction outputs, the
Stepper library doesn't support this.
Ok here are two pictures of the setup with the potentiometer. Ideally I would like to have an EOG signal input into the A0 pin on the Arduino instead of the potentiometer but the potentiometer is just a way of testing that the circuit is running properly.
I have downloaded the Accelstepper library and the Adafruit motor shield library to use.
I don’t know how to use it with the potentiometer.
This is the code that I wrote to take in an EOG signal and use it to move the stepper motor. I have a feeling there is something very wrong with it so any advice would help thanks!
#include <AccelStepper.h>
int pinSTEP=3;
int pinDIR=2;
const int analogInPin= A0;
Use moveTo(), not move(), if you read the AccelStepper.h description of each function its
fairly clear what each one does. move() is relative to the last call to move(), which you don't want.
Don't call setCurrentPosition() at all except after homing the motor to a known position.
Ok so I removed the setCurrentPosition function and I changed the code so that I am using the moveTo function instead.
I also added an if-else statement so that if the voltage input from the EOG is larger than two volts, it will move the stepper in the CW direction, otherwise it should move in the CCW direction.
The issue is I think that it is drawing power from the voltage source and not from the EOG input at all.
Here is my new code:
#include <AccelStepper.h>
int pinSTEP=3;
int pinDIR=2;
const int analogInPin= A0;
void loop()
{
float sensorval = (analogRead(analogInPin)*5)/1024; //conversion from integer to volts
float degreeval= (sensorval-0.0113)/0.0045; //conversion from voltage to degrees
float stepval = degreeval/1.8; //conversion from degrees to steps
if (sensorval>=2)
stepper.moveTo(stepval); //moving steps in CW direction
else
stepper.moveTo(-stepval); //moving steps in CCW direction
stepper.run();