DRO – New Version

The current madness in the world has given me the chance to spend more time updating some designs. I’ve been meaning to update the DRO files for a while now. Here’s the first part of the latest versions.

Starting with the single axis display.

This is another ATMega328p based board so you can treat it like an Arduino Uno. My previous designs have used the LS7366 Quadrature counter IC to off-load the pulse counting task from the 328p. It’s possible to count pulses with the ATMega328p PROVIDING you don’t try and count them too fast. I’ve made this optional on this board. There are two solder jumpers -SJ1 and SJ2, that switch the A + B quadrature signals to either an optional LS7366 OR the two ATMega328p interrupt pins D2 and D3. Options shown below:

Using the interrupts will work quite well providing you don’t try and move an axis faster than about 70mm/sec. More than this and it will skip steps. If you want to move the axis faster than this, then install the LS7366 on the PCB. (I recommend using the LS7366 in any case)

Here’s the circuit:

DRO Schematic

And the layout:

Note that a 20 MHz crystal is shown on the schematic for the LS7366. For best performance use a 40MHz.  I used what I had at the time.

The board supports either a SSD1309 1.5” 128×64 or SSD1305 2.2” 128×32 OLED displays. Other than this, you can use any other I2C display connected to the 4-pin header provided on the board.

A count reset and Unit (mm’s or inches) Toggle switch inputs are provided via the D4 and D5 pins on the PCB. There’s also a standard ICP connector with the Reset/SPI bus pin for installing the bootloader.

Finally, I got sick of using FTDI adapter boards to load sketches, so I’ve included an FT232RL for USB connection.

Eagle Schematic and layout files with the code can be found here:


The DRO requires a 4 wire connection to the AS5311 sensor board – A + B quadrature signals and GND and +5V.

Here’s the sensor board circuit:

Sensor Schematic

I’ve made this a general purpose board that breaks out all the AS5311 outputs should you wish to experiment or feel brave and write your own code for the serial interface to try and get that 0.5um resolution. I’ll stick to the 1.95um resolution that’s offered using the quadrature signals.

Note that the CS pin on the PCB needs to be pulled low to enable the encoder.

I’ll make the boards available at least in bare PCB form shortly. Maybe a small production run of built up boards depending on interest.

Example code uses the U8g2 Display library and Paul Stoffregen’s Encoder library for the interrupt version.

Next – the 3 Axis board….coming soon.

CNC Automatic Tool Changer

It’s been about a year now since I’ve built the ATC for my CNC mill.

Since it works pretty well, I thought I would do a basic description and share some of the design files.

Basically it’s a carousel type on a sliding arm. 10 positions.


The electronics is based on the Cubloc CB320 Mini PLC controller.


This device is programmable in either Cubloc basic or PLC ladder. It supports serial Modbus and I2C and has commands for driving stepper motors built in. Since I planned to use it with Mach3, Modbus was the main attraction for me.

I created a backing PCB with a few extras.

The board has a serial port for prog. download and a USB port for Modbus.

I made this a general purpose board with a few extra opto isolated inputs and relays to drive Air/Mist/Coolant if required.

My setup uses the following sensors:

  1. Long range opto spindle sensor – to detect if a tool is loaded.
  2. Opto index sensor on carousel – for a fixed rotational point.
  3. Opto position sensor for inventory of the carousel.
  4. 2 x slide on/out opto sensors for the slide mechanism.
  5. Opto drawbar sensor – to determine drawbar status.

One relay is used for a 5 way Pneumatic valve for the power drawbar.

The I2C bus is used to communicate with an optional status display. The status display is a standalone board with an ATMega328p driving an OLED display. It’s sole purpose being to scan the I2C bus from the Cubloc and decode the status messages.

Mechanically – There are two IKO 18mm Linear rails with a 12mm ballscrew -4mm pitch driven by a stepper.

The carousel is driven by a 3:1 reduction toothed pulley with another stepper. The ATC ‘fingers’ are a combination sandwich of Aluminium and Delrin to grip the Tool holders.

Tool holders are 20mm shank going into an R8 collet controlled by the drwabar.

The drawbar is based on a Watts linkage to provide parallel motion for the air cylinder with about a 10:1 lever. Air cylinder is 50mm diameter, 25mm stroke running at about 100psi.

The drawbar has a Belleville spring cup washer stack to provide tension.

Tool change speed is relatively slow on my machine. Speed will depend on your Z-axis speed and how fast you drive the carousel and slide steppers.

