2-Axis Arduino Automation Program

I currently have a simple 2-axis CNC which I use for controlling a router to flatten wood, running off Openbuilds blackbox and GrblHAL. I would like to simplify the system by removing the need to upload gcode everytime and having it operational without a computer.

So I figure a custom Arduino program would be the way to go?

I would like to have 2 modes of travel, one running down the y-axis first and the other running down the x-axis first.

zigzag_Y-1
zigzag_X

Basically I just want to manually move limit switches to define the mix/max travel of the gantry depending on the size of the piece to flatten.

Then the router would be moved to the starting position by using a joystick, followed by starting the process by pressing either of the two buttons; zigzag along x-axis or zigzag along y axis.

The stepover is adjusted by a potentiometer with a pre-defined range of 1-XXmm, and another pot to adjust the feed rate/speed of the stepper motors (2x 2a Nema 17's) with a 1-100% pre-defined range.

Once the gantry/sled reaches the first limit switch, the adjacent axis would move the stopover amount and the direction of the first motor is reversed zig zagging down the workpiece until the final limit switch is triggered, when the sled should return to its start position where the router can be manually lowered and the operational run again until the wood is completely flat.

I would like to work with someone to achieve this program and happy to pay for their time to code what I need!

a days job with testing, but what's the budget?

If you've been doing this using gcode, the simplest solution may be a second arduino preloaded with those two gcode sequences that are triggered by pushbuttons that then drip feeds the gcode to Openbuilds.

1 Like

That would be perfect, any idea of how I could implement that though?

No budget, can you quote for this?

Used ChatGPT to generate g-code for a 50x75mm rectangle. Did not check.
Here's sample code that should work. Uses software serial to talk to the controller or could use a hardware serial port if you are using an arduino that has additional hardware ports, like a Blackpill.

May need tweaking. If it works out the box, you're welcome. If it doesn't, PM me for a quote to implement.

#include <SoftwareSerial.h>

constexpr int cmds = 13;
char* gcode[cmds] =
{
"G21",
"G90",
"$X_MIN = 0",
"$Y_MIN = 0",
"$X_MAX = 75",
"$Y_MAX = 50",
"G0 X$X_MIN Y$Y_MIN",
"G1 X$X_MAX",
"G1 Y$Y_MAX",
"G1 X$X_MIN",
"G1 Y$Y_MIN",
"G0 X$X_MIN Y$Y_MIN",
"M2 ; End of program"
};

SoftwareSerial mySerial (2, 3);

void setup() 
{
    mySerial.begin(9600);
    // Use pin 4 as trigger
    pinMode(4, INPUT_PULLUP);

}

void loop() 
{
    // Wait for start
    while(digitalRead(4));
    // Send each command with short delay in between
    for (int i = 0; i < cmds; i++)
    {
        mySerial.println(gcode[i]);
        delay(100);
    }

    // Hold in case button still depressed
    while(digitalRead(4) == LOW);
}

This approach is fresh in my mind because I just did something similar to generate text strings to simulate a barcode reader.

[edit]
Fixed a bug.

Don't want to spoil the fun, but to get GRBL behave halfedecent you need to constantly monitor it's state.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.