Coding and hardware for NEMA 23 x1

Hi
I'm trying to make a NEMA 23 (19kg.cm)(just one motor) move clockwise and counterclockwise by pushing 2 buttons( when I push the button it will rotate/do a certain amount of steps which i will define later on), and another 3erd button to reset it's position.

I don't need for it to be fast ( 40mm/seg ; the total distance it has to do 80mm), but I do need to have as much torque as possible

This is the hardware I have, but i do not know if it's the correct hardware or if I need something else.

-Arduino UNO
-NEMA 23 ( datasheet https://www.gizmojo.com.ar/system/datasheets/57BYGH633.pdf )
-CNC SHIELD ( I know it's to control 3 xis even though i only need one)
-DRV8825
-3 push buttons / analog stick ( like the Play Stations ones).
-Power supply: 12V/5A for the stepper
-Power supply: 12v for the Arduino

I can't figure out how to/where to connect the pins for the analog stick/or push buttons

So far this is the code I have ( which will only make it go CW and CCW automatically)

#define EN 8

//Direction pin
#define X_DIR 5
#define Y_DIR 6
#define Z_DIR 7

//Step pin
#define X_STP 2
#define Y_STP 3
#define Z_STP 4

//DRV8825
int delayTime=30; //Delay between each pause (uS)
int stps=6400;// Steps to move

void step(boolean dir, byte dirPin, byte stepperPin, int steps)

{

digitalWrite(dirPin, dir);

delay(100);

for (int i = 0; i < steps; i++) {

digitalWrite(stepperPin, HIGH);

delayMicroseconds(delayTime);

digitalWrite(stepperPin, LOW);

delayMicroseconds(delayTime);

}

}

void setup(){

pinMode(X_DIR, OUTPUT); pinMode(X_STP, OUTPUT);

pinMode(Y_DIR, OUTPUT); pinMode(Y_STP, OUTPUT);

pinMode(Z_DIR, OUTPUT); pinMode(Z_STP, OUTPUT);

pinMode(EN, OUTPUT);

digitalWrite(EN, LOW);

}

void loop(){

step(false, X_DIR, X_STP, stps); //X, Clockwise
step(false, Y_DIR, Y_STP, stps); //Y, Clockwise
step(false, Z_DIR, Z_STP, stps); //Z, Clockwise

delay(100);

step(true, X_DIR, X_STP, stps); //X, Counterclockwise
step(true, Y_DIR, Y_STP, stps); //Y, Counterclockwise
step(true, Z_DIR, Z_STP, stps); //X, Counterclockwise

delay(100);

}

Could somebody please help me?
Thanks in advance

Could somebody please help me?

Do you know how to read the state of a digital input ?

Most probably not...
Could you please provide me a little bit of guidance?

(sorry.... electronics it's all pretty new to me, but i do know about electricity( DC-AC, ohm's law etc...)

and as for the driver.... i think a TB6560 could be a better option? as it can go up to 3.5 amps ( while I need 3 at most)

Thank you

The TB6560 would be better as the DRV8825 is good for only about 1.5A without active cooling and 1.5 to 2.2A require a heatsink and fan cooling. 2.2A is max.

-CNC SHIELD ( I know it's to control 3 xis even though i only need one)

Which, exact, CNC shield. I am familiar with the CNC shield V4.

There are several pins on that CNC shield that can be used for switch inputs (your buttons). And the analog inputs are also available on the CNC shield.

The digitalRead() function.
The analogRead() function.

The Arduino language reference.

cnc shield Uno pins.jpg

cnc shield Uno pins.jpg

The CNC Shield I have is a Shield CNC V3 just as this one ( Shield CNC V3 )

I'm guessing that the pins on the upper right corner or in the lower right corner of the CNC's image below could be the ones used for the switch inputs.... right?

The pins on the upper right are to set 4th stepper control so not for switches. The pins on the left (black and white headers) are for the limit pins, spindle, machine and coolant control. Those pins can be use for switches and analog inputs (see Uno pinout image in previous post to cross refeence between shield pins and Uno pins).


CNC Shield V3 front

How do the joysticks control the motors? Motor position proportional to joystick position, motor speed proportional to joystick position or some other strategy?

What, exact, joystick do you have? Data sheet?

tinback123:
Most probably not...
Could you please provide me a little bit of guidance?

Start by looking at the Button example in the IDE

groundFungus:
How do the joysticks control the motors? Motor position proportional to joystick position, motor speed proportional to joystick position or some other strategy?

What, exact, joystick do you have? Data sheet?

I'll be attaching to the shaft a GT2 20 Dent pulley ( I will drill the inner diameter in order to fit the 6.35mm Nema 23's shaft )
This pulley has a 12mm diameter (where the dents are).
I need to do 80mm in 2 seconds, so pid= pi12mm=37.7mm --> 80mm/37.7= 2.12 revolutions= 1.06rev/seg =60RPM

The motor speed will always remain the same (at least that's what i'm trying to achieve, i do not know if it is possible (i have a lenght up to 120 mm to use, i think i could even use 40mm to accelerate and another 40 to deaccelerate)(40+80+40).

If it is with the stick, just by moving the joystick to the left or right (just a tap), it will perform the 2.12 rev it has to do, and by pressing it it will the counting to zero. This is the joystick I have. Unfortunatly I do not have the datasheet.

after it goes right or left, it cannot go to the same direction again

I will upload a pic of where I want to use what im trying to create so you can have a better look

Attached is where i want to put the Nema
My idea is to make that black table move one way and another(back and forth) with a belt and pulley system.

above that table is where prepainted metal sheets will be put in order to perform scratch and hardness test on the paint's sheet, and what it appears to be a pencil is where you put the load, which can be up to 4kg ( as a maximum- but is almost never reached/ scratches appear way sooner)

So i looked at this

http://www.arduinotutorialonline.com/2018/07/how-to-control-stepper-motor-using.html

which pretty much is what i'm trying to do, but using a NEMA 23, instead of a 17 and a TB6560 driver
instead of an Easy Driver. ( but there's no CNC Shield (V3) on that tutorial, does that mean that I could make it work without a CNC Shield?)

Basically, the Arduino-Joystick connection should remain the same ( there's an "MS" pin on the joystick that's not being used and I do not know what it is for, hoping that's OK).

My question is... if I follow that tutorial but connecting everything on a TB6560 instead of an Easy driver from , should it work properly? Do I also need to connect it to a CNC Shield V3? ( if the answeris yes, then i'm lost in the shield-tb6560 connection/wiring as it does not "perfectly fit" like with the a4988 or drv8825....

here's the code I'm going to try:

//Declare pin functions on Redboard
#define stp 2
#define dir 3
#define MS1 4
#define MS2 5
#define EN 6

//Declare variables for functions
char user_input;
int x;
int y;
int state;

int joyX = A0;
int joyVal;

void setup() {

pinMode(stp, OUTPUT);
pinMode(dir, OUTPUT);
pinMode(MS1, OUTPUT);
pinMode(MS2, OUTPUT);
pinMode(EN, OUTPUT);

digitalWrite(stp, LOW);
digitalWrite(dir, LOW);
digitalWrite(MS1, LOW);
digitalWrite(MS2, LOW);
digitalWrite(EN, HIGH);

Serial.begin(9600); //Open Serial connection for debugging

}

//Main loop
void loop() {

while( (analogRead(joyX) == 0 ) || (analogRead(joyX) > 1000 )){
joyVal = analogRead(joyX);
digitalWrite(EN, LOW);
if( joyVal == 0){

digitalWrite(dir, LOW);

}
else if( joyVal > 1000){

digitalWrite(dir, HIGH);

}
digitalWrite(stp,HIGH); //Trigger one step forward
delay(1);
digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
delay(1);

} // while loop

digitalWrite(EN, HIGH);
}

I'd download the AccelStepper library and check out some of the examples. You will definitely need acceleration
for that large stepper to be reliable, and AccelStepper makes that easy.

Set the stepper driver to a modest level of microstepping in the first instance, such as x8 or x16, this will greatly
improve behaviour (noise, vibration, resonances and miss-steps).

With a 200 step motor and x8 microstepping, thats 1600 steps per revolution, so you'll want to set a speed of
at least 1700 steps/second - some experimentation with the acceleration value will be needed for best performance.

The MS on the joystick is probably SW upside down or the output for the switch that is activated by pushing the joystick down.

An advantage of using the CNC shield is easy connection of the motor drivers. If you use drivers that don't plug into the shield, then its use is less attractive. If you do not use the shield, the pin use can be decided by you, not tied to how the shield is wired. So you would wire straight from the pins to the motor drivers, joystick and switches.

groundFungus:
The MS on the joystick is probably SW upside down or the output for the switch that is activated by pushing the joystick down.

An advantage of using the CNC shield is easy connection of the motor drivers. If you use drivers that don't plug into the shield, then its use is less attractive. If you do not use the shield, the pin use can be decided by you, not tied to how the shield is wired. So you would wire straight from the pins to the motor drivers, joystick and switches.

Thank you for the MS/SW clarification! (lol my bad)
just to be more clear with the wiring

In the example from the link above wiring is as follows:

From the Joystick to the Arduino UNO:
Vcc --> 5V
GND --> GND
Y-Axis --> Pin A0

this should remain the same...

From the Arduino to the Easy Driver( as in the example)

Arduino GND --> GND Easy Driver
Pin 2 --> Step
Pin 3 --> Dir
Pin 4 --> MS1
Pin 5 --> MS2
Pin 6 --Enable

Now the driver I'll be using it's a TB6560

I understand the wiring on the left, the setting on the MS1, MS2 MS3 and DP 1,2,3,4,5,6.

Now on the right there are 6pins:

EN- ; EN+, CW-; CW+; CLK -;CLK+

Should this be the wiring for my case (Arduino UNO- TB6560):

Pin 2 ---> CLK+
Pin 3 --> CW+
Pin 4 --> ?
Pin 5 --> ?
Pin 6 --> EN+

I have MS1 and MS2 buttons? are they replaced? am i missing something?
Do i need to use Pins 4,and 5 from the Arduino?

This page shows the wiring for a TB6560. Note that the inputs to the driver are optoisolated. Step, dir and enable have 2 pins each. One for the anode of the optoisolator LED and the other for the cathode. In the drawing on the linked page, all of the cathodes (step -, dir - and enable -) are wired to ground. Step +, dir + and enable + are wired to their respective Arduino outputs.

The microstepping (MS1 and MS2) is set with the dip switches and cannot be controlled by the processor (Arduino) so there are no outputs to MS1 and MS2.

MarkT:
I'd download the AccelStepper library and check out some of the examples. You will definitely need acceleration
for that large stepper to be reliable, and AccelStepper makes that easy.

Set the stepper driver to a modest level of microstepping in the first instance, such as x8 or x16, this will greatly
improve behaviour (noise, vibration, resonances and miss-steps).

With a 200 step motor and x8 microstepping, thats 1600 steps per revolution, so you'll want to set a speed of
at least 1700 steps/second - some experimentation with the acceleration value will be needed for best performance.

Thank you, i'm going to try this, at least making it go back and forth, until I figure how to configure/wire the Arduino to the TB6560 for pins 4 and 5 where I'm not really sure where to go form there....
thank you

groundFungus:
This page shows the wiring for a TB6560. Note that the inputs to the driver are optoisolated. Step, dir and enable have 2 pins each. One for the anode of the optoisolator LED and the other for the cathode. In the drawing on the linked page, all of the cathodes (step -, dir - and enable -) are wired to ground. Step +, dir + and enable + are wired to their respective Arduino outputs.

The microstepping (MS1 and MS2) is set with the dip switches and cannot be controlled by the processor (Arduino) so there are no outputs to MS1 and MS2.

Thank you,
I'm going to have a look at it and see if I can get my problem running, changing that potentiometer for an analog stick. I'll let you know how it goes

So I finally made it work (at least it moves) at about 120 RPM

The code I'm using is this one :

//APROX 120 RPM
//Declare pin functions on Redboard
#define stp 2
#define dir 3
#define EN 6

//Declare variables for functions
char user_input;
int x;
int y;
int state;

int joyX = A0;
int joyVal;

void setup() {

pinMode(stp, OUTPUT);
pinMode(dir, OUTPUT);
pinMode(EN, OUTPUT);

digitalWrite(stp, LOW);
digitalWrite(dir, LOW);
digitalWrite(EN, HIGH);

Serial.begin(9600); //Open Serial connection for debugging

}

//Main loop
void loop() {

while( (analogRead(joyX) == 0 ) || (analogRead(joyX) > 1000 )){
joyVal = analogRead(joyX);
digitalWrite(EN, LOW);
if( joyVal == 0){

digitalWrite(dir, LOW);

}
else if( joyVal > 1000){

digitalWrite(dir, HIGH);

}
digitalWrite(stp,HIGH); //Trigger one step forward
delay(1);
digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
delay(1);

} // while loop

digitalWrite(EN, HIGH);
}

The motor moves while I move the Joystick ( I think i'm going to stay with this option), so that's OK

but I have 2 doubts/questions:

1)How do I include the AccelStepper Library to that code, and, what code related to the acceleration should I write and where?

  1. As it is known, some manufacterers provide RPM vs Torque Graphics, some don't.... ( The higher the Torque, the less the RPM).
    As it is running now, it should be at about 120 RPM, which will mean it has a considerable Torque...
    Is there a way to prove this? ( I do not know if a motor can provide low speed AND low torque at the same time and if i'm having a small torque....)

I'm attaching for those of you who'd like to know some pics of the TB5869 config, and a little video of the motor running with the joystick