DIY 3-axis CNC controller. CNC milling machine with autonomous controller on STM32

Among the wide variety of controllers, users are looking for self-assembly those schemes that will be acceptable and most effective. Both single-channel and multi-channel devices are used: 3- and 4-axis controllers.

Device options

Multichannel stepper motor controllers (stepper motors) with standard sizes of 42 or 57 mm are used in the case of a small working field of the machine - up to 1 m. When assembling a machine with a larger working field - over 1 m, a standard size of 86 mm is needed. It can be controlled using a single-channel driver (control current exceeding 4.2 A).

Control the machine with numerical control program controlled, in particular, it is possible with a controller created on the basis of specialized driver microcircuits intended for use for SD up to 3A. The CNC controller of the machine is controlled by a special program. It is installed on a PC with a processor frequency of over 1 GHz and a memory capacity of 1 GB). With a smaller volume, the system is optimized.

NOTE! Compared to a laptop, if you connect a desktop computer, you get better results, and it’s cheaper.

When connecting the controller to a computer, use a USB or LPT parallel port connector. If these ports are not available, then expander boards or controller converters are used.

Excursion into history

The milestones of technological progress can be schematically outlined as follows:

  • The first controller on the chip was conventionally called the “blue board”. This option has disadvantages and the scheme required improvement. The main advantage is that there is a connector, and the control panel was connected to it.
  • Following the blue one, a controller called the “red board” appeared. It already used fast (high-frequency) optocouplers, a 10A spindle relay, power isolation (galvanic) and a connector where the fourth axis drivers would be connected.
  • Another similar device with red markings was also used, but more simplified. With its help, it was possible to control a small desktop type machine - one of the 3-axis ones.

  • The next in the line of technological progress was a controller with galvanic power supply isolation, fast optocouplers and special capacitors, having aluminium case, which provided protection from dust. Instead of a control relay that would turn on the spindle, the design had two outputs and the ability to connect a relay or PWM (pulse width modulation) speed control.
  • Now, for the manufacture of a homemade milling and engraving machine with a stepper motor, there are options - a 4-axis controller, a stepper motor driver from Allegro, a single-channel driver for a machine with a large working field.

IMPORTANT! Do not overload the motor by using higher and higher speeds.


Controller made from scrap materials

Most craftsmen prefer control via the LPT port for most amateur-level control programs. Instead of using a set of special microcircuits for this purpose, some people build a controller from scrap materials - field-effect transistors from burnt motherboards(at a voltage of over 30 volts and a current of more than 2 amperes).

And since a machine for cutting foam plastic was created, the inventor used car incandescent lamps as a current limiter, and the SD was removed from old printers or scanners. This controller was installed without changes to the circuit.

To do the simplest machine Do-it-yourself CNC, when disassembling the scanner, in addition to the SD, the ULN2003 chip and two steel rods are removed, they will go to the test portal. In addition you will need:

  • A cardboard box (from which the device body will be mounted). An option with textolite or plywood sheet is possible, but cardboard is easier to cut; pieces of wood;
  • tools - in the form of wire cutters, scissors, screwdrivers; glue gun and soldering accessories;
  • board option that is suitable for a homemade CNC machine;
  • connector for LPT port;
  • a cylinder-shaped socket for arranging a power supply;
  • connection elements - threaded rods, nuts, washers and screws;
  • program for TurboCNC.

Assembling a homemade device

Starting work on homemade controller For CNC, the first step is to carefully solder the chip onto a breadboard with two power rails. Next will be the connection of the ULN2003 output and the LPT connector. Next, we connect the remaining pins according to the diagram. The zero pin (25th parallel port) is connected to the negative pin on the board's power bus.

Then the motor is connected to the control device, and the power supply socket is connected to the corresponding bus. To ensure the reliability of the wire connections, they are fixed with hot glue.

Connecting Turbo CNC will not be difficult. The program is effective with MS-DOS and is also compatible with Windows, but in this case some errors and failures are possible.

