Grbl syntax

Hi, I’ve made great strides lately thanks to mcdanlj and someone off site.
I’m now confident editing files such as Machine.h in the Grbl build, but is there a source of the correct terminology and syntax to use?
For instance I would like to be able to define a spindle (yes I know examples are out there but this was an existing example).
I’d also like to be able to define a ganged motor so I can have 2 Y axis.
Can someone point me in the right direction please?
many thanks.

It’s hard to know what terminology and syntax you might have trouble with.

I just want to make sure you are starting from this:


#define Y_STEP_PIN          GPIO_NUM_12 // whatever you set for the 1st Y motor
#define Y_DIRECTION_PIN     GPIO_NUM_26 // whatever you set for BOTH Y motors

#define Y2_STEP_PIN         GPIO_NUM_22     // for your other Y motor
#define Y2_DIRECTION_PIN    Y_DIRECTION_PIN // ESP32 doesn't have many pins, so use the same pin

You can see examples of this in the source code in Grbl_Esp32/src/Machines/

Squaring uses the motors and homing switches to separately home each motor. To reduce the number of I/O pins needed, there is a special trick. Each axis uses two step pins, but only one home switch pin and one direction pin. Each motor has its own home switch switch, but they are wired to the same I/O pin. The homing sequence drives both motors towards the switches. As soon as one switch is touched, each motor homes separately. As long as the switches are square, the axis should now be square. The $1 setting (step idle delay) should be set to 255 to prevent the motors from turning off, thus preserving the squareness held by the motors. If the motors turn off, residual stress in the mechanical system could cause the axis to “relax” out of square.

See Machines/mpcnc.h as an example of a ganged setup.

I don’t understand the parenthetical remark.

I think you’ll need to ask more specific questions.


Hi Michael, you answered the ganged motor part perfectly thank you, and yes I’m starting with Grbl_Esp32.
The parenthetical remark is basically stating that I can see the syntax for defining a spindle from existing code, but what I need to understand are the ‘rules’, terminology and the requirements from the user to create the code in the correct format.

In one sense it’s trivial. You can almost certainly copy a pattern and modify for specifics.

In the other sense, it’s “ask me what time it is and I’ll tell you how a watch is made” — I don’t know of a general answer for the rules that doesn’t go into the C language and how a C preprocessor (a separate macro language kind of bodged onto the top of the C language) works, and maybe the parts of the discrete math curriculum that cover logical bitwise operations, etc. :grin:

At the heart it’s basically the same as the ganged configuration. For a bunch of the types, it’s just like this:

#define SPINDLE_TYPE SpindleType::something

Then something would be PWM or RELAY or LASER

If you have a Huanyang spindle and want to configure it by serial, the configuration is different:

#define SPINDLE_TYPE            SpindleType::HUANYANG
#define VFD_RS485_TXD_PIN               GPIO_NUM_a
#define VFD_RS485_RXD_PIN               GPIO_NUM_b
#define VFD_RS485_RTS_PIN               GPIO_NUM_c

That’s because these spindles are controlled by a serial connection. That needs to go through a logic-level to RS485 converter board.

There are other types listed in that page. But here’s an important point from the Spindle Types page that I linked to:

When Grbl_ESP32 boots, it will send some messages to the USB/Serial port. It will tell you what spindle type is active. If there are any pin definitions missing from from your machine definition file, it will send error messages about that too. [emphasis mine]

So go through that page and ask specific questions. Someone may or not have specific answers. You can start by sharing what actual spindle you have or are considering buying in order to ask specific questions.

many thanks one again Michael.

1 Like