Sawmill Setworks

All I am looking to do the same sort of thing except I am looking to do a little simpler setup.

I am looking to only count steps up and down for set heights. I already have a backup encoder which is from US digital, which has 512CPR.

Example:
a button for drops 1inch
b button for drops 1.5
c button for drops 2
d button for drops 2.5
d button is for half up raises .5inch

When advance switch is trigger reset height to 0

the problem I am having now is how to setup the sketch to store each button as a value and stop the relay when x value is hit.

I am very new to coding arduinos so please forgive my dumb questions. my mill already has setworks but it is very very old and I would like to have a backup for whenever it breaks again.

Sorry, having never seen your saw and not knowing what "half up" and "reach button" means, I can't advise.

tylerltr450:
All I am looking to do the same sort of thing except I am looking to do a little simpler setup.

You have asked a new question in an old Thread so I am suggesting to the Moderator to move you to your own Thread.

Post the program that represents your best attempt and tell us in detail what it actually does and what you want it to do that is different. And please use the code button </> when posting code
codeButton.png

...R

Posts split from an old topic

@tylerltr450 - please explain what you are doing and the problems encountered

All I am looking to do the same sort of thing except I am looking to do a little simpler setup.

I am looking to only count steps up and down for set heights. I already have a backup encoder which is from US digital, which has 512CPR.

Example:
a button for 1inch
b button for 1.5
c button for 2
d button for 2.5
d button is for half up move blade .5inch up

When advance switch is trigger reset height to 0

the problem I am having now is how to setup the sketch to store each button as a value and stop the relay when x value is hit.

I am very new to coding arduinos so please forgive my dumb questions. my mill already has setworks but it is very very old and I would like to have a backup for whenever it breaks again.

UKHeliBob:
Posts split from an old topic

@tylerltr450 - please explain what you are doing and the problems encountered

The issue I am having is how to say that if button a is clicked enable relay to turn the encoder 512 CPRs

JCA34F:
Sorry, having never seen your saw and not knowing what "half up" and "reach button" means, I can't advise.

Sorry half up means the saw head rises .5inch to let the blade clear the last cut. and Reach button i meant to say each button.

I am struggling to figure out how to say if x button is clicked move encoder x clicks once x clicks is reached turn off relay.

Currently the mill works like this

If 1 inch is pushed the head will drop 1 1/8 inch. when the advance toggle is triggered the computer will 0 the encodercount, and the saw head moves forward.
Once at the end of the cut I click half up. the saw head rises .5nch and then I pull back the cut board with the return button.

I then click 1 inch button and the head drops .5 plus 11/8 inch. so i can start my next cut.

I would like to keep this simple logic because it gets the job done that I need.

Please note the only thing I am trying to automate is the up and down for the saw head.

I would suggest you study some of the examples in the IDE (File->Examples->02. Digital ->Button and Debounce). This will get you started to figure out how to tell if button a,b,c,d... are pressed.

The second item is the encoder. You don't actually move an encoder - you energize some sort of motor and the encoder provides feedback as to how far the motor/shaft has moved. There is an encoder library with examples about how to read/use an encoder.

Speaking of the motor, how are you driving it? Since this seems like an industrial sort of application, I'm imagining a large motor with high voltage. Or maybe you simply need to provide logic level signals to the motor to make it run?

More details are in order...

blh64:
I would suggest you study some of the examples in the IDE (File->Examples->02. Digital ->Button and Debounce). This will get you started to figure out how to tell if button a,b,c,d... are pressed.

The second item is the encoder. You don't actually move an encoder - you energize some sort of motor and the encoder provides feedback as to how far the motor/shaft has moved. There is an encoder library with examples about how to read/use an encoder.

Speaking of the motor, how are you driving it? Since this seems like an industrial sort of application, I'm imagining a large motor with high voltage. Or maybe you simply need to provide logic level signals to the motor to make it run?

More details are in order...

The mill is currently all hydraulic so all I need to do is fire the relay. I understand how to fire buttons and tell if they are pushed or not.

The encoder is attached to the top shaft which is connected to the motor via a worm gear box. Like i said before this is a very simple setup.

Button pushed makes a relay fire and hold for x encoder counts. Once x count is hit it will stop the delay that that will stop the head from moving.

I am not completely new to Arduino, I just need some help with this since it seems no one has done a sawmill setup with all hydraulic power and relays. Everyone has been using stepper motors and the logic in stepperlibrary.

tylerltr450:
The encoder is attached to the top shaft which is connected to the motor via a worm gear box. Like i said before this is a very simple setup.

It may be simple but that does not mean we are familiar with it in the way that you are. We can't see it, or experiment with it.

Do you have an existing Arduino program that you are trying to modify? If so, please post it.

...R

tylerltr450:
The mill is currently all hydraulic so all I need to do is fire the relay.

The encoder is attached to the top shaft which is connected to the motor via a worm gear box.

Would this be a *hydraulic *motor?

A picture or two of this arrangement would be nice.

Here is the picture of the current board and then the drive motor.

Please note that the shaft runs to the encoder to power the encoder up or down.

