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
}
}
}
}
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.
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
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?
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
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
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.
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