Decoder step/dir

Hello ! I engaged CNC not so long and faced with the fact that the program provides a signal format step / dir, and I does not found that I needed for my controller, but it is for arduino mega 2560 mach3を使ってみた -   北の国から電子工作(仮) Can I change the code for arduino UNO?
I am a novice, it is difficult for me

/*MP4401?FET??????????MACH3??????Ardunio??????????
 Dsub25Pin???step/dia???Arduino?????MP4401??????????
 ????????????????XYZ?????????
 0?5?STEP/dia×3?????6?17??????(4PIN*3=12PIN),18&19??? 
 ???????x??y????????????????????????????????
 ???loop???????????????????????????????mach????????????????
*/ 
#define X1 17//?????????
#define Y1 14
#define lX1 16
#define lY1 15
#define X2 13
#define Y2 10
#define lX2 12
#define lY2 11
#define X3 9
#define Y3 6
#define lX3 8
#define lY3 7

#define X_step 3
#define X_dia 4
#define Y_step 2
#define Y_dia 5
#define Z_step 0
#define Z_dia 1
//---------------------------------------------------------------------------------------------------------*/

//setup------------------------------------------------------------------------
void setup()
{
  pinMode(X1,OUTPUT);
  pinMode(lX1,OUTPUT);
  pinMode(Y1,OUTPUT);
  pinMode(lY1,OUTPUT);
  pinMode(X2,OUTPUT);
  pinMode(lX2,OUTPUT);
  pinMode(Y2,OUTPUT);
  pinMode(lY2,OUTPUT);
  pinMode(X3,OUTPUT);
  pinMode(lX3,OUTPUT);
  pinMode(Y3,OUTPUT);
  pinMode(lY3,OUTPUT);
  pinMode(18,INPUT);
  pinMode(19,INPUT);


  pinMode(X_dia,INPUT_PULLUP);
  pinMode(X_step,INPUT_PULLUP);
  pinMode(Y_dia,INPUT_PULLUP);
  pinMode(Y_step,INPUT_PULLUP);
  pinMode(Z_dia,INPUT_PULLUP);
  pinMode(Z_step,INPUT_PULLUP); 

//???????
  driveXp();
  driveYp();
  driveZp();
  delay(1000);
  driveXp();
  driveYp();
  driveZp();
  delay(1000);
  driveXp();
  driveYp();
  driveZp();
  delay(1000);
  driveXp();
  driveYp();
  driveZp();
  delay(1000);

//???????
  attachInterrupt(1, X_FALLING, FALLING);
  attachInterrupt(0, Y_FALLING, FALLING);
}

void X_FALLING(){
  if(digitalRead(X_dia))driveXp();
  else driveXm();
}
void Y_FALLING(){
  if(digitalRead(Y_dia))driveYm();
  else driveYp();
}
//main-------------------------------------------------------------------------
void loop(){
  /* if(!digitalRead(Z_step)){//LOW??
   if(digitalRead(Z_dia)){
   driveZp();
   }
   else{
   driveZm();
   }
   while(!digitalRead(Z_step)){
   }
   }
   */
}

byte t1=1; //x?????????????
byte t2=1;//??????????????
byte t3=1;//z?????????????

