Notifications
Clear all

Arduino with Stepper and LiquidCrystal Issue

Page 5 / 21

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

@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.

I will try that but I see more new posts so let me get caught up reading... 🙂

 

Thanks,
Voltage


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

@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 🙂

No target means keep spinning I think. No clue, I just started with a set of plans... but I sure am learning a lot. 🙂

 

Thanks,
Voltage


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 2 years ago
Posts: 345
 
Posted by: @will

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,

Hmm. My interpretation of that was that a step was due if the current one ended. So when you send that command, it will step and if you send it again before that step is done, it will wait until that step is done before sending the next one.


ReplyQuote
Voltage
(@voltage)
Estimable Member
Joined: 1 year ago
Posts: 169
Topic starter  
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.

 

@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.

So connect all of the buttons lines with a resistor to 5V? No smoke will come out? 😆 

 

Thanks,
Voltage


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 2 years ago
Posts: 345
 
Posted by: @voltage
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.

 

@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.

So connect all of the buttons lines with a resistor to 5V? No smoke will come out? 😆 

 

No, I set the interrupt on change so it might work if you upload that one. It should be set to how you have yours set.


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

@madmisha

I think it says that because if you're using a very slow speed, run may get called more often than you need to pulse, so it'll ignore that request until the next pulse is due to step at that speed. 

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


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

@voltage

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

Sure. The stepper has a gear ratio of 4.250 : 1 so for one revolution of the output shaft I need 5 rpms of the stepper. I want a range of 0 to 12 or 0 to 15 (I can always adjust it later). But the output has a 10t sprocket and goes to a 30t sprocket so in total it's 7.250 : 1 and that means the stepper needs to spin at 162 rpms for 0-12 or 202.5 for 0-15 at the end.

Thanks,
Voltage


ReplyQuote
MadMisha
(@madmisha)
Reputable Member
Joined: 2 years ago
Posts: 345
 

@voltage

I need to take a break from this. I think I'm starting to confuse myself. Falling edge should have worked too. I suggest before going any further with the Accel Stepper library, try out the example and see if they work without any changes other than

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

That will have to be changed. But if you can't get the basic examples to work then you will be running all over the place chasing random problems.


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

@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();
  }
}

 

Still no go. The only thing I didn't do is move the stop pin but changed it in the code to 12 as that is where I had it last. I will try if the serial outputs make a difference. Let me know.

 

Thanks,
Voltage


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

@voltage

I need to take a break from this. I think I'm starting to confuse myself. Falling edge should have worked too. I suggest before going any further with the Accel Stepper library, try out the example and see if they work without any changes other than

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

That will have to be changed. But if you can't get the basic examples to work then you will be running all over the place chasing random problems.

I thought AccelStepper stepper(1,2,3); is correct for my code as my PUL- and DIR- pins are set as 2 and 3. And 1 is for the 2 wire connection to a driver. Right? I will try some of the examples and see how it goes, more likely tomorrow. Thanks for your time and effort guys.

 

Edit: I see what you mean as the examples all default to a different setting namely:

 // Define a stepper and the pins it will use AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

 

Thanks,
Voltage


ReplyQuote
Mark Bolton
(@mark-bolton)
Estimable Member
Joined: 1 year ago
Posts: 106
 

Guys I am reluctant to buy into this discussion and will not do so beyond sharing some basics.

My first boss / Foreman (swiss)  when I was a raw little techy straight out of Trade School asked me

"so in your training did they instruct you  on the Correct use of Pockets?

No I didn't thinks so...  If you are not sure about what you are doing you put your hands in them......


ReplyQuote
Mark Bolton
(@mark-bolton)
Estimable Member
Joined: 1 year ago
Posts: 106
 

Stepper motors were an ingredient in machines that we has singing and dancing even before the 8080 .. just snap the whip!


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

@voltage

I'm not as smart as @madmisha, so I'm not stopping yet. I decided to try modifying the original version which uses Stepper.h since it seems to be the only version that runs at all.

So, if you feel up to another increasingly desperate version ...

And again please verify or change the pins used for the stepper driver.

  

/*
  Stepper Motor Test Altered/Butchered
  Uses MA860H or similar Stepper Driver Unit
  Has speed control & direction and stop switches
  
  Original: DroneBot Workshop 2019
    https://dronebotworkshop.com  

  Rendered totally unrecognizable by Voltage, MadMisha and Will in
        August, 2021.
*/

#include <Stepper.h>
#include <LiquidCrystal.h>


// Define our three button pins and the stepper driver pins
int LEFT_PIN = 11;
int STOP_PIN = 12;
int RIGHT_PIN = 13;
int driverPUL = 2;      // PUL- pin
int driverDIR = 3;      // DIR- pin

// Variables
LiquidCrystal lcd(8,9,4,5,6,7);
bool go = false;        // Rotating or stopped
int mSpd = 0;           // Motor speed
boolean setdir = LOW;   // Set Direction
int stepsPerRevolution = 400;
int spd = A1;           // Potentiometer
int RPM;                // Speed in RPMs
Stepper myStepper(stepsPerRevolution, driverPUL, driverDIR);

// Interrupt Handlers
//
void formotor (){
  setdir = HIGH;
}
//
void bacmotor (){
  setdir = LOW;
}
//
//  If we were going, stop now. If we were stopped, go now
//
void stpmotor (){
  go = !go;
}

//*****************************************************
void setup() {
  // Set pin modes
  pinMode(LEFT_PIN, INPUT_PULLUP);
  pinMode(STOP_PIN, INPUT_PULLUP);
  pinMode(RIGHT_PIN, INPUT_PULLUP);
  pinMode (driverPUL, OUTPUT);
  pinMode (driverDIR, OUTPUT);
  
  // LCD initialization
  lcd.begin(16, 2);
  lcd.setCursor(1,0);
  lcd.print("Speed:      RPM");
  
  // Interrupt associations
  attachInterrupt(digitalPinToInterrupt(LEFT_PIN), formotor, FALLING);
  attachInterrupt(digitalPinToInterrupt(RIGHT_PIN), bacmotor, FALLING);
  attachInterrupt(digitalPinToInterrupt(STOP_PIN), stpmotor, FALLING);
}

//**************************************************
//
//      Read the speed potentiometer and display the RPM.
//      Ccontinue doing this until the go button is
//      pushed again.
//
void getNewSpeed() {
  while (!go) {
    //
    //   Stepper method setSpeed sets speed in RPM units
    //
    RPM = map((analogRead(spd)),0,1023,0,10);       // Map pot to RPMs
    myStepper.setSpeed(RPM);                        // Set stepper speed
    //
    lcd.setCursor(7,0);
    lcd.print("     "); // Clear area for new speed calculated
    lcd.setCursor(7,0);
    lcd.print(RPM,1);   // Display new speed
    //
    delay(50);     // Wait for LCD to settle
  } 
}

//*****************************************************
void loop() {
  if (go) {
    //
    // We're running, take a single step in the current direction
    //
    myStepper.step( (setdir==HIGH) ? +4 : -4);      // One step in current direction
  } else {
    //
    //  Not running, try getting a new speed from the user
    //
    getNewSpeed();
  }
}

 

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


Voltage liked
ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 1929
 

@voltage

By the way, have any tests been done to verify that all three buttons are working ? If they aren't then we're likely wasting a lot of time (especially the go button).

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


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

@will

They are all working fine as I can recompile with my original and they all work. I did think of it though and pulled the jumpers earlier just to touch the ends together to bypass the switch. 😀 

Thanks,
Voltage


ReplyQuote
Page 5 / 21