Author: cebalo

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:

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 UN5804LB 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:

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 – 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 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: – (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.


Ready for testing….

The display housing is to be made from a 1″ thick block of Aluminum.
Shown here ready to be attacked by my Tom Senior M1 mill.


A few hours and many chips later… this is now complete and mounted on the Taig mill.
Buttons have been recessed into the front panel along with some 3mm clear acrylic to cover the display.


Ready for testing. (still have that blocky font – still on the list to modify)

Here’s the Taig with it’s new DRO.


The Taig has a few modifications from standard. Single to 3-phase VSD /motor and ER16 spindle.

Lead screw cover still to be re-installed. This will need some modification due to the installation of X & Y axis sensor mounts shown below.


The magnetic strips are mounted in 16mm U channel. This provides protection for the strips against swarf/chips.




Prototype 3

More progress on the prototype DRO. Buttons are now working – Axis reset and Measurement toggle.
Also added a startup config option to allow default metric/imperial measurement and reverse axis options.

New board has been designed and back from the PCB house. I have added a header for S/W SPI port and select
lines in case anyone whats to use standard 7-segment displays via MAX7219/MAX7221 drivers.

display-p3 Display-p3-2

The board uses a surface mount TQFP ATMEGA328P. ICP and FTDI headers provided for Bootloader/Prog.
I managed to load the bootloader using either an UNO as a programmer or using a cheap USBASP programmer board.
Both worked. The board is treated as a Arduino Uno and must be set as this in the Arduino ADE for either bootloading or programming via FTDI.

Font still needs updating for the OLED display.

Sensors have been mounted in the aluminium cases I made earlier. I have potted these in epoxy resin and added armoured cable.

The top of the AS5311 sensor sits above the resin and casing by a small amount.


My small Taig mill will be the first recipient of the DRO. I’ve spent a few days making the mounting brackets for this.
Here’s the Z Axis sensor mounted and ready to go. The magnetic strip is mounted in a 16mm square aluminium U channel.

I’m in the process of mounting the X and Y sensors.


Next step is to mount the display board. For this I plan to mill the case from a solid block of one inch thick aluminium.

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.


Sensor case looks like a good candidate for some home anodising….(or Anodizing if you are American)
You can do this pretty easily without acid and get pretty good results.
I’m in New Zealand… The nice caring authorities here don’t trust people like me with sulphuric acid needed for the usual methods. It’s not that easy to buy here. Never mind.. there are alternatives.

Sodium Bisulphate – commonly used to lower the PH of swimming pools. This is a salt of Sulphuric acid and for my purpose, will work fine.  Usual disclaimers here… I’m not responsible for any damage you do to yourself etc if you attempt this. Use common sense when using these chemicals.  This works for me.

Here’s how I do it.

First I make sure the aluminium is really clean and all those machining marks have been taken out. And when you think it’s really clean, clean it again.  I like to etch the aluminium in some Sodium hydroxide (NAOH, Drain cleaner) for a few minutes. A few teaspoons in a 1/2 litre of water is all you really need.  Sodium Hydroxide is nasty stuff on skin and eyes….cover them. I don’t soak it longer than about 5 minutes. This eats aluminium nicely.

I wash in water taking care not to touch with my oily hands….

I use a piece of aluminium about 120mmx100mmx6mm thick for the cathode. I use a low current car battery charger. Mine is 2200ma capacity. This is more than enough for such small objects and finally a Sodium Bisulphate solution. I use about 1 part NaHSO4 to 4 parts water by weight. So about 200g disolved in 800ml water. Negative to the cathode, positive to the nicely cleaned case connected with some aluminium wire. Place them a few inches apart and let it bubble away for anything from 1 to 2 hours. Small hydrogen bubbles will be seen bubbling up from the cathode. Best done outside since hydrogen is of course flammable…..Here’s one of the cases being anodised. Current is about 250mA. (bubbles not really visible in the photo)


So I have my newly anodised case. Time to dye it.
I’ve experimented with a number of dyes/inks. I’ve had varying degrees of success with black acrylic dyes and inks. Most of these give a blue or purple colour on aluminium. So black acrylic ink gives me any colour between purple and black depending on concentration. A bit of experimmentation is required here. For this, I’m using some ‘Pebeo colorex’ black ink.

I now use the ink non diluted. I apply it with a small brush. Providing your anodizing process has worked properly, this should soak up the ink almost instantly. If you can still see the metal after applying the ink, the aluminium is either not clean enough or hasn’t been anodized long enough. I then boil it for about 20 minutes in boiling water to seal.

You can remove the anodised coating if necessary by soaking it in Sodium Hydroxide again.