step dir motor and speed control without library

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

nick you can delete the post, i have found the way to solve my problem, so this its closed

We don't just delete threads because they are solved. This forum is supposed to be a knowledge-base, to help other people.

i know, but i never solved the problem with the IDE, and my bad programming, so i just wrote i new code with accelstepper, but this thread its not working save since there its not good information here

copachino:
i know, but i never solved the problem with the IDE, and my bad programming, so i just wrote i new code with accelstepper, but this thread its not working save since there its not good information here

It would help others if you post your working code and explain why the information here was not suitable for your project and how you figured out your solution.

I would also like to learn so that my advice can be better focused next time.

...R

Robin2:

copachino:
i know, but i never solved the problem with the IDE, and my bad programming, so i just wrote i new code with accelstepper, but this thread its not working save since there its not good information here

It would help others if you post your working code and explain why the information here was not suitable for your project and how you figured out your solution.

I would also like to learn so that my advice can be better focused next time.

...R

ok here its the working code, and i could not figure out what was wrong in the library but i suppect there was something wrong on my object declarations, this code im posting uses accelstepper, the lib its way huge improve of the original stepper.h, and its perfect to work with step/dir drivers.

#include <AccelStepper.h>

// Define the stepper and the pins it will use
AccelStepper stepper1(1, 9, 8);

// Define our three input button pins
#define  LEFT_PIN  4 // left and right its one switch a spdt on/on with center pin at ground
#define  STOP_PIN  3
#define  RIGHT_PIN 2

// Define our analog pot input pin
#define  SPEED_PIN 0

// Define our maximum and minimum speed in steps per second (scale pot to these)
#define  MAX_SPEED 4000
#define  MIN_SPEED 0.1

void setup() {
  // The only AccelStepper value we have to set here is the max speeed, which is higher than we'll ever go 
  stepper1.setMaxSpeed(10000.0);
  
  // Set up the three button inputs, with pullups
  pinMode(LEFT_PIN, INPUT_PULLUP);
  pinMode(STOP_PIN, INPUT_PULLUP);
  pinMode(RIGHT_PIN, INPUT_PULLUP);
}

void loop() {
  static float current_speed = 0.0;         // Holds current motor speed in steps/second
  static int analog_read_counter = 1000;    // Counts down to 0 to fire analog read
  static char sign = 0;                     // Holds -1, 1 or 0 to turn the motor on/off and control direction
  static int analog_value = 0;              // Holds raw analog value.
  
  // If a switch is pushed down (low), set the sign value appropriately
  if (digitalRead(LEFT_PIN) == 0) {
    sign = 1;
  }
  else if (digitalRead(RIGHT_PIN) == 0) {    
    sign = -1;
  }
  else if (digitalRead(STOP_PIN) == 0) {
    sign = 0;
  }

  // We only want to read the pot every so often (because it takes a long time we don't
  // want to do it every time through the main loop).  
  if (analog_read_counter > 0) {
    analog_read_counter--;
  }
  else {
    analog_read_counter = 3000;
    // Now read the pot (from 0 to 1023)
    analog_value = analogRead(SPEED_PIN);
    // Give the stepper a chance to step if it needs to
    stepper1.runSpeed();
    //  And scale the pot's value from min to max speeds
    current_speed = sign * ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED;
    // Update the stepper to run at this new speed
    stepper1.setSpeed(current_speed);
  }

  // This will run the stepper at a constant speed
  stepper1.runSpeed();
  
  

}

copachino:
ok here its the working code,

Thanks.

I guess I had assumed from the title of your Thread that you didn't want to use a library.

...R