Notifications
Clear all

Mitersaw fence

17 Posts
6 Users
0 Reactions
2,643 Views
(@haakon-th)
Member
Joined: 2 years ago
Posts: 4
Topic starter  

Hello DroneBot Workshop Forums

My name is Haakon Th. I am a retired carpenter and woodturner from Norway. I have worked with wood my entire professional career. Woodworking has always been my hobby as well. Now I am retired and spend a lot of time in my workshop. A couple of years ago I discovered Arduino on You Tube. This looked very exciting. A beginner's kit was acquired. Old PCs and copiers are dismantled and usable parts taken care of. DroneBot workshop and other sites have taught me a lot about electronics. The knowledge that Bill and other like-minded people give us on the web, is simply amazing. I have mostly worked with Arduino Uno, Arduino Mega and ESP32. Very interesting and fun.
I have built a measuring device (fence?) for my miter saw in my workshop. It works, but the constructor is not completely satisfied. The device is built around an Arduino Mega and TMC2208 stepper driver. Otherwise with 4x4 keypad and a Nokia 5110 LCD display. The code is borrowed from Brainy-Bits Electronic Miter box.

What I would like to improve:

1 Automatic homing at startup.
2 Backlash compensation

The accuracy must be whole millimeters, not tenths.
Reach 999 mm.
I plan to use a proximate sensor as a homing switch.
Backlaschproblem: When the next value is smaller than the previous one, the new position is slightly incorrect. The stepper motor runs a little too short.
Otherwise, I have inserted a correction factor in the code (1.00375). This works very well. I have also inserted a sleep function at the end of the loop to prevent the stepper motor from getting too hot.

IDE coding is not my area of ​​expertise. Is there anyone in the DroneBot Workshop Forums who can help me further.

Greetings Haakon Th.

IMG 2823
/* Arduino Control Stepper with Keypad and LCD

Created by Yvan /  https://Brainy-Bits.com 
This code is in the public domain...
You can: copy it, use it, modify it, share it or just plain ignore it!
Thx!
Modifisert av Haakon Th mars2023.
*/
#include "AccelStepper.h" // AccelStepper Library
#include <Keypad.h>  // Keypad Library
#include "U8glib.h"  // U8glib for Nokia LCD   
#define SLEEP      12


// Variables to hold entered number on Keypad
volatile int firstnumber=99;  // used to tell how many numbers were entered on keypad
volatile int secondnumber=99;
volatile int thirdnumber=99;

// Variables to hold Distance and CurrentPosition
unsigned long keyfullnumber=0;  // used to store the final calculated distance value
String currentposition = "";  // Used for display on Nokia LCD
float steppcm = ((24));

// Keypad Setup
const byte ROWS = 4; // Four Rows
const byte COLS = 4; // Four Columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {22, 24, 26, 28}; // Arduino pins connected to the row pins of the keypad
byte colPins[COLS] = {31, 33, 35, 37}; // Arduino pins connected to the column pins of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );  // Keypad Library definition


// U8glib Setup for Nokia LCD
#define backlight_pin 11
U8GLIB_PCD8544 u8g(3, 4, 6, 5, 7);  // Arduino pins connected to Nokia pins:
                                    // CLK=3, DIN=4, CE=6, DC=5, RST=7
                                    
                                    
// AccelStepper Setup
AccelStepper stepper(1, A0, A1);  // 1 = Easy Driver interface
                                  // Arduino A0 connected to STEP pin of Easy Driver
                                  // Arduino A1 connected to DIR pin of Easy Driver
                                  


void setup(void) {
  
  //  Light up the LCD backlight LEDS
  analogWrite(backlight_pin, 80);  // Set the Backlight intensity (0=Bright, 255=Dim)
    
  //  AccelStepper speed and acceleration setup
  stepper.setMaxSpeed(1000);  // Not to fast or you will have missed steps
  stepper.setAcceleration(200);  //  Same here
  
  // Draw starting screen on Nokia LCD
  u8g.firstPage();
  do {
  u8g.drawHLine(0, 15, 84);
  u8g.drawVLine(50, 16, 38);
  u8g.drawHLine(0, 35, 84); 
  u8g.setFont(u8g_font_profont11);
  u8g.drawStr(0, 10, "ENTER DISTANCE");
  u8g.drawStr(62, 29, "MM");
  u8g.drawStr(4, 46, "cur-pos");
  }
  while( u8g.nextPage() );
   pinMode(SLEEP,OUTPUT);
}


