Programming hex file on Mega2560

If you want to be able to control a 4-axis CNC with grbl and Grbl Controller you will need an Arduino Mega 2560. Be aware that I’ve only added support for it in Grbl Controller, I haven’t actually hooked up a 4th axis yet, other users have done so, however.

NOTE: grbl is meant to work on the Uno or equivalent – Don’t spend money unnecessarily on the Mega if you don’t need 4-axis!

I’ve moved old info on programming hex files here and updated this page to focus more on Grbl Controller and grbl support on Mega 2560.

Our friend Letartare has created some new versions of 4-axis grbl based on various hardware and grbl versions on github. What is important to note is that you no longer have to compile and upload with the AVR tools, instead, he has told the Arduino IDE to compile and upload grbl, which makes working with the files much easier for everyone.

Before you begin, I strongly recommend that you are able to build and run a basic Arduino sketch like Blink on the 2560 – this makes sure you have all the drivers installed properly.

Once you have that, do the following (these instructions are on the project’s readme on github):

  1. Clone the repository: git clone https://github.com/LETARTARE/Grbl_with_Arduino
  2. Copy the desired build, which is a subfolder, i.e. Grbl84Mega2560, into your Arduino 1.0.5x libraries folder.
  3. Restart Arduino IDE if open
  4. Open the example ino: File | Examples | Grbl84Mega2560 | GRBLtoMega
  5. Compiled and Upload
  6. Connect with Grbl Controller at 57600 baud (or choose correct rate based on the particular build)
  7. You should see the appropriate greeting from grbl

Windows Grbl Controller using A-axis

