Step Motor - Serial step controlled

Hi, i’m working on a project where i need to control a step motor by serial monitor,
what i’ve done so far doesn’t seen to work, the stepper only move a number of steps with
one digit number (0 - 9), and if i try to use more than one, the program just sums all digits, for example, if you type 12, it will move 3 steps.

Also, i can’t use negative numbers apparently.

Please help!

#include <Stepper.h>
#include <stdlib.h>
#define STEPS 200
Stepper motor(STEPS, 8, 9, 10, 11);
int i=0, g;
char ascii[10];
void setup() {
Serial.begin(9600);
motor.setSpeed(1);

}

void loop() {

if(Serial.available() > 0){
for(i=0;i<10;i++){
ascii*=Serial.read();*
if((ascii!=’-’)&&(ascii!=’.’)&&(ascii!=‘0’)&&(ascii!=‘1’)&&(ascii!=‘2’)&&(ascii!=‘3’)&&(ascii!=‘4’)&&(ascii!=‘5’)&&(ascii!=‘6’)&&(ascii!=‘7’)&&(ascii_!=‘8’)&&(ascii*!=‘9’)){
ascii=’\0’;
}
//int g = atoi(ascii);
int g = atoi(ascii);
motor.step(g);
}
}*_

Example 4 of serial input basics shows how to read a multi digit number from the serial port.

Thanks for the help, i'll test it

didn't work, help!

didn't work, help!

What didn't work. How can you expect for us to know what you tried?

And please read the "how to use the forum" stickies to see how to format and post code. Do you see how the forum software italicized the code that you posted in the original post?

meowmeow:
didn't work, help!

Post the program that you tried and tell us more about what happened. "Didn't work" does not provide any useful info from which to help you.

...R