Controlling two stepper motors using arduino uno two tb6600 motor drivers and radio controller flysky fsi6

I want to control two stepper motors using flysky fs-i6 rc on two different channels .I am using tb6600 motor drivers for each stepper motor nema 23 and nema 17 are my stepper motor.I am using arduino uno as m microcontroller and i have flysky fs-i6 transmitter and fsia6b receiver. I am able to control single motor easily by the code i am using however when it coms to controlling two stepper motors only of them receive signals from the channel of transmitter via receiver while the other doesnt receive signal because of which there is no stepper motor moment . I am a newbie and i wish some could help me solve my problem by letting me know what exact changes shall i make . Below is the code which i am using for two stepper motors controlling using rc

#include <Stepper.h>

int ch2 = 2; // Input pin for pulse width signal from transmitter for stepper 1
int ch4 = 5; // Input pin for pulse width signal from transmitter for stepper 2

const int stepsPerRevolution1 = 3000;
const int stepsPerRevolution2 = 3000;

Stepper myStepper(stepsPerRevolution1, 9, 6); // Stepper 1 motor configuration
Stepper wStepper(stepsPerRevolution2, 10, 11); // Stepper 2 motor configuration

int centerPulseWidth1 = 1500; // Manually set the center pulse width value for stepper 1
int highLimit1 = 2000; // High limit of pulse width signal for stepper 1 (adjust as needed)
int lowLimit1 = 1000; // Low limit of pulse width signal for stepper 1 (adjust as needed)
int Eangle = 0; // Current angle position for stepper 1

int centerPulseWidth2 = 1750; // Manually set the center pulse width value for stepper 2
int highLimit2 = 2200; // High limit of pulse width signal for stepper 2 (adjust as needed)
int lowLimit2 = 1100; // Low limit of pulse width signal for stepper 2 (adjust as needed)
int Wangle = 0; // Current angle position for stepper 2

void setup() {
  Serial.begin(9600); // Initialize serial communication
  
  pinMode(ch2, INPUT); // Set ch2 pin as input for pulse width signal for stepper 1
  myStepper.setSpeed(10); // Set stepper 1 motor speed
  digitalWrite(6, LOW); // Ensure pin 6 is LOW
  digitalWrite(9, LOW); // Ensure pin 9 is LOW
  
  pinMode(ch4, INPUT); // Set ch4 pin as input for pulse width signal for stepper 2
  wStepper.setSpeed(10); // Set stepper 2 motor speed
  digitalWrite(10, LOW); // Ensure pin 10 is LOW
  digitalWrite(11, LOW); // Ensure pin 11 is LOW
  
  Serial.print("Center Pulse Width 1: ");
  Serial.println(centerPulseWidth1);
  
  Serial.print("Center Pulse Width 2: ");
  Serial.println(centerPulseWidth2);
}

void loop() {
  int pulseWidth1 = pulseIn(ch2, HIGH, 25000); // Read the pulse width from transmitter for stepper 1
  int pulseWidth2 = pulseIn(ch4, HIGH, 25000); // Read the pulse width from transmitter for stepper 2

  // Control logic for stepper 1
  if (pulseWidth1 == 0 || (pulseWidth1 >= centerPulseWidth1 - 20 && pulseWidth1 <= centerPulseWidth1 + 20)) {
    myStepper.step(0); // Stop stepper 1 if no input or within tolerance range around center pulse width
  } else {
    if (pulseWidth1 < centerPulseWidth1 && pulseWidth1 >= lowLimit1) {
      if (Eangle < 45) {
        Serial.println("Stepper 1: Clockwise");
        myStepper.step(30); // Step stepper 1 clockwise
        Eangle++; // Increment angle for stepper 1
      }
    } else if (pulseWidth1 > centerPulseWidth1 && pulseWidth1 <= highLimit1) {
      if (Eangle > -45) {
        Serial.println("Stepper 1: Counter-clockwise");
        myStepper.step(-30); // Step stepper 1 counter-clockwise
        Eangle--; // Decrement angle for stepper 1
      }
    }
  }

  // Control logic for stepper 2
  if (pulseWidth2 == 0 || (pulseWidth2 >= centerPulseWidth2 - 20 && pulseWidth2 <= centerPulseWidth2 + 20)) {
    wStepper.step(0); // Stop stepper 2 if no input or within tolerance range around center pulse width
  } else {
    if (pulseWidth2 < centerPulseWidth2 && pulseWidth2 >= lowLimit2) {
      if (Wangle < 45) {
        Serial.println("Stepper 2: Clockwise");
        wStepper.step(30); // Step stepper 2 clockwise
        Wangle++; // Increment angle for stepper 2
      }
    } else if (pulseWidth2 > centerPulseWidth2 && pulseWidth2 <= highLimit2) {
      if (Wangle > -45) {
        Serial.println("Stepper 2: Counter-clockwise");
        wStepper.step(-30); // Step stepper 2 counter-clockwise
        Wangle--; // Decrement angle for stepper 2
      }
    }
  }
}

