Difference between revisions of "Grbl"

From ShapeOko
Jump to: navigation, search
m (clarifications)
(Added Grbl build config known to work with v0.7.)
Line 77: Line 77:
 
     STEPPERS_ENABLE_PORT |= 1<<STEPPERS_ENABLE_BIT; // bit high is enable
 
     STEPPERS_ENABLE_PORT |= 1<<STEPPERS_ENABLE_BIT; // bit high is enable
 
  </nowiki>
 
  </nowiki>
 +
 +
=== Config for Grbl 0.7 (the stable branch) ===
 +
 +
I don't know why but the config.h I (DrRob) have used for 0.7 is quite different to the above:
 +
 +
#define STEPPERS_DISABLE_DDR    DDRB
 +
#define STEPPERS_DISABLE_PORT    PORTB
 +
#define STEPPERS_DISABLE_BIT        0
 +
 +
#define STEPPING_DDR      DDRD
 +
#define STEPPING_PORT      PORTD
 +
#define X_STEP_BIT          2
 +
#define Y_STEP_BIT          4
 +
#define Z_STEP_BIT          6
 +
#define X_DIRECTION_BIT      3
 +
#define Y_DIRECTION_BIT      5
 +
#define Z_DIRECTION_BIT      7
 +
 +
#define LIMIT_DDR      DDRB
 +
#define LIMIT_PIN    PINB
 +
#define X_LIMIT_BIT          1
 +
#define Y_LIMIT_BIT          2
 +
#define Z_LIMIT_BIT          3
 +
 +
#define SPINDLE_ENABLE_DDR DDRB
 +
#define SPINDLE_ENABLE_PORT PORTB
 +
#define SPINDLE_ENABLE_BIT 4
 +
 +
#define SPINDLE_DIRECTION_DDR DDRB
 +
#define SPINDLE_DIRECTION_PORT PORTB
 +
#define SPINDLE_DIRECTION_BIT 5
 +
 +
and no changes to any C files.  I'm using this with my [[Stripboard_stepper_driver_carrier_board]], which has the same pin assignments as the Buildlog Stepper Shield.
  
 
==Installation and configuration==
 
==Installation and configuration==

Revision as of 09:03, 1 April 2012

Overview

