I'm beyond help with this Stepper Motor

Hello.

I have been trying for weeks now to control a stepper motor using an Arduino and a joystick. I took on a project for a buddy of mine thinking this would be relatively "easy" for me, but apparently I am dumber than I thought. Now it's getting closer to the deadline and I am not anywhere close to getting it to work properly. I have tried many, many examples and tutorials. Of course, I can never have "exactly" every component being shown in the examples/tutorials so maybe that's why they don't work.

That being said, I have used someone else's example to make the Arduino control the motor and it words fine, so I know the equipment and wiring are good. But I can't seem to control it with a joystick (and yes, I did change out the joystick a couple of times).

I'm at the point of giving up, so I'm looking for someone to make it work for me. I'm willing to pay someone to take care of this project that I should never had volunteered for. If there is anyone interested, please let me know.

Thank you for your time.
Ron.

You are likely to get help for free if you provide enough information.

Post the requirements of the project. What should it do?

Read the forum guidelines to see how to properly post code and some hints on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Post the code that you have so far. Describe what the code actually does and how that differs from what you want.

What Arduino board?

Post a schematic showing all parts, their values and/or part numbers and power supplies showing how it should be wired.

Post clear photos showing how it is wired.

Post data sheets for parts as appropriate (stepper, stepper driver, joystick, etc.).

If you really just want to have someone do it flag your post and have a moderator move it to the Jobs and Paid Consultancy category. It is more likely to be seen by members that do paid work there. You will need to provide, at least, the above information to whoever does the job.

groundFungus,

Thank you for the insight. I had no idea there was a "Jobs and Paid Consultancy" category. I also felt that I was so lost, nobody would want to take the time to fix my errors.

"If" anyone would like to help, it would surly be appreciated. So here's my project: I am to control a NEMA 23 sized bi-polar stepper motor with an Arduino type control board and a joystick. The speed of the motor should be consistent with the distance that the joystick is moved (the further it's moved, the faster the motor goes. The object is to move a carriage on a linear screw drive to a certain exact position, click a button and have the controller be able to go back to that position at a push of a button (maybe the same button???). There will be several of these positions to record and return to. There will also be end stops installed. I'm not going to deal with the positions or the end stops on the code right now. I just want to get the motor working properly.

I have tried many examples and even tried to write my own code, but I couldn't get any of them to work correctly (if at all). My latest revision will be pasted below and it's kind of a hybrid of an example I found and my own code. I'm using an Arduino Uno currently (but I would like to go with an ESP8266 Node MCU due to the smaller size and larger storage/memory). I've tried several stepper drivers but the current model is using an Easydriver. I have 3v from the Arduino powering the joystick, 5v from the Arduino powering the Easydriver, and 24v from a shop power supply powering the stepper motor. If I can figure out how to get photos up here, I'll post a couple of my set up and wiring diagram.

Thank you in advance for any who can help.

My code:

#define step_pin 2  // Pin D2 connected to Pulse pin on Driver
#define dir_pin 3   // Pin D3 connected to Direction pin

int x_pin = A0;    // Pin A0 connected to joystick x axis
int step_speed = 0;  // Speed of Stepper motor (higher = slower)
int joyVal;          // Used to store joystick value

void setup() {
  Serial.begin(115200);
  pinMode(dir_pin, OUTPUT);
  pinMode(step_pin, OUTPUT);

  Serial.println("End of Set-up");  //  Just used for troubleshooting
}

void loop() {
  Serial.println("Start of Loop");   //  Just used for troubleshooting
  joyVal = analogRead(x_pin);
  if (joyVal > 333); {
    joyVal = map(joyVal, 333, 700, 10, 0);
    delay(500);  // delay for deboucing
    digitalWrite(dir_pin, HIGH);  // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(step_pin, HIGH);
  }

  if (joyVal < 333); {
    joyVal = map(joyVal, 0, 332, 10, 0);
    delay(500);  // delay for deboucing
    digitalWrite(dir_pin, LOW);  // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(step_pin, HIGH);
    delay(step_speed / 2);
    digitalWrite(step_pin, LOW);
    delay(step_speed / 2);
  }


  Serial.print("Low side step-speed = ");   //  Just used for troubleshooting
  Serial.println(step_speed);
  Serial.print("X value is:  ");       //  Just used for troubleshooting
  Serial.println(x_pin);

  Serial.println("End of Loop");      //  Just used for troubleshooting
}

Wiring and photos:
Stepper layout with easy driver



Can you describe what is not working as you expect.

LOL! Yeah.

The motor doesn't move in either direction when I move the joystick.

The best way to solve this is to divide and conquer... break the problem down and confirm which bit's do work, so they can be eliminated.

I would focus on the joystick input first.

Try adding some debug prints to the Serial monitor to confirm what is going on...

