decimal rotations in stepper library

Hai to all,

I am using arduino UNO , Stepper motor, and L293d driver.

I am able to work with integer values but i can't get any result with decimal values(1.2, 3.5, 4.7 like that).

I am using the arduino stepper motor standard standard library.

Thanks in advance.

It would help if you posted all of your code. Since stepper motors usually have known step values, it would seem you could use integer values yet still get the granularity you need.

but i can't get any result with decimal values(1.2, 3.5, 4.7 like that).

How do you expect a stepper to take 1.2 steps? Earth to Manidhar...

This is my code,

/* 
 Stepper Motor Control - one revolution
 
 This program drives a unipolar or bipolar stepper motor. 
 The motor is attached to digital pins 8 - 11 of the Arduino.
 
 The motor should revolve one revolution in one direction, then
 one revolution in the other direction.  
 
  
 Created 11 Mar. 2007
 Modified 30 Nov. 2009
 by Tom Igoe
 
 */

#include <Stepper.h>

int pin1=8;
int pin2=9;
int pin3=10;
int pin4=11;
const int stepsPerRevolution = 400;  // change this to fit the number of steps per revolution


// initialize the stepper library on pins 8 through 11:

Stepper myStepper(stepsPerRevolution, 8,9,10,11);                   

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(100);
  // initialize the serial port:
  Serial.begin(9600);
  pinMode(pin1,OUTPUT);
  pinMode(pin2,OUTPUT);
  pinMode(pin3,OUTPUT);
  pinMode(pin4,OUTPUT);
}

void cw(int j)
{
  int count=0;
  while(count<j)
  {
      count++;   
      myStepper.step(stepsPerRevolution);
  }
  off();
}
void ccw(int l)
{
   int count=0;
   while(count>l)
   {
      count--;
      myStepper.step(-stepsPerRevolution);
   }
   off();
}

void clearbuf(char *b)// clearing the buffer
{
	while(*b)
		*b++='\0';
}

void off()
{
  
        digitalWrite(pin1,LOW);
        digitalWrite(pin2,LOW);
        digitalWrite(pin3,LOW);
        digitalWrite(pin4,LOW);
}

void loop() {
  
	char j[10];
        int m,i;
	while(Serial.available()>0)
                while(!(j[i++]=Serial.read()));
	m=atoi(j);// converting string/char to integer
	Serial.print("m: ");
	Serial.println(m);

	if(m>0)// checking Clockwise
	{
            Serial.println("clockwise");
            cw(m);
            i=0;
	}   
	else if(m<0)// checking AntiClockwise checking
	{
            Serial.println("counterclockwise");
            ccw(m);
            i=0;
	}
	delay(2000);
        m=0;
        off();
        clearbuf(j);
}

Not like that paulS I want to 1.2 rotations

Not like that paulS I want to 1.2 rotations

I don't understand what that code is trying to accomplish. It looks like you are reading all available serial data, converting a char array (NOT a string) to a value using a function that expects a string, and returns an int, and expecting to get a float. As I said, Earth to...

You should, since you don't know what you are doing when reading serial data, be using Serial.parseInt() or Serial.parseFloat() to get data from the serial port and converting the stream of digits to a value.

Somewhere, of course, you need to multiply the value that you get by the number of steps per revolution, so that you can tell the stepper to step the proper number of times.

Not like that paulS I want to 1.2 rotations

Does that mean: 400 * 1.2 = 480? Either way, it still must resolve to an integer number. Also, if the stepper were attached to a "position" thing, like an antenna, why rotate through a complete circle? That is, 1.2 rotations is the same as moving 80 steps. Why the full rotation? If it's a valve or something that gets larger or smaller with rotation, that would make sense. Your comments suggest it's like an antenna.

Now I am understanding clearly.

Thanks paulS, econjack.

This is interesting, since i is never initialized...

int m,i;

while(Serial.available()>0)
      while(!(j[i++]=Serial.read()));