Having configured the program to work with the controller, you can make a test axis. The sequence of actions for connecting the machines is as follows:

  • In holes drilled at the same level in three wooden blocks, insert steel rods and secure with small screws.
  • The SD is connected to the second bar, putting it on the free ends of the rods and screwing it using screws.
  • The lead screw is threaded through the third hole and a nut is installed. The screw inserted into the hole of the second bar is screwed in until it stops so that it passes through these holes and comes out onto the motor shaft.
  • Next, you need to connect the rod to the engine shaft with a piece of rubber hose and a wire clamp.
  • Additional screws are required to secure the running nut.
  • The made stand is also attached to the second block using screws. The horizontal level is adjusted with additional screws and nuts.
  • Typically, motors are connected along with the controllers and tested to ensure correct connections. This is followed by checking the CNC scaling and running a test program.
  • All that remains is to make the body of the device and this will be the final stage of the work of those who create homemade machines.

When programming the operation of a 3-axis machine, there are no changes in the settings for the first two axes. But when programming the first 4 phases of the third, changes are introduced.

Attention! Using a simplified diagram of the ATMega32 controller (Appendix 1), in some cases you may encounter incorrect processing of the Z axis - half-step mode. But in full version its boards (Appendix 2), axes currents are regulated by external hardware PWM.

Conclusion

In controllers, assembled by CNC machines - a wide range of uses: in plotters, small milling cutters, working with wood and plastic parts, steel engravers, miniature drilling machines.

Devices with axial functionality are also used in plotters; they can be used to draw and make printed circuit boards. So the efforts spent on assembly by skilled craftsmen will definitely pay off in the future controller.

The article describes homemade machine with CNC. The main advantage of this version of the machine is the simple method of connecting stepper motors to a computer via the LPT port.

Mechanical part

bed
The bed of our machine is made of plastic with a thickness of 11-12mm. The material is not critical, aluminum can be used, organic glass plywood and any other available material. The main parts of the frame are attached using self-tapping screws; if desired, you can additionally decorate the fastening points with glue; if you use wood, you can use PVA glue.

Calipers and guides
Steel rods with a diameter of 12mm, length 200mm (Z axis 90mm), two pieces per axis, were used as guides. The calipers are made of textolite with dimensions 25X100X45. Textolite has three through holes, two of them for the guides and one for the nut. The guide parts are fastened with M6 screws. The X and Y supports have 4 threaded holes at the top for attaching the table and Z axis assembly.


Caliper Z
The Z axis guides are attached to the X support through a steel plate, which is a transition plate, the dimensions of the plate are 45x100x4.


Stepper motors are mounted on fasteners, which can be made of sheet steel with a thickness of 2-3mm. The screw must be connected to the axis of the stepper motor using a flexible shaft, which can be used as rubber hose. If you use a rigid shaft, the system will not work accurately. The nut is made of brass, which is glued into the caliper.


Assembly
Assembly homemade CNC machine, is carried out in the following sequence:

  • First you need to install all the guide components in the calipers and screw them to the sidewalls, which are not first installed on the base.
  • We move the caliper along the guides until we achieve smooth movement.
  • Tighten the bolts, fixing the guide parts.
  • We attach the caliper, guide assembly and side frame to the base; we use self-tapping screws for fastening.
  • We assemble assembly Z and, together with the adapter plate, attach it to support X.
  • Next we install lead screws along with couplings.
  • We install stepper motors by connecting the motor rotor and the screw with a coupling. Please note strict attention to ensure that the lead screws rotate smoothly.

Recommendations for assembling the machine:
Nuts can also be made from cast iron; there is no need to use other materials; screws can be bought at any hardware store and cut to suit your needs. When using screws with M6x1 thread, the nut length will be 10 mm.

Machine drawings.rar

Let's move on to the second part of assembling a CNC machine with our own hands, namely the electronics.

Electronics

power unit
A 12Volt 3A unit was used as a power source. The block is designed to power stepper motors. Another voltage source of 5 Volts and a current of 0.3 A was used to power the controller microcircuits. The power supply depends on the power of the stepper motors.

Here is the calculation of the power supply. The calculation is simple - 3x2x1=6A, where 3 is the number of stepper motors used, 2 is the number of powered windings, 1 is the current in Amperes.


Controller
The control controller was assembled using only 3 555TM7 series microcircuits. The controller does not require firmware and has a fairly simple schematic diagram, thanks to this, this CNC machine can be made by a person who is not particularly versed in electronics.

Description and purpose of the LPT port connector pins.

