Homemade bandsaw sawmill arduino controlled lift

I just can't wrap my head around this though. If it starts at 2000 and decreases by anything it is still larger than the bottom value (fastest) of 500 I think is what we have it set at.

I’m just confused… as usual.

@cattledog

No I am assuming it will not work at 12v. I have net tried it with my a4988 driver. I’m not sure that I even have a good one left…. :blush:

The point is that after a mere fifteen steps, it's being asked to run at full speed, it would apparently prefer to get up to that pace a little more gently.

I assume that if you try the 870 code and start off with a 500mIcrosecond delay, it fails?

I think I understand now…I’m just slow.
I’m not sure that I need to get to that speed (500) any way. But I did want to understand it.

@cattledog suggested some kind of spring scale, but not sure that I have one.

How will you know when you catch that record Bass?

One additional suggestion on measuring the lever torque is to remove the throttle lever and get an automotive torque wrench on the shaft.

I would think that it is stiff because it is designed not to move with the engine vibrations.

My fishing skills are about as good as my programming…. No chance of any records! Lol

So I have played with the speed and have it all the way down to starting at 500micro seconds between the pulses… it is working fine. I really don’t know what was going on yesterday.

A couple of notes though. The stepper is getting “burn you” hot! If I leave the arduino connected after it runs the code in setup it remains hot. Why?

I’m not sure if it is getting hot with the arduino not connected and the power supply connected or not. I am going to check and see.
Once the setup runs shouldn’t there be nothing going on to the motor driver for it to be signaling to the stepper?

Also, it is apparently micro stepping because 200 revs is supposed to be one revolution, but it is not. Somewhere slightly above 400 is one revolution. Not sure why.

It is micro stepping - that driver insists. Should be 400 steps, so if it's more, perhaps it's taking a few failed attempts to get moving.

As I mentioned above, steppers do get pretty hot. It may not matter. However, if you really do have the current limit set to 4.9A, I would be worried about whether that stepper can stand it for long.

The coil windings of the stepper take the same current when holding as when stepping. Your throttle lever should require very low torque(if any) to hold position when not turning, and you should be able turn off the power to the stepper completely.

There are ways of reducing the current from a running level to a lower holding value, but you probably don't need this.

Have you tried running at the 1.4 amp setting instead of the 2.1?

Ah duh. That’s what I have it set to.
I will turn it town to a lower amperage.

Can I do this in code?

Thanks

Well that was annoying - clone of a Leadshine driver, including designation, but the dip settings are different. If you trust what's printed on the case.

You can use the enable pins to cut power I think.

good point... I guess I could check the current with a volt meter?
Enable Pins makes sense....except I don't have any more pins.... Going to have to bite the mega bullet sooner than later.

So if the dm556 has power connected to it and nothing is done to the enable pins, it sends current to the stepper?

Yes. To make it easier for you, the default is to have the stepper enabled. The enable pins might be better named "disable". In the one project I did that used such a driver, we didn't bother connecting them.

But, if I leave it so its enabled all the time, I am draining my battery all the time to right? Maybe, I should look in to doing what @cattledog suggested:

Not sure what @cattledog has in mind, but I expect it too will need a pin. I think it's bullet biting time.

I am trying to figure out how to add a button press to rev up/ rev down the motor or turn the stepper x number of steps.
As suggested earlier, the status of where the stepper is needs to be "remembered" with eeprom. I am trying to figure this out. I came up with something using the code we already have, but I have no idea if it is right or even close....

#include <EEPROM.h>

const int dirPin = 2;  // Direction
const int stepPin = 3; // Step
int delayPeriod = 2000;
const int button = 4;

// Motor steps per rotation
const int STEPS_PER_REV = 200;

volatile boolean RevUp = false; 
volatile boolean RevDown = false;

void setup()
{
  // Setup the pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(button, OUTPUT);

  checkRevState();
}

void loop()
{
  if (button == LOW){
    rev();
  }
}

