Go Down

Topic: Stepper Motor Knob (Read 2 times) previous topic - next topic

eduardomag

On this example there is no information on how to connect the potentiometer to the circuit. It says the potentiometer is connected to the analog 0 of the Arduino. The pot has three legs. How do i conect it?
I am building a circuit to controll two steppers with a joystick. Two axes ( vertical and horizontal).
How should i modify this code:

/*
* MotorKnob
*
* A stepper motor follows the turns of a potentiometer
* (or other sensor) on analog input 0.
*
* http://www.arduino.cc/en/Reference/Stepper
* This example code is in the public domain.
*/

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 100

// 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, 8, 9, 10, 11);

// 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;
}

to control my two steppers?
Thanks so much.

jackrae

Connect the middle terminal to your analogue input, connect one of the two remaining legs to +5 volts, connect the other to arduino ground.  If the direction of travel is opposite to that you desire then reverse the connections to +5 and ground terminals.
jack

eduardomag

Thank you so much.
One more question:
Is it possible to use a joystick to controll a stepper back and forth and with variable speed depending on how far i push the joystick?
I´d like to build a circuit with two steppers and two drivers for this experiment. And of course in case there is a code that could allow that. I want to build this setup to test linear stages and steppers performance.Thanks again

Grumpy_Mike

There are two sorts of joystick, one that is proportional that has pots in them, they can be wired up just like the pot.
The other type are digital, these give just an on / off signal. It is possible to use this type but you need to write the software to time how long they have been pushed and move the motor accordingly.

eduardomag

This is the joystick i have.(http://www.sparkfun.com/products/9032).They do have pots. I am building his circuit and will try out. I am using the Arduino sample circuit with the SN754410NE H-bridge. It would be wonderful to be able to vary the speed from mid point up or down, left or right.I´ll try it out and post my results.

Grumpy_Mike

Well seeing the description says:-
Quote
Directional movements are simply two potentiometers - one for each axis. Pots are ~10k each.

Then yes.

eduardomag

Hi again, I´ve been trying to make it work precisely like Arduino claims but there on precision at all.
The code i am using is this:


#include <Stepper.h>

#define STEPS 100


Stepper stepper(10, 8, 9, 10, 11);



int previous = 0;

void setup()
{
 
  stepper.setSpeed(30);
}

void loop()
{
 
  int val = analogRead(0);

 
  stepper.step(val - previous);

 
  previous = val;
}

The stepper moves back and forth following the pot but very erratically. I tried to change some of the numbers and nothing works. The pot is working but in a very small portion of the cursor limits. This code does not allow much changing or i dont know how to make these changes.
Maybe there is somebody out there that made this example work like it claims. Any word?
Thanks


eduardomag


Grumpy_Mike

Get it to print out the values from the pot so you can see what range you are getting. Are you using that joystick? You don't always get the full travel from a joystick.

eduardomag

Since I'm not experienced with programming i would not know how to print the values from the pot. I am not using the joystick, i have a 10K pot hooked up. I can change speed and number of steps but need to learn about that pot values changing task.Thanks Mike.

Grumpy_Mike

Quote
Since I'm not experienced with programming i would not know how to print the values from the pot

put in the setup:-
Serial.begin(9600);

then add after:-
int val = analogRead(0);

Serial.println(val);

jackrae

On the photograph you have supplied it appears that the top connection on the pot isn't soldered to the connecting wire.  This might be the source of your erratic behaviour.
Apart from that I like your "breadboard" (or should that be MDF) layout
jack

eduardomag

Thanks Jack,
The pot connections are all positively connected. The sweeper goes to 0 analog, the top goes to the +5V and the bottom goes to ground. Yes i mounted the breadboard, motors and Arduino to a rectangle MDF plate i had around. And the soldering is also very good on all three leads despite the appearance. I even inverted the stepper wire connections on the H bridge chips. First i want to make one motor work and after that try to make them both respond to the thumb joystick not shown on the photo.

eduardomag

Mike,
I will try that and post the result. Thanks for the teaching.

eduardomag

Hi again.
This is the code that does not work properly.



#include <Stepper.h>


#define STEPS 100


Stepper stepper(STEPS, 8, 9, 10, 11);


int previous = 0;

void setup()
{
 
  stepper.setSpeed(30);
}

void loop()
{
 
  int val = analogRead(0);


  stepper.step(val - previous);

 
  previous = val;
}

I tried to add the  serail.begin(9600)
and  int Val= analogRead(0)
and Serial.println(val)

But could not figure out where to write these. I ask to please tell me where exactly  should they go. After the curly braces? or before?

Go Up