Vvyv. Name Direction Description
1 STROBE input and output Sets the PC after each data transfer is completed
2..9 DO-D7 conclusion Conclusion
10 ASK input Set to "0" external device after receiving the byte
11 BUSY input The device indicates that it is busy by setting this line to "1"
12 Paper out input For printers
13 Select input The device indicates that it is ready by setting this line to "1"
14 Autofeed
15 Error input Indicates an error
16 Initialize input and output
17 Select In input and output
18..25 Ground GND GND Common wire

For the experiment, a stepper motor from an old 5.25-inch was used. In the circuit, 7 bits are not used because 3 engines are used. You can hang the key to turn on the main engine (mill or drill) on it.

Driver for stepper motors
To control the stepper motor, a driver is used, which is an amplifier with 4 channels. The design is implemented using only 4 transistors of the KT917 type.


You can also use serial microcircuits, for example - ULN 2004 (9 keys) with a current of 0.5-0.6A.


The vri-cnc program is used for control. Detailed description and instructions for using the program are located at.


By assembling this CNC machine with your own hands, you will become the owner of a machine capable of performing mechanical processing (drilling, milling) of plastics. Engraving on steel. Also, a homemade CNC machine can be used as a plotter; you can draw and drill printed circuit boards on it.

Based on materials from the site: vri-cnc.ru

This is my first CNC machine assembled with my own hands from available materials. The cost of the machine is about $170.

I have been dreaming of assembling a CNC machine for a long time. I mainly need it for cutting plywood and plastic, cutting some parts for modeling, homemade products and other machines. My hands itched to assemble the machine for almost two years, during which time I collected parts, electronics and knowledge.

The machine is budget, its cost is minimal. In what follows I will use words that to an ordinary person may seem very scary and this can scare away self-built machine, but in fact it’s all very simple and easy to master in a few days.

Electronics assembled on Arduino + GRBL firmware

The mechanics are the simplest, a frame made of 10mm plywood + 8mm screws and bolts, linear guides made of a metal angle 25*25*3 mm + bearings 8*7*22 mm. The Z axis moves on an M8 stud, and the X and Y axes on T2.5 belts.

The spindle for CNC is homemade, assembled from a brushless motor and a collet clamp + a toothed belt drive. It should be noted that the spindle motor is powered from the main 24 volt power supply. IN technical specifications The motor is stated to be 80 amps, but in reality it consumes 4 amps under heavy load. I can’t explain why this happens, but the motor works great and does its job.

Initially, the Z axis was on homemade linear guides made of angles and bearings, later I remade it, photos and description below.

The working space is approximately 45 cm in X and 33 cm in Y, 4 cm in Z. Taking into account the first experience, I will make the next machine with larger dimensions and will install two motors on the X axis, one on each side. This is due to the large arm and the load on it, when work is carried out at the maximum distance along the Y axis. Now there is only one motor and this leads to distortion of the parts, the circle turns out to be a bit elliptical due to the resulting flexion of the carriage along the X.

The original bearings on the motor quickly became loose because they were not designed for lateral load, and this is serious. Therefore, I installed two large bearings with a diameter of 8 mm on the top and bottom of the axle, this should have been done right away, now there is vibration because of this.

Here in the photo you can see that the Z axis is already on other linear guides, the description will be below.

The guides themselves are very simple design, I somehow accidentally found it on Youtube. Then this design seemed ideal to me from all sides, minimum effort, minimum details, easy assembly. But as practice has shown, these guides do not work for long. The photo shows the groove that formed on the Z axis after a week of my test runs of the CNC machine.

I replaced the homemade guides on the Z axis with furniture ones; they cost less than a dollar for two pieces. I shortened them, leaving a stroke of 8 cm. There are still old guides on the X and Y axes, I won’t change them for now, I plan to cut out parts for a new machine on this machine, then I’ll just disassemble this one.

A few words about cutters. I have never worked with CNC and I also have very little milling experience. I bought several cutters in China, all of them have 3 and 4 grooves, later I realized that these cutters are good for metal, but for milling plywood you need other cutters. While new cutters cover the distance from China to Belarus, I am trying to work with what I have.

The photo shows how a 4 mm cutter burned on 10 mm birch plywood, I still didn’t understand why, the plywood was clean, but on the cutter there was carbon deposits similar to pine resin.