//2???------------
void driveXp(){//p???????
  switch(t1){//????
  case 1:
    digitalWrite(lY1,LOW);
    digitalWrite(X1,HIGH);
    t1=2;
    break;
  case 2:
    digitalWrite(X1,LOW);
    digitalWrite(Y1,HIGH);
    t1=3;
    break;
  case 3:
    digitalWrite(Y1,LOW);
    digitalWrite(lX1,HIGH);
    t1=4;
    break;
  case 4:
    digitalWrite(lX1,LOW);
    digitalWrite(lY1,HIGH);
    t1=1;
    break;
  }
}
void driveXm(){//m????????
  switch(t1){
  case 1:
    digitalWrite(lY1,LOW );
    digitalWrite(lX1,HIGH);
    t1=4;
    break;
  case 2:
    digitalWrite(X1,LOW);
    digitalWrite(lY1,HIGH);
    t1=1;
    break;
  case 3:
    digitalWrite(Y1,LOW);
    digitalWrite(X1,HIGH);
    t1=2;
    break;
  case 4:
    digitalWrite(lX1,LOW);
    digitalWrite(Y1,HIGH);
    t1=3;
    break;
  }
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void driveYp(){
  switch(t2){
  case 1:
    digitalWrite(lX2,LOW);
    digitalWrite(X2,HIGH);
    t2=2;
    break;
  case 2:
    digitalWrite(lY2,LOW);
    digitalWrite(Y2,HIGH);
    t2=3;
    break;
  case 3:
    digitalWrite(X2,LOW);
    digitalWrite(lX2,HIGH);
    t2=4;
    break;
  case 4:
    digitalWrite(Y2,LOW);
    digitalWrite(lY2,HIGH);
    t2=1;
    break;
  }
}

void driveYm(){
  switch(t2){
  case 1:
    digitalWrite(lY2,LOW );
    digitalWrite(Y2,HIGH);
    t2=4;
    break;
  case 2:
    digitalWrite(X2,LOW);
    digitalWrite(lX2,HIGH);
    t2=1;
    break;
  case 3:
    digitalWrite(Y2,LOW);
    digitalWrite(lY2,HIGH);
    t2=2;
    break;
  case 4:
    digitalWrite(lX2,LOW);
    digitalWrite(X2,HIGH);
    t2=3;
    break;
  }
}

void driveZp(){
  switch(t3){
  case 1:
    digitalWrite(X3,HIGH);
    digitalWrite(lY3,LOW);
    t3=2;
    break;
  case 2:
    digitalWrite(Y3,HIGH);
    digitalWrite(X3,LOW);
    t3=3;
    break;
  case 3:
    digitalWrite(lX3,HIGH);
    digitalWrite(Y3,LOW);
    t3=4;
    break;
  case 4:
    digitalWrite(lY3,HIGH);
    digitalWrite(lX3,LOW);
    t3=1;
    break;
  }
}
void driveZm(){
  switch(t3){
  case 1:
    digitalWrite(lX3,HIGH);
    digitalWrite(lY3,LOW);
    t3=4;
    break;
  case 2:
    digitalWrite(lY3,HIGH);
    digitalWrite(X3,LOW);
    t3=1;
    break;
  case 3:
    digitalWrite(X3,HIGH);
    digitalWrite(Y3,LOW);
    t3=2;
    break;
  case 4:
    digitalWrite(Y3,HIGH);
    digitalWrite(lX3,LOW);
    t3=3;
    break;
  }
}
//----------------------------------------------------------------------------

I can't read the other language. What I see of the code shows me state machines to run motors, looks like Gray Code (look it up) but what it is supposed to do, what you want is not apparent.

You want to run motors with Arduino then maybe easier for you to learn what is known works than to explain what you don't know how to work. At least then you will be able to understand the latter in terms of the former.

It would take a very long time to figure out that code without an extensive English explanation of it.

If it is designed to drive 3 or 4 stepper motors it probably can't be converted to an Uno because the Uno has far fewer I/O pins.

If all you want to do is drive a stepper motor then there are examples for that with the Arduino IDE.

If you explain what you want to do you might get more useful advice.

...R

I need to run 2 or 3 stepper motor
I do not speak English and I find it difficult explains
At the output of Arduino should be signally for transistors http://bezkz.su/_pu/3/69565762.jpg

The CNC is maybe 3 axis (milling machine?) and the first block of #defines are the motor/driver control pins.
Note in setup() they are all set for OUTPUT.

With identical hardware, time and motivation it can be known.

I see some struggle. But what works?

void loop(){
  /* if(!digitalRead(Z_step)){//LOW??
   if(digitalRead(Z_dia)){
   driveZp();
   }
   else{
   driveZm();
   }
   while(!digitalRead(Z_step)){
   }
   }
   */
}

Perhaps make a simple sketch to experiment getting just 1 motor to turn as desired?

I have a device that produces step/direction signals for stepper motor driver . Arduino just must take this step/dir signals on input pins , convert it to signal for four driver transistors and output this signals on out pins. I want convert two independent signals for two motors on single arduino . I hope now you understand what I want and can help me . Thanks !

Are you able to turn one stepper as you desire?
A simple sketch to turn the stepper one way, stop, other way, stop.

If not then there are web pages and Youtube showing this, perhaps in your language too.

This is a step towards the goal, I promise. But I need to be away from the computer for a while now.

motorist828:
I need to run 2 or 3 stepper motor
I do not speak English and I find it difficult explains
At the output of Arduino should be signally for transistors http://bezkz.su/_pu/3/69565762.jpg

The Arduino needs to control the stepper motors through a proper stepper motor driver board, especially for CNC. This webpage has a lot of good information. However the A4988 stepper driver may not be able to supply the full current for your stepper motor and if so you would have to find a suitable driver. The principle of operation will be the same. An important feature of proper stepper driver boards is that they can limit the current to protect the motor and then use a high voltage to get good performance from the motor.

Have you looked for information on some of the CNC forums. There is also an Arduino program called GRBL which may be of interest.

...R

I am already working with GRBL
A4988 driver booked very long delivery
I want to make a simple analog drivers based on the second Arduino

motorist828:
I want to make a simple analog drivers based on the second Arduino

I understand, but that would be much to complicated for me.

...R

Analog driver for stepper motor?
PWM pulses or true analog?

The driver you have, the code for that is in what you first posted?
If so then have you ever made one motor turn using that?

Yes, analog
I took the code from the Japanese site of the first message
I probyval change firmware for Arduino Uno conclusions, but it did not work

There is a Motors, Mechanics and Power section of the forum that should have answers, even how to build your own driver. There is a lot of expertise of that on the forum, all far better than myself.

Find out what power the steppers you have use and all you can about the drivers just to be ready.

Thanks for your help, I solved the problem of special firmware for the old version Grbl