image
this is the basic circuit diagram i am following , the only difference is i am supplying seperate power supply to both motors via motor drivers

Crank up the baudrate in Serial.begin to 115200. Adjust serial monitor to the same value.
Add some temporary Serial.print telling the values of pulswidth1 and 2 are read.

This will give more info.

I did change the baud to 115200 but could u please help me as in where i can write the print statements for the pulsewidth as i am not actually able to understand that

the problem still persist as only one stepper motor is working

Which Arduino pin is for STEP and which pin is for DIR?
Which Library are you using?

i am using pins 9 and 11 for step and pin 6 and 10 for dir and i am using stepper.h library

I don't see anything in the library that specified a STEP and DIR pin.
How did you decide which is which?
Also you diagram is quite fuzzy, can you make a bettor one?
I think you may have it wired wrong?

Please don't use screen shots.
Add the Serial.print directly after they got their vallues.


This maybe helpful ....I k the drawing aint that great but this is the wiring circuit i m doing. I am connecting tb6600 driver 1 step(pul+) to 9 and dir+ to 6 and i am connecting another tb6600 step and dir to pin 11 and 10 ....in the code i am directly mentioning the pins in stepper my stepper(stepsPerRevolution , 6, 9) these lines and in setup i am defining them as digital write with low parameter

Ok sir I understood one thing from the changes i made as per your suggestion ......the pulsewidth at channel 2 is coming zero while the pulsewidth at channel one is perfectly fluctuating .....Also whichever channel pin i am connecting at digital pin 2 of arduino that channel gives signal and the arduino receives it and the other digital pin whether it be 3, 4, 5(these pins i changed and checked ) at these pins the pulsewidth2 is coming zero and no signal is being transmitted

I don't see anything in the library that specified a STEP and DIR pin.
How did you decide which is which?

sir i am relatively very new to arduino coding so plz can you suggest me how and what changes i shall make in the code to declare step and direction pins

That Library is not for controlling a driver with STEP and DIR.
Most people use this library

1 Like

can you please help me create the entire code because i am finding it difficult to change the library

After you install the AccelStepper library, try this code to make sure your steppers are working.

#include <AccelStepper.h>
 
// Stepper 1 pins
#define STEPPER1_DIR_PIN 6
#define STEPPER1_STEP_PIN 9
// Stepper 2 pins
#define STEPPER2_DIR_PIN 11
#define STEPPER2_STEP_PIN 10
 
// Define steppers and the pins they will use
AccelStepper stepper1(AccelStepper::DRIVER, STEPPER1_STEP_PIN, STEPPER1_DIR_PIN);
AccelStepper stepper2(AccelStepper::DRIVER, STEPPER2_STEP_PIN, STEPPER2_DIR_PIN);
 
void setup()
{  
    stepper1.setMaxSpeed(100.0);
    stepper1.setAcceleration(100.0);
    stepper1.moveTo(100);
    
    stepper2.setMaxSpeed(100.0);
    stepper2.setAcceleration(100.0);
    stepper2.moveTo(100);
}
 
void loop()
{
    // Change direction at the limits
    if (stepper1.distanceToGo() == 0)
        stepper1.moveTo(-stepper1.currentPosition());
    if (stepper2.distanceToGo() == 0)
        stepper2.moveTo(-stepper2.currentPosition());
    stepper1.run();
    stepper2.run();
}

Sir this code is working perfectly now could you help me to add the code for the flysky fsi6 two channels seperately for two stepper motors ....because thats the main issue i am facing

Interesting and valuable observation!
Next idea is that You consult the Arduino/refrence/pulseIn and check what's told there.
Reading constant zero no code will work.

1 Like

i did copy the code so shall i test it or not???

Test it but I made a mistake pulseWidth1 and 2 should be unsigned long

  unsigned long pulseWidth1 = pulseIn(ch2, HIGH, 25000); // Read the pulse width from transmitter for stepper 1
  unsigned long pulseWidth2 = pulseIn(ch4, HIGH, 25000); // Read the pulse width from transmitter for stepper 2

Sir i tried testing the code you refered however there are two tings i am still not able to overcome ....Still one channel is not able to send the signal from transmitter to arduino ....sometimes very rarely it is sending signals while the second error i am facing is that both steppers are not working even if one of them is giving signals