TB 6600 4A Bluetooth Control

I am trying to run my stepper motor on Arduino with TB6600 4A via Bluetooth and its very slow or kinda dragging but it runs smoothly and fast when using push button. Please help me

CODE FOR PUSH BUTTON

#include <AccelStepper.h>
#define BUTTON_PIN 26
char val;
int value = 0;
AccelStepper stepper(1, 6, 7);

void setup(){
Serial.begin(9600);
stepper.setSpeed(2000);
pinMode(BUTTON_PIN,INPUT_PULLUP);
}
void stepperA(){
stepper.setSpeed(-2000);// Reversing the stepper
stepper.runSpeed();
}

void loop(){
value = digitalRead(BUTTON_PIN);
if ( value == LOW ) {
stepperA();
}
}

CODE FOR BLUETOOTH

#include <AccelStepper.h>
#include <SoftwareSerial.h>

int rx = 10;
int tx = 11;
char val;
SoftwareSerial bluetooth(tx, rx);
AccelStepper stepper(1, 6, 7);

void setup()
{
Serial.begin(9600);
bluetooth.begin(9600);
stepper.setSpeed(2000);
}

void stepperA(){
stepper.setSpeed(-2000);
stepper.runSpeed();
}
void loop(){
val = bluetooth.read();
if (val== ‘F’){
stepperA();
}
}

In both programs you should have the line stepper.runSpeed() in loop() so that it is always called.

And you don't seem to have any code to tell AccelStepper how many steps you want the motor to take. It would be usual to have stepper.move(NNN); where NNN is the number of steps

Try these changes and see what happens.

...R

Tried all that and its still slow and dragging.

Taffie:
Tried all that and its still slow and dragging.

Post the latest code in your next Reply so we can see exactly what you did.

What happens if you temporarily reduce the speed to (say) 500? Will both programs work the same at that speed?

...R

At speed of 500, the push button code is driving the stepper at a lower speed and the Bluetooth is even slower than before.

Find the code below:

#include <AccelStepper.h>
#include <SoftwareSerial.h>

int rx = 10;
int tx = 11;
char val;
SoftwareSerial bluetooth(tx, rx);
AccelStepper stepper(1, 6, 7);

void setup()
{
Serial.begin(9600);
bluetooth.begin(9600);
stepper.setSpeed(500);
stepper.moveTo(10000);
}

void stepperA(){
stepper.setSpeed(500);
stepper.runSpeed();
}
void loop(){
val = bluetooth.read();
if (val== ‘F’){
stepper.runSpeed();
stepperA();
}
}

You did not do what I wanted with stepper.runSpeed(). It should not be inside any conditional code.

Try this version and study the changes I have made carefully - I have added comments

#include <AccelStepper.h>
#include <SoftwareSerial.h>

int rx = 10;
int tx = 11;
char val;
SoftwareSerial bluetooth(tx, rx);
AccelStepper stepper(1, 6, 7);

void setup()
{ 
  Serial.begin(9600);
  bluetooth.begin(9600);
  stepper.setSpeed(500);
  stepper.move(200);   // changed
}

void stepperA(){
  // stepper.setSpeed(500);  // not needed, but not harmful
  //stepper.runSpeed();  // remove altogether
  stepper.move(200);   // new
}

void loop(){ 
  val = bluetooth.read();
  if (val== 'F'){
    stepperA();
  }
  stepper.runSpeed();  // moved
}

Well it uploaded the code but its running fast and smoothly on its own and the moment I connect my Bluetooth device its dropping its speed.

Taffie:
Well it uploaded the code but its running fast and smoothly on its own and the moment I connect my Bluetooth device its dropping its speed.

Once again, please post the code you are using (even if it is identical to mine).

...R

#include <AccelStepper.h>
#include <SoftwareSerial.h>

int rx = 10;
int tx = 11;
char val;
SoftwareSerial bluetooth(tx, rx);
AccelStepper stepper(1, 6, 7);

void setup()
{
Serial.begin(9600);
bluetooth.begin(9600);
stepper.setSpeed(500);
stepper.move(200); // changed
}

void stepperA(){
// stepper.setSpeed(500); // not needed, but not harmful
//stepper.runSpeed(); // remove altogether
stepper.move(200); // new
}

void loop(){
val = bluetooth.read();
if (val== ‘F’){
stepperA();

}
stepper.runSpeed(); // moved
}

Thanks. For the future please use the code button </> when uploading code. It make it much easier. See how I did it in Reply #5

You said in Reply #6 "but its running fast and smoothly on its own and the moment I connect my Bluetooth device its dropping its speed. "

Your code should cause the motor to do one revolution and then stop. If you send a single ‘F’ it should do another revolution and stop.

Is that what it is doing?

Change this piece so that you can be sure that it is only receiving a single ‘F’

  if (val== 'F'){
    Serial.println("F received");  // new
    stepperA();
   
  }

…R

For every F received its not running a full revolution but just a step.

Taffie:
For every F received its not running a full revolution but just a step.

How much time are you allowing between the transmission of 'F's - make sure you allow more time than it takes for a full revolution.

Can you confirm that it completes 1 full revolution at startup BEFORE you send any 'F's ?

...R

The time interval is 50ms and its affirmative that before I transmit the F command its already running continuously.

Taffie:
The time interval is 50ms and its affirmative that before I transmit the F command its already running continuously.

Well the motor is not going to do a revolution in 50ms. Change it to 5000 msecs for testing and see what happens.

If you can't change the 50msec interval then you will need a different style of program for the receiver.

...R