Go Down

Topic: Ramp 1.4 + NEMA 17 + Keypad Branching Problems (Read 395 times) previous topic - next topic

sagaraBilly

Hello all  :D

So, to be honest, i'm not really expert in Arduino programming but i'm trying to control 3 stepper motor (NEMA 17) using 4x4 keypad module. I'm also using lcd display 16x2 just for the user interface. The problem that I encountered is all 3 motors didn't work somehow.

Here is the program that i made:

Code: [Select]
#include <LiquidCrystal.h>
#include <Keypad.h>

LiquidCrystal lcd(16, 17, 29, 27, 25, 23);

const byte ROWS = 4;
const byte COLS = 4;

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {33, 35, 37, 38};
byte colPins[COLS] = {41, 43, 45, 47};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

#define X_STEP_PIN         54
#define X_DIR_PIN          55
#define X_ENABLE_PIN       38
#define X_MIN_PIN           3
#define X_MAX_PIN           2

#define Y_STEP_PIN         60
#define Y_DIR_PIN          61
#define Y_ENABLE_PIN       56
#define Y_MIN_PIN          14
#define Y_MAX_PIN          15

#define Z_STEP_PIN         46
#define Z_DIR_PIN          48
#define Z_ENABLE_PIN       62
#define Z_MIN_PIN          18
#define Z_MAX_PIN          19

#define SDPOWER            -1
#define SDSS               53
#define LED_PIN            13

#define PS_ON_PIN          12
#define KILL_PIN           -1

void setup() {
  lcd.begin(16,2);
  Serial.begin(9600);
  pinMode(LED_PIN  , OUTPUT);
 
  pinMode(X_STEP_PIN  , OUTPUT);
  pinMode(X_DIR_PIN    , OUTPUT);
  pinMode(X_ENABLE_PIN    , OUTPUT);
 
  pinMode(Y_STEP_PIN  , OUTPUT);
  pinMode(Y_DIR_PIN    , OUTPUT);
  pinMode(Y_ENABLE_PIN    , OUTPUT);
 
  pinMode(Z_STEP_PIN  , OUTPUT);
  pinMode(Z_DIR_PIN    , OUTPUT);
  pinMode(Z_ENABLE_PIN    , OUTPUT);
 
   digitalWrite(X_ENABLE_PIN    , LOW);
   digitalWrite(Y_ENABLE_PIN    , LOW);
   digitalWrite(Z_ENABLE_PIN    , LOW);

}

void loop () {

 lcd.setCursor(0,0);
 lcd.print("TEST");
 lcd.setCursor(1,1);
 lcd.print("choose motor:");
 char customKey = customKeypad.getKey();
 int pil = customKey - '0' ;

if(pil){
if(pil==1)
  { Serial.println("pil 1");
    lcd.clear();
    lcd.print("Z");
    delay (1000);
    lcd.clear();
    motorz();
  }

if(pil==2)
  { Serial.println("pil 2");
    lcd.clear();
    lcd.print("Y");
    delay (1000);
    lcd.clear();
    motory();
  }

if(pil==3)
  { Serial.println("pil 3");
    lcd.clear();
    lcd.print("x");
    delay (1000);
    lcd.clear();
    motorx();
  }
}
}

void motorx () {
  for(;;){
  Serial.println("loop");
  digitalWrite(X_DIR_PIN    , HIGH);
  digitalWrite(X_STEP_PIN    , HIGH);
  delay(1);
  digitalWrite(X_STEP_PIN    , LOW);
  }
}

void motory () {
  for(;;){
  Serial.println("loop");
  digitalWrite(Y_DIR_PIN    , HIGH);
  digitalWrite(Y_STEP_PIN    , HIGH);
  delay(1);
  digitalWrite(Z_STEP_PIN    , LOW);
  }
}

void motorz () {
  for(;;){   
  Serial.println("loop");
  digitalWrite(Z_DIR_PIN    , HIGH);
  digitalWrite(Z_STEP_PIN    , HIGH);
  delay(1);
  digitalWrite(Z_STEP_PIN    , LOW);
  }
}


I'm pretty sure that my problem is not on the wiring schematics section because when i tried this simple program just to test my NEMA 17, it works :

Code: [Select]
#include <LiquidCrystal.h>
#include <Keypad.h>

LiquidCrystal lcd(16, 17, 29, 27, 25, 23);

const byte ROWS = 4;
const byte COLS = 4;

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {33, 35, 37, 38};
byte colPins[COLS] = {41, 43, 45, 47};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

#define X_STEP_PIN         54
#define X_DIR_PIN          55
#define X_ENABLE_PIN       38
#define X_MIN_PIN           3
#define X_MAX_PIN           2