Next in the photo is a 2 mm four-flute cutter after an attempt to mill plastic. This piece of melted plastic was then very difficult to remove; I had to bite it off a little bit with pliers. Even at low speeds the cutter still gets stuck, 4 grooves are clearly for metal :)

The other day it was my uncle's birthday, on this occasion I decided to make a gift on my toy :)

As a gift, I made a full house for a plywood house. First of all, I tried milling on foam plastic to test the program and not spoil the plywood.

Due to backlash and bending, the horseshoe could only be cut out the seventh time.

In total, this full house (in pure form) milled for about 5 hours + a lot of time for what was spoiled.

I once published an article about a key holder, below in the photo is the same key holder, but already cut on a CNC machine. Minimum effort, maximum precision. Due to the backlash, the accuracy is certainly not maximum, but I will make the second machine more rigid.

I also used a CNC machine to cut gears out of plywood, it’s much more convenient and faster than cutting it yourself with a jigsaw.

Later I cut out square gears from plywood, they actually spin :)

The results are positive. Now I’ll start developing a new machine, I’ll cut out parts on this machine, manual labor practically comes down to assembly.

You need to master cutting plastic, because you are working on a homemade robot vacuum cleaner. Actually, the robot also pushed me to create my own CNC. For the robot I will cut gears and other parts from plastic.

Update: Now I buy straight cutters with two edges (3.175 * 2.0 * 12 mm), they cut without severe scoring on both sides of the plywood.

Since I assembled a CNC machine for myself a long time ago and have been using it regularly for hobby purposes for a long time, I hope my experience will be useful, as will the source codes of the controller.

I tried to write only those points that I personally found important.

The link to the controller sources and the configured Eclipse+gcc shell, etc. are located in the same place as the video:

History of creation

Regularly faced with the need to make one or another small “thing” of a complex shape, I initially thought about a 3D printer. And he even started doing it. But I read the forums and assessed the speed of the 3D printer, the quality and accuracy of the result, the percentage of defects and the structural properties of thermoplastic, and I realized that this is nothing more than a toy.

The order for components from China arrived within a month. And after 2 weeks the machine was working with LinuxCNC control. I assembled it from whatever crap I had at hand, because I wanted to do it quickly (profile + studs). I was going to redo it later, but, as it turned out, the machine turned out to be quite rigid, and the nuts on the studs did not have to be tightened even once. So the design remained unchanged.

Initial operation of the machine showed that:

  1. Do not use a “china noname” 220V drill as a spindle best idea. It overheats and is terribly loud. The lateral play of the cutter (bearings?) can be felt by hand.
  2. The Proxon drill is quiet. The play is not noticeable. But it overheats and turns off after 5 minutes.
  3. A borrowed computer with a bidirectional LPT port is not convenient. Borrowed for a while (finding PCI-LPT turned out to be a problem). Takes up space. And generally speaking..
After initial use, I ordered a water-cooled spindle and decided to make a controller for battery life on the cheapest version STM32F103, sold complete with a 320x240 LCD screen.
Why people still stubbornly torment 8-bit ATMega for relatively complex tasks, and even through Arduino, is a mystery to me. They probably love difficulties.

Controller development

I created the program after thoughtfully reviewing the LinuxCNC and gbrl sources. However, I did not take either of the sources for calculating the trajectory. I wanted to try to write a calculation module without using float. Exclusively on 32-bit arithmetic.
The result suits me for all operating modes and I haven’t touched the firmware for a long time.
Maximum speed, selected experimentally: X: 2000 mm/min Y: 1600 Z: 700 (1600 step/mm. mode 1/8).
But it is not limited by controller resources. It’s just that the disgusting sound of skipping steps even on straight sections through the air is higher. The budget Chinese stepper control board on the TB6560 is not the best option.
In fact, I don’t set the speed for wood (beech, 5mm depth, d=1mm cutter, step 0.15mm) to more than 1200 mm. The likelihood of cutter failure increases.

