My journey with the Arduino PCB's began a year ago when I purchased Chinese K40 Laser cutter and engraver from eBay which I upgraded with a Grbl controller based on the UNO R4. After experimenting with a stock Arduino UNO R3, I decided that I needed a better Arduino with at least one additional 16 bits PWM channel without an added price tag. Since I am controlling a CO2 laser, speed or additional processing power are not a requirement since the CO2 gas needs time to ionize and quality engraving takes time. Throwing in a huge ARM processor on 80MHz is not going to make a huge difference. Since the stock laser beam is 0.15 mm wide, a better focusing lens or lower power (slower movement) to reduce the beams width would help. Of course you can buy existing upgrades now but they weren't available a year ago when I got my K40. For those interested, here is my kickstarter. My latest Kickstarter uses a STM32 (super Gerbil see here Super Gerbil.

I did find a good candidate in the 328PB which is a more powerful sibling processor because of its extended features (additional ports, two additional 16bit timers, 2 USART’s) and it’s actually cheaper as well.

Atmega328PBAtmega328
Unique Device ID-
2* Serial Interface1* Serial Interface
2* SPI1* SPI
2* I²C/TWI1* I²C/TWI
27* Digital IO23* Digital IO
3* 16Bit Timer1* 16Bit Timer
10 PWM Channel (PD2 double used)6 PWM Channel
Clock Failure Detection-
Waveform Generator-
USART Sleep Mode Wake up-

Since I could not find any new Arduino boards based on the 328PB, I decided to make my own R4 based on a R3 board. My first attempt was using a stock Arduino board and carefully removing its current Atmega 328 processor and soldering in a new advanced Atmega 328PB. Unfortunately, it did not work so I had a second attempt with another board which failed as well. I could program it but that was it, no ‘hello’ life sign from Grbl when starting it up. After carefully reading the Datasheet, I discovered that the manufacturer removed the so-called ‘full swing oscillator’ clock circuit in order to make room for the additional features and that the chip needed a high performance crystal rather than the cheap crystals or RC based circuits that are being utilized in the current clone Arduino boards. So I made a board for the 328PB but first the software hack before we jump into that.

The Grbl changes.

To make this work we need access to an additional 16 bits Timer so we can do detailed engraving. I had a TMR3 and TMR4 available but both share the UART0 port pins that does the comms with the G-code sender. So the hack here is to move that port from UART0 to UART1 and reroute the USB interface. I did put in two circuit jumpers so I can swap the port easily around and allows me to use OPTIBOOT see here

In Grbl firmware, we need to look up the UART registers and replace the -0 indicator with -1, simple. i.e. UDRE1, USART1 etc. I have posted the Grbl converted firmware on my Github (please do check the code)

USART1_RX_vect, USART1_UDRE_vect (see cpu_map.h and serial.c)

Next thing is moving the PWM output from Port 2 to Port 4 and configure it.

#define PWM_MAX_VALUE 653534.0
#define TCCRA_REGISTER TCCR4A
#define TCCRB_REGISTER TCCR4B
#define OCR_REGISTER OCR4A // Top value Use Channel B for PWM output! PWM Channel B is tied to Dig Pin 10
//Timer 2 to timer 4 conversion. COM1A1 was set for Dig Pin 11 Channel A
// #define COMB0_BIT COM4A0
#define COMB_BIT COM4A1 //uses channel B dig pin 10 while channel A is dig pin 9
#define WAVE0_REGISTER WGM40
#define WAVE1_REGISTER WGM41
#define WAVE2_REGISTER WGM42
#define WAVE3_REGISTER WGM43

Here we assign Pin 1 to the PWM output.

#define SPINDLE_PWM_BIT1// Uno Digital Pin 1 - PD1 OC4A

Next step is to convert the pwm spindle parameter from 8 to 16 bits. (spindle_control.c)

#ifdef CPU_MAP_ATMEGA328PB //uno R4 Channel A -> COMA, PD1 port used OC4A
TCCRA_REGISTER = (1<<COMB_BIT) | (1<<WAVE1_REGISTER) | (1<<WAVE0_REGISTER);
TCCRB_REGISTER = (TCCRB_REGISTER & 0b11100000) | 0x02 | (1<<WAVE2_REGISTER) | (1<<WAVE3_REGISTER);// set to 1/8 Prescaler
OCR4A = 0xFFFE; // set the top 16bit value in PWM generator
uint16_t current_pwm;
#endif

Next is building the Arduino and Shield.

The schematic is basically identical to the UNO accept we need to add jumpers for the UART selection. Further we need to remove the 3v circuit since we don't really need that and is just more cost effective. You can even just by an AVR xpained mini board from Digikey or others and add an additional USB port (FTDI232XN).

The shield circuit consists of two A4988 or DRV8255 stepsticks (pololu chips, look up the data sheet and you have the schematic). You can set the A4988 or DRV8255 in 16 microsteps. Any higher for the DRV chip does not make any difference in engraving. Just makes it slower because the 328PB needs to double its processing in pulsing the step sticks. Will post the schematics here soon because I left them on my other PC but you can basically work this out very easily yourself by googling the UNO and Pololu circuits.

Having little experience with surface mounted devices, I decided to take the designed the board to a Chinese manufacturer of PCBs since I did not had any SMD experience neither the tools. They did the whole manufacturing job of my ten boards from PCB to SMD assembly for me. Unfortunately, I made a few mistakes in selecting the components from an online components catalog, like a reset button which was too small in size and a wrong model header but that was easy to rectify by myself. It shows you never can rely on catalogs alone.

All ten boards worked immediately after installing Grbl! The manufacturer did a truly excellent job and the quality and finish is definitely professional. I could not tell this apart from the boards that I buy from commercial suppliers.

Now I can use the CNC firmware Grbl on my laser and do 16 bits engraving (10 bits actually, any higher does not work well. 10 bits gives me enough range to engraving between2 and 4 mA of the 20 mA range). Can't be happier and more satisfied!

Now friends have been asking me for these boards so they all have gone. I have visited the Makerfaire in San Mateo and there was enough interest for a small production run, so started my Kickstarter on the 7th of July.

If you don't want to solder and build it yourself or just want to help the K40 community to get a cheap working alternative than have a look at https://www.kickstarter.com/projects/2118335444/gerbil-the-open-upgrade-for-your-k40-laser