Hello all
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:
#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 :
#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