Working with AccelStepper

Greetings!

I am working on an Arduino Nano project to control a equatorial telescope mount using two stepper motors and Bluetooth being generated from Keuwlsoft's Bluetooth controller. The Keuwlsoft program send 1-2 digit codes to the Nano via a Xbee Bluetooth interface.

Only the commands to move the stepper motors ("B" & "E") are being sent every 100ms...all other functions send the character once.

Everything works but the stepper motors move slowly even when given a fast setSpeed setting.

Please look over my code and suggest a way to modify it for better stepper operation...I have tried everything I can think of.

Thanks

Tonys_Stepper_Motor_Control_With_Bluetooth_and_Pololu_Stepper_4.ino (4.48 KB)

You should not have this line

Motor_1.runSpeed();

inside any IF statement. Just put it at the end of loop() so it gets called every time loop() repeats. And make sure that loop() can repeat much faster than the fastest step rate that you require.

The same for the other motor.

The way your program is written now runSpeed() will only be called once for every time that a 'B' is received.

That LCD code will also slow things down. The LCD does not need to be updated on every iteration of loop().

Is that a program you wrote yourself or one you found somewhere? Either way it is a bit of a dog's breakfast.

Serial.parseInt() is also slow. Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

Separate the business of receiving data from the business of setting the AccelStepper parameters and that from the business of actually making the motors move.

If you want some action to happen while a button or key is pressed send a message when the key is pressed and send a separate message when it is released. For example send 'B' when it is pressed and 'b' when it is released.

...R

As I am new to this can you show me an example of how to do this by modifing my code?

Thanks

tsenneville:
As I am new to this can you show me an example of how to do this by modifing my code?

That would be a huge job - a complete rewrite.

If you want someone to write a program for you please ask in the Gigs and Collaborations section of the Forum and be prepared to pay.

If you want to learn how to do it yourself start by studying some of the examples that come with the AccelStepper library.

...R
Stepper Motor Basics
Simple Stepper Code
Serial Input Basics - simple reliable ways to receive data.
Planning and Implementing a Program

Thanks for the information...I solved the problem!

I did what you suggested and moved the Motor_1.runSpeed() and Motor_2.runSpeed() to the end of the loop, changed the Motor Stop commands to "b" & "e" and added the following lines to the Motor Stop command...If (BluetoothData=='b') { Motor_1.setSpeed(0); Motor_1.stop() }.

Did this for both motors and now everything works as planned.

Thanks again,

Speedboat