#define Y_STEP_PIN         60
#define Y_DIR_PIN          61
#define Y_ENABLE_PIN       56
#define Y_MIN_PIN          14
#define Y_MAX_PIN          15

#define Z_STEP_PIN         46
#define Z_DIR_PIN          48
#define Z_ENABLE_PIN       62
#define Z_MIN_PIN          18
#define Z_MAX_PIN          19

#define SDPOWER            -1
#define SDSS               53
#define LED_PIN            13

#define PS_ON_PIN          12
#define KILL_PIN           -1

void setup() {
  lcd.begin(16,2);
  lcd.setCursor(1,1);
  lcd.print("ASRS BILLY");
  Serial.begin(9600);
 
  pinMode(LED_PIN  , OUTPUT);
 
  pinMode(X_STEP_PIN  , OUTPUT);
  pinMode(X_DIR_PIN    , OUTPUT);
  pinMode(X_ENABLE_PIN    , OUTPUT);
 
  pinMode(Y_STEP_PIN  , OUTPUT);
  pinMode(Y_DIR_PIN    , OUTPUT);
  pinMode(Y_ENABLE_PIN    , OUTPUT);
 
  pinMode(Z_STEP_PIN  , OUTPUT);
  pinMode(Z_DIR_PIN    , OUTPUT);
  pinMode(Z_ENABLE_PIN    , OUTPUT);
 
   digitalWrite(X_ENABLE_PIN    , LOW);
   digitalWrite(Y_ENABLE_PIN    , LOW);
   digitalWrite(Z_ENABLE_PIN    , LOW);
}

void loop () {
  //I've tried the y and z too
    digitalWrite(X_DIR_PIN    , LOW);     
    digitalWrite(X_STEP_PIN    , HIGH);
    delay(1);
    digitalWrite(X_STEP_PIN    , LOW);
}


I have searched this problem on the internet but no one seems to have the same problem
please help me
I know you guys are expert in this thing

btw, this is for my school project if you're wondering   

Thankyou  :D

Robin2

The problem that I encountered is all 3 motors didn't work somehow.
That does not tell us anything from which to help you.

You need to tell us in as much detail as possible what actually happens when you run the program and what you want to happen that is different.

Also, have you written a short program to get each of the motors working separately?

...R
Stepper Motor Basics
Simple Stepper Code
Two or three hours spent thinking and reading documentation solves most programming problems.

sagaraBilly

#2
May 22, 2019, 07:40 pm Last Edit: May 22, 2019, 07:54 pm by sagaraBilly
Quote
The problem that I encountered is all 3 motors didn't work somehow.
What i mean by that is, the motors didn't move at all when i pressed 1 or 2 or 3 in the keypad.
there is no error message or anything when i'm compiling and upload the program

what i want to happen is when i pressed 1 on the keypad then the motor z moves infinitely (stop until i reset the program)
same as motor y (if i pressed 2) and motor x (if i pressed 3).
I think it's all clear from the program that i post earlier.

here are some steps explanation of my main idea in the program:
- keypad waiting for an input (the input saved on int pil)
- if int pil = 1 then the lcd print "motor z" and calls the method void motor z (motor z moves infinitely)
- if int pil = 2 then the lcd print "motor y" and calls the method void motor y (motor y moves infinitely)
- if int pil = 3 then the lcd print "motor x" and calls the method void motor x (motor x moves infinitely)
Also, have you written a short program to get each of the motors working separately?

Yes I have, and it works fine. The short program that i used for testing NEMA 17 individually also already been posted earlier too.

Thanks btw for replying my post


Robin2

This code
Code: [Select]
void motorx () {
    for(;;){
        Serial.println("loop");
        digitalWrite(X_DIR_PIN    , HIGH);
        digitalWrite(X_STEP_PIN    , HIGH);
        delay(1);
        digitalWrite(X_STEP_PIN    , LOW);
    }
}

is going to get stuck permanently in the FOR loop

And it will be trying to print at such a fast rate that it will block the Serial Output buffer. You do NOT have any print command in loop() in the code that does work

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

sagaraBilly

Quote
And it will be trying to print at such a fast rate that it will block the Serial Output buffer. You do NOT have any print command in loop() in the code that does work
Okay, thanks a lot to Robin2. I wasn't thinking that serial print would be the issue. I was using it for checking if the void was called successfully or not.
After i remove the serial print the motor Y and Z works fine.  :)

however the problem still occurs in motor X...
it seems that this X-axis motor would not work with keypad, but it works fine without the keypad.
but then i realized that i declared the pin D38 to both motor X (X_ENABLE_PIN) and keypad (byte row pins)

Again, Thanks a lot. It all works fine now.
problem solved  :)

Go Up