Notifications
Clear all

Arduino with Stepper and LiquidCrystal Issue

Page 4 / 21

Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2017
 

@voltage

Hmmm ... interesting, but annoying.

I'll keep looking at it too.

I was kidnapped by mimes.
They did unspeakable things to me.


ReplyQuote
Voltage
(@voltage)
Estimable Member
Joined: 1 year ago
Posts: 175
Topic starter  

Madmisha,

  Ok, I will take your other code and set that back to what you said and give it a go first.

 

Switches on driver:ON OFF OFF OFF OFF ON ON ON

First 3 = 2.69A RMS

4th switch = Half Current

5-8 = 400 Microsteps

Thanks,
Voltage


ReplyQuote
Voltage
(@voltage)
Estimable Member
Joined: 1 year ago
Posts: 175
Topic starter  

Weird. When I try to verify this code below now I get an error that "dirfor" was not declared in this scope.

Arduino: 1.8.15 (Windows 10), Board: "Arduino Uno"

 

Oh yeah, I fixed that before by changing the spelling to "dirFor".

 

 

 

 

 

 

 

 

Thanks,
Voltage


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 3 years ago
Posts: 346
 
Posted by: @voltage

4th switch = Half Current

That might have been your thump. The LCD took more than 0.4 seconds to update and it cut power. I do not really know much about this setting though.

 

Posted by: @voltage

5-8 = 400 Microsteps

I think that is 2 microsteps = 400 steps/rev, assuming I am looking at the right datasheet. You might want to up that a little. Isn't that the lowest setting?


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 3 years ago
Posts: 346
 
Posted by: @voltage

Weird. When I try to verify this code below now I get an error that "dirfor" was not declared in this scope.

I just verified it on mine and had no problem. I just did a search and all say dirFor although it might have lost case in the debug. I also confirmed that I was on Uno. That is odd. I am running 1.8.13 though.


ReplyQuote
Voltage
(@voltage)
Estimable Member
Joined: 1 year ago
Posts: 175
Topic starter  
Posted by: @madmisha
Posted by: @voltage

4th switch = Half Current

That might have been your thump. The LCD took more than 0.4 seconds to update and it cut power. I do not really know much about this setting though.

 

Posted by: @voltage

5-8 = 400 Microsteps

I think that is 2 microsteps = 400 steps/rev, assuming I am looking at the right datasheet. You might want to up that a little. Isn't that the lowest setting?

I believe the half/full current mode is just to keep the stepper from getting too hot when it has power applied but is not running. That is the right datasheet. I had the thumping in all of the settings I tried but thought it would be less work to microstep less per step so I set it to 400 assuming that 200 = a full step and 400 would = 1/2 step and so on.

 

 

Thanks,
Voltage


ReplyQuote
Voltage
(@voltage)
Estimable Member
Joined: 1 year ago
Posts: 175
Topic starter  
Posted by: @madmisha
Posted by: @voltage

Weird. When I try to verify this code below now I get an error that "dirfor" was not declared in this scope.

I just verified it on mine and had no problem. I just did a search and all say dirFor although it might have lost case in the debug. I also confirmed that I was on Uno. That is odd. I am running 1.8.13 though.

I am running 18.15 so maybe it was a bug. Still getting this error though.

error

Edit: Adding int before it corrected it. 🙂

Thanks,
Voltage


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 3 years ago
Posts: 346
 

@voltage

Its weird, I just updated the IDE and it caught the typos that I don't thin k I checked but would not let the pot go without declaring it as int. Before the update, it would allow that. I thought you were testing the one with the buttons at first. Updated pot one.

 

 

//Test of accelstepper

#include <AccelStepper.h>

//Define pins
int LEFT_PIN = 11;
int STOP_PIN = 1;
int RIGHT_PIN = 0;
int driverPUL = 2;    // PUL- pin
int driverDIR = 3;    // DIR- pin
int spd = A1;     // Potentiometer
bool go = false;  //Is it running
bool dirFor = true; //Direction to go in

AccelStepper stepper(1,2,3); // This needs to change in any example(Mode, Pul, Dir)

//Interupt Handlers
void formotor (){

  dirFor = true;
  go = true;
  
}

void bacmotor (){

  dirFor = false;
  go = true;
  
}

void stpmotor (){

  stepper.stop();
  go = false;
  
}


void setup()
{  
   pinMode(LEFT_PIN, INPUT_PULLUP);
   pinMode(STOP_PIN, INPUT_PULLUP);
   pinMode(RIGHT_PIN, INPUT_PULLUP);

   attachInterrupt(digitalPinToInterrupt(LEFT_PIN), formotor, FALLING);
   attachInterrupt(digitalPinToInterrupt(RIGHT_PIN), bacmotor, FALLING);
   attachInterrupt(digitalPinToInterrupt(STOP_PIN), stpmotor, FALLING);
   
   stepper.setMaxSpeed(1000);
}

void loop()
{  
  if(go == true){
    int sp_pot = map((analogRead(spd)),0,1023,2000,50);
    if(dirFor == true){
      stepper.setSpeed(sp_pot);
    } else {
      stepper.setSpeed((sp_pot*-1));
    }
    stepper.runSpeed();
  } else {
    stepper.stop();
  }
}

 


ReplyQuote
Voltage
(@voltage)
Estimable Member
Joined: 1 year ago
Posts: 175
Topic starter  
Posted by: @madmisha

@voltage

Its weird, I just updated the IDE and it caught the typos that I don't thin k I checked but would not let the pot go without declaring it as int. Before the update, it would allow that. I thought you were testing the one with the buttons at first. Updated pot one.

 

 

