GRBL ESP32 Shield – New controller for K40 laser machine

Written by Avataar120

This post is not the latest one. I have developed a new shield for our K40s.
Please click here to reach the good post.

As described in the K40 presentation article, the original electronic controller is really limited and offers poor functionalities.

There is two electronic cards in the stock K40 :

  • One main board, located on the frame of the K40 which is a MOSHI Nano M2. It handles stepper motors, laser firing and endstops. This board is piloted by a computer with a compatible software like K40 Whisperer or Meerk40t.
  • A secondary board, located on the right cover of the machine which exclusively manages the power of the laser, its inhibition but also a manual triggering for test or alignment of the mirrors. This board is not controllable from computer

We have two main limitations related to this electronics: the first is that the computing power of the main board does not allow the interpretation of GCODE and therefore prohibits the use of more advanced and powerful software such as Lightburn and the second is that the laser power must be adjusted by hand. Certainly, Meerk40t tries to get around this limitation by proposing a modulation of the laser in PPM (Pulse per minute) but this has nothing to do with a true modulation of the laser power.

The following article will allow you to solve both problems at once by installing an GRBL ESP32 shield on your machine.

My need

I wanted to be able to use the lightburn software because it is specialized in laser cutting and has many practical features. I also wanted to be able to manage the 3 axis of my machine since I added a motorized bed to adjust the focus of the laser

For that, I could have turned to Ruida type controllers but it is much too expensive (~300€) for my use. Another solution would have been the MiniGerbil card (~100€) but it remains expensive without allowing the management of the motorized bed (Z axis).

I was directed to a GRBL solution on Arduino Uno + CNC Shield V3.0 …
This solution works. However, the Arduino Uno is not powerful enough to handle the accelerations needed by a laser machine, nor to generate the right PWM frequency for the laser power management, and gives bad results in image engraving (because of the limitations mentioned above).
Moreover, this solution requires a lot of wiring, and may even require modifying the small electronic board at the end of the X axis (the one managing endstops)

As the Arduino Uno was not 100% compatible with my needs, I decided to switch to a GRBL solution based on ESP 32 which is much more powerful than the Arduino Uno ! On the other hand, there is no existing shield 100% compatible with the K40. For information, the shield that is proposed on the Github is only rarely available for sale and leads to two problems for use with a K40:

  • No connector for the ribbon cable of the K40 -> same problem as with the arduino Uno and its Shield CNC V3.0
  • The LASER_ENABLE signal is also used to activate the 3.3V->5V level adaptation component of the PWM signal. This shield works well with lasers working in positive logic (laser activation on 5V signal). But the K40 works with a 0V signal to activate the laser.

So I decided to create my own Laser Shield for ESP32 that is 100% compatible with the K40 with an easy and straight forward wiring.

GRBL ESP32 shield for K40 :

Shield GRBL ESP32 compatible K40

Features and benefits of the GRBL ESP32 shield:

  • Compatible with GRBL for ESP32
  • Compatible with Lightburn
  • Laser power is managed by software (Lightburn for instance)
  • 3 axis (X, Y and Z) with endstop management
  • 100% compatible wiring for K40. Easy and straight forward installation
  • Integrated noise filters for end stops and various inputs
  • 2 dry contact relays for air assist management and another function of your choice
  • Compatible with both types of laser activation: Active on 0V or on 5V (GRBL setting only)
  • SD CARD management (from version 3)

Assembly of the GRBL ESP32 shield:

Depending on the option you choose, your shield will be more or less complete upon delivery.