(from https://github.com/simen/grbl) Grbl is a no-compromise, high performance, low cost alternative to parallel-port-based motion control for CNC milling. It will run on a vanilla Arduino (Duemillanove/Uno) as long as it sports an Atmega 328.

The controller is written in highly optimized C utilizing every clever feature of the AVR-chips to achieve precise timing and asynchronous operation. It is able to maintain more than 30kHz of stable, jitter free control pulses.

It accepts standards-compliant G-code and has been tested with the output of several CAM tools with no problems. Arcs, circles and helical motion are fully supported – but no support for tool offsets, functions or variables as these are apocryphal and fell into disuse after humans left G-code authoring to machines some time in the 80s.

Grbl includes full acceleration management with look ahead. That means the controller will look up to 20 motions into the future and plan its velocities ahead to deliver smooth acceleration and jerk-free cornering.

Important note for Atmega 168 users: Grbl used to be compatible with both the older Ardunios running atmega 168 and the newer with 328p. The full version of Grbl now compiles without support for circles/arcs if you target 168. If you need arcs, but not acceleration-management I am still maintaining Grbl 0.51 in the branch called ‘v0_51’.

Note for users upgrading from 0.51 to 0.6: The new version has new and improved default pin-out. If nothing works when you upgrade, that is because the pulse trains are coming from the wrong pins. This is a simple matter of editing config.h – the whole legacy pin assignment is there for you to uncomment.

The project was initially inspired by the Arduino GCode Interpreter by Mike Ellery

Downloading

There are two different files to download.

  1. Hex file - The code that'll run on the Arduino.
  2. XLoader - A program that will upload the hex file to your Arduino.


There are many hex files available for your use:

  • Pre-Compiled Stepper Shield Compatible Hex Files:
    • Version 0.7D here.
    • Version 0.8E here (save as grbl8.hex)

General Hex Files:

Editing for Buildlog.net Stepper Shield

Using the buildlog.net stepper shield requires modifications to the pin assignments prior to compiling grbl. Make these edits to the source (this is taken from around Grbl 0.8, posted by Edward on the mailing list):

Config.h:

#define STEPPERS_DISABLE_DDR     DDRB
#define STEPPERS_DISABLE_PORT    PORTB
#define STEPPERS_DISABLE_BIT         0

#define STEPPERS_ENABLE_DDR     DDRB
#define STEPPERS_ENABLE_PORT    PORTB
#define STEPPERS_ENABLE_BIT     0
#define STEPPERS_ENABLE_VAL     0  // 0=low 1=high

#define STEPPING_DDR       DDRD
#define STEPPING_PORT      PORTD
#define X_STEP_BIT           2
#define Y_STEP_BIT           4
#define Z_STEP_BIT           6
#define X_DIRECTION_BIT      3
#define Y_DIRECTION_BIT      5
#define Z_DIRECTION_BIT      7

#define LIMIT_DDR      DDRB
#define LIMIT_PIN     PINB
#define X_LIMIT_BIT          1
#define Y_LIMIT_BIT          4
#define Z_LIMIT_BIT          5

#define SPINDLE_ENABLE_DDR DDRB
#define SPINDLE_ENABLE_PORT PORTB
#define SPINDLE_ENABLE_BIT 2

#define SPINDLE_DIRECTION_DDR DDRB
#define SPINDLE_DIRECTION_PORT PORTB
#define SPINDLE_DIRECTION_BIT 3

Stepper.c (insert this text on line 276):

// set enable pin
  if (STEPPERS_ENABLE_VAL)
    STEPPERS_ENABLE_DDR &= 1<<STEPPERS_ENABLE_BIT;  // bit low is enable
  else
    STEPPERS_ENABLE_PORT |= 1<<STEPPERS_ENABLE_BIT; // bit high is enable
 

Config for Grbl 0.7 (the stable branch)

I don't know why but the config.h I (DrRob) have used for 0.7 is quite different to the above:

#define STEPPERS_DISABLE_DDR     DDRB
#define STEPPERS_DISABLE_PORT    PORTB
#define STEPPERS_DISABLE_BIT         0

#define STEPPING_DDR       DDRD
#define STEPPING_PORT      PORTD
#define X_STEP_BIT           2
#define Y_STEP_BIT           4
#define Z_STEP_BIT           6
#define X_DIRECTION_BIT      3
#define Y_DIRECTION_BIT      5
#define Z_DIRECTION_BIT      7

#define LIMIT_DDR      DDRB
#define LIMIT_PIN     PINB
#define X_LIMIT_BIT          1
#define Y_LIMIT_BIT          2
#define Z_LIMIT_BIT          3

#define SPINDLE_ENABLE_DDR DDRB
#define SPINDLE_ENABLE_PORT PORTB
#define SPINDLE_ENABLE_BIT 4

#define SPINDLE_DIRECTION_DDR DDRB
#define SPINDLE_DIRECTION_PORT PORTB
#define SPINDLE_DIRECTION_BIT 5

and no changes to any C files. I'm using this with my Stripboard_stepper_driver_carrier_board, which has the same pin assignments as the Buildlog Stepper Shield.

Installation and configuration

Windows

Flashing a hex file to your arduino is simple with windows.

Xloader.jpg

(For information on how to compile grbl from scratch on windows, see this page)

  • Download and extract xloader.
  • Open xloader and select your arduinos COM port from the drop down menu on the lower left
    • To Determine your arduino's COM port:
      • Windows XP: Right click on "My Computer", select "properties", select "device manager".
      • Windows 7: Start -> Right Click Computer -> Select Manage -> Select Device Manager from left pane
    • In the tree, expand "Ports (COM & LPT)"
    • your arduino will be the USB Serial Port (COMX), where the “X” represents the COM number.
    • * If there are multiple USB serial ports, right click each one and check the manufacturer, the arduino will be FTDI. (Mine is Com6)
  • After your COM port has been determined, set the BAUD Speed to 57600.
  • Select the appropriate device from the dropdown list titled "Device"
  • Now use the browse button on the top right of the form to browse to your hex file.
  • Once your hex file is selected, click "upload"


After clicking upload, you'll see the rx/tx lights going wild on your arduino. The upload process generally takes about 10 seconds to finish. Once completed, a message will appear in the bottom left corner of xloader telling you how many bytes were uploaded. If there was an error, it would show instead of the total bytes uploaded. Steps should be similar and may be done through the command prompt.

Linux

  • Linux use avrdude (Tested on Arduino Duemlianove and Arduino UNO)
    • Download latest release from http://arduino.cc/hu/Main/Software and extract files on Desktop.
    • Download one of the prebuilt .hex-files from the Github downloads-page.
    • Locate avrdude inside the Arduino IDE folder. It will be something like this:
  /home/[user name]/Desktop/arduino-1.0/hardware/tools/avrdude
    • Connect the arduino to you computer.
    • Discover the name of the Arduino serial port. Duemilanove boards appear like ttyUSBX where X is a number. Uno boards appear like ttyACMX where X is a number. You can use the command:
  ls /dev/tty*
    • In case you have more than one ttyUSBX or ttyACMX, unplug the board, run the command again, and compare the two lists.
    • For versions previous to Arduino 1.0 go to the avrdude location and run this command:
  ./avrdude -C avrdude.conf -pm328p -cstk500 -P/dev/[port name] -D -Uflash:w:[hex-file location and name].hex
    • For Arduino 1.0 the command is:
  ./avrdude -C avrdude.conf -pm328p -carduino -P/dev/[port name] -D -Uflash:w:[hex-file location and name].hex
  • Note: some bootloaders (eg Arduino Pro) use 57600 baud rate. If you get "programmer is not responding" or "not in sync", try adding "-b 57600" to the avrdude command line
    • You should see something like this:
  avrdude: AVR device initialized and ready to accept instructions
  
  Reading | ################################################## | 100% 0.01s
  
  avrdude: Device signature = 0×1e9406
  avrdude: erasing chip
  avrdude: reading input file “grbl.hex”
  avrdude: input file grbl.hex auto detected as Intel Hex
  avrdude: writing flash (14228 bytes):
  
  Writing | ################################################## | 100% 8.06s
  
  avrdude: 14228 bytes of flash written
  avrdude: verifying flash memory against grbl.hex:
  avrdude: load data flash data from input file grbl.hex:
  avrdude: input file grbl.hex auto detected as Intel Hex
  avrdude: input file grbl.hex contains 14228 bytes
  avrdude: reading on-chip flash data:
  
  Reading | ################################################## | 100% 6.45s
  
  avrdude: verifying …
  avrdude: 14228 bytes of flash verified
  
  avrdude: safemode: Fuses OK
  
  avrdude done. Thank you.

Mac

Configuring Grbl

The ShapeOko Grbl calculator can help you to choose the settings for Grbl.

Use a serial terminal to connect to grbl (to-do: how to determine which serial/usb device to connect the terminal to). The default connection parameters are: 9600 baud, 8 bits, no parity, 1 stop bit. After connecting, you can type $ and press Enter to see the current configuration.

The folks over at the grbl github repository recommend that "the step sizes should be just under the precision of the machine, which is usually around 0.01mm for just about any machine, even production CNCs." In other words, around 100 steps/mm. They also explained that increasing the number of microsteps decreases torque and maximum speed, so we want to keep this number to a minimum if we can do so without excessively reducing the resolution.

The Z axis moves with 320 steps/mm with no microstepping, so it doesn't seem necessary to use microstepping on that axis. With 400 steps/rev motors, we get closest to 100 steps/mm with 8x microstepping.

Therefore, the following grbl configuration is suitable for:

  • 400 steps/rev stepper motors
  • 8 microsteps per step for X and Y
  • Full stepping for Z
$0=87.489
$1=87.489
$2=320
$3=30
$4=750
$5=1100
$6=0.1
$7=0
$8=9.8
$9=0.05

You can copy and paste the above into the serial terminal to change the settings, which are stored into EEPROM immediately. Type $ and press Enter and check that the settings have been saved correctly.

Using GRBL