step dir motor and speed control without library

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?

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.

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

digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);

repeat as required.

...R

1 Like

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

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

#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 );
}
  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

Robin2:

  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

#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

copachino:
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"

copachino:
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

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??

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

Robin2:

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:

#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

#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

i see my error, but still does not complie

#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 );
  
  
   
}

copachino:
i see my error, but still does not complie

And what message/s are you getting back from the IDE about this?

copachino:
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

Robin2:

copachino:
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

  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

hi im trying to program a stepper to move with a potenciometer and change the speed, also with a switch to control to rotation, cww or cw, but i have some trouble with the library, some how seems not to work fine, and IDE its asking me to declare the funtions on the library itself

#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) {
    setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    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 );
  
  
   
}
Arduino: 1.0.6 (Windows 7), Board: "Arduino Uno"
D:\arduino-1.0.6\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -ID:\arduino-1.0.6\hardware\arduino\cores\arduino -ID:\arduino-1.0.6\hardware\arduino\variants\standard -ID:\arduino-1.0.6\libraries\Stepper C:\Users\MILAU\AppData\Local\Temp\build6855970105847057216.tmp\sketch_oct18a.cpp -o C:\Users\MILAU\AppData\Local\Temp\build6855970105847057216.tmp\sketch_oct18a.cpp.o 

sketch_oct18a.ino: In function 'void loop()':
sketch_oct18a:36: error: 'setSpeed' was not declared in this scope
sketch_oct18a:38: error: 'step' was not declared in this scope

I have been trying to answer this question in your other Thread. Why have you started a new Thread just to waste people's time?

I am asking the Moderator to merge this with the other Thread.

...R

copachino:
i see my error, but still does not complie

I tried to compile the code in Reply #11 and the only error was on this line

Stepper myStepper(stepsPerRevolution, 5, 3,);

and the problem is that there is comma after the '3'.

When I delete that comma it compiles. That does not mean it would work because it may be that there should be a number after that extra comma.

HOWEVER ...
That code does NOT give the error you have quoted

sketch_oct18a:37: error: 'myStepper' was not declared in this scope

which leads me to the conclusion that you have not posted the code that is actually causing you a problem.

AND ...
You started another Thread about the same problem - controlling a stepper without a library. I have already explained how to do that in this Thread. If there is part of my explanation that you don't understand please let me know.

...R

Robin2:
I have been trying to answer this question in your other Thread. Why have you started a new Thread just to waste people's time?

I am asking the Moderator to merge this with the other Thread.

...R

you can you wharever you want to do...

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

  • Moderator