I have allot of questions about setting the axis directions for the Shapeoko 2. The official instructions make sense to me as a programmer but may well mean nothing to you? What doesn't make sense to me is why Universal Gcode Sender and the likes are not doing this simple calculation in the background while presenting you with a simple tick box for each axis you would like to reverse?
At the bottom of this post are the official 'de-structions', however here is a more simple approach and explanation.
The Uno has very little space to store anything, and so the designers have incorporated the direction instructions for all 3 axis into one byte of information. There are two of these bytes of information that GRBL uses to control the directions. In GRBL V0.8, they are known as $6 and $18.
- $6 (Step Port Invert Mask) being the byte to control motor directions during standard movements like those issued in G-code and in manual jogging commands you issue through the universal G-code sender.
- $18 (Homing Dir Invert Mask) is the motor direction that GRBL will use when you issue a $H home command.
A byte is the of the smallest datatypes and takes very little memory to hold, about a byte in fact;) It holds a value from 0 to 255, GRBLs designers needed a way to encode into this value the direction of each axis and this is what they came up with.
The value that we put in these two bytes can be though of like so.
X axis is the value: 32
Y axis is the value: 64
and Z axis value: 128.
For any axis that we want to change the direction of, we add its value to the $6 or $18 invert mask byte.
So starting at zero, add (as in multiply together) the values from above for each axis that you want to reverse.
- If I want to reverse only the X axis, my total value is 0 + 32.
- If I want to reverse the X & Y axis, my total value is 0 + 32 + 64 = 96
- If I want to reverse the X & Z axis, my total value is 0 + 32 + 128 = 160
So starting with a value of 0, which means don't reverse any axis, I can add the X and / or Y and / or Z values together to reverse any combination of axis. In example 3 above I wasn't interested in changing the Y axis, it happened to be correct already, so I didn't add the 64, so more correctly example 3 is: 0 + 32 + 0 + 128 = 160 - with the bold 0 being the Y axis.
So by this stage it will make sense that if you don't want to reverse any axis you use 0, and if you want to reverse all 3 axis you use 224!
The direction that your axis start at is unknown, because it has been decided by the way you terminated your motor wires.
For some reason, that I haven't looked into, the standard setting in GRBL (v0.8) for $6 is 28. I don't really care why, I don't suppose you do either, just ignore that.
Chances are your reading this because one or more of your axis don't go the way you expect when jogging that axis in the universal g-code sender. Take note of the fact that there is a second step port invert mask variable, $18, for controlling the direction your machine runs when homing. You will also need to run a test home to see if you need to make the same changes to this variable. When homing you expect your z to go up, the x left and they Y forward.
If you came here looking for an answer as to why your Y motors are not spinning in opposite directions like they should, you need to switch two of the wires from one pair of one of the y motors around, this will change the direction of one of the y motors, once they are spinning in opposite directions then you can use the explanation above to set them both in the right direction. Simply put, take the back and green wires from one of the y motors and swap them over with each other, this motor will now spin the opposite way than it had previously.
Swapping wires like this also works to get you around having to understand the whole above explination, but its actaully more effort than just doing it with the step port invert masks, there is also a jumper on the CNC shield if you are using that alternate electronics to reverse motor directions.
Here are the official instructions to confuse you further, : found here. If your not into C coding then you dont need to understand bit shifting and it will in fact just give you a headache so don't read any further.
$6 – Step port invert mask, int:binary
Some cnc-stepper controllers needs its high-low inputs inverted for both direction and steps. Signal lines are normally held high or low to signal direction or held high and goes low for a couple of microseconds to signal a step event. To achieve this, Grbl can invert the output bits to accomodate particular needs. The invert mask value is a byte that is xored with the step and direction data before it is sent down the stepping port. That way you can use this both to invert step pulses or to invert one or more of the directions of the axes. The bits in this byte corresponds to the pins assigned to stepping in config.h. Note that bits 0 and 1 are not used for inversion. Per default bits are assigned like this:
#define X_STEP_BIT 2 #define Y_STEP_BIT 3 #define Z_STEP_BIT 4 #define X_DIRECTION_BIT 5 #define Y_DIRECTION_BIT 6 #define Z_DIRECTION_BIT 7
If you wanted to invert the X and Y direction in this setup you would calculate a value by bitshifting like this (in your favorite calculating environment):
Which is equal to 96, so issuing this command would invert them:
Now when you view the current settings, you should now see this in your invert mask line with the binary representation of the number (bits 5 and 6 should now show a 1 to indicate inversion.)
$6=96 (step port invert mask. int:1100000)