Calling up gcode with button push

Hello,

This is a follow up to my original post:

I want to use the Grbl library to read gcode but I want to make my machine portable and able to run a few movements without being serially attached to a computer. I would like to have a button push activate a movement and when it is not pushed go back to it’s original position.

Not sure if this is possible but here is my code:

#include <grbl.h> // load the grbl library.

const int buttonPin = 13; // the number of the pushbutton pin

int buttonState = 0; // variable for reading the pushbutton status

void setup() {

// initialize the pushbutton pin as an input:

pinMode(buttonPin, INPUT);

}

void loop(){

// read the state of the pushbutton value:

buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.

if (buttonState == HIGH) {

// run this g code

g00x100;
}

else {

// run this g code
g00x0;
}
}

I thought maybe I might have to use a workaround the serial port somehow maybe? Like write and read to the serial port somehow (like Serial.write(“g00 x100”) and Serial.read)

Any help or direction is greatly appreciated :slight_smile:

Does that work ?

I did not know GRBL is a library. I thought it is a complete program ?

...R

It is referred to as a library here and there around the internet but maybe you are right. I am looking at the source code for it now.

There is a version (protoneer?) which is configured as a standard Arduino library so
you can compile and load it from the Arduino IDE and not flap about building as an AVR binary.

MarkT:
which is configured as a standard Arduino library so you can compile and load it from the Arduino IDE

Do you know if it actually is a library in the sense that it can be called from the OPs Arduino program in the same way that (for example) the Servo library can be called ?

...R

No, not at all, its just so you can install GRBL easily. Have a play with it, its just
an Arduino sketch + library

MarkT:
No, not at all, its just so you can install GRBL easily.

That's what I thought. But if you look at the Original Post the OP is trying to / hoping to use it as an adjunct to his own program.

@Tronimus, you can't use it the way you are thinking. GRBL needs to get its GCode from somewhere - such as a PC or an SD Card. That means your Arduino cannot make it up on the fly. I guess your PC could - assuming GRBL can work with GCode sent via Serial.

...R

What's the problem (in theory) with hacking the GRBL code to do this? It may already have
some mechanism(s) that help inject GCODE scripts/canned sequences? Its been a while
since I played with it so can't remember.

MarkT:
What's the problem (in theory) with hacking the GRBL code to do this?

I'm sure that could be done - but probably not by an inexperienced Arduino user. Frankly I suspect it would be easier to write your own stepper code.

...R

Thank you so much MarkT and Robin2 for your replies! I will be trying what you mentioned MarkT and hack the Grbl sketch and use one of its mechanisms to feed it code. If I am successful...no...when I am successful I will post the changes I made to the sketch for anyone interested.