//Test of accelstepper

#include <AccelStepper.h>

//Define pins
int LEFT_PIN = 11;
int STOP_PIN = 1;
int RIGHT_PIN = 0;
int driverPUL = 2;    // PUL- pin
int driverDIR = 3;    // DIR- pin
int spd = A1;     // Potentiometer
bool go = false;  //Is it running
bool dirFor = true; //Direction to go in

AccelStepper stepper(1,2,3); // This needs to change in any example(Mode, Pul, Dir)

//Interupt Handlers
void formotor (){

  dirFor = true;
  go = true;
  
}

void bacmotor (){

  dirFor = false;
  go = true;
  
}

void stpmotor (){

  stepper.stop();
  go = false;
  
}


void setup()
{  
   pinMode(LEFT_PIN, INPUT_PULLUP);
   pinMode(STOP_PIN, INPUT_PULLUP);
   pinMode(RIGHT_PIN, INPUT_PULLUP);

   attachInterrupt(digitalPinToInterrupt(LEFT_PIN), formotor, FALLING);
   attachInterrupt(digitalPinToInterrupt(RIGHT_PIN), bacmotor, FALLING);
   attachInterrupt(digitalPinToInterrupt(STOP_PIN), stpmotor, FALLING);
   
   stepper.setMaxSpeed(1000);
}

void loop()
{  
  if(go == true){
    int sp_pot = map((analogRead(spd)),0,1023,2000,50);
    if(dirFor == true){
      stepper.setSpeed(sp_pot);
    } else {
      stepper.setSpeed((sp_pot*-1));
    }
    stepper.runSpeed();
  } else {
    stepper.stop();
  }
}

 

I just reran the sketch after I fixed it and still no go. I did already change pins 0,1 to 12,13 so I will take the sketch here on this page and edit the 2 pin numbers and give it another go so at least we know what sketch and where we are at. Be right back.

 

Ok, I'm back. Still a no go. I still have the shield plugged in but that shouldn't matter. I have a Left, Stop, and Right button and a potentiometer connected.

 

Thanks,
Voltage


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 3 years ago
Posts: 346
 

@voltage

I set max speed to 1000 because that is what their example used, but:

Posted by: @madmisha

int sp_pot = map((analogRead(spd)),0,1023,2000,50);

Try changing the 2000 to 1000. It might be going over and stopping on an error.


ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2017
 

@voltage

Has anybody noticed yet that you're setting the speed and telling the stepper to run but you've never given it a target position ?

It may be standing still, not out of truculence, but simply because it hasn't been told where to go 🙂

I was kidnapped by mimes.
They did unspeakable things to me.


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 3 years ago
Posts: 346
 

@will

Constant speed example didn't do that. You are pulsing for move and setting the direction. Between those 2 things, it should know where to go.

 

@voltage

I just noticed that you have the buttons connected to ground. The interrupts won't trigger. That is the problem. I was combining Bills sketch and that's where I went wrong. He has his connected with a resistor to 5V and no pin mode because the interrupt is doing that.


ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2017
 
Posted by: @madmisha

@will

Constant speed example didn't do that. You are pulsing for move and setting the direction. Between those 2 things, it should know where to go.

◆ runSpeed()

boolean AccelStepper::runSpeed (   )  

Poll the motor and step it if a step is due, implementing a constant speed as set by the most recent call to setSpeed(). You must call this as frequently as possible, but at least once per step interval,

Returns
true if the motor was stepped.

References _direction, DIRECTION_CW, and step().

Referenced by MultiStepper::run(), run(), and runSpeedToPosition().

 

Note: ... if a step is due ...

I was kidnapped by mimes.
They did unspeakable things to me.


ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2017
 

@voltage

Can you please give us an idea of what speed range (in RPM) you will require ?

I was kidnapped by mimes.
They did unspeakable things to me.


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 3 years ago
Posts: 346
 

@voltage

I might have fixed my stupidity:

 

//Test of accelstepper

#include <AccelStepper.h>

//Define pins
int LEFT_PIN = 11;
int STOP_PIN = 1;
int RIGHT_PIN = 0;
int driverPUL = 2;    // PUL- pin
int driverDIR = 3;    // DIR- pin
int spd = A1;     // Potentiometer
bool go = false;  //Is it running
bool dirFor = true; //Direction to go in

AccelStepper stepper(1,2,3); // This needs to change in any example(Mode, Pul, Dir)

//Interupt Handlers
void formotor (){

  dirFor = true;
  go = true;
  
}

void bacmotor (){

  dirFor = false;
  go = true;
  
}

void stpmotor (){

  stepper.stop();
  go = false;
  
}


void setup()
{  
   pinMode(LEFT_PIN, INPUT_PULLUP);
   pinMode(STOP_PIN, INPUT_PULLUP);
   pinMode(RIGHT_PIN, INPUT_PULLUP);

   attachInterrupt(digitalPinToInterrupt(LEFT_PIN), formotor, CHANGE);
   attachInterrupt(digitalPinToInterrupt(RIGHT_PIN), bacmotor, CHANGE);
   attachInterrupt(digitalPinToInterrupt(STOP_PIN), stpmotor, CHANGE);
   
   stepper.setMaxSpeed(1000);
}

void loop()
{  
  if(go == true){
    int sp_pot = map((analogRead(spd)),0,1023,1000,50);
    if(dirFor == true){
      stepper.setSpeed(sp_pot);
    } else {
      stepper.setSpeed((sp_pot*-1));
    }
    stepper.runSpeed();
  } else {
    stepper.stop();
  }
}

 


ReplyQuote
Page 4 / 21