Problem with stepper motor

Hello
Got small robot on Blynk with esp8266 as WiFi shield.
So what I not right there... 2 steppers motors works not as they have in code. Before it was working fine. Now something changed in code (a lot in some time) and now working not "correctly". What I mean -
that part in code:

if (state == 4) {
rightStepper.step(1);
leftStepper.step(1);

motors rotating in 100th part on whole wheel single rotation. But if change to like that:

if (state == 4) {
rightStepper.step(stepsPerRevolution);
leftStepper.step(stepsPerRevolution);

it rotating in one revolution absolutely fine. Before code changed with step(1) it was rotating for unlimited time, till not get another command. Here is link to full code, it's made for Blynk. It's in pastebin.HERE.
Much thanks for any help.

It's in pastebin.

Why not post it or attach it here ?

what is really the question? what does not work?

rightStepper.step(stepsPerRevolution); will do one full revolution

rightStepper.step(1); will take only 1 step (probably not 1/100th of a full revolution as it seems you have 2048 steps for one revolution) but move a small bit

if it was rotating continuously in the past and it stopped, it means something was asking to step multiple times and now it doesn't... what did you change besides the 1 and stepsPerRevolution ?

cookins:
Now something changed in code (a lot in some time)

Why don't you tell us what you changed? It will save us a lot of time trying to guess what the problem is.

...R

Pardon me, if there something missing in explanation. Code was changed to Blynk environment. What I need that motor worked continuously from pressed button or from switch, like usual DC motor. It was changed from next code:

//include libraries
#include <SoftwareSerial.h>
#include <Stepper.h>

SoftwareSerial esp8266(3, 2); //RX pin = 3, TX pin = 2

//definition of variables
#define DEBUG true //show messages between ESP8266 and Arduino in serial port
const int stepsPerRevolution = 500;
int state = 5;

Stepper rightStepper(stepsPerRevolution, 8,10,9,11);
Stepper leftStepper(stepsPerRevolution, 4,6,5,7);

//*****
//SETUP
//*****
void setup()
{
//start communication
Serial.begin(9600);
esp8266.begin(19200);

sendData("AT+RST\r\n", 2000, DEBUG); //reset module
sendData("AT+CWMODE=1\r\n", 1000, DEBUG); //set station mode
sendData("AT+CWJAP="Thaiane","1391162683"\r\n", 2000, DEBUG); //connect wi-fi network
while(!esp8266.find("OK")) { //wait for connection
}
sendData("AT+CIFSR\r\n", 1000, DEBUG); //show IP address
sendData("AT+CIPMUX=1\r\n", 1000, DEBUG); //allow multiple connections
sendData("AT+CIPSERVER=1,80\r\n", 1000, DEBUG); // start web server on port 80

//Define motor speed
rightStepper.setSpeed(60);
leftStepper.setSpeed(60);

}

void loop()
{

if (esp8266.available()) //verify incoming data
{
if (esp8266.find("+IPD,")) //if there is a message
{
String msg;
esp8266.find("?"); //look for the message
msg = esp8266.readStringUntil(' '); //read whole message
String command = msg.substring(0, 3); //first 3 characters = command
String valueStr = msg.substring(4); //next 3 characters = value
int value = valueStr.toInt();
if (DEBUG) {
Serial.println(command);
Serial.println(value);
}

//move forward
if(command == "cm1") {
state = 1;
}

//move backward
if(command == "cm2") {
state = 2;
}

//turn right
if(command == "cm3") {
state = 3;
}

//turn left
if(command == "cm4") {
state = 4;
}

//do nothing
if(command == "cm5") {
state = 5;
}

}
}

//move forward
if (state == 1) {
rightStepper.step(1);
leftStepper.step(-1);
}
//move backward
if (state == 2) {
rightStepper.step(-1);
leftStepper.step(1);
}
//move right
if (state == 3) {
rightStepper.step(1);
leftStepper.step(1);
}
//move left
if (state == 4) {
rightStepper.step(-1);
leftStepper.step(-1);
}
//do nothing
if (state == 5) {
}

}

//*******************
//Auxiliary functions
//*******************

String sendData(String command, const int timeout, boolean debug)
{
String response = "";
esp8266.print(command);
long int time = millis();
while ( (time + timeout) > millis())
{
while (esp8266.available())
{
char c = esp8266.read();
response += c;
}
}
if (debug)
{
Serial.print(response);
}
return response;
}

Original project HERE.

In that code if there is no input from your esp you still execute always the if (state == xx) tests so you keep stepping 1 step at a time.

Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

J-M-L:
In that code if there is no input from your esp you still execute always the if (state == xx) tests so you keep stepping 1 step at a time.

Can me write me example of your suggestion? In old code it was working fine. You mean input from rx tx must be defined here? But Blynk library control it itself.