void rev()
{
  if(RevUp == false){
    
    digitalWrite(dirPin, LOW);
    
for (int i = 0; i <= 200; i++) //2400 steps is 12 revolutions
    {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(delayPeriod);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(delayPeriod);
    if (delayPeriod > 500)
       {
      delayPeriod -= 20;
       }
    RevUp = true;
    RevDown = false;
    EEPROM.update(0, RevUp);
    EEPROM.update(1, RevDown); 
    }
  }
   else{
    revDown();
   }
}

void revDown()
{
  if(RevDown == false){
    digitalWrite(dirPin, HIGH);
    
for (int i = 0; i <= 200; i++) //2400 steps is 12 revolutions
    {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(delayPeriod);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(delayPeriod);
    if (delayPeriod > 500)
       {
      delayPeriod -= 20;
       }
    RevUp = false;
    RevDown = true; 
    }
  }
}

void checkRevState()
{
  EEPROM.read(0, RevUp);
  EEPROM.read(1, RevDown); 
}

Thanks!

Edit: I know it won't work it won't even compile...

Pay closer attention to the EEPROM library examples to see the syntax correct for EEPROM.read().

void checkRevState()
{
  //EEPROM.read(0, RevUp);
  //EEPROM.read(1, RevDown);
  RevUp = EEPROM.read(0);
  RevDown = EEPROM.read(1);
}

You also need to add the EEPROM.update() to the revDown() function.

#include <EEPROM.h>

const int dirPin = 2;  // Direction
const int stepPin = 3; // Step
int delayPeriod = 2000;
const int button = 4;

// Motor steps per rotation
const int STEPS_PER_REV = 200;

volatile boolean RevUp = false;
volatile boolean RevDown = false;

void setup()
{
  // Setup the pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(button, OUTPUT);

  checkRevState();
}

void loop()
{
  if (button == LOW) {
    rev();
  }
}

void rev()
{
  if (RevUp == false) {

    digitalWrite(dirPin, LOW);

    for (int i = 0; i <= 200; i++) //2400 steps is 12 revolutions
    {
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(delayPeriod);
      digitalWrite(stepPin, LOW);
      delayMicroseconds(delayPeriod);
      if (delayPeriod > 500)
      {
        delayPeriod -= 20;
      }
      RevUp = true;
      RevDown = false;
      EEPROM.update(0, RevUp);
      EEPROM.update(1, RevDown);
    }
  }
  else {
    revDown();
  }
}

void revDown()
{
  if (RevDown == false) {
    digitalWrite(dirPin, HIGH);

    for (int i = 0; i <= 200; i++) //2400 steps is 12 revolutions
    {
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(delayPeriod);
      digitalWrite(stepPin, LOW);
      delayMicroseconds(delayPeriod);
      if (delayPeriod > 500)
      {
        delayPeriod -= 20;
      }
      RevUp = false;
      RevDown = true;
      EEPROM.update(0, RevUp); //add update
      EEPROM.update(1, RevDown);//add update 
    }
  }
}

void checkRevState()
{
  //EEPROM.read(0, RevUp);
  //EEPROM.read(1, RevDown);
  RevUp = EEPROM.read(0);
  RevDown = EEPROM.read(1);
}

Awesome. Thanks!
So using the drv8825 or a4988, in order to put in sleep mode, i should have it set low until I am ready to move the motor. And then set it high in the rev functions when I am ready to move? Should I put any delay in it to give it time to get out of sleep mode before trying to start stepping?

Just noticed this error.

void loop()
{
 // if (button == LOW) {
    if(digitalRead(button) == LOW){
    rev();
  }
}

Should I put any delay in it to give it time to get out of sleep mode before trying to start stepping?

No idea if its needed. A small delay() certainly can't hurt.

I couldn’t get the code to work. I looked back at it and think I figured out that it had something to do with my eeprom. I am calling for the function that is supposed to get what state the Booleans are in as soon as the arduino comes on. Well, it was never letting it actually receive a true or false state because the eeprom had never received it. I didn’t and still don’t know how you’re supposed to fix it, but I set the boolean false in the rev() and uploaded it. It worked. Then I removed that (setting the Boolean false) from the code and reuploaded. And it remembered its state and seemed to work as it should (I only had a short time. I will have to go back and check).
I know there is a better way to do that, but I’m not sure how.