void loop(){
  
  char keypressed = keypad.getKey();  // Get value of keypad button if pressed
  if (keypressed != NO_KEY){  // If keypad button pressed check which key it was
    switch (keypressed) {
      
      case '1':
        checknumber(1);
      break;
        
      case '2':
        checknumber(2);
      break;

      case '3':
        checknumber(3);
      break;

      case '4':
        checknumber(4);
      break;

      case '5':
        checknumber(5);
      break;

      case '6':
        checknumber(6);
      break;

      case '7':
        checknumber(7);
      break;

      case '8':
        checknumber(8);
      break;

      case '9':
        checknumber(9);
      break;

      case '0':
        checknumber(0);
      break;

      case '*':
        deletenumber();
      break;

      case '#':
        calculatedistance();
      break;
    }
  }

}

void checknumber(int x){
  if (firstnumber == 99) { // Check if this is the first number entered
    firstnumber=x;
    String displayvalue = String(firstnumber);  //  Transform int to a string for display
    drawnokiascreen(displayvalue); // Redraw Nokia lcd
    
  } else {
    if (secondnumber == 99) {  // Check if it's the second number entered
      secondnumber=x;
      String displayvalue = (String(firstnumber) + String(secondnumber));
      drawnokiascreen(displayvalue);

    } else {  // It must be the 3rd number entered
      thirdnumber=x;
      String displayvalue = (String(firstnumber) + String(secondnumber) + String(thirdnumber));
      drawnokiascreen(displayvalue);

    }
  }
}

 
void deletenumber() {  // Used to backspace entered numbers
  if (thirdnumber !=99) {
      String displayvalue = (String(firstnumber) + String(secondnumber));
      drawnokiascreen(displayvalue);

    thirdnumber=99;
  } 
  else {
    if (secondnumber !=99) {
      String displayvalue = String(firstnumber);
      drawnokiascreen(displayvalue);

      secondnumber=99;
   } 
   else {
     if (firstnumber !=99) {
       String displayvalue = "";
       drawnokiascreen(displayvalue);

       firstnumber=99;
      }
    }
  }
}
  
void calculatedistance() {  // Used to create a full number from entered numbers

    if (thirdnumber == 99 && secondnumber == 99 && firstnumber != 99) {
      keyfullnumber=firstnumber;
      movestepper(keyfullnumber);
    }
    
    if (secondnumber != 99 && thirdnumber == 99) {
      keyfullnumber=(firstnumber*10)+secondnumber;
      movestepper(keyfullnumber);
    }
    
    if (thirdnumber != 99) {
      keyfullnumber=(firstnumber*100)+(secondnumber*10)+thirdnumber;
      movestepper(keyfullnumber);
    }
    
    resetnumbers(); // Reset numbers to get ready for new entry
  } 


void movestepper(int z) {  //  Move the stepper
  digitalWrite(SLEEP,LOW); //Haakon Th

  unsigned long calculatedmove=((float)z * steppcm *1.00375);  //  (1.00375 HaakonTh)Calculate number of steps needed in mm
  stepper.runToNewPosition(calculatedmove);
  digitalWrite(SLEEP,HIGH);  //Haakon Th
  currentposition = String(z);
  u8g.firstPage();
  do {
    u8g.drawHLine(0, 15, 84);
    u8g.drawVLine(50, 16, 38);
    u8g.drawHLine(0, 35, 84); 
    u8g.setFont(u8g_font_profont11);
    u8g.drawStr(0, 10, "ENTER DISTANCE");
    u8g.drawStr(62, 29, "MM");
    u8g.drawStr(4, 46, "cur-pos");
    u8g.setPrintPos(57,47);
    u8g.print(currentposition);       
  }
  while( u8g.nextPage() ); 
}
                
void resetnumbers() {  // Reset numbers for next entry
  firstnumber=99;
  secondnumber=99;
  thirdnumber=99;
} 

void drawnokiascreen(String y) {

    u8g.firstPage();
    do {
      u8g.drawHLine(0, 15, 84);
      u8g.drawVLine(50, 16, 38);
      u8g.drawHLine(0, 35, 84); 
      u8g.setFont(u8g_font_profont11);
      u8g.drawStr(0, 10, "ENTER DISTANCE");
      u8g.setPrintPos(0,29);
      u8g.print(y);  // Put entered number on Nokia lcd    
      u8g.drawStr(62, 29, "MM");
      u8g.drawStr(4, 46, "cur-pos");
      u8g.setPrintPos(57,47); 
      u8g.print(currentposition);  //  Display current position of stepper
    }
      while( u8g.nextPage() );

}

This topic was modified 2 years ago by Haakon Th

   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 5 years ago
Posts: 8047
 

@haakon-th If you could post your project/problem in the appropriate forum/sub forum it would be appreciated as this forum is to introduce yourself.

I used to have a wood shop so have some idea what you might be doing.

Perhaps start with the problem you are trying to solve, then tell us the design to solve it and finally where it isn't meeting your needs.

