Go Down

Topic: step dir motor and speed control without library (Read 8089 times) previous topic - next topic

copachino

hi does anybody have a step dir code a simple one a have a driver bases on the DRV8818 chip, and i know its active low, but i dont know or have any example on how to program it to be use with the motor on arduino, any help?

MarkT

The step and direction inputs to the DRV8818 are standard, positive-edge triggered
step.  The AccelStepper library is probably a good starting point.

You probably can just hard-wire the other logic inputs.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Robin2

Just put the direction pin HIGH or LOW as required and this code will create a single step

Code: [Select]
digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);


repeat as required.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

copachino


Just put the direction pin HIGH or LOW as required and this code will create a single step

Code: [Select]
digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);


repeat as required.

...R


like this??, this has two push bottoms to change the spin of the stepper, i still have no tried but, seems ok as you said

Code: [Select]
#include <configMe.h>
#include <stepper.h>


#define MI_PIN_STEP 5
#define MI_PIN_DIR 2
const int  ccw = 10;   
const int cw = 13;

void setup()
{
  //Wire.begin ();
  Serial.begin ( 57600 );
 
  pinMode ( MI_PIN_STEP, OUTPUT );
  pinMode ( MI_PIN_DIR, OUTPUT );
 
  pinMode(ccw,INPUT);
  pinMode(cw, INPUT);


 
}

void loop()
{
 
 
// {

if(cw==HIGH)
{
  digitalWrite ( MI_PIN_DIR, HIGH );

}
  if(ccw==HIGH)
{
digitalWrite ( MI_PIN_DIR, LOW ); // chage rotation

}

  // steps
  digitalWrite ( MI_PIN_STEP, LOW );
  delay ( 10 );
  digitalWrite ( MI_PIN_STEP, HIGH );
   delay ( 10 );
}

Robin2

Code: [Select]
  digitalWrite ( MI_PIN_STEP, LOW );
  delay ( 10 );
  digitalWrite ( MI_PIN_STEP, HIGH );
   delay ( 10 );


My code didn't have any delay between the HIGH and LOW - why have you got one?

Put all the delay between the steps. The actual pulse can be very short and the digitalWrite() function is slow enough on its own.

The Arduino is a great system for learning-by-doing.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

copachino


Code: [Select]
  digitalWrite ( MI_PIN_STEP, LOW );
  delay ( 10 );
  digitalWrite ( MI_PIN_STEP, HIGH );
   delay ( 10 );


My code didn't have any delay between the HIGH and LOW - why have you got one?

Put all the delay between the steps. The actual pulse can be very short and the digitalWrite() function is slow enough on its own.

The Arduino is a great system for learning-by-doing.

...R


they are just to avoid the microcontroller to overload data, or thats the idea, i see i dont need two bottoms just one HIGH or LOW will give me HIGH or LOW DIR steps, i need to add a revolutions counter to the loos, and a potenciometer to change the speed, i still have no tried the code mybe will do tomorrow

copachino

#6
Oct 17, 2014, 10:11 pm Last Edit: Oct 17, 2014, 10:16 pm by copachino Reason: 1
Code: [Select]
#include <configMe.h>

#include <Stepper.h>


#define MI_PIN_STEP 5
#define MI_PIN_DIR 2
const int  gir = 10;  
const int stepsPerRevolution = 200;
int stepCount = 0;

void setup()
{
 //Wire.begin ();
 Serial.begin ( 57600 );
 
 pinMode ( MI_PIN_STEP, OUTPUT );
 pinMode ( MI_PIN_DIR, OUTPUT );
 
 pinMode(gir,INPUT);
 
 



 
}

void loop()
{
 
 int sensorReading = analogRead(A0);
 int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
 
 if (motorSpeed > 0) {
   myStepper.setSpeed(motorSpeed);
   // step 1/100 of a revolution:
   myStepper.step(stepsPerRevolution / 100);
 }
 
 
// {

if(gir==HIGH)
{
 digitalWrite ( MI_PIN_DIR, HIGH );

}
 if(gir==LOW)
 {
digitalWrite ( MI_PIN_DIR, LOW );

}

 // pasos
 digitalWrite ( MI_PIN_STEP, LOW );
 
 digitalWrite ( MI_PIN_STEP, HIGH );
 
 
 
}

Arduino: 1.5.8 (Windows 8), Placa:"Arduino Uno"

sketch_oct16a.ino: In function 'void loop()':
sketch_oct16a.ino:36:5: error: 'myStepper' was not declared in this scope
Error de compilación

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.



i dont see where its the problem with the prpgram i just tried to add a potenciometer to set speed, but i cant see the errors

Robin2

#7
Oct 17, 2014, 10:37 pm Last Edit: Oct 17, 2014, 10:39 pm by Robin2 Reason: 1

they are just to avoid the microcontroller to overload data, or thats the idea, i see i dont need two bottoms just one HIGH or LOW will give me HIGH or LOW DIR steps, i need to add a revolutions counter to the loos, and a potenciometer to change the speed, i still have no tried the code mybe will do tomorrow


I assume you use the word "they" to refer to the 2 instances of delay(10). I did not say to remove both of them - just the first one, and then make the second one delay(20) to compensate.

Doing it my way will NOT overload anything.

I don't understand the rest of the sentence after the word "idea"


sketch_oct16a.ino:36:5: error: 'myStepper' was not declared in this scope

