Grbl CNC Firmware on ESP32


I have been working on this for months. I am happy to announce that it is finally working right. The ESP32 will be a great option for CNC. Here are some things I am excited about.

  • Fast – Two 32 bit Cores at 240MHz Each, FPU, 80MHz Timers
  • Memory – Tons of Flash and RAM
  • Low Cost – $3-$10 depending how you buy it.
  • Small Size – Not much bigger than an Arduino Nano
  • I/O – It has about the same number of pins as an Arduino UNO, which is the target for Grbl
  • BlueTooth and WiFi – This is great and actually the primary reason for my port.


The bulk of the code was very easy to port over, but getting very low jitter, step pulse timing took a long time to achieve. This is not my first port of Grbl. My first port was to the PSoC5. That was much easier, but this was my first major project on the ESP32.

A goal was to use the Arduino IDE to develop the code. I thought it would make the project a lot more accessible to novice programmers that just need to make a few tweaks. I also tried to make the code easy to maintain with Grbl. This means there a few throwbacks/workarounds to AVR port numbering. etc.


The ESP32 uses an RTOS (Real Time Operating System). While “real time” sounds perfect for CNC, it is not good for step pulse timing. An RTOS allows multiple tasks to run “at the same time” and it manages the priorities and interaction of those tasks. The RTOS switches tasks at a “tick rate”. The tick rate is typically about 1000Hz. This means each task gets at least 1ms of time and the others wait. You can designate a high priority task to prevent these interruptions, but some tasks have watchdogs that must be reset so you need to give them some time.  You can set the tick rate higher, but I need a more than 50,000 hz step rate. That is not practical for the RTOS. I can turn off the RTOS and/or the watchdogs, but a major appeal of the ESP32 is the WiFi and BlueTooth. These need the RTOS.


The normal Grbl way generate step pulse timing is to use interrupts. As long as you follow the rules for interrupts, they will interrupt the RTOS without any delays in very deterministic manner. The rules are about how much time you can spend in the interrupt and what things you can do in the interrupt. The interrupt duration was not an issue because the code in the interrupt only takes a few micro seconds. What you can do in the interrupt took a while to figure out. The ESP32 does a “panic” reboot when it does not like something. That happened a lot during development. Most of my problems were related to how I used the peripherals. Things like the RMT feature simply can’t be used.

My Dev Board

I designed a little Dev Board to help me with this project. The features include…

  • 3 Stepper Drivers
  • 3 Limit Switches
  • 1 Touch Probe connector
  • Mist / Flood Coolant outputs
  • Start / Hold / Reset / Door switch connector.
  • Spindle / Servo / Laser – Connector
  • SD Card – This is just a breakout to a header that can be wired into the CPU if I ever decide to do that.

Next Steps

Testing – I need to do a lot of testing. I tested most of the features along the way, but need to double check all the config options.

Clean up – I have a lot of commented out debug code that needs to be removed

Publish on GitHub – Done. GitHub Repo

BlueTooth – That is the first new feature I want to add.

Hobby Servo Features – I use them a lot in my small machines and 328P Grbl doesn’t handle them well because the lack of 16 bit timer availability. I want high resolution jitter free servos as an option for any axis.

Simple Kinematics – GCode can be converted on the fly to alternate coordinate systems. This would not consider joint dynamics.


If you want to be notified of future blog posts, please subscribe.

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks

34 Responses to “Grbl CNC Firmware on ESP32”

  1. Craig Hollabaugh

    This is great!

  2. James Lewis

    Amazing work! I’ve been looking for a first time project to try out the ESP32, I think I just found it.

  3. Grbl Ported to the ESP32 - HudsonWerks

    […] Well, quite a few things in fact. As [bdring] explains, Grbl pushes the capability of the Arduino to the very limit; making it something of a dead-end for future development. Plus the Arduino needs to be plugged into the host computer via USB to function, a rather quaint idea to many in 2018. These were just some of the reasons he decided to port Grbl to the ESP32 board. […]

  4. avion23

    Hey thanks for all the work!

    I think the writeup doesn’t do your project justice. Can you look it over? I found some strange sentences and mistakes, f.e.
    Grbl does handle them well -> doesn’t
    That was CPU easier -> That was much easier

    I’ve invested roughly 16 hours into getting a high rate Interrupt running on the ESP8266 without RTOS. When I added a webserver the interrupts crashed. This doesn’t happen immediately, sometakes it takes 10 minutes. Do you run into the same problem in your project?

  5. bdring

    Thanks for the edits.

    I have not used any WiFi or BlueTooth features yet with this code, I hope I don’t have problems. The dual cores might help. How long are your interrupts? What is your interrupt frequency?

  6. Daniel

    Thats a great work! Thanks a lot for this!

    Do you use at the moment only one Core of the ESP32?
    If so, it would be a great platform to run a webserver on the second core offering a webinterface for machine control and gcode storage/streaming. Therefor the otherwise required PC (or Raspberry Pi) just for sending over gcode to the machine could be eliminated.

    One feature that was quite often requested in GRBL is the ability of controlling 4 axis. On the ATMega328 this is not possible to implement due to resource limitations. On the ESP32 of course you have a lot more resources available.
    What do you think how much effort it would be to add a forth axis to the code?

  7. bdring


    Only 1 core is currently used. The other will be good for WiFi and BlueTooth.

    Adding additional axes is not hard at all. Search my blog and YouTube channel for PSoC related posts. I have had up to 6 coordinated axes working without any issues.


  8. jmaniac

    The Git you have given is pointing to your previous work of Grbl port of PSoC. The right repo is

  9. bdring

    @jmaniac Thanks…fixed

  10. iosias

    Hi there, i’m really happy to see your work! i think the esp32 has a huge potential over the old school ATMega328. i’m looking forward to a standalone solution, with a jog-pad and a display-solution (LCD).


  11. bdring

    Right now that is any smart phone or tablet via bluetooth.

    Added a jog pad to the firmware would be easy, but it is not a priority because a phone is preferred right now.

  12. xinosuke

    It looks awesome!

    I’m doing a little project and I will need to clone one axis. I have been looking you board and it is just 3 axis. Do you think is it difficult to add this to PCB? Or maybe the firmware can not handle it?

    Thank you very much!

    PD: I am sorry for my poor English…:(

  13. bdring

    A cloned axis would not affect firmware. It would require a new revision of the PCB. I could do that for you, but there would be development cost. I can do it for $100+ $35 per board.

  14. Alexander Kratzer

    Great job!
    Is anywere a download for this cool testing/simulation equipment? The 3d printer models?

    BR Alexander

  15. bdring

    I can’t seem to find that model. It was printed years ago.

  16. Brian C (warhawk8080)

    Is there a possibility of getting the .brd design and/or gerbers so we can build the dev board from your website please?

  17. bdring

    Check out this blog post

  18. Brian C (warhawk8080)

    Cool cool…I shared your idea/design on a really cool CNC machine all 3D printable and uses electrical conduit called the MPCNC

    I also put your board on OSHPark..with links back to your stuff

    Such a VERY VERY cool design and build….now all we gotta do is get the ESP32 to do marlin with your proto-board and BOOM…3D printer with 32bit!

    Great job and keep up the awesome work sir!

  19. bdring

    Thanks, If you want a custom PCB designed for MPCNC, I can do that. I can also add machine profiles to the firmware for the MPCNC.

  20. Brian C (warhawk8080)

    Might want to run that by the developers and designer of MPCNC over at their forums…but that would be very cool!! 🙂

  21. JimF
  22. bdring

    For best performance with high gcode rate, like laser jobs have, try the SD card.

  23. Jimf

    Hi Bart
    Increased the buffers and recompiled. ESP32/grbl is now really fast for grayscale raster image laser scanning. Faster than grbl-lpc running on the smoothieboard. This is great.

    Thank you!!!

  24. Brian C (WarHawk8080)
  25. bdring

    Thanks Brian,

    I am not sure what your question is. I think it might work to provide video to the WebUI of Grbl_ESP32, but it won’t run my firmware too.

    The WebUI has a page to include steaming video from an IP address.

  26. James E

    In your next version of the board it would be nice if you could put the end stop pins in line 5v GND CL(control Line or end stop pin)


    would work with more end stops
    Nice work

  27. bdring

    Thanks, I will consider that. It would have to be 3.3V with the ESP32 though.

  28. marekesz

    Great project! Specially about the use of the web server making it a self sufficient CNC controller.
    I thought of using the new ESP32 for GRBL for some time, but my programming knowledge is rather on the basic level.
    So basic in fact, that I’m not even able to run your code –
    There’s a compilation error saying:

    “In file included from sketch\Grbl_Esp32.ino.cpp:1:0:

    C:\Users\marek\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\cores\esp32/Arduino.h:148:21: fatal error: algorithm: No such file or directory

    compilation terminated.

    exit status 1
    Compilation error for board LOLIN D32 PRO.”

    I’ve checked the link and the file is there, I have only doubt about the use of the “/” instead of “\” in the path before the file name. I’ve reinstalled the Arduino IDE with no improvement. And yes – I’m using LOLIN D32 Pro that uses WROVER module instead of WROOM but I don’t think this should be an issue, or is it?

    Can you help?

  29. bdring

    Read the wiki on how to compile at the github repo.

  30. Nick

    Hi all, Compiled the ptogram, uploaded it, the GRBL Configuration Panel does not show any information.
    Am I doing something wrong ?
    Compiled with PlatformIO and VSCode.
    Nothing changed in program, all standard.
    Help Please.

  31. bdring

    Please ask this question on the github repo.

  32. James E

    Great work Thank You
    After a Smoothieware fail on my DIY Laser Engraver.
    I went looking for a 32 Bit GRBL and found your setup.
    So I learned how to use KiCad and made my own board.
    Now I see how much work goes into making just the board.
    Had to fight with Arduino IDE to get the firmware compiled.
    Still working out the bugs but getting there.

    Thank You and Keep up the great work

  33. Paul D.!Wilkie

    I am looking for a “Naked ESP32”, exactly like Fuzzy Noodle’s Naked MAGA on Tindie?

    I only want access to the micro only as I attempt to migrate from the 2560 MAGA to the much more powerful ESP32 micro.

  34. bdring

    I assume you mean ‘Naked Mega”. Most ESP32 development boards are in a similar format.