I am looking forward to seeing what you are up to.


First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 4 years ago
Posts: 2606
 

Posted by: @haakon-th

What I would like to improve:

1 Automatic homing at startup.
2 Backlash compensation

Hi haakon-th, welcome to the forum.

To do your automatic homing, you'll need a limit switch or some other kind of sensor to tell you when to stop. Here is a sample of the logic to do that.

It sets a target location as -100,000 steps and then enters while loop. The loop moves backwards as long as there are still steps to go (from the 100,000) AND the limit switch is not triggered. As long as both of these conditions are true, the while loop takes a step backwards. When the switch is triggered, the while loop exits. The current position is set to -10 and the stepper is moved to new position zero.

The reason for setting the origin a bit off from the switch is that it makes sure that the switch isn't triggered every time the platform rolls back to it. This reduces wear and tear on both parts of the device.

//
//	Home the given stepper. Find the limit switch and step back from there
//	Origin is set as 10 steps before limit switch to give clearance
//	atLimit()  is false if limit switch open or true if limit switch triggered
//
void homeStepper( AccelStepper &stepper) {
	stepper.moveTo(-100000);
	while (stepper.distanceToGo()!=0 && !atLimit())
		stepper.run();
	//
	//		Found limit, now move across to origin
	//
	stepper.setCurrentPosition(-10);
	stepper.runToNewPosition(0);
}

 It's difficult to address the backlash problem since you have given us no information about the mechanism used to move whatever it is you're moving.

Your code (or Yvan's code) is pretty good, he wrote simple but effective sketches. There are some points to make however.

1) you are using almost identical code to draw onto the Nokia screen in 3 different places, despite the fact that you have a subroutine called drawnokiascreen to do that. You should just call the subroutine from the other two locations. In the setup() call, just pass "" as the string to draw

2) the drawnokiascreen screen has a parameter that seems never to be used ? You should change the subroutine code to draw the string passed and send the appropriate value from the places where you call it.

 

 


Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@davee)
Member
Joined: 5 years ago
Posts: 2006
 

Hi @haakon-th,

  Welcome to forum .. I hope you find it friendly and helpful.

   I would agree with Ron @zander's, advice to post your technical part of the query in a separate post, in an appropriate section of the forum, as this section is meant for newcomers introducing themselves.

---------

However, in the hope of making your revised post more helpful, I would like to offer a comment for you to consider.

I confess to not having read the Arduino code, but notice you indicate the problem is one of backlash. Simplistically, I normally think of backlash as being mechanical 'space' or 'looseness', which usually shows up when the direction of motion of something is reversed.

For example, when a nut or a gear can be rotated a certain amount in the new (reverse) direction, before it appears to have any effect, other than to take up the slack in the mechanics of the system.

Does your query have its origin in the mechanics? Are you trying to use the Arduino code to compensate for such slack, which in practice, most mechanical systems have to a greater or lesser extent?

Of course, I may be completely misunderstanding your question, but please try to understand, when presenting with a piece of program code or similar, it is important to ensure the viewer, who does not know your project or see your bench, knows what you would like it to do, as well as what it actually does.

And it is usually helpful to provide exact web references when they are relevant. I guess you are starting with:

https://www.brainy-bits.com/post/electronic-miter-box-control-a-stepper-motor-with-a-keypad-and-an-arduino

Is that correct? If so, is your project identical, or does it differ?

-------------

I hope these hints are helpful. I appreciate it is difficult for you to start asking for help in a new place.

Best wishes for your project, Dave



   
ReplyQuote
(@haakon-th)
Member
Joined: 2 years ago
Posts: 4
Topic starter  

Hi Dave!

Thank you very much for the quick reply.

The link you mention is correct. My project is almost identical.Stepper motor and belt.
Is it  something I can do to correct the mistake that has been made? Should I move my question to the workshop forum?
Haakon Th



   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 5 years ago
Posts: 8047
 

@haakon-th Any design using a belt will have some slack; change it to a screw rod for a tighter fit. I am 99.99999% sure all the commercial motorized fences use that. It might even be wise to provide a vernier-type fine adjuster. mount a (sorry for the ASA, I don't know the metric equivalents) 8-32 screw in a rig that bears against the fence, so one turn moves 1/32, a quarter turn is 1/128 which is way beyond woodworking tolerances. I believe the Delta cabinet table saw uses that mechanism.


First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@haakon-th)
Member
Joined: 2 years ago
Posts: 4
Topic starter  

Hi Will!
Thank you very much for the quick reply.
Looking forward to trying the code you sent me. The mechanism is a stepper motor and belt. The backlash error is the same all the time. If I add or subtract 24 steps when the direction of travel changes, the result will be correct
Haakon Th



   
ReplyQuote
(@haakon-th)
Member
Joined: 2 years ago
Posts: 4
Topic starter  