i dont see where its the problem with the prpgram i just tried to add a potenciometer to set speed, but i cant see the errors


The error message says it all. You should have a line Stepper myStepper(xxx); before setup() and you have omitted it.

However if you are just trying to move the stepper without using the stepper library then the error is that you still have lines with myStepper.setSpeed(motorSpeed); etc which are no longer needed.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

copachino

im almost like copy-page from the igor code on the exmples, and the example compiles ok, but mine have this problem in the setup its not declared nothing on the original code, so maybe my lib its wrong??

Robin2


im almost like copy-page from the igor code on the exmples, and the example compiles ok, but mine have this problem in the setup its not declared nothing on the original code, so maybe my lib its wrong??


I don't understand.

Did you read my Reply #7 ?
Did you try my suggestions?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

copachino



im almost like copy-page from the igor code on the exmples, and the example compiles ok, but mine have this problem in the setup its not declared nothing on the original code, so maybe my lib its wrong??


I don't understand.

Did you read my Reply #7 ?
Did you try my suggestions?

...R


ys i tried, but mystepper. its somethingon the Stepper.h library, so i doesnt need to be declared, i am calling stepper.h lib but doesnt work on this code, im trying to just implement the stepper speed control with a potenciometer that its on the data base of steppers examples. but software keeps asking to declare Mystepper function.

this its my code:
Code: [Select]
#include <configMe.h>

#include <Stepper.h>


#define MI_PIN_STEP 5
#define MI_PIN_DIR 2
const int  gir = 10;   
const int stepsPerRevolution = 200;
int stepCount = 0;

void setup()
{
  //Wire.begin ();
  Serial.begin ( 57600 );
 
  pinMode ( MI_PIN_STEP, OUTPUT );
  pinMode ( MI_PIN_DIR, OUTPUT );
 
  pinMode(gir,INPUT);
 
 



 
}

void loop()
{
 
  int sensorReading = analogRead(A0);
  int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
 
  if (motorSpeed > 0) {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution /200);
  }
 
 
// {

if(gir==HIGH)
{
  digitalWrite ( MI_PIN_DIR, HIGH );

}
  if(gir==LOW)
  {
digitalWrite ( MI_PIN_DIR, LOW );
}

  // pasos
  digitalWrite ( MI_PIN_STEP, LOW );
 
  digitalWrite ( MI_PIN_STEP, HIGH );
 
 
   



and this its the one on the examples
Code: [Select]

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor


// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

int stepCount = 0;  // number of steps the motor has taken

void setup() {
  // nothing to do inside the setup
}

void loop() {
  // read the sensor value:
  int sensorReading = analogRead(A0);
  // map it to a range from 0 to 100:
  int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
  // set the motor speed:
  if (motorSpeed > 0) {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution / 100);
  }
}



as you see mystepper doesnt need to be declared, but i dont know why the compliler keeps asking to declare it

copachino

i see my error, but still does not complie

Code: [Select]
#include <configMe.h>

#include <Stepper.h>


#define MI_PIN_STEP 5
#define MI_PIN_DIR 2
const int  gir = 10;   
const int stepsPerRevolution = 200;
int stepCount = 0;
Stepper myStepper(stepsPerRevolution, 5, 3,);

void setup()
{
  //Wire.begin ();
  Serial.begin ( 57600 );
 
  pinMode ( MI_PIN_STEP, OUTPUT );
  pinMode ( MI_PIN_DIR, OUTPUT );
 
  pinMode(gir,INPUT);
 
 



 
}

void loop()
{
 
  int sensorReading = analogRead(A0);
  int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
 
  if (motorSpeed > 0) {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution / 100);
  }
 
 
// {

if(gir==HIGH)
{
  digitalWrite ( MI_PIN_DIR, HIGH ); // Poner una dirección

}
  if(gir==LOW)
  {
digitalWrite ( MI_PIN_DIR, LOW ); // Poner la otra dirección

}

  // pasos
  digitalWrite ( MI_PIN_STEP, LOW );
 
  digitalWrite ( MI_PIN_STEP, HIGH );
 
 
   
}

runaway_pancake


i see my error, but still does not complie


And what message/s are you getting back from the IDE about this?
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!

Robin2


ys i tried, but mystepper. its somethingon


The step code that I suggested is used without the Stepper library - it has nothing to do with the Stepper library. You can use the Stepper library OR my code but not both.

And, as @Runaway Pancake has asked, what error message are you getting?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

copachino

#14
Oct 18, 2014, 03:58 pm Last Edit: Oct 18, 2014, 04:03 pm by copachino Reason: 1


ys i tried, but mystepper. its somethingon


The step code that I suggested is used without the Stepper library - it has nothing to do with the Stepper library. You can use the Stepper library OR my code but not both.

And, as @Runaway Pancake has asked, what error message are you getting?

...R


im getting the same error from myStepper

Code: [Select]
 This report would have more information with
 "Show verbose output during compilation"
 enabled in File > Preferences.
Arduino: 1.0.6 (Windows 7), Board: "Arduino Uno"
sketch_oct18a:11: error: expected constructor, destructor, or type conversion before '(' token
sketch_oct18a.ino: In function 'void loop()':
sketch_oct18a:37: error: 'myStepper' was not declared in this scope



also im using this driver, and the lib that comes with itm that lib have in the step and dir funtions that im using so, calling stepper,h wont e a problem, but still IDE dont recognizes mystepper funtion

Go Up