If you are assembling on your own the GRBL ESP32 shield, please carefully follow the below instructions .
We always start by assembling the smallest and thinnest components to facilitate the soldering steps

  • Solder the resistors :
    • R1 to R12 : 100ohms
    • R15 et R16 : 220ohms
    • if you have the shield v2, R14 : 10k ohms
    • if you have the shield v3, R13 : 10k ohms, R17 : 1k ohms, please don’t solder R14
  • Solder the diodes :
    • D1 and D2 taking care of the polarity. See photo below, the white line must be oriented downwards
  • Solder the capacitors :
    • C1 to C10 : 100nF – no polarity
    • C11 to C13 : 47uF – 63V – Be careful with the polarity ! a + is indicated on the PCB, otherwise the white band of the negative side of the capacitor must be directed towards the top of the PCB if we refer to the picture of the PCB below
      Warning : A chemical capacitor mounted upside down explodes …
  • Solder the transistors :
    • Q1 and Q2 : 2N2222 – Pay attention to the mounting direction, respect the orientation of the keying tab visible on the PCB (directed downwards if we refer to the PCB picture below)
  • Solder the FFC connector (ribbon cable) – Pay attention to the mounting direction!!!
    The face in the photo below must be facing down if you refer to the PCB photo below.
  • Solder the male headers :
    • Jumper headers for the 3 stepper drivers (2×3)
    • Power supply headers 5V and 3.3V (2×6)
    • Stepper headers for the 3 motors (1×4)
    • Input headers (1×8)
    • SDCARD headers (1×6)
    • Laser power modulation header (1×4 if v2 shield, 1×5 if v3 shield)
    • Endstop headers (1×8)
  • Solder female headers :
    • 6 headers (1×8) to host the stepper motor drivers.
      Insert a header on each side of a stepper motor driver,
      Insert the whole assembly in the PCB, then solder
      This will allow you to orientate the headers well and to solder them straight
    • The two headers (2×20) to host the ESP32 :
      Insert a header on each side of the ESP32, insert the whole in the PCB, then solder
      This will allow you to orientate the headers well and to solder them straight
  • Solder the terminal blocks :
    • Snap the two terminal blocks together if already done
    • Solder them on Air Assist et Coolant location
  • Solder the relays :
    • K1 et K2
  • Insert relay drivers :
    • If you have chosen DRV8825 drivers, the adjustment screw must be oriented towards the ESP32 (as on my picture)
    • Si vous avez choisi des drivers A4988, la vis de réglage doit être orientée vers l’extérieur de la carte (sens inverse de la photo)
    • Warning!!! A bad assembly and you will burn your driver AND your ESP32 (this is not due to the shield itself but to the drivers pinout)
  • Insert ESP32 :
    • Attention !!
      The ESP 32 is set up as shown in the picture. The USB port must be located towards the power connector (see blue circle)
    • Attention !!
      There must be a free row on the female header on the J3 connector side (see the two red circles below)

Setting the number of micro-steps to perform a step :

I recommend setting your drivers to 1/4 step per pulse.

For a DRV8825 driver, you have to set the jumper on M1
For an A4988 driver, you have to put the jumper on M1
More informations :

Pololu A4988 Stepper Driver configuration:
MS0       MS1       MS2       Microstep Resolution
Low        Low       Low       Full step
High       Low       Low       Half step
Low        High      Low       Quarter step
High      High       Low       Eighth step
High       High      High      Sixteenth step

Pololu DRV8825 Stepper Driver configuration:
MODE0     MODE1     MODE2     Microstep Resolution
Low            Low           Low           Full step
High           Low           Low           Half step
Low            High          Low           1/4 step
High           High          Low           1/8 step
Low            Low            High         1/16 step
High           Low            High         1/32 step
Low            High           High         1/32 step
High           High           High         1/32 step

GRBL ESP32 Shield installation in K40 :

Assembly is extremely simple.

Unplug :

  • On the power supply, don’t touch the left connector. On the two right connectors :
    Unplug L, G, IN, 5V, 24V, G, 5V et L (so the 8 slots located on the right).
    On the 24V slot, keep the connections for fume extractors and lights.
    Please just unplug the wire that is going to the former electronic board
  • Ribbon cable from main electronic board (located on the K40 frame)
  • Y Axis stepper motor connector from the electronic board (located on the K40 frame)
  • Don’t unplug anything on the left connector of the power supply (L-, FG, AC, AC)

Shield version 5.2 :

Connecter :

StepLaser ShieldK40AWG gauge
1Connector J3
ENA on laser Shield
Central connector of power supply
L slot
2Connector J3
GND on laser Shield
Central connector of power supply G slot between L and IN22
3Connector J3
PWM_POW on laser Shield (Shield v3)
PWM on laser Shield (Shiel v2)
Central connector of power supply
IN slot
4Connector Alims
24V on Laser Shield
Right connector of power supply
24V slot
6Connector Alims
G slots on Laser Shield
One wire on the G slot of the right connector of the power supply

