Python, Java, C++ programming combine to control my CNC mill

Overview

This page documents my journey building a CNC Pendant to control my X-Carve mill. It began with an interface to Universal G-Code Sender (UGS), starting out as a simple idea. Quickly grew into a fantastic exploration of design, construction, coding, and interface concepts.

Many iterations, many proofs of concept, many do overs. Lots of fun, and lots of learning, exactly what I love about embedded electronics and software engineering. Some of the skills involved are:

  • Programming in Python, Java, and C++
  • Interfacing to multiple 3rd party applications
  • USB serial communication
  • Embedded electronic design
  • 3d Modelling
  • Woodworking

As of this writing the Production 2020 model is in place on my X-Carve controlling my mill, bringing joy and efficiency to my manufacturing process.

Iterations

This page is all about the Production 2020 model.

The earlier iterations (Prototype v2, Prototype B, Prototype A) have their own page.

Prototype v2
Prototype B
Prototype A

High Level Design

Production 2020 - system diagram
  • The Device / Client (lower right) is the wooden thingie that the rest of this page talks about constructing.
  • The Controller / Host (upper middle) is the Python application that controls the overall pendant system.
  • The two green arrows represent two different USB connections (one to the device, one to the GRBL Controller).

When you press a button on the device:

  1. Serial message gets sent to the Serial Message Bridge
  2. Serial Message Bridge puts a message on the queue
  3. Message Processor picks the message up off the queue:
  4. Preprocess the message to convert it to proper G-code
  5. Transmit to the G-Code Sender
  6. G-Code Sender communicates with the GRBL Controller to move the router

GitHub

Arduino C++, Python, and CAD source files are available in the hc-cnc-pendant GitHub repository.

Final Results

It is always fun to start with a view of where we’re going before we dig into the journey.

  • Left picture shows the beautiful face panel of the pendant.
  • Middle picture does not do justice to how cool the front text looks, painted in a fun graphite enamel
  • Right picture is a screenshot of the Python controller and emulator
Production 2020 - face
Production 2020 - angle view
Production 2020 - python screenshot

Solderless Prototype

While the overall pendant has gone through many prototypes over the last 2 years, the production 2020 model is a full rebuild, and so warrants its own solderless prototype to verify the circuitry and communication.

Production 2020 - solderless prototype
Production 2020 - solderless prototype

How much fun is the in focus / out of focus view of the pushbuttons on their long solid-core wire leads?

Computer Aided Design (CAD)

Once the basics were designed and tested on the ole breadboard, we move to designing the final layout.

AutoDesk to the rescue, with Eagle for electronics and Fusion 360 for enclosure.

Production 2020 - schematic
Production 2020 - EAGLE board
Production 2020 - Fusion 360

Extra special care went into ensuring the USB port lined up just right. The physical dimensions of the circuit board and the enclosure must mate perfectly or else the USB connector will not fit or line up.

I chose a professionally manufactured printed circuit board (PCB) for this project. I really did not want to point-to-point solder all those resistors. $2 and 3 weeks is all it took to get beautiful boards shipped right to my door.

Woodworking

While the circuit boards were on the slow boat, I got to work on the wooden enclosure. A scrap piece of pine from a bed headboard project was perfect.

Production 2020 - raw wood
Production 2020 - cut wood
Production 2020 - countersink wood screws
  • Rough cut the two halves.
  • Drill and countersink screws in the 4 corners.
  • Belt sander to match the halves exactly.
  • Hand sand to really smooth things out.
  • Stain preconditioner
  • 2 coats Varathane Special Walnut stain
  • 1 coat sanding sealer.
  • 4 coats polycrylic.
Production 2020 - stained wood back
Production 2020 - stained wood front

Vertical Clamping Fixture

My last project HC Sippy gave me some initial experience milling the narrow sides of tall pieces of wood.

Key learning from that was the need for rigid vertical clamping.

Enter the fixture.