Hi Ron!
Thank you very much for the quick reply.
I'm sorry I made a mistake in the beginning.
Haakon Th



   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 4 years ago
Posts: 2606
 

@haakon-th 

As Ron (@zander) has said, there'll always be some play in a belt; furthermore, it'll probably get worse as the belt ages and gets stretched from being pulled back and forth.

Using a screw to perform the move can reduce the backlash considerably. I have successfully used a T8 (8mm Acme threaded rod) with an anti backlash nut such as (remove quotes and change ".ca" to your country's code)

"https://www.amazon.ca/gp/product/B074JYFW6B/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1"

I'd recommend against the single part brass nuts that usually come with these rods, I find them very sloppy and not good for precise work. The addition of the second threaded section and spring to keep both threaded sections in compression is very good for reducing backlash.

You'd need to rotate the stepper 90 degrees and buy an adapter to connect the stepper shaft to the 8mm threaded rod.


Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 5 years ago
Posts: 8047
 

@haakon-th It happens all the time, I should just have a standard response to copy/paste.

Another common new user mistake is not clicking the Reply link at the bottom right. That way a @xxxxx tag gets inserted automatically into your replay and I get an email telling me IF I am subscribed.

Don't be confused by the fact I live in Canada but don't really know metric, I am an old-timer and a lot of stuff here is still Imperial. I can handle temperature, speed, less so length, no knowledge of weights or volumes although I know a Litre and Quart are close.

Check out my other replies to you.

You said

I have built a measuring device (fence?) for my miter saw 

In my country, the fence on a Mitre saw is at 90 degrees to the saw blade unless it is rotated to do say a 45-degree cut. The fence on that saw does not move. A tablesaw however does have a fence that moves to allow ripping wood to a specific width. Can you show a picture of the saw?

 

 

 


First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@hilldweller)
Member
Joined: 3 years ago
Posts: 111
 

Anti backlash is easy.

 

Speed( fast );

Stepto( target + 10 );

Speed( slow );

Stepto( target );

 

 



   
ReplyQuote
(@davee)
Member
Joined: 5 years ago
Posts: 2006
 

Hi @haakon-th,

  The list of forums is at https://forum.dronebotworkshop.com/

Have a look down the list and start a new thread in the one you think is most appropriate. At a quick glance, you might choose between Project Corner and High Tech Hobbies. Recommend you copy over the details which are still part of the main discussion and build in any new items.

--------------

As a side comment, my only vaguely comparable experience is with a small commercial 3D printer, with the x belt moving the print head over about 25 cm maximum (and the bed similarly in the y direction), typically over a 15 cm range during a print, as few objects completely span the bed, which is only a quarter or less, of your 1 metre span. However, to make a reasonable print, this involves continual back & forth motions with a repeatability to hit the 'same spot' to 1/10 of a mm, and I suspect it usually much better than 1/10 of a mm.

So, whilst there may be software tricks to compensate for backlash effects, maybe the first place is to try to identify the true cause of the problem. Is the machine structure stiff enough, belt tension correct and so on?

Also note, the 3D printers, and I think your machine, do not step at a constant rate, but rather accelerate and decelerate. I notice your code has an acceleration parameter, but I don't know if the value to appropriate. Have you tried slowing the acceleration and step speed, to see if it reduces the backlash effect?

Also note, the 3D printers often use simple microswitches to determine a 'homing position', at power on, but after that they rely on absolute counting of steps. For X and Y, the small uncertainity in the microswitch operating position is of no importance. In the Z direction, they are moving to higher resolution, aiming towards 1/100th mm. It maybe worth trying a microswitch first, as it might meet your requirements.  

Good luck, Dave



   
ReplyQuote
(@hilldweller)
Member
Joined: 3 years ago
Posts: 111
 

Posted by: @zander

@haakon-th Any design using a belt will have some slack; change it to a screw rod for a tighter fit. I am 99.99999% sure all the commercial motorized fences use that.

 

Not so Ron.

Lead screws and ball screws have problems, expensive and above a certain length suffer whiplash.

Top commercial stops use rack and pinion - rock solid but with a bit of backlash. Easily corrected.

Cheap to good use timing belt. It's reliable but of course it is a spring so can give a different length depending on length+load.

 



   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 4 years ago
Posts: 2606
 

Posted by: @hilldweller

Lead screws and ball screws have problems, expensive and above a certain length suffer whiplash.

Really ? I've never had a T8 with whiplash !

 


Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 5 years ago
Posts: 8047
 

@hilldweller That's not my experience


First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Page 1 / 2