This is the up down motor and you can see the back the hydraulic controls for flow.

Here is the encoder with the computer

So it sounds like you detect a button press, turn on a relay and start counting encoder pulses. When you reach the desired number of pulses, you turn off the relay. Depending on which button is pressed, your desired number of pulses varies.

What part of this are you having trouble with? What have you tried? Please post your code.

blh64:
So it sounds like you detect a button press, turn on a relay and start counting encoder pulses. When you reach the desired number of pulses, you turn off the relay. Depending on which button is pressed, your desired number of pulses varies.

What part of this are you having trouble with? What have you tried? Please post your code.

Yes that is what I am looking to do. Let me find the code that I have been playing with.

I guess right now I am having the issue of associating number of pulses of the encoder to desired pulses of the button. While counting the pulses.

I'd use a state machine. Gather the pushbutton closures into one variable and use same as input to a switch/case. Each pushbutton has its own case to control the motor and monitor the encoder. When x case starts, reset encoder counter, energize the proper directional relay, and start counting encoder pulses. When counts reach preset for that state stop motor and return to idle state.

tylerltr450:
I guess right now I am having the issue of associating number of pulses of the encoder to desired pulses of the button. While counting the pulses.

Check out several things at the same time.

dougp:
I'd use a state machine. Gather the pushbutton closures into one variable and use same as input to a switch/case. Each pushbutton has its own case to control the motor and monitor the encoder. When x case starts, reset encoder counter, energize the proper directional relay, and start counting encoder pulses. When counts reach preset for that state stop motor and return to idle state.

Check out several things at the same time.

Thanks for the idea, that might be a better way to control all items.

@tylerltr450, you have now been asked a few times to post your program. Is there some problem doing that?

...R

when writing code, you have to have an idea what you want. if you have it firmly set, then it is easier to do.

in your case, you want to .
lower blade manually to set the first cut.
take the first cut
manually lower blade to take second cut.
take second cut. at this point you may or may not want to start slabbing, or roll the log.
so, there is a lot of manual stuff going on.

assume you have a cant with the desired width and are ready to start slabbling
( a cant is a square log after your took off the rounded bits, ideally one side is cut to the desired width and all you need to do is to take off slabs of the right thickness.)

since you just took off that last manual , you want to take a cut that is X thick.
that means drop the saw head by X plus blade cut thickness.

take a cut,
hit end switch
raise head by x + 1 inch
retract saw to start
lower head by x +1 inch to get back to the last cut
lower head by + plus blade,
take second cut, to end,
raise to 2x plus 1 inch - if you have not removed the boards
raise to 1x plus 1 inch if you had already removed the first board
raise to plus 1 inch if you have an automatic board pusher.

Lets assume that you set the encoder to be 0 at 1 inch over the deck.
all logs will be higher and you work from a high number down.
you still have to know the level of any dogs you set
you still have to set for your blade thickness after a change.

if you take your last manual cut and hit the end stop
LastCut = (whatever the encoder was showing when you hit the end stop)
say your cant is 16 inches
you take off 1.5 inch, hit the end stop
LastCut = 14.5
you lift to 17, retract, remove the last board
hit "2"
the head should drop to 13 as that would be ....
LastCut - button2 ; // button 2 is 1.5 inches

after your cut, hit that end switch
LastCut = 13

now, you still have to tell the Arduino how many counts = 1 inch
and instead of LastCut=13
it might be LastCut = 6656; // 1 inch is 512 encoder counts.

what becomes 'simpler than what the other guy did'
takes a whole lot for granted.
you will always remove the last board.....
you will always know the height of your dogs....

since you cannot plan for every possible need or want, the basics are not hard and you can do it.
as you start cutting, you might naturally want to add features.
my suggestion is that you create a bench setup with a second Arduino.
do all your testing on that one, and then once you think it is working, reprogram the one on the mill.

This is the code I am working with right now.
All this is doing is reading the encoder to give me accurate counts.

enum PinAssignments {
  encoderPinA = 3,   // rigth
  encoderPinB = 2,   // left
};

volatile unsigned int encoderPos = 0;  // a counter for the dial
unsigned int lastReportedPos = 1;   // change management
static boolean rotating=false;      // debounce management

// interrupt service routine vars
boolean A_set = false;              
boolean B_set = false;

void setup() {

  pinMode(encoderPinA, INPUT); 
  pinMode(encoderPinB, INPUT); 
// turn on pullup resistors
  digitalWrite(encoderPinA, HIGH);
  digitalWrite(encoderPinB, HIGH);

// encoder pin on interrupt 0 (pin 2)
  attachInterrupt(0, doEncoderA, CHANGE);
// encoder pin on interrupt 1 (pin 3)
  attachInterrupt(1, doEncoderB, CHANGE);

  Serial.begin(9600);  // output
}

// main loop, work is done by interrupt service routines, this one only prints stuff
void loop() { 
  rotating = true;  // reset the debouncer

  if (lastReportedPos != encoderPos) {
    Serial.print("Index:");
    Serial.println(encoderPos, DEC);
    lastReportedPos = encoderPos;
  }
}

