Go Down

Topic: Arduino Motor Shield Stepper Motor control with Joystick (Read 8 times) previous topic - next topic

TheBlommie

Hi

I recently purchased an Arduino Uno R3 board with a Arduino Motor Shield Rev3 as well as a joystick breakout board. My aim is to use the thumb joystick to control the direction of the stepper motor on the X-axis, left to right as well as the speed. So far I've been looking for good tutorials on the net with regards to the subject but had no luck so far.

Attached to this article are two photos showing how I connected my joystick to the motor shield board as well as a closeup view of the specific joystick I bought. Here is a link to the joystick as well:

http://robotics.org.za/index.php?route=product/product&keyword=joystick%20breakout%20board&category_id=0&product_id=217

Below is some sample code I downloaded from the net which rotates the shaft from one direction to the other with a delay. How can I modify this code to work with my setup and control the motor via the joystick:

#include <Stepper.h>

const int spr = 200; // motor steps per revolution
const int pwm_cha = 3;
const int pwm_chb = 11;
const int dir_cha = 12;
const int dir_chb = 13;
const int brake_cha = 9;
const int brake_chb = 8;

Stepper stepper(spr, dir_cha, dir_chb);

void setup()
{
    pinMode(pwm_cha, OUTPUT);
    pinMode(pwm_chb, OUTPUT);
    pinMode(brake_cha, OUTPUT);
    pinMode(brake_chb, OUTPUT);
    digitalWrite(pwm_cha, HIGH);
    digitalWrite(pwm_chb, HIGH);
    digitalWrite(brake_cha, LOW);
    digitalWrite(brake_chb, LOW);

    stepper.setSpeed(75);
}

void loop()
{
  stepper.step(spr);

  delay(0);

  stepper.step(-spr);

  delay(0);
}

Any help would really be appreciated!

Regards



ash901226

could you give more info on how exactly you one to control the motor with the joystick.
what i mean is what does pushing the joystick to the right do to the motor and what know, please explain so we could help you more

TheBlommie

Well, when the joystick is in the center and not moving, the motor shouldn't do anything and stop. When the joystick is pressed to the left or right, the motor must move in the respective direction and the further the joystick moves from the center, the faster the speed of the motor must be. So basically left and right movement via the joystick as well as speed adjusting as the joystick moves further from the center pin.

The purpose of this setup is to slide a camera left and right, faster and slower on a rail of plus minus 1.5m in length. Attached to the stepper motor's shaft will be a pulley and on the other side just a normal shaft enclosed in a bearing unit also containing a pulley. I'll then use timing belt to slide the camera left and right.

Here are my stepper motor specs:

2 Phase Hybrid (Model: 23HS6430)
3A
Bipolar
4 Wires
1.8 degree step angle

I'm really not very clued up with prototyping and therefore if you can help me to amend the code to work with my setup, I'll really be happy since I've been battling and struggling to get the project going. But looking at my connection setup, is everything connected to the right pins etc?

Looking forward to hear from you.

Regards

Ian

ash901226


ash901226

well what you need to do is to divide the value of a pot into half
so i would say that 507 until 517 is a good middle value.
then take the value between 517 until 1023 and map it with the min and max of the stepper speed.
after that take between 0 to 507 value of pot n map it with the min n max of the stepper speed.
third is that determine which side of the pot make the stepper move clockwise. what i give here should give you an idea on how to do it

Go Up