One thing to be aware of is the rotation inertia of the carousel fully loaded. You require a stepper with good holding torque to prevent loosing position as the tools rotate. Something I found out the hard way…..

Improvements – currently the code is based on tool numbers 1 to 10. I may change this and the tool slot sensor to use an RFID button on the top of the tool shank to sense the tool number – otherwise, you need to remember that tool no. 1 goes in slot no. 1 and you are limited to 10 tools at a time. Some additional error checking and custom Mach3 screens are also on the list.

Design files for the PCBs and Mach3 macro are here: https://github.com/pcm52/CNC-ATC

CO2 Laser

Another Toy. I have purchased a small CO2 laser cutter/engraver.

After a bit of research, I decided on a Chinese made ‘K40D’ type machine.

The advantage of this model over the more common ‘K40’ is the addition of a linear slide on the X axis and built in air assist. The air assist has the benefit of keeping your optics free from smoke deposits.

With a bit of modification these cheap machines can be made quite useful.

The ‘K40D’

To me, the biggest issues are the fixed Z axis – requiring the bed to be manually moved to get the correct focus and the need to always be attached to a PC to operate. Here’s a brief description of the mods I’ve done to correct this. 

The Z axis.

With the standard bed removed there about 70mm between the focus point and the bottom of the metal case. Others have solved this problem with a adjustable single stepper motor and belts/cogs.

Bed Removed

While browsing one of my favourite sites, I came across some hollow shaft NEMA 17 stepper motors.  My Z axis design evolved from these.

The motors are bored 6.1 mm. Four motors mount on each corner of a 40mm aluminium frame should do the trick. Unfortunately, these motors are 5 wire with a common centre tap on the windings meaning that the only way to drive them is in unipolar mode. Probably the reason they are only about US$6.50 each…

We can get around this by using the UCN5804LB motor driver chip. While it is now obsolete, there are still plenty available and it is very easy to use.

I created a small PCB to for this.  One for each motor.

Stepper driver board

These will be fed common Step/Direction signals. I also wanted a push button up/down setup so created a driver board to able to manually drive these or also accept a control signal from the new off-line controller that I plan to install next.

A small amount of addition logic was added to opto-isolate, buffer the signals and effectively disconnect the direction control line from the controller when using manual mode.

The motors draw about 0.22A per winding at 12V so well within the 5804’s 1.25A limit.

The board also has a jumper to select ‘wave’ mode driving two windings at the same time for increased torque. (At the expense of increased current draw)

Here’s quick drawing of the setup (motors are attached to the top section, threaded rods attached to bottom section)

The motor’s shaft is 8mm. A brass threaded coupling was turned up to fit this as shown in the sectioned view below. (Excuse the quick and dirty CAD) Threaded coupling is then attached with loctite to stepper shaft.

Four threaded rods approx. 120mm in length screwed into the base complete the design.

If you reproduce this, good accuracy is required between the centres on the threaded rod and stepper shaft centres.

The control board:

And schematic:

The board mounted switches are for testing. The switch connections are broken out on a three pin header for manual control.

The basic frame is made from 40x6mm aluminium extrusion lapped at each corner.

Two opto-isolated inputs are provided for Step/Direction signals from a new laser controller board or alternatively, control can be manual with your existing laser control board.

New Z-axis about to be installed

The new axis has two separate beds. One as shown above giving maximum available height and one shown below with the bed at the standard level.

While the 2mm Aluminium plate is not the ideal bed being highly reflective, I will probably replace with some sort of metal mesh once I find something thin enough.

Electronics design files can be found here: https://github.com/pcm52/K40-Laser-Z-Axis

To house the electronics, I machined some 13mm Al Plate on the CNC mill.

Next – the new off-line controller.

LoRaWAN Gateway

Recently I have been playing with LoRa radio transceivers. – Long Range, low power.

I found it is easy to to setup a point to point link with two LoRa modules but as soon as you start playing with the LoRaWAN protocol, you find you need a gateway device to go much further.

RAKWireless recently released a low cost gateway concentrator board – the RAK831.

Most current DIY gateways use the Raspberry Pi to drive the gateway board. I looked at using this with the RAK831 but decided to try and find a neater/smaller solution.

Enter the NanoPi Neo.  Friendly Elec – http://www.friendlyarm.com/ sell the NanoPi Neo – significantly cheaper and smaller than the full sized Raspberry Pi and easier to use than the Raspberry Pi Zero.