The other one on the GND of your dedicated 5V power supply (if needed – see below)
7Connector Alims
5V on Laser Shield
Don’t connect it if you intend to use USB connection with your computer (my recommendation)

Otherwise, connect it to your dedicated 5V power supply

Please don’t power the ESP32 with 2 different sources (USB and power supply)
8X_Axis ribbon connector
Metallic connectors of the cable have to be oriented toward the exterior of the board
Ribbon cable
X axis stepper motor is powered through ribbon cable
No need to connect it except if your K40 does not have the ribbon cable
Orientate the connector in order red wire faces the JP_Z connector
Y axis stepper motor cable

At this stage, all the necessary connections are done.

It is normal that nothing is connected to :

  • The central connector of the power supply on the rightmost pin marked 5V
  • The right-hand connector of the power supply on the rightmost pin marked L
  • The pins of the J2 connector of the shield (GND, Hold, GND, Start, GND, GRBL Reset, GND, Door): these connections are optional
    • Set HOLD to ground to pause the work of your cutter (laser off of course)
    • Set START to ground to resume work after HOLD
    • Set RESET to ground to restart GRBL
    • Setting DOOR to ground pauses the work AND stops the air assist. You can resume work with START (the program restarts with a short pause to allow the air assist to restart)
  • The PWM 3V pin of the J3 connector of the shield (and the PWM pin if you have the shield v3)
  • The pins of connector J1 of the shield (GND, Probe, GND, Z Lim, GND, Y Lim, GND, X Lim)
    • PROBE allows to put a probe to determine automatically the thickness of the material
    • Z Lim allows you to connect the limit switch of your motorized bed
    • Y Lim is useless on a K40 (because it is taken care of by the ribbon cable)
    • X Lim is useless on a K40 (because it is taken care of by the ribbon cable)
  • The pins of the JP1 connector of the shield (5V, 5V, 5V, 3.3V, 3.3V, 3.3V): these connections can be used to supply small consumers in 5V or 3.3V – note that positive pins are located on the marked side, GND pins are located on the ESP32 side.

You can optionally connect the Z axis stepper motor and the Z axis limit switch (between GND and Z Lim) to the J1 connector.

Mechanical installation in the K40:

I integrated the shield on the left of the electronic area of the K40 to use the holes already existing in my frame. Attached is the STL of my bracket:

Link to the Shield bracket for Shields v2 & v3

Link to the Shield bracket for shields v5.x

The arrow indicates the direction of mounting in the chassis (arrow pointing down).
The shield must be mounted with the USB port pointing downwards

The fastener circled in red is not or hardly accessible once in the electronic area of the K40. For my part, I do not put any screw. It should be possible to put the PCB with only this screw, install the PCB holder in the K40 by putting the 3 screws to fix the PCB holder on the chassis of the K40 (the PCB can still turn around the axis in red) then fix the PCB on its holder

First power up with the GRBL ESP32 shield:

It’s not time to turn on your machine yet.

You must first install GRBL for ESP32 : see this article

Et surtout lire l’article sur la première mise en route de votre K40 équipée du Shield Laser car il faut prendre un certain nombres de précautions pour éviter de crasher les axes.

And especially read the article on the first startup of your K40 equipped with the Laser Shield because it is necessary to take a certain number of precautions to avoid crashing the axes.

Adjusting the stepper motor drivers:

You will find on the web several tutorials to set the max current of stepper motor drivers.

For my part,

  • I set them to minimum (Turn the potentiometer clockwise for DRV8825)
  • I trigger a long and slow movement on one of the axis
  • I adjust the potentiometer (counter-clockwise) so that the axis moves correctly (no noise, no jerkiness)
  • I am looking for the minimum setting to avoid heating the drivers or even the stepper motors

Buy a GRBL ESP32 shield for your K40 :

I sell the laser shield for K40 with several options:

  • PCB standalone with surface components already soldered
  • PCB with electronic components and connectors (without ESP32, without stepper motor drivers) – pre-soldered surface mounted components
  • PCB with electronic components and connectors + ESP32 (without stepper motor drivers) – pre-soldered surface mounted components
  • Complete package (PCB, soldering components and connectors, ESP32 and 3 stepper motor drivers) – pre-soldered surface mounted component
  • PCB assembled, software installed & tested

About the author


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.