void loop() {
  Serial.println("Start of Loop");   //  Just used for troubleshooting
  joyVal = analogRead(x_pin);

  Serial.print("Joystick input:");
  Serial.println(joyVal);
  

Let's confirm what input you are getting first.

step_speed

seems to be set to zero and never updated?

Red_car,

I appreciate your assistance. When I run the program and move the joystick, the "step_speed" and the "Joystick input" don't change. In fact, the joystick input says "14" constantly.

Screenshot:
Serial 1

How did you know that prior to me posting?

I read the code...

  Serial.println(x_pin);

This is printing out the pin number of A0 which is 14 - what are you trying to display?

I'm trying to display it's value.

It's value is given by joyVal = analogRead(x_pin);
You should print out joyVal

Okay. Just added it. Now the joystick has a reading high and low along with "idle" (in the middle).
Serial 2

So I adjusted the values for the joystick range (with the "idle" value between 370 and 415) and took the delays out. Now the motor slowly pulses in one direction with or without joystick input. The joystick still doesn't have an effect.

OK.. we're getting somewhere.

So what os the full range of values that come from the joystick... from full left to full right?

Post your latest code.

The range is from 0 to 758. I have updated my code to account for that ( I think).
Code:

#define step_pin 2  // Pin D2 connected to Pulse pin on Driver
#define dir_pin 3   // Pin D3 connected to Direction pin

int x_pin = A0;    // Pin A0 connected to joystick x axis

int step_speed = 0;  // Speed of Stepper motor (higher = slower)
int joyVal;          // Used to store joystick value

void setup() {
  Serial.begin(115200);
  pinMode(dir_pin, OUTPUT);
  pinMode(step_pin, OUTPUT);

  Serial.println("End of Set-up");  //  Just used for troubleshooting
}

void loop() {
  Serial.println("Start of Loop");   //  Just used for troubleshooting
  joyVal = analogRead(x_pin);
  Serial.println(" )");
  Serial.print("Joystick input: ");
  Serial.println(joyVal);
  Serial.println(" ");
  if (joyVal > 415); {
    joyVal = map(joyVal, 415, 758, 10, 0);
    // delay(500);  // delay for deboucing
    digitalWrite(dir_pin, HIGH);  // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(step_pin, HIGH);
  }

  if (joyVal < 360); {
    joyVal = map(joyVal, 0, 360, 10, 0);
    // delay(500);  // delay for deboucing
    digitalWrite(dir_pin, LOW);  // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(step_pin, HIGH);
    delay(step_speed / 2);
    digitalWrite(step_pin, LOW);
    delay(step_speed / 2);
  }


  Serial.print("Low side step-speed = ");   //  Just used for troubleshooting
  Serial.println(step_speed);

  Serial.print("X value is:  ");  //  Just used for troubleshooting
  Serial.println(x_pin);

  Serial.println("End of Loop");
}

Try running this simpler version of the sketch... and see what happens.

#define step_pin 2  // Pin D2 connected to Pulse pin on Driver
#define dir_pin 3   // Pin D3 connected to Direction pin

int x_pin = A0;    // Pin A0 connected to joystick x axis

int onTime = 0   ;  // Determine how long to spin for
int joyVal;          // Used to store joystick value

void setup() 
{
  Serial.begin(115200);

  pinMode(dir_pin, OUTPUT);
  pinMode(step_pin, OUTPUT);
}

void loop() 
{
  joyVal = analogRead(x_pin);

  Serial.print("Joystick input: ");
  Serial.println(joyVal);

  
  if (joyVal > 415); 
  {
    digitalWrite(dir_pin, HIGH);  // HIGH = anti-clockwise 
    digitalWrite(step_pin, HIGH);
  }

  if (joyVal < 360); 
  {
    digitalWrite(dir_pin, LOW);  //  LOW = clockwise)
    digitalWrite(step_pin, HIGH);
  }

  delay(50);
  
  // Stop moving.
  digitalWrite(step_pin, LOW);

}

Will do.

Well, I'm still getting a reading from the joystick, but the motor still creeps clockwise (slower now than before) and it still doesn't respond to the joystick movement.

Let's take the delay out...

#define step_pin 2  // Pin D2 connected to Pulse pin on Driver
#define dir_pin 3   // Pin D3 connected to Direction pin

int x_pin = A0;    // Pin A0 connected to joystick x axis

int onTime = 0   ;  // Determine how long to spin for
int joyVal;          // Used to store joystick value

void setup() 
{
  Serial.begin(115200);

  pinMode(dir_pin, OUTPUT);
  pinMode(step_pin, OUTPUT);
}

void loop() 
{
  joyVal = analogRead(x_pin);

  Serial.print("Joystick input: ");
  Serial.println(joyVal);

  
  if (joyVal > 415); 
  {
    digitalWrite(dir_pin, HIGH);  // HIGH = anti-clockwise 
    digitalWrite(step_pin, HIGH);
  }

  if (joyVal < 360); 
  {
    digitalWrite(dir_pin, LOW);  //  LOW = clockwise)
    digitalWrite(step_pin, HIGH);
  }


  if (joyVal >= 360 && joyVal <= 415); 
  {
    digitalWrite(step_pin, LOW);
  }

}