I was able to get the stepper/worm gear mounted with clamps to the mill. It did work after several modifications and changing of code values. For some reason when I start the code at a higher delay period value and decrement it by a value, it doesn't sound near as smooth nor work as good. I have them commented out in the code I am posting. This code did work, but will need adjustment on the number of steps needed to turn the throttle (i had some slack in the lever mechanism that I need to address). I also have the functions reversed of what actually happened revDown is actually revving up the motor.

When I tested this, I did it with a seperate uno from what is connected to the sawmill now. the stepper worked perfectly while the engine was off. However, when cranking the engine it did not work right. it would work as soon as the arduino was powered up one time and then would not work again unless I reset the arduino. The arduino was right next to the running enging along with all my connections and the drv 8825 board that I was using to control the stepper. I am assuming it was noise that was causing this issue? Maybe when I patch this code into the arduino that is mounted in a box farther from the engine it will help?

Also, I am going to have to run long wires to control this from my "control station" which wires will be "better" being long? the 4 wires going to the stepper? How long do you thing they can be? 5 feet?

Here is the code I used:

#include <EEPROM.h>

const int dirPin = 2;  // Direction
const int stepPin = 3; // Step
int delayPeriod;
const int button = A5;
const int enable = 4;

// Motor steps per rotation
const int STEPS_PER_REV = 400;

volatile boolean RevUp = false;
volatile boolean RevDown = false;

 

void setup()
{
  Serial.begin(9600);
  // Setup the pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(button, INPUT_PULLUP);
  pinMode(enable, OUTPUT);
  

  checkRevState();
  //digitalWrite(enable, HIGH);//for dm556
  digitalWrite(enable, LOW); // for A4988 

}

void loop()
{ 
  delayPeriod = 1000;
  if(digitalRead(button) == LOW){
    rev();
  }
 // digitalWrite(enable,HIGH);//for dm556
 digitalWrite(enable, LOW); // for A4988 or drv 8825
}

void rev()
{
  
  if (RevUp == false) {
    Serial.println("Rev up");
    digitalWrite(enable, HIGH); //USE THIS FOR a4988 or drv8825 and comment out the line below
    //  digitalWrite(enable, LOW); // USE this for dm556
    delay(100);
    digitalWrite(dirPin, LOW);

    for (int i = 0; i <= 3000; i++) //2400 steps is 12 revolutions
    {
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(delayPeriod);
      digitalWrite(stepPin, LOW);
      delayMicroseconds(delayPeriod);
      //if (delayPeriod > 800)
      //{
      //  delayPeriod -= 250;
      //}
      RevUp = true;
      RevDown = false;
      
      EEPROM.update(0, RevUp);
      EEPROM.update(1, RevDown);
    }
  }
  else {
    revDown();
  }
}

void revDown()
{
  if (RevDown == false) {
    Serial.println("Rev down");
     digitalWrite(enable, HIGH); // USE THIS FOR a4988 or drv8825 and comment out the line below
    //  digitalWrite(enable, LOW); // USE this for dm556
    delay(100);
    digitalWrite(dirPin, HIGH);
    
    for (int i = 0; i <= 3000; i++) //2400 steps is 12 revolutions
    {
      digitalWrite(stepPin, HIGH);
      delayMicroseconds(delayPeriod);
      digitalWrite(stepPin, LOW);
      delayMicroseconds(delayPeriod);
      //if (delayPeriod > 800)
      //{
      //  delayPeriod -= 20;
      //}
      RevUp = false;
      RevDown = true;
      EEPROM.update(0, RevUp); //add update
      EEPROM.update(1, RevDown);//add update 
    }
  }
}

void checkRevState()
{
  //EEPROM.read(0, RevUp);
  //EEPROM.read(1, RevDown);
  RevUp = EEPROM.read(0);
  RevDown = EEPROM.read(1);
}