Hello. how to make separate lines according to the "encoder - stepper motor"?

want to make for the project 6 axial controlled robotic arm with easy driver and omron rotary encoder A and B channel. I tried everything. noob/

Moved your topic to it's current location as it is more suitable.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

schaikan92:
want to make for the project 6 axial controlled robotic arm with easy driver and omron rotary encoder A and B channel. I tried everything. noob/

You can't seriously expect a useful answer when you have provided no useful information.

Post the program that represents your best attempt and tell us in detail what it actually does and what you want it to do that is different. It will make it much easier to focus on the parts you need help with rather than wasting time on things that you can do.

A diagram of your robotic arm and links to the datasheets for the external parts you are using will also help.

Plus what's in Reply #1

...R

To be honest you have not even scratched the surface as to what is out there or or come close to trying everything. Figure out how you are going to make the arm move. Get the Arduino cookbook and read it. Also on line there are many videos etc showing the Arduino and how to do what you want. This additional information will go a long way in getting your problem solved.

schaikan92:
The first successful attempt on one line taken from YouTube, only there is one line.

You obviously did not read the links in Reply #1. Please do so now and use the code button </> for your code.

Help us to help you.

…R

Hi! Can you please help me with my code? I attach a copy below. hardware - arduino mcupro robotdyn mega 2560. driver - easydriver4.4. stepper motor - nema8. encoder - omron 1000P/R A and B channel.
source code which is working to one line.

//Arduino code for controlling stepper motor from encoder
//video at https://www.youtube.com/watch?v=2dh6TIkN6jE
//reconstructed code from 5+ years ago
//untested in current form

 #define encoder_a 2    //encoder a = arduino pin 2 
 #define encoder_b 3    //encoder b = arduino pin 3 
 #define motor_step 4    //motor step = arduino pin 4 
 #define motor_direction 5    //motor direction = arduino pin 5

volatile long motor_position, encoder; 

void setup () 
{ 
    //set up the various outputs 
    pinMode(motor_step, OUTPUT); 
    pinMode(motor_direction, OUTPUT); 
    // then the encoder inputs 
    pinMode(encoder_a, INPUT); 
    pinMode(encoder_b, INPUT); 
    digitalWrite(encoder_a, HIGH); 
    digitalWrite(encoder_b, HIGH);
    // encoder pin on interrupt 0 (pin 2) 
    attachInterrupt(0, encoderPinChangeA, CHANGE); 
    // encoder pin on interrupt 1 (pin 3) 
    attachInterrupt(1, encoderPinChangeB, CHANGE); 
    encoder = 0; 
}

void encoderPinChangeA() 
{
    if (digitalRead(encoder_a) == digitalRead(encoder_b)) 
    {
        encoder--;
    } 
    else
    {
        encoder++;
    } 
} 

void encoderPinChangeB() 
{
    if (digitalRead(encoder_a) != digitalRead(encoder_b)) 
    { 
        encoder--; 
    } 
    else 
    { 
        encoder++; 
    } 
}


void loop() 
{ 
//do stuff dependent on encoder position here 
//such as move a stepper motor to match encoder position 
//if you want to make it 1:1 ensure the encoder res matches the motor res by dividing/multiplying 
    if (encoder > 0) 
    { 
        digitalWrite(motor_direction, HIGH); 
        digitalWrite(motor_step, HIGH); 
        digitalWrite(motor_step, LOW); 
        _delay_us(200); 
        motor_position++; 
        encoder = 0; 
    }
    else if (encoder < 0) 
    {
        digitalWrite(motor_direction, LOW); 
        digitalWrite(motor_step, HIGH); 
        digitalWrite(motor_step, LOW); 
        _delay_us(200); 
        motor_position--; 
        encoder = 0; 
    }
}

then I tried a little to modify the code for the four control lines. arduino mega 2560 restriction interapt 8 pin for 4 encoders (two channel).(thank god there are two arduino boards) uploaded the firmware but separately on the lines could not work. one duplicated the other. please tell me how to logically divide the work of the line so that they can work separately. I understand electrical engineering but just starting to program.attached the image of the circuit. thank you in advance

#define encoder_a 2    //encoder a = arduino pin 2 
 #define encoder_b 3    //encoder b = arduino pin 3 
 #define encoder_a1 19    //encoder a1 = arduino pin 19 
 #define encoder_b1 18    //encoder b1 = arduino pin 18 
 #define encoder_a2 21    //encoder a2 = arduino pin 21 
 #define encoder_b2 20    //encoder b2 = arduino pin 20 
 #define encoder_a3 84    //encoder a3 = arduino pin 84 
 #define encoder_b3 83    //encoder b3 = arduino pin 83 
 #define motor_step 4    //motor step = arduino pin 4 
 #define motor_direction 5    //motor direction = arduino pin 5
 #define motor_step1 16    //motor step = arduino pin 16 
 #define motor_direction1 17    //motor direction = arduino pin 17
 #define motor_step2 22    //motor step = arduino pin 22 
 #define motor_direction2 23    //motor direction = arduino pin 23
 #define motor_step3 82    //motor step = arduino pin 82 
 #define motor_direction3 85    //motor direction = arduino pin 85