Production 2020 - clamping fixture 1
Production 2020 - clamping fixture 2

Simple wood base, glued and screwed to a vertical upright, secured to the CNC wasteboard via 5M screws. Then clamp the workpiece stock to the secured fixture and you’re in business.

Slick, simple, effective.

Production 2020 - clamping fixture 3
Production 2020 - clamping fixture 4
Production 2020 - clamping fixture 5

Clamping Fail

Whilst my vertical clamping jig was a smashing success, not all my clamping operations were quite up to standards.

The first milling job on the front of the enclosure is the v-carve text and artwork.

The picture on the left shows the result. Details towards the left and top barely cut through the oramask. Details towards the right and bottom cut so deeply that the text is borderline unreadable.

Examine the situation from all angles and quickly identify the problem.

Production 2020 - clamping fail 1
Production 2020 - clamping fail 2
Production 2020 - clamping fail 3

Failure to clamp the workpiece down to the wasteboard surface. The middle picture shows the gap nicely.

Redo with proper clamping and all details cut fine. Still stuck with some poorly carved words from the first too-deep run, but close enough for my own use and I can clean it up a bit during painting and finishing.

Enclosure Top half

Continue on milling the holes in the face and the pocket in the backside of the top. She’s starting to look like a pendant now.

Notice how the pocket corners get tighter as the radius of the endmill gets smaller with subsequent milling operations. That’s the fun of REST machining in Fusion 360, and it saves tons of time. I really pushed the speed and depth on my rough operations with the 3/4 inch endmill, very happy with the results.

Production 2020 - carve top 3
Production 2020 - carve top 1
Production 2020 - carve top 2

Enclosure Bottom Half

The bottom half of the enclosure was more straight forward. Basic rectangular pocket with small risers in the corners to raise the circuit board up off the floor and allow space for the wire ends that stick through.

Again, notice how the radius of any interior corners gets tighter as the endmills get smaller.

Production 2020 - carving the bottom 1
Production 2020 - carving the bottom 2
Production 2020 - carving the bottom 3

Painting

With the carves done, time to paint the text and artwork. Testors oil-based enamels, some of which are 30 years old, still hanging around from model airplanes I made when I was a kid.

Production 2020 - painting text 1
Production 2020 - painting text 2
Production 2020 - painting text 3

Interesting side note for an uninsulated basement during a cold streak in the winter in Buffalo. Oil-based enamels don’t like freezing temperatures even though they’re not water based.

Bring them upstairs for a few hours to warm up, and do the painting in the soldering cave rather than in the painting cave.

Production 2020 - painting face 1
Production 2020 - painting face 2
Production 2020 - painting face 3

USB Alignment

Earlier I alluded to the special care I took when designing the enclosure in F360 and the circuit board in Eagle. Need to ensure the USB jack on the Arduino Nano lines up with the hold in the enclosure wall.

With the enclosure done and the slow boat with the PCB’s finally arrived, time to see how it worked out…

Production 2020 - usb alignment 1
Production 2020 - usb alignment 2
Production 2020 - usb alignment 3

A little work with the drill press to make and countersink mounting holes and we’re in business. A dab of clear nail polish on each nut (applied after all the soldering was done) to keep it together in a workshop environment.

Black paint on the inside of the USB port makes it look pretty cool, even though I’ll really never see that part when its sitting on my bench in action.

Electronics

I always LOVE soldering onto a printed circuit board, way more fun than point-to-point. Double the fun when it is a professionally manufactured board with the spiffy solder mask and silk screen.

With all these buttons there’s still quite a bit of clipping, twisting, soldering, heat shrinking, splicing, and crimping to do.

Production 2020 - wiring 1
Production 2020 - wiring 2

Conclusion

Love. This. Project.

I learned so much over the two years and four iterations of this project.

Woodworking, 3d design, milling, Arduino electronics, Python programming, on and on.

The end result is a rugged, pretty, compact device that works beyond my expectations.

Production 2020 - face