Why do you have the centerpulsewith and high and low limits different for the two channels?
i did change the and kept same centre pulse width and high low limit for both steppers ....this is what i am getting in receiver however i am not able to move any of the stepper
As @Railroader said screenshots are unreadable. You need to post your new code and the output.
Also I know nothing about your RC transmitter and receiver. Maybe the transmitter is not sending or the receiver not receiving.
the transmitter is sending signals and the receiver is receiving it now however the stepper motors are not rotating according to the loop conditions I tried increasing the speed and max speed also one more thing this tb6600 stepper motor driver has stepsperrevolution i.e microsteps as constant which is nowhere mentiond in the code so will that be a reason why steppers are not rotating
#include <AccelStepper.h>
int ch2 = 2; // Input pin for pulse width signal from transmitter for stepper 1
int ch4 = 4; // Input pin for pulse width signal from transmitter for stepper 2
int centerPulseWidth1 = 1500; // Manually set the center pulse width value for stepper 1
int highLimit1 = 2500; // High limit of pulse width signal for stepper 1 (adjust as needed)
int lowLimit1 = 700; // Low limit of pulse width signal for stepper 1 (adjust as needed)
int Eangle = 0; // Current angle position for stepper 1
int centerPulseWidth2 = 1500; // Manually set the center pulse width value for stepper 2
int highLimit2 = 2500; // High limit of pulse width signal for stepper 2 (adjust as needed)
int lowLimit2 = 700; // Low limit of pulse width signal for stepper 2 (adjust as needed)
int Wangle = 0; // Current angle position for stepper 2
// Stepper 1 pins
#define STEPPER1_DIR_PIN 6
#define STEPPER1_STEP_PIN 9
// Stepper 2 pins
#define STEPPER2_DIR_PIN 5
#define STEPPER2_STEP_PIN 10
// Define steppers and the pins used
AccelStepper stepper1(AccelStepper::DRIVER, STEPPER1_STEP_PIN, STEPPER1_DIR_PIN);
AccelStepper stepper2(AccelStepper::DRIVER, STEPPER2_STEP_PIN, STEPPER2_DIR_PIN);
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(ch2, INPUT); // Set ch2 pin as input for pulse width signal for stepper 1
pinMode(ch4, INPUT); // Set ch4 pin as input for pulse width signal for stepper 2
Serial.print("Center Pulse Width 1: ");
Serial.println(centerPulseWidth1);
Serial.print("Center Pulse Width 2: ");
Serial.println(centerPulseWidth2);
stepper1.setMaxSpeed(3000.0);
stepper1.setSpeed(2000.0); // 500 steps/second
stepper2.setMaxSpeed(3000.0);
stepper2.setSpeed(2000.0); // 500 steps/second
}
void loop() {
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
// Control logic for stepper 1
if (pulseWidth1 == 0 || (pulseWidth1 >= centerPulseWidth1 - 20 && pulseWidth1 <= centerPulseWidth1 + 20)) {
stepper1.move(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");
stepper1.move(30); // Step stepper 1 clockwise, move 30 steps
Eangle++; // Increment angle for stepper 1
}
} else if (pulseWidth1 > centerPulseWidth1 && pulseWidth1 <= highLimit1) {
if (Eangle > -45) {
Serial.println("Stepper 1: Counter-clockwise");
stepper1.move(-30); // Step stepper 1 counter-clockwise, move 30 steps
Eangle--; // Decrement angle for stepper 1
}
}
}
// Control logic for stepper 2
if (pulseWidth2 == 0 || (pulseWidth2 >= centerPulseWidth2 - 20 && pulseWidth2 <= centerPulseWidth2 + 20)) {
stepper2.move(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");
stepper2.move(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");
stepper2.move(-30); // Step stepper 2 counter-clockwise
Wangle--; // Decrement angle for stepper 2
}
}
}
stepper1.runSpeedToPosition();
stepper2.runSpeedToPosition();
}
You changed the max speed and set speed.
yes i did change the set speed and max speed after testing it once as at that speed there was no revolution or any change in stepper
You also changed the pin numbers. It difficult for me to debug the problem if you make changes to the code I sent you, without telling me, or why you made the changes.
How do you know the receiver is sending pulses to the arduino. Did you check it with a scope?
i have given serial.print line in code so thats why when i am moving the joysticks it shows the cw and ccw moment in serialmonitor as per my joystick movement hence i am assuming that the stepper is workig ....I changed the pins for better understanding for myself during wiring (sorry for that )
Do you have the TB6600 DIP switched set to the correct positions?
This code works a little differently
Change the pin numbers according to your wiring
//*****************************
// *****NOTE PIN NUMBERS!!*****
#include <AccelStepper.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
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 = 1500; // Manually set the center pulse width value for stepper 2
int highLimit2 = 2000; // High limit of pulse width signal for stepper 2 (adjust as needed)
int lowLimit2 = 1000; // Low limit of pulse width signal for stepper 2 (adjust as needed)
int Wangle = 0; // Current angle position for stepper 2
// 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 used
AccelStepper stepper1(AccelStepper::DRIVER, STEPPER1_STEP_PIN, STEPPER1_DIR_PIN);
AccelStepper stepper2(AccelStepper::DRIVER, STEPPER2_STEP_PIN, STEPPER2_DIR_PIN);
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(ch2, INPUT); // Set ch2 pin as input for pulse width signal for stepper 1
pinMode(ch4, INPUT); // Set ch4 pin as input for pulse width signal for stepper 2
Serial.print("Center Pulse Width 1: ");
Serial.println(centerPulseWidth1);
Serial.print("Center Pulse Width 2: ");
Serial.println(centerPulseWidth2);
stepper1.setMaxSpeed(1000.0);
stepper1.setAcceleration(1000.0);
stepper1.setSpeed(500.0); // 500 steps/second
stepper2.setMaxSpeed(1000.0);
stepper2.setAcceleration(1000.0);
stepper2.setSpeed(500.0); // 500 steps/second
}
void loop() {
unsigned long pulseWidth1 = pulseIn(ch2, HIGH, 25000); // Read the pulse width from transmitter for stepper 1
// Control logic for stepper 1
if (pulseWidth1 == 0 || (pulseWidth1 >= centerPulseWidth1 - 20 && pulseWidth1 <= centerPulseWidth1 + 20)) {
stepper1.runToNewPosition(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");
stepper1.runToNewPosition(30); // Step stepper 1 clockwise, move 30 steps
Eangle++; // Increment angle for stepper 1
}
} else if (pulseWidth1 > centerPulseWidth1 && pulseWidth1 <= highLimit1) {
if (Eangle > -45) {
Serial.println("Stepper 1: Counter-clockwise");
stepper1.runToNewPosition(-30); // Step stepper 1 counter-clockwise, move 30 steps
Eangle--; // Decrement angle for stepper 1
}
}
}
unsigned long pulseWidth2 = pulseIn(ch4, HIGH, 25000); // Read the pulse width from transmitter for stepper 2
// Control logic for stepper 2
if (pulseWidth2 == 0 || (pulseWidth2 >= centerPulseWidth2 - 20 && pulseWidth2 <= centerPulseWidth2 + 20)) {
stepper2.runToNewPosition(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");
stepper2.runToNewPosition(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");
stepper2.runToNewPosition(-30); // Step stepper 2 counter-clockwise
Wangle--; // Decrement angle for stepper 2
}
}
}
}
sir the stepper motor is showing slight movements but the thing is the receiver is giving very light centre pulse width for both channels so what can i do to make these pulsewidths more stronger ...i hope you understanding what i m trying to say...I am trying my best to explain you this
I'm not familiar with your RC transmitter/receiver but there is usually a way to set to min and max pulsewidths for the min and max joystick travel.
Put a Serial.println for the pulseWidth to see what they are.
I tried changing the centre pulsewidth and the end limits but the problem still seems to persist .....I observed one thing that as the transmitter is giving very very light signals at slightest deviation that time the motors are trying to move according to the joystick deviation however still i am not able to get the best solution for my problem (I did try changing various values for all centre pulsewidth and high lowlimits )
#include <AccelStepper.h>
int ch2 = 2; // Input pin for pulse width signal from transmitter for stepper 1
int ch4 = 3; // Input pin for pulse width signal from transmitter for stepper 2
int centerPulseWidth1 = 1500; // Manually set the center pulse width value for stepper 1
int highLimit1 = 1900; // High limit of pulse width signal for stepper 1 (adjust as needed)
int lowLimit1 = 1100; // Low limit of pulse width signal for stepper 1 (adjust as needed)
int Eangle = 0; // Current angle position for stepper 1
int centerPulseWidth2 = 1500; // Manually set the center pulse width value for stepper 2
int highLimit2 = 1900; // 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
// 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 used
AccelStepper stepper1(AccelStepper::DRIVER, STEPPER1_STEP_PIN, STEPPER1_DIR_PIN);
AccelStepper stepper2(AccelStepper::DRIVER, STEPPER2_STEP_PIN, STEPPER2_DIR_PIN);
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(ch2, INPUT); // Set ch2 pin as input for pulse width signal for stepper 1
pinMode(ch4, INPUT); // Set ch4 pin as input for pulse width signal for stepper 2
Serial.print("Center Pulse Width 1: ");
Serial.println(centerPulseWidth1);
Serial.print("Center Pulse Width 2: ");
Serial.println(centerPulseWidth2);
stepper1.setMaxSpeed(1000.0);
stepper1.setAcceleration(1000.0);
stepper1.setSpeed(500.0); // 500 steps/second
stepper2.setMaxSpeed(1000.0);
stepper2.setAcceleration(1000.0);
stepper2.setSpeed(500.0); // 500 steps/second
}
void loop() {
unsigned long pulseWidth1 = pulseIn(ch2, HIGH, 25000); // Read the pulse width from transmitter for stepper 1
// Control logic for stepper 1
if (pulseWidth1 == 0 || (pulseWidth1 >= centerPulseWidth1 - 15 && pulseWidth1 <= centerPulseWidth1 + 15)) {
stepper1.runToNewPosition(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");
stepper1.runToNewPosition(30); // Step stepper 1 clockwise, move 30 steps
Eangle++; // Increment angle for stepper 1
}
} else if (pulseWidth1 > centerPulseWidth1 && pulseWidth1 <= highLimit1) {
if (Eangle > -45) {
Serial.println("Stepper 1: Counter-clockwise");
stepper1.runToNewPosition(-30); // Step stepper 1 counter-clockwise, move 30 steps
Eangle--; // Decrement angle for stepper 1
}
}
}
unsigned long pulseWidth2 = pulseIn(ch4, HIGH, 25000); // Read the pulse width from transmitter for stepper 2
// Control logic for stepper 2
if (pulseWidth2 == 0 || (pulseWidth2 >= centerPulseWidth2 - 15 && pulseWidth2 <= centerPulseWidth2 + 15)) {
stepper2.runToNewPosition(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");
stepper2.runToNewPosition(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");
stepper2.runToNewPosition(-30); // Step stepper 2 counter-clockwise
Wangle--; // Decrement angle for stepper 2
}
}
}
}
Do they match what the transmitter is sending?
Is the TB6600 configured for your motors?
Did you include the print for the pulsewidth?
What is supposed to happen when Eangle and Wangle increment to greater than 45?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.