volatile long motor_position, encoder;  

void setup () 
{ 
    //set up the various outputs 
    pinMode(motor_step, OUTPUT); 
    pinMode(motor_direction, OUTPUT); 
    pinMode(motor_step1, OUTPUT); 
    pinMode(motor_direction1, OUTPUT); 
    pinMode(motor_step2, OUTPUT); 
    pinMode(motor_direction2, OUTPUT); 
    pinMode(motor_step3, OUTPUT); 
    pinMode(motor_direction3, OUTPUT); 
    // then the encoder inputs 
    pinMode(encoder_a, INPUT); 
    pinMode(encoder_b, INPUT); 
    pinMode(encoder_a1, INPUT); 
    pinMode(encoder_b1, INPUT); 
    pinMode(encoder_a2, INPUT); 
    pinMode(encoder_b2, INPUT); 
    pinMode(encoder_a3, INPUT); 
    pinMode(encoder_b3, INPUT); 
    digitalWrite(encoder_a, HIGH); 
    digitalWrite(encoder_b, HIGH);
    digitalWrite(encoder_a1, HIGH); 
    digitalWrite(encoder_b1, HIGH);
    digitalWrite(encoder_a2, HIGH); 
    digitalWrite(encoder_b2, HIGH);
    digitalWrite(encoder_a3, HIGH); 
    digitalWrite(encoder_b3, HIGH);
    // encoder pin on interrupt 4 (pin 2) 
    attachInterrupt(4, encoderPinChangeA, CHANGE); 
    // encoder pin on interrupt 5 (pin 3) 
    attachInterrupt(5, encoderPinChangeB, CHANGE); 
    // encoder pin on interrupt 2 (pin 19) 
    attachInterrupt(2, encoderPinChangeA, CHANGE); 
    // encoder pin on interrupt 3 (pin 18) 
    attachInterrupt(3, encoderPinChangeB, CHANGE); 
    // encoder pin on interrupt 0 (pin 21) 
    attachInterrupt(0, encoderPinChangeA, CHANGE); 
    // encoder pin on interrupt 1 (pin 20) 
    attachInterrupt(1, encoderPinChangeB, CHANGE); 
    // encoder pin on interrupt 6 (pin 84) 
    attachInterrupt(6, encoderPinChangeA, CHANGE); 
    // encoder pin on interrupt 7 (pin 83) 
    attachInterrupt(7, encoderPinChangeB, CHANGE); 
    encoder = 0; 
}

void encoderPinChangeA() 
{
    if (digitalRead(encoder_a) == digitalRead(encoder_b)) 
    if (digitalRead(encoder_a1) == digitalRead(encoder_b1))
    if (digitalRead(encoder_a2) == digitalRead(encoder_b2))
    if (digitalRead(encoder_a3) == digitalRead(encoder_b3))
    {
        encoder--;
    } 
    else
    {
        encoder++;
    } 
} 

void encoderPinChangeB() 
{
    if (digitalRead(encoder_a) != digitalRead(encoder_b)) 
    if (digitalRead(encoder_a1) != digitalRead(encoder_b1))
    if (digitalRead(encoder_a2) != digitalRead(encoder_b2))
    if (digitalRead(encoder_a3) != digitalRead(encoder_b3))
    { 
        encoder--; 
    } 
    else 
    { 
        encoder++; 
    } 
}


void loop() 
{ 
//do stuff dependent on encoder position here 
//such as move a stepper motor to match encoder position 
//if you want to make it 1:1 ensure the encoder res matches the motor res by dividing/multiplying 
    if (encoder > 0) 
    { 
        digitalWrite(motor_direction, HIGH); 
        digitalWrite(motor_step, HIGH); 
        digitalWrite(motor_step, LOW); 
        digitalWrite(motor_direction1, HIGH); 
        digitalWrite(motor_step1, HIGH); 
        digitalWrite(motor_step1, LOW); 
        digitalWrite(motor_direction2, HIGH); 
        digitalWrite(motor_step2, HIGH); 
        digitalWrite(motor_step2, LOW); 
        digitalWrite(motor_direction3, HIGH); 
        digitalWrite(motor_step3, HIGH); 
        digitalWrite(motor_step3, LOW); 
        _delay_us(200); 
        motor_position++; 
        encoder = 0; 
    }
    else if (encoder < 0) 
    {
        digitalWrite(motor_direction, LOW); 
        digitalWrite(motor_step, HIGH); 
        digitalWrite(motor_step, LOW); 
        digitalWrite(motor_direction1, LOW); 
        digitalWrite(motor_step1, HIGH); 
        digitalWrite(motor_step1, LOW);
        digitalWrite(motor_direction2, LOW); 
        digitalWrite(motor_step2, HIGH); 
        digitalWrite(motor_step2, LOW);
        digitalWrite(motor_direction3, LOW); 
        digitalWrite(motor_step3, HIGH); 
        digitalWrite(motor_step3, LOW);
        _delay_us(200); 
        motor_position--; 
        encoder = 0; 
    }
}

Image from Reply #5 so we don't have to download it. See this Simple Image Posting Guide

...R