37 thoughts on “Programming hex file on Mega2560

  1. Hi, thank you for your project . I would like to work with yuor new grbl controller 3.4.6 using fourth axis. As i understand after programing Mega 2560 the ports that work with axis X Y Z in controller 3.4.2 are the same . Which port do you use for 4-axle?

    • I am pretty sure that the following information is correct, from the modified grbl source code in config.h:

      #define STEPPING_DDR DDRA
      #define STEPPING_PORT PORTA
      #define STEPPING_PIN PINA
      #define X_STEP_BIT 0 // MEGA2560 Digital Pin 22
      #define Y_STEP_BIT 2 // MEGA2560 Digital Pin 24
      #define Z_STEP_BIT 4 // MEGA2560 Digital Pin 26
      #define C_STEP_BIT 6 // MEGA2560 Digital Pin 28
      #define X_DIRECTION_BIT 1 // MEGA2560 Digital Pin 23
      #define Y_DIRECTION_BIT 3 // MEGA2560 Digital Pin 25
      #define Z_DIRECTION_BIT 5 // MEGA2560 Digital Pin 27
      #define C_DIRECTION_BIT 7 // MEGA2560 Digital Pin 29

  2. Hi, thank you for your project .I would like to use yuor new grbl controller 3.5 with fourth axis.But i find a small bug.When i press ” soft reset grbl “then press “Go home”
    The X axis Lcd was setted “0” right now ,and the X axis has no move.The other axises go home step by step.

      • For some reason that file has a bug in it. I suspect it may be an older fork. I tested this one and it doesn’t have the problem

        http://zapmaker.org/downloads/grbl-081-arduino-mega2560-16u2-38400.hex

        Unfortunately I don’t know if this version is better than the other version in other parts of the code. This will need to be investigated.

        It is worth noting that the “bad” file prints out Mega2560 Grbl 0.81 at startup and the “good” prints out just Grbl 0.81

        The bad code has this in main.c: double last_coord_system[N_COORDINATE_SYSTEM][3];

        where the number should be 4 not 3. There may be other issues in that code.

        I’ve updated the page to reflect your findings. Thanks!

    • I like it! Video is fine – nice and smooth motions on the Z axis.

      Glad you got it working. I assume you are eventually going to use 4 axes? Otherwise for only 3 axes you can use a standard Arduino Uno.

      • The only trick was to figure out that for my tb6560 board i had to increase step pulse width from default 30 to 50.

        Actually i will not use 4th axis, i just had extra mega2560 from my repstrap spares and i don’t have Uno.
        Well, it works, and i’m really happy i don’t need and lpt-enabled computers or expensive usb-cnc adapters.

        Thanks again!

    • Hi EliteENG

      Great work on the 0.8 GRBL MEGA convertion!! It is working brilliantly for me except for one thing which I hope you can advice me on. How do I use homing, as the normal homing feature (i.e. $16) is missing? Your advice would be greatly appreciated. Kind regards

  3. Hi Guys, great tutorial and the comments are helpfull. I have the following problem using mega2560 and the …38400.hex, I can not get $16 command, ie I can’t activate homing. Any advice would be greatly appreciated! Thanks in advance.

      • Wow thanks for the super fast response Zapmaker! I have used 2 of the lastest conversion forks both from GRBL 0.81 but the problem is the same with both instances. Everything else works just limits & homing have disappeared, I can;t find anyone with the same problem so I must be doing something stupid.

        I can get homing working with a normal GRBL & Uno system. I have also tested it on a separate MEGA2560 board with the same problem, I use the normal “make clean” then “make hex” commands in command prompt to build the hex file. Any ideas?

  4. Hello, that is very good project .I live in china, I want make a 3d printer, so I need 4-axis control, the 4th word is “c”. Could you share you source code about “grbl-081-arduino-mega2560-16u2-38400.hex”? I want make some changer.
    Thanks again!
    hans

  5. Pingback: Mega 2560 (Old grbl information) | zapmaker

  6. Hi and thanks for your project ;)
    Does this code work with Arduino 2560 and RAMPS 1.4 ?
    Does it use the good pin for RAMPS motor drivers and endstop ?
    regards,

  7. excuse my bad grammar

    but my problem is after uploading to my mega2560 I opened grbl controller select my com port 5 select the 57600 baud click open and I get a msg saying
    |
    >(CTRL-X)
    no data from COM port after connect. Expecting grbl string.

    also if I select 115200 baud I get a msg saying
    grbl0.9d['$' for help]
    $G
    [G0 G54 G17 G90 G94 M0 M5 M9 T0 F254.000]
    ok
    idk what I did im really new to this if you could give me a run down thatd be great thanks in advance

    • I have not tested the 0.9 versions with Grbl Controller – but if you look at the link above, those versions are for 115200 baud – you are getting a response, which is good, so it may work fine at 115200.

      To try 57600, you must use the 0.8 versions like Grbl844Mega2560 (found on the link above).

      • well I put the grbl844mega2560 on my mega now and im still getting the same error msg. as before idk if this helps or not but im using windows 8 and arduino IDE 1.0.5r-2
        also i notice on your screen you have command prompt open is there something i need to be doing? i’m extremely new to all of this and my drivers all work cuzz i was able to get the blink code to work

        • First off – I decided to try the steps with the most recent code – and I had the same issues! I was able to get it working, but I don’t understand why what I did helped. I am running Windows 7 64 bit and Arduino 1.0.5-r2. I’ll explain what is supposed to happen first, then describe my workaround…

          The blink code requires you have the arduino code installed on the chip, whereas grbl is installed on the chip replacing the arduino code. It is possible to go back and forth by uploading the appropriate hex file. You need to have the right commands and files to do this.

          Here’s where it gets interesting – what Letartare has done is taken the source code for grbl and turned it into what looks like an arduino sketch. This means you can upload whatever you want – grbl, blink, etc. from the Arduino IDE. Very cool.

          Normal procedure is (a) copy the Grbl844Mega2560 folder that you extracted from the download zip off github into your Arduino folder so that you have something like this kind of folder: C:\Program Files (x86)\Arduino\libraries\Grbl84Mega2560

          Then, your restart the Arduino IDE and go to File | Examples and find Grbl84Mega2560 and pick GrblToMega and open it, then click Upload. This should all succeed – you should see the rx/tx LEDs blink while it is uploading. If you don’t you may have chosen the wrong COM port, etc.

          Once done, fire up Grbl Controller and open the correct COM port – it should very shortly discover that grbl is running on the Arduino.

          On the screenshot, the command prompt is due to how I launched it on Linux and won’t show on Windows.

          To get it working, I uploaded an older version using a command line tool, then connected via Grbl Controller. Once that worked, I went back to the Arduino IDE and uploaded it that way and the new code worked.

          One thing to note is that Letartare indicated that it is important that only one of the projects be in the libraries folder, thus don’t put Grbl84Mega2560 and Grbl83Mega2560 in there at the same time.

          To manually upload see my original page now archived at http://zapmaker.org/arduino/programming-hex-file-on-mega2560/mega-2560-original-page/ The command you can try is given below – you’ll need to adjust the path, run it from the command line or batch file in the same folder as the hex file. There is a link to the hex file on the archive page. If that works, then try the Arduino IDE approach immediately after with the new code. Hope this works for you.

          C:\Users\[username]\Downloads\arduino-1.0.5\hardware\tools\avr\bin\avrdude.exe -C C:\Users\[username]\Downloads\arduino-1.0.5\hardware\tools\avr\etc\avrdude.conf -c wiring -p atmega2560 -P\\.\COM10 -b115200 -F -V -D -Uflash:w:grbl-081-arduino-mega2560-16u2-38400.hex

          • okay so instead of using 844 I used 84 this time and it fired up thanks again also will this work with the sparkfun easy drivers they are still coming in on shipping so I don’t have them or the steppers here yet sadly I wont get them till after my birthday this is my lil birthday present to myself lol

  8. Great project. compiled and ran grbl controller 3.6 on arduino mega2560 all axis work and are faster than other version of grbl controller but jog only moves in one direction no matter what direction you click but running gcode works fine except i get lost steps

  9. Hey, great stuff thanks, can’t wait to try it out. How easy would it be to port this to the arduino due, the extra processor grunt would bring it inline with commercial options imho

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>