Here’s a board with the NanoPi Neo that also supports a GPS module, OLED display and BMP280/BME280 sensor. All these are of course optional and the board only needs a few resistors to operate as a gateway.


The GPS module is a UBLOX Neo 7m. This has a USB interface to allow the GPS module to be configured. The PPS output is made available to the RAK831 along with the serial data output to the NanoPi Neo on serial port 1. I have provided a jumper to disable/enable the Nano transmit/GPS receive line. I found that the echo from the Nano would cause the GPS serial port problems…and sometime stop valid data being sent from the GPS.

You could also disable serial port echo on the Nano if needed.

The OLED display is a 128×32 0.91″ i2c model. The OLED is soldered directly to the back of the board. Reasonably easy to solder if you have good soldering skills. The OLED display is on the bus at address 0x3C (pretty standard for SSD1306 type displays).

Should you not wish to use or install the on board display, I have provided a 4 pin i2c header for remote display or whatever.

There is also a BME/BMP280 sensor option should you want to monitor your gateway’s environment.

The Nano/RAK/PCB can be powered by the common 5V connector or the Nano can be powered separately through the Nano USB port. A jumper on the PCB is provided for this.

The Nano is running Friendly Elec’s supported version of Ubuntu.

The OLED is driven by the Luma OLED library.

Gateway software for “The Things Network” gateway can be found here:


You will need to edit the start.sh file to change the reset pin for the NanoPi Neo – Pin1

If you use the GPS option, you will also need to change the serial port to ttyS1 in the global_conf.json file.


Here’s my unmounted board. I recommend you buy the optional NanoPi Neo heatsink.

My board runs at fairly cool. Operating after 3 hours my board was running at about 32 deg C.  (background temp is about 18 deg at the moment).

Eagle Schematic and PCB files can be found here:


As always, use at your own risk. It works for me!










Somewhere along the way I decided to build another CNC machine.
This is still work in progress. Of course it had to have DROs.
I plan to have a manual mode on this machine so they should come in handy.

The DRO version used on this machine consists of a separate module for each axis. Each axis uses a 2.2″ OLED 128×32 display and a ATMega328p.cnc4-1

More on the machine later…