The result is a controller with the following functionality:

  • Connection to an external computer as a standard usb mass storage device (FAT16 on an SD card). Working with standard G-code format files
  • Deleting files through the controller user interface.
  • View the trajectory of the selected file (as far as the 640x320 screen allows) and calculate the execution time. In fact, emulation of execution with time summation.
  • View the contents of files in test form.
  • Manual control mode from the keyboard (moving and setting “0”).
  • Start execution of a task using the selected file (G-code).
  • Pause/resume execution. (sometimes useful).
  • Emergency software stop.
The controller will be connected to the stepper control board via the same LPT connector. Those. it acts as a control computer with LinuxCNC/Mach3 and is interchangeable with it.

After creative experiments in cutting out hand-drawn reliefs on wood, and experiments with acceleration settings in the program, I also wanted additional encoders on the axes. Just on e-bay I found relatively cheap optical ecocoders (1/512), the division pitch of which for my ball screws was 5/512 = 0.0098 mm.
By the way, the use of optical encoders high resolution, without a hardware circuit for working with them (the STM32 has it) is pointless. Neither interrupt processing, nor, especially, software polling will ever cope with the “bounce” (I’m saying this for ATMega fans).

First of all, I wanted for the following tasks:

  1. Manual positioning on the table with high precision.
  2. Control of missed steps with control of deviation of the trajectory from the calculated one.

However, I found another use for them, albeit in a rather narrow task.

Using encoders to correct the trajectory of a machine with stepper motors

I noticed that when cutting out a relief, when setting the acceleration in Z to more than a certain value, the Z axis begins to slowly but surely creep down. But, the time for cutting relief with this acceleration is 20% less. Upon completion of cutting out a 17x20 cm relief with a step of 0.1 mm, the cutter can go down 1-2 mm from the calculated trajectory.
Analysis of the situation in dynamics using encoders showed that when lifting the cutter, 1-2 steps are sometimes lost.
A simple step correction algorithm using an encoder gives a deviation of no more than 0.03 mm and reduces processing time by 20%. And even a 0.1 mm protrusion on wood is difficult to notice.

Design


I considered it an ideal option for hobby purposes. desktop version with a field slightly larger than A4. And this is still enough for me.

Movable table

It still remains a mystery to me why everyone chooses a design with a movable portal for tabletop machines. Its only advantage is the ability to process parts very long board or, if you have to regularly process material whose weight is greater than the weight of the portal.

During the entire period of operation, there was never a need to cut out a relief piece by piece on a 3-meter board or engrave on a stone slab.

The movable table has the following advantages for tabletop machines:

  1. The design is simpler and, in general, the structure is more rigid.
  2. All the internals (power supplies, boards, etc.) are hung on a fixed portal and the machine turns out to be more compact and more convenient to carry.
  3. Weight of table and piece typical material for processing is significantly lower than the weight of the portal and spindle.
  4. The problem with cables and spindle water cooling hoses practically disappears.

Spindle

I would like to note that this machine is not for power processing. The easiest way to make a CNC machine for power processing is on the basis of a conventional milling machine.

In my opinion, a machine for power processing of metal and a machine with a high-speed spindle for processing wood/plastics are absolutely perfect different types equipment.

Create conditions at home universal machine at least it makes no sense.

The choice of a spindle for a machine with this type of ball screw and guides with linear bearings is straightforward. This is a high speed spindle.

For a typical high-speed spindle (20,000 rpm), milling non-ferrous metals (steel is out of the question) is an extreme mode for the spindle. Well, unless it’s really necessary and then I’ll eat 0.3 mm per pass with watering the coolant.
I would recommend a water-cooled spindle for the machine. With it, during operation, you can only hear the “singing” of the stepper motors and the gurgling of the aquarium pump in the cooling circuit.

What can be done on such a machine?

First of all, I got rid of the housing problem. The body of any shape is milled from “plexiglass” and glued together with a solvent along ideally smooth cuts.

Fiberglass has become a universal material. The precision of the machine allows you to cut seat under the bearing, into which it will go cold, as it should be, with a slight tension, and then you can’t pull it out. Textolite gears are perfectly cut with an honest involute profile.

Wood processing (reliefs, etc.) is a wide scope for the realization of one’s creative impulses, or, at a minimum, for the realization of other people’s impulses (ready-made models).

I just haven’t tried the jewelry. There is no place to calcinate/melt/cast the flasks. Although a block of jewelry wax is waiting in the wings.