// Interrupt on A changing state
void doEncoderA(){
  // debounce

  // Test transition, did things really change? 
  if( digitalRead(encoderPinA) != A_set ) {  // debounce once more
    A_set = !A_set;

    // adjust counter + if A leads B
    if ( A_set && !B_set ) 
      encoderPos += 1;

    rotating = false;  // no more debouncing until loop() hits again
  }
}

// Interrupt on B changing state, same as A above
void doEncoderB(){
  if( digitalRead(encoderPinB) != B_set ) {
    B_set = !B_set;
    //  adjust counter - 1 if B leads A
    if( B_set && !A_set ) 
      encoderPos -= 1;

    rotating = false;
  }
}

dave-in-nj:
when writing code, you have to have an idea what you want. if you have it firmly set, then it is easier to do.

in your case, you want to .
lower blade manually to set the first cut.
take the first cut
manually lower blade to take second cut.
take second cut. at this point you may or may not want to start slabbing, or roll the log.
so, there is a lot of manual stuff going on.

assume you have a cant with the desired width and are ready to start slabbling
( a cant is a square log after your took off the rounded bits, ideally one side is cut to the desired width and all you need to do is to take off slabs of the right thickness.)

since you just took off that last manual , you want to take a cut that is X thick.
that means drop the saw head by X plus blade cut thickness.

take a cut,
hit end switch
raise head by x + 1 inch
retract saw to start
lower head by x +1 inch to get back to the last cut
lower head by + plus blade,
take second cut, to end,
raise to 2x plus 1 inch - if you have not removed the boards
raise to 1x plus 1 inch if you had already removed the first board
raise to plus 1 inch if you have an automatic board pusher.

Lets assume that you set the encoder to be 0 at 1 inch over the deck.
all logs will be higher and you work from a high number down.
you still have to know the level of any dogs you set
you still have to set for your blade thickness after a change.

if you take your last manual cut and hit the end stop
LastCut = (whatever the encoder was showing when you hit the end stop)
say your cant is 16 inches
you take off 1.5 inch, hit the end stop
LastCut = 14.5
you lift to 17, retract, remove the last board
hit "2"
the head should drop to 13 as that would be ....
LastCut - button2 ; // button 2 is 1.5 inches

after your cut, hit that end switch
LastCut = 13

now, you still have to tell the Arduino how many counts = 1 inch
and instead of LastCut=13
it might be LastCut = 6656; // 1 inch is 512 encoder counts.

what becomes 'simpler than what the other guy did'
takes a whole lot for granted.
you will always remove the last board.....
you will always know the height of your dogs....

since you cannot plan for every possible need or want, the basics are not hard and you can do it.
as you start cutting, you might naturally want to add features.
my suggestion is that you create a bench setup with a second Arduino.
do all your testing on that one, and then once you think it is working, reprogram the one on the mill.

Dave,

You are right in the sense that I will want more, however currently I dont care about bed height.
All I really want to be able to do is raise the head .5 inch to drag the board back. and then lower the head to my next cut based on the button.

Currently I do have a bench setup i am limited at the way I can use it since I wont have a motor connected however my plan is it use the encoder manually to trigger the relays on and off.

dave-in-nj:
when writing code, you have to have an idea what you want. if you have it firmly set, then it is easier to do.

in your case, you want to .
lower blade manually to set the first cut.
take the first cut
manually lower blade to take second cut.
take second cut. at this point you may or may not want to start slabbing, or roll the log.
so, there is a lot of manual stuff going on.

My goal is to do this.
in your case, you want to .
Move blade manually to set the first cut.
take the first cut
Auto up .5inch to drag board back.
Auto lower blade to take second cut.
take second cut.

at any point I may or may not want to start slabbing, or roll the log.
That is why when the head moves forward it will reset the count to 0.

Based on the current setup on the mill one tick of the encoder is .012 (twelve thousands of an inch)

tylerltr450:
All I really want to be able to do is raise the head .5 inch to drag the board back. and then lower the head to my next cut based on the button.

The program you posted in Reply #16 is a long way short of that requirement.

I have been under the impression (perhaps mistakenly) that you have a program that does move the head but not in the way you want? Or perhaps it controls other elements but not the head?

...R

Robin2:
The program you posted in Reply #16 is a long way short of that requirement.

I have been under the impression (perhaps mistakenly) that you have a program that does move the head but not in the way you want? Or perhaps it controls other elements but not the head?

…R

Robin,

I understand the code that isnt what I want to do it is just an example I have.

What I am trying to do is break this into parts.

Step 1. Build code that accurately reads my encoder count. I know encoder is 512CPR and that code does that
Step 2. build code that reads a button count and and encoder count and turn off relay when that count is hit.
Step 3. Start applying this logic to a complete code set.

I know the flow and breakdown I want, the issue i am struggling to wrap my head around is how to say

x button count is 512 → turn on relay until encoder count = xbutton.

I am wondering if it would be better to create a library for encoder count.

i understand I am not senior level at arduino, however I am looking to learn and research and not just expect folks to do the leg work for me.