Again, the case is made from 1″ solid aluminium plate. one side is removable to access the USB ports for programming. (I got tired of using FTDI adapters and ICP headers.



Each axis has a OLED display board and ATMega328p board.

First – the display board.  The 2.2″ displays come in 4 different colours – Green, Yellow, Blue and white. They are based on the SSD1305 controller chip. The display panel requires 13V and 3.3V for operation. The 13V is provided using a FAN5331 boost regulator and logic level conversion is done by using a 74HC4050. Interface to the display is through SPI.

Previously I had used I2C to communicate with the displays. SPI is a lot faster. The OLED connects with a 0.5mm pitch socket. Difficult to solder 0.5mm with a standard soldering iron. You really need a SMD rework station for this.

The SSD1305 is not supported by the u8glib library at this stage. It is however very similar to the other SSD series chips. You can modify the code to support these quite easily.

More to come.



Height Gauge



It’s been a while since my last post.
Been busy building up more DROs for friends to install and test.
This has evolved into a number of 1,2 and 3 axis designs with various sized displays.
More on this to come.

I’ve been distracted with the idea of making a digital height gauge using the same magnetic scales. Most of the basic electronics design is covered in my previous posts on DROs with a few exceptions.

The height gauge needed to be battery powered, auto power off and have a simple push on/push off function. I’ve decided on the LTC2954-1 pushbutton on/off controller made by Linear. This device has an enable and kill output. Perfect for this project.

The electronics is powered by a 6V lithium camera battery. A 3.3V LDO regulator is connected to the on/off controller and the Kill input connected to the ATMega328p to allow shutdown after a pre-determined time. Drawing about 6uA (according to datasheet) in power off mode, the LTC2954-1 seems like a good option for this application.


The ATMega328p is running at 8MHz loaded with the Arduino 8Mhz boot loader.

Schematic below:


As with the DROs described earlier, the magnetic sensor is made up of the AS6511 / LS7366 combination. the LS7366 being read by the ATMega328p on the SPI bus. Also attached to the SPI bus is a 0.91″ SSD1306 based 128×32 pixel OLED display. Current draw is about 30mA. This should give many hours use from the 6V camera battery.

Display zero reset and metric/imperial units switches are connected to the ATMega328p interupt lines with some hardware debouncing.

The code to run this is pretty straight forward but I’m sure someone can improve it. Values and settings could be stored on power off for example. I haven’t bothered with this. I’m using the U8glib display library rather than my OLED library used on the prototype DROs. Mainly because of the extra fonts and the U8glib library now supports more OLED types. I’ll most likely change the DRO code to use U8glib shortly becasue of this.

The ATMega328p sends a kill signal to the on/off controller after 5 minutes to conserve battery power.

Onto the mechcanical side.

I should say now that the accuracy of this unit will be limited by your machining skills and your machines’s ability to bore accurate parallel holes. I had more than one go at making the body and bronze bushes…. Movement in the gauge slides due to sloppy bush fit on the bars, will lead to disappointment….The sensor and electronics will be more accurate than your machining…


The main body of the gauge is made from a length of 2″ x 1″ (50mmx25mm) aluminium bar. Bronze bushes are installed into the block to run on 16mm and 12mm ground rods. In my case i used good quality silver steel (or drill rod as some of you call it) Again – the bronze bushes MUST be a good fit on these bars. I bored all holes on my milling machine with the stops set left and right. This allowed me to bore the base, body and top all parallel. Brass locking screw on the left of the gauge acts directly on the 12mm bar.

My base is made from a block of cast iron and the scribe made from a piece of 6mm gauge plate (or 01).
My gauge has a range of about 200mm but this can easily be changed by the length of your bars and length of magnetic strip.

The magnetic strip is set into the 16mm bar in a 10mm slot.  From experience, I can say it is best to make the slot run to the end of the bar on at least one end. The AS5311 sensor sits less than 0.5mm above the magnetic strip. The sensor can easily be ripped of the circuit board at the end of the slot if you forget the slot doesn’t go to the end of the bar…ask me how i know this….


The PCB layout shown above allows the sensor portion on the left hand side to be ‘snapped’ off the board to allow mounting of the sensor. This can be seen below where the sensor is mount below the main PCB.


Shown above with the front panel removed. (It’s hard to photograph the OLED display to demonstrate how sharp and bright the display actually is.)

If you decide to make one of these – providing you take care machining, you should end up with a very usable, easy to read height gauge.

Eagle layout files and the code can be found here:- Design files

OLED displays can be purchased here: – buydisplay.com (for the blue display. Also available in white on black but I find the blue on black brighter)

These guys have a good selection of displays. This is where I purchase most of my displays.


Prototype 2

So the first batch of PCBs for the DRO display have arrived. Looking good.
First problem, I made the holes too small for the header pins on the Nano and OLED display.
Drilling will remove the thru-hole plate so since this is a prototype, I will use strip sockets with smaller pins to mount these.

I plan to use a SMD ATMega328p TQFP chip on the final board. the final board will have a FTDI and ICP header.
I also purchased a TQFP 32pin socket to allow me to pre program the chips.

Still waiting on some voltage regulators and shottky diodes to complete but have enough bits to make a start.
Hooked up three sensor boards, the Nano and the OLED. modified my single axis code to support three.
Seems to be working well. Basic code fits in about 13k program space. No noticable lag in display update.
The encoder read happens every 50mS and the Arduino seems to cope with this.


Remember that most of the work is done by the LS7366 Encoder/counters. The LS7366’s sole purpose being to count the pulses from the AS5311 encoders and store the count. All the Arduino needs to do is retrieve the count over the SPI bus and display to the OLED in either metric or imperial. No interrupts needed…. 

Next step is to add the zero and metric/Imp switches for each axis (6 switches). I’m planning on doing this with one analog input and six 1k ohm resistors in a ladder configuration. So here’s the schematic with the planned switches. The switch portion being untested so far.


The display font is a scaled 5×7 pixel standard font. As shown in the photos, it is scaled twice size so looks a bit blocky. I’ll look at adding some better looking fonts so the layout looks better. One I confirm the switch design is working, I will re-design to use a smaller PCB with a SMD ATMega328p. I’ll also add a jumper to select the default measurement unit at power on. Currently this is set to imperial but can be changed on any axis by the push buttons.

These OLED displays are really impressive. I originally planned to use standard MAX7221 driven seven segment displays as seen in the first prototype but after using these OLEDs, I can’t see the point. I’ll include a 3 channel SPI header on the final board for anyone that wants to stick with seven segments, but OLEDs are now my favourite.

For those who are keen on the seven segments, here’s the schematic.


One for each axis. Use either MAX7219 or MAX7221. Datasheet is online.