CNC

Why CNC? | CNC and the Z axis | X axis | Y axis | Jog Buttons | Pendant | Spindle and speed | DRO | Pi-5 | Pi-5 setup | Pi-5 advanced setup | Mesa | MesaCT | Mesa wiring | Wi-Fi aerial | Video | Crunch

What is CNC and why do I want it?

OK. So now I have a
milling machine with a DRO (Digital ReadOut) in my workshop and hence I can cut metal accurately. I like it, I like it a lot, but this is 'hands on' machining. You turn on the spindle motor, a cutting tool goes round and round and you work the handles so the job moves under the cutter and is cut. Flat is pretty easy and so is straight. I first did this at school and teenaged me was enthralled. However remember that now, sixty years later, I have
Hitachi Seiki
, once a big league maker of large CNC (Computer Numerical Control) machine tools, on my CV. I can also admit that I had a
CNC controller
sitting next to my desk for years before I retired so I could write and test interfaces for it. Hence, when I think of machine tools, I tend to think in terms of, at minimum, power feeds with aspirations to full control to industry standards. CNC is the noble art of 'hands off' machining so... What I really need here is a comprehensive plan.

First point: I want a CNC option not a wholesale putsh. I want to be able to cut proper curves. Cutting curves by drawing them on the workpiece and then juggling the X and Y handles to stay on the line works but it doesn't really work (see the horrible picture on the right). Conversely I see a lot of YouTube videos where a mill has been CNCed to the point where just bunging a piece of metal on it to flatten it off will involve writing the production g-code. That is not what I want. I would like to do some CNC today and make a complex, designed part, then tomorrow rough out a bit of mechanical fix-it by hand and maybe type in a scrappy three liner to add a circle or a rounded corner.

So, I have three axes and a spindle motor to control: I decided to go with a simple stepper motor solution although this might/will probably call for the positioning lead screws to be upgraded to precision ball-screws at some point later on. Hence I need some stepper motors, plus the micro-step drivers and PSUs to suit. I will use that Pi-5 I previously bought to play with and a nice 15.6 inch 1920x1200 touch screen.

I was roughing out the software I would need to write when I came across references to LinuxCNC. This looked rather interesting and had to be worth a dig. Sadly the documentation is complicated. Well admittedly CNC is complicated. Here, if you understand things already, you can look up that obscure detail you need in moments, the manual is comprehensive, like 1400 pages of comprehensive. Everything is there but there is no ELI5 (ELI75?) version however. Then, sadly lots of the 'how I did it' videos on YouTube labour the obvious and skip over the important.
Now after a lifetime in the business of computers and electronics they are pretty much second nature to me now but I still need that first step to get on board with a new system. However all the examples I found jumped straight in with huge wire by wire hook up guides and then covered software with a brisque 'use these files'. However I sadly discovered that 'these files' were never quite enough to get a working system.
I almost gave up several times but it does G-code. Real G-code! Like
proper CNCs
.

The one really good thing about LinuxCNC is the forum. Those guys have dug me out when I was misunderstanding something and either explained it or pointed me in the right direction to figure it out for myself. I've tried not to be a pest and ask too many dumb questions but when I've been confused somebody always helped.

So, before we start let's be perfectly clear:
I offer this to the WWW as a totally unsupported example of 'this worked for me' or at least I think this is what I did. If you copy it and the resulting explosion wipes half your city and you thrown in jail forever that's not my fault. I'm not promising this is in any way right, best practice, according to the laws of where either you or I live nor conforms to Aristotelian ethics. It may be fattening, cause cancer in rats and invoke the endless wrath of the elder gods.
However may I wish you good luck. I found that rolling my own CNC was been lots of fun.


ELI75 style
I'm assuming your not 5, not computer illiterate and capable of googling if I use big words like sudo.
These are my notes. Brief notes or I'd be all day typing it. If you get to the screen I'm talking about my minimal comments will probably make more sense.
Yes I am 75 as I write this.

Warning: I have put the information on how I set up the Pi-5 and the Mesa 7i95t card that I used near the end of this page so it didn't mess up with the flow of the milling machine modifications (Click the Pi-5 on the bar at the top). Naturally this is not how I handled it. The Pi5/Mesa combo was my key tool for all stages of testing the steppers, the sensors and their signals.

Also: Watchout for the popups
-Hi Sally-
designated by the dotty underline as they are often used to clarify points. Also when I refer to 'the archive' that is the place where I zipped up lots of miscellaneous files and pictures that are relevant. Download archive.zip. The usual caveats apply especially with 3D printer stuff but as you get the openSCAD source and the STL files so you should be able to work it out. I didn't include the GCODE as isn't much use unless you sneak into my workshop and steal my printers because it is heavily optimised. Feel free to take off my logo and put on your own.


CNC, strategy, 42 and the Z axis

So the first thing I did was to buy a nice 19 inch 3U cabinet in steel (Ebay) to install all the components inside. I have too many very unhappy memories of prototype things, just connected by hook-up wire, skittering around on my bench and trying to throw themselves on the floor while I'm trying to do software.

It didn't take long to realise that that Z feed wheel on the top, at the back, would need to be considered first. Once installed on the bench, my bench is a good height while my ceiling isn't, it would be a problem to even reach it so winding in a big Z change could be tiresome to say the least. Hence the CNC design work needed to start with deciding how to put a power feed on that as a matter of priority.

The slide will go up another 9cms So pick a stepper motor. There isn't a huge range available in commonly available.

A simple check with a piece of wood, a piece of string and the old archery 'pull' gauge (probably just a rebadged suitcase scale marked up) shows the max 'stiction' torque winding upwards as variable but always less than 1.2Nm (measured 0.27Kg at 38cms). Also an important note here is that the Z thread gives 4mm travel per revolution.

So if I use a 4:1 belt drive with a Nema 23 stepper motor and controller I get the motors 1.9Nm holding torque scaled up by 4 to 7.6Nm so that should be adequate even as things get old and stiff (I know how that feels). Also the motor's 200 steps per rev gives me 200 steps per mm (aka 0.005mm/step), more if I want to multi-step it. The DRO also counts in 0.005mm steps aka 5 microns.

The Nema 23 is
a 58mm square, 76cm long motor
with a 1/4" shaft which I can get from StepperOnLine via Amazon. I will need a 10mm wide GT2 belt to handle the tension at max torque.
I displaced the motor rearwards a bit to ensure it always cleared the lock-screws and the support pillar.

The supplied Z axis
handwheel
is on a 10mm shaft with a 4mm keyway. The big snag is that the whole quill assembly is hanging from the fancy nut holding the handwheel. (Do not undo it without locking the Z-axis clamps or lowering the quill onto a block of wood or something first or it just hangs on the keyway block. Also note that it has a grubscrew within the nut to set the bearing tension.)

I ordered the stepper motor, a suitable controller (DM556T), an 80T 10mm bore 10mm belt wheel and a pack of 20T 6.35mm (aka 1/4inch) bore 10mm belt wheels. I had a 48V PSU on the shelf already.

An
online calculator gives me 98.14mm between centres for a 300mm belt so I also ordered 2 x 300mm x 10mm belts and planned around that spacing.
The stepper motor is rated for up to 1500rpm so 375rpm on the thread so 6.25rps so 25mm/second travel at full speed. Seems adequate but we shall see.

First I will need a mounting plate. If I replace the four M8 15mm cap head bolts holding the top onto the vertical slide with longer ones and use sleeves to transfer the tightening load from the base of the plate to the bottom of the counterbores I can select the length of the sleeves to align the ends of the belt. A quick check in the nuts and bolts draw came up empty handed so I ordered some 70mm M8 bolts. Probably too way long but they will cut down easily enough.

OK the top of the pillar is dimensioned in funny units and made in calliper unfriendly curves so I mocked up my initial
plate design
in the openSCAD 3D modeler, exported the STL model to UltiMaker Cura to get GCODE and 3D printed the relevant parts in ABS to
check the fit
. It was worth doing this as it was wrong and tweaking a number and hitting reprint is way easier than trying to recut precise holes in steel without, at this point, a DRO. The
final version
was plasma cut in 5mm steel for about £30.

Well the shaft at the top of the Z-screw was long enough for the handwheel or a pulley but not both. So I
turned the pulley boss down
so it was the same thickness as the handwheel and broached a keyway into it. To get the handwheel back on I drilled and tapped the pulley for three M8 bolts, made
some more spacers in brass
long enough to clear the long nut with a set screw inside, a top plate and a
'bolt'
with matching keys to suit the handwheel and it just bolted on and felt perfectly rigid.

So I tried to transfer the plate design into LibreCAD to get DXF but decided to write a file to be converted into LibreCAD commands which I shall include. This allows me to keep the design separate from the dimensions.
Here is a list of the files for the Z-axis system in the archive.
Z-plate.txt Z-plate definition to be expanded into LibreCAD commands
Z-plate.dxf Z-plate CAD file that I sent to the laser cutting people
Z-cover.scad OpenSCAD file for the box part of the cover
Z-cover.stl STL image for 3D printing
Z-chimney.scad Tube to cover the handwheel mount
Z-chimney.stl
Z-sensor.scad Microswitch mount for Z axis top/home switch
Z-sensor.stl
The 3D printer did a lovely cover and an 8 way cable carries lines for the two motor windings, the up/down switches and the top limit switch.
There is a LED in series with the limit switch that illuminates when the limit is reached.
I also made a carrier for a standard lever microswitch which goes at the top of the pillar and can be seen in the picture bottom centre. It is tripped by the top Z motion lock screw.

I set the switches on the driver module as
SW1on2.7A RMS
SW2on
SW3off
SW4onFull current
SW5off400 pulses/rev (2 pulses/step)
SW6on
SW7on
SW8on

I will discuss the wiring in the Mesa section.


X axis

The X axis was more of a problem fitting stuff in. I made a plate that mounted on the bolts astride the handwheel and shaved down the pulley to make things fit with both the pulley and the handle on the shaft.

At the other end the cable inlet needed a specially made right angle shroud so as not to foul the surrounding parts and still be able to flex as both X and Y move.

In the middle I needed to make a 3D printed part to work the microswitch to provide the limit switch. All the covers are retained by M6x30mm knurled clamping knobs.

The motor is a Nema17 running on a TB6600 driver from a 36V PSU it shares with the Y diver. It uses a 5mm GT2 belt on 80/20 tooth pullies.

I set the switches on the driver module as
SW1onStep mode 2A, 400 steps per rev
SW2off
SW3on
SW4onCurrent 1.0A (Max 1.2A)
SW5off
SW6on

The limit switch is tripped by part X-sensor which is retained by a bolt into where one of the Y-axis lock screws went.

X-plate.txt X-plate definition to be expanded into LibreCAD commands
X-plate.dxf X-plate CAD file that I sent to the laser cutting people
X-cover.scad OpenSCAD file for the box part of the cover
X-cover.stl STL image for 3D printing
X-sensor.scad An extender to press the home switch
X-sensor.stl


Y axis

The Y is a similar design concept but with a far more complicated shape to negotiate all the mill parts and the DRO encoder. Then I had to grind back the heads of the (longer) bolts to clear the back of the pulley. The blue round part in the middle is a cap to go over a convenient bolt head to make it trip the limit switch. Frankly it is not as swarf resistant and I hoped and might need a printed backplate to improve the seal.
Also removing the little settings turner under the handwheel did not give as much spare shaft as the X one did so the wheel intrudes into the casing a bit.

The rest of the details pretty much match the X axis although a normal, off the shelf, cable entry gland can be used.

Incidentally my use of 8 way plug and socket green connectors in a 3D printed screw down clip that worked other places was less successful here. It is just too bulky and the wires initially couldn't get round it without being carefully dressed every time I want to put the lid back on. I rewired things and that improved matters but it's a bit cramped.
Y-plate.txt Y-plate definition to be expanded into LibreCAD commands
Y-plate.dxf Y-plate CAD file that I sent to the laser cutting people
Y-cover.scad OpenSCAD file for the box part of the cover
Y-cover.stl STL image for 3D printing
Y-sensor.scad An extender to press the home switch
Y-sensor.stl


Jog Buttons

My Jog buttons aren't Jog buttons. There are perfectly good jog buttons on the touch screen with scale, step, speed selections and step or continuous modes, plus, of course I could use the pendant. However to use them you must first home the motion system so it knows where things are so it doesn't do anything stupid.

However a big part of my motivation to start this project was just that the Z-axis wheel was definitely not in a convenient position and I wanted to power operate it. These Jog buttons work when you just power up the system and in fact the simple interface I use doesn't even work once the system is homed. However I can flip on the CNC power switch and as soon as the Pi has booted and started linuxCNC enough to actually run the stepper motors these switches will work.

So I have my switches, nice, centre off, sprung to the centre rocker switches built into the protective covers over the stepper motor belts and wired back to the 7i95t.

The code is in
jog.hal and all it does is copy the debounced (slow) button signals to the halui.joint jog inputs which do work 'pre-homed'.


Pendant

I admit I bought this toy because I remember the dials in HS machines and I wanted one. It is a pretty simplistic Chinese device but it was relatively cheap on AliExpress.
I bought the model with the long springy cable and a 'wires only' interface and hooked it up to a DB15 plug so it was easy to attach. You can see the pinouts in the files but I ended up wiring the plug
like this and I swapped the resistor on the LED so it ran on 5V not 24.

The pin numbers are for my DB15 and they connect to the 7i95t's input pins with the commons taken to 5V to provide a pull-up.

Here are the connections to the 7i95t:
1Lamp+TB5-19OUT03
2ATB6-1IN1
3BTB6-2IN2
4A-
5B-
6MPG+5Vbus
7E-STOPTB5-11IN23
8GNDbus
9XTB5-1IN16
10YTB5-2IN17
11ZTB5-4IN18
124TB5-5IN19
13x1TB5-7IN20
14x10TB5-8IN21
15x100TB5-10IN22
TB5-3,6,9,12 and TB6-3 are connected to +5V (they provide a 4K7 pull-up to the pins)

The system is controlled by mpg.hal which is a deviant form of the mpg.hal in the LinuxCNC manual. I had to add a fast thread to accumulate the steps, something that the 7i95t driver does not usually need, and to convert their multiplexer friendly switch inputs to something to manage my three wires. This is the point where I discovered I could write my own HAL components and do it in C suddenly making HAL all simple (see sel3.comp).

NB: This is the exact opposite of my jog buttons in that it only works after you have homed the system.

I have coded the speed switch settings as x1 = .001mm, x10 = 0.01mm and x100 = 0.1mm so you can tweak to more detail than the motion system can deliver but still do a 10cm rapid on a single turn of the handle.

I have a preliminary system to control the spindle speed from the MPG using the axis4 channel. Press the button and move the dial and it takes over the spindle speed. Hold the button for ten seconds without moving the dial (configured in mgp.hal) and it drops control and reverts. Later I aim to add 'if a program is running then use Axis4 to control the spindle override function'. This is all software.

Well also...
...I had this bare rotary encoder that I pulled from an item going for scrap in a previous life. I thought it must be a good idea so, well before I bought the pendant, I cut a hole in the controller front panel and fitted it. Well I wired it into the 7i95t's encoder3 channel. I've checked it and it counts so I'm sure it will be really useful for something one day.

I wired it as
ATB2-1
BTB2-4
VCCTB2-6
GND3
This gives output in hm2_7i95.0.encoder.03.count at 4 counts per tick as it is counting the quadrature ticks.


Spindle speed control

Well the 7i95t promises a PWM (Pulse Width Modulation) output and that is why I am using the 7i95t_1pwmd.bin firmware load.
Halshow reveals the hm2_7i95.0.pwmgen.00.enable and hm2_7i95.0.pwmgen.00.value pins, I connected and a quick test shows that with .enable true .value is 0 to 1.0. Pin TB4-8 (STEP5-) being solid high at 0.0 and all low at 1.0 with TB4-9 (STEP5+) being the opposite.
The oscilloscope shows these outputs when set for 300rpm on my system configured for a 1500rpm max (ie: one fifth of the time the line is active), pin8 is at the top trace and pin 9 at the bottom.

I wrote a preliminary spin.hal and called it from postgui.hal. This did nice tests into an oscilloscope but now I needed some hardware to drive the 0-10V input:...
...allowing for the annoying fact that the speed controller on this mill is live to mains power.

I decided to make a box to go under the current controller because, although there isn't much in the existing compartment, it somehow manages to not have much space left either. The lid of my box is permanently bolted to the bottom of the existing spindle control box (dismantling everything to drill it while protecting the electronics from swarf was a bit fraught). My new parts all go in the bottom part which has 4 M3 bolts into
hot-fix brass ferules
in the lid to make it easy to release to work on it. (Use a soldering iron tool at 250°C.)

As usual the manual was missing a few bits. This is the how the mill was actually wired and this is what I built. This is second attempt at the box as 3D printed and as assembled.
The usual .scad and .stl files are in the archive.
ElectricalBoxTop.scad
ElectricalBoxTop.stl
ElectricalBoxBottom.scad
ElectricalBoxBottom.stl

The original plan, due to the 'live' speed controller's disrespectable attitude to mains power, was to use a simple opto-isolator fed resistor/capacitor low-pass filter (charge/discharge) circuit to swap in on the three wires to the speed control knob with no active parts. Disappointingly I could neither get it up to 10V nor any semblance of linear. So I found a compact, uncased 24V PSU on Amazon and put that in the box with the PWM signal feeding through an opto-isolator and now having lots of voltage headroom made things more manageable.

You can see from the schematics that what I did was to add
a pair of high current relays to takeover the motor direction wires so I can subvert the existing L-0-R reversing switch,
a solid state relay to actually turn the motor system on and off
a small relay to take the speed control potentiometer off line and substitute the smoothed PWM signal via a high voltage opto-isolator.
NB: Remember the potentiometer is a 'high insulation' part (because mains) and if you break it trying to get the knob off (spoiler: slacken the 10mm nut under the cover) Amazon lists them for £43 next day and AliExpress for 49p two weeks.
This provides for 'normal' manual mill operation if the CNC box is off but when it is calling for spindle rotation then it gives full spindle control ignoring the normal controls when the on-line relays pull in.

I have wired it to the controller with:
Spindle onOUT0-TB5-13
Spindle CCWOUT1TB5-15 Spindle PowerOUT2TB5-17
PWMSTEP5+TD4-9
Spindle pulsesQA5TB2-17

My current spin.hal and postgui.hal are here. You also need the two controls sspindle.comp, sstep.comp and the little script doit.sh to compile and make the man entries for them.

The spin.hal also provides delay functions so that on issuing an M3 the direction relays are allowed a moment to settle before the power comes on and then the spindle is allowed some more time to get up to speed before the ensuing motion commands are allowed to be executed.

The file also contains two implementations of demanded spindle-rpm to PWM value translation. The first is the simple linear model where 0 is 0, 1500 is 1.0 and everything else is just factored in. I used this for initial testing and it let me use the MPG to dial up and down but it is not realistic. The second is a table based system to get round the differences between predicted and actual. The controller isn't 0-10V as its documentation says but maxes out at about 5.7V in and is not very linear. I could adjust the resistors to get less than 10V on full scale but the table give quite reasonable results. This will do until the feedback control is built.

Speed
I wanted to send the spindle speed back to close the loop and servo control the spindle speed. I decided to accomplish this by fitting an additional opto-sensor to the 60 tooth chopper wheel in the head (because mains) so I pulled out the now redundant lead to the front tool guard hinge and put in a thin 3-core cable. This involved dismantling the power controller hinging arm and was not, I must confess, the most pleasant wiring job I've done recently.

I powered it with the 'on-line' 5V and linked the wires in my additional control box and fed it to encoder 5 on the 7i95t as +QA5 TB2-17.
Then I needed to switch the encoder into counter mode and scale it for rpm so I added these lines to spin.hal:
setp hm2_7i95.0.encoder.05.counter-mode true
setp hm2_7i95.0.encoder.05.scale -60
That gives me an RPM value in hm2_7i95.0.encoder.05.velocity-rpm
It's a bit jittery...

DRO

OK so I have the DRO and its 0.005mm linear encoders and I wanted to get that data onto the Pi and ideally for it to be of use to LinuxCNC to frig out some of the remaining 0.15mm backlash in my lead screws.
However there are snags all the way down.

Well electrically I was pleasantly surprised. There are two ways DROs connect: a two wire RS422 derivative or alternatively the bog-standard TTL that was my bread and butter design tool for years. The 7i97t has provision for both but RS422 doesn't share nicely so I would need a buffer. Get out the 'scope and it's bang-bang rail to rail 5V. Fake, but the best fake, TTL.
A quick check that my earths are safe and I can wire it straight in.
I put pairs of IDC DB9s male and female on the CNC computer box ad plugged the linear encoders into one and a M-F extender cable into the other to go to the DRO box. Everything worked boringly well.

There are, unfortunately, three or four wildly incompatible ways the 9 pin plug can be wired. I googled for them then prodded about with the 'scope and it was pretty obvious which one mine was. 2 GND, 6 A, 8 B. Hence I wired:
XYZ
2TB1-3TB1-11TB1-19GND
6TB1-1TB1-9TB1-17A
8TB1-4TB1-12TB1-20B

In the setup (see mesact later) I set the encoders to -200 aka 0.005mm and negative because we want the tool position when we are really measuring the bed.

This delivers X counts into hm2_7i95.0.encoder.00.counts and millimetres to hm2_7i95.0.encoder.00.position
Use encoder.01 for Y and encoder.02 for Z.

Pi-5

OK if you know Linux and the Raspberry Pi-5 this section is just going to be something you just dip into to see if I did it right.
If you use something other than a Pi then some of the discussion of Linux/Debian may help.

So what did I use?
Basically a
Pi-5 8G with a heatsink/fan bolt-on and a 500G NVME SSD on a Pimoroni adapter card.

Why the SSD?
Although SD cards aren't bad they have slightly dubious rep in Pi circles and anyway, the thing runs much faster on the SSD and we all like faster. Any reason for picking that particular interface card/hat style? None. Luck of the early adopter draw I guess. I like this implementation because the ribbon cable curves round the SD card holder and this has allowed me to pop in a standard Rasberryian SD and run something Raspberry specific to do test and set up things.

Why 8G?
Same thinking. 4G of RAM will probably do but if I want to grow my own stuff on it needing to upgrade would suck. In fact with the Mesa card doing the critical timings a Pi-4 would probably more than adequate.

Add to that the Mesa 7i95t interface card that actually costs a lot more than the Pi but it does all the heavy lifting in communicating with the Mill. There are other ways to do it but the 7i95t has a lot of IO and does its own internal step timing so you are not dependant on software running on the Pi to apply precise ticks to the drivers.

I used a 16inch/40cm touch screen with oodles of resolution. Touch on the Pi admittedly isn't good with known bugs going back years so I have experimented with a
hand held bluetooth keyboard/mousepad
but it's a bit small for my fumbly old fingers. I placed the Pi so its ports faced out of the front panel of the case so I can revert to a standard keyboard and mouse if required.

Basic Pi setup
I was assured I needed LinuxCNC 2.9 to handle the Mesa card I have so:
download the Pi5 version of 2.9.3 from https://linuxcnc.org/downloads
mine was rpi-5-debian-bookworm-6.1.61-rt15-arm64-ext4-2023-11-17-1520.img.xz

Burn it into a 16G SD with the Raspberry Pi Imager.
I think using a smaller card helps setting up as this makes the copy to SSD faster. You don't need big yet but use what you have.

Plug in the monitor/mouse/keyboard/power
Log on with username/password cnc/cnc
Open a terminal window.

Notice at the right of the top toolbar the
four boxes
. These are 'alternative' windows. You can open the configuration program in one, edit text in another and run linuxcnc in yet another. However beware. Letting the configuration program change a file you have open will not change that file in that editor and just going 'save' will probably all end in tears.
Also as the mouse wheel steps through these windows so if your display suddenly vanishes you probably just nudged the wheel.

If the text on the terminal window is stupidly small due to using a fancy high resolution screen, small size monitor or low resolution eyes:
select Edit | Preferences | Appearance | Font
increase the number at the end of the first line from the default 12 to 17 or above.

run sudo menu-config
Wireless | Activate a connection | NIGNET-5G etc.
Hostname:Pi-CNC
Networking:Activate: NIGNET-5G
Keyboard:Generic 105 | Other | English (UK) | English (UK) | OK OK No
Timezone:Europe London
Quit
Then I did
sudo reboot
so I got the name, the wifi and the keyboard active.

Create the usual update job:
nano update
remembering nano is not a mouse aware program (I tend to use micro) so move the cursor with arrow keys and put these lines in.
#! /bin/bash
sudo apt update
echo ""
sudo apt upgrade -y
echo ""
sudo apt autoremove -y

^O<enter> to save
^X to exit
don't forget to make it executable with
chmod +x update
Then run it, there was a bit to do
./update
And run it regularly.

Turn off the 'auto power down' feature before it drives you mad
Applications | Settings | Power Manager
General
When power button is pressed: Shutdown
Display
Display power management | Off
Security
Automatically lock session | Never Lock screen when system is going to sleep | uncheck

Now copy the SD to the SSD
These are the instructions for my unit, yours may differ but they usually put it in the box notes
(if it refers to a Raspberryian program it's good but you don't have it so modify my command line by changing the out-file from /dev/nvme0n1 to yours
sudo dd if=/dev/mmcblk0 of=/dev/nvme0n1 status=progress
It took about 5mins

sudo poweroff, pull out power, pull out the SD, power up again. We are now running on the SSD with LinuxCNC in the Activate menu ready to go.


Advanced Pi setup

OK. What I really want to do is to access this system from my familiar old desk top PC with its three big screens and my big comfortable chair not standing in the workshop.
That means I want to click on an RDC (Remote Desktop Client) in Windows and get a user screen into the Linux system and that the 'disk' drive comes up as a network device on my Wifi so I can copy files about as normal.

You need the Pi's IP address
hostname -I    note that is a capital i. Mine is 192.168.1.220

Install RDC so we can access it from a PC
sudo apt install xrdp -y
it starts itself.

NB: you have to log out the screen to login to cnc/cnc over the RDP as you can only have one user cnc logged in at a time.

Run RDC on a windows PC, put in the ip address, click Save and put it on your desktop. Open, use advanced to put in cnc as a username, password, save my credentials et al. You should be rewarded by a window into your Pi5.

To get rid of the "Authentication is required to create a color managed device" message
sudo nano /etc/polkit-1/localauthority/50-local.d/45-allow-colord.pkla
[Allow Colord all Users]
Identity=unix-user:*
Action=org.freedesktop.color-manager.create-device;org.freedesktop.color-manager.create-profile;org.freedesktop.color-manager.delete-device;org.freedesktop.color-manager.delete-profile;org.freedesktop.color-manager.modify-device;org.freedesktop.color-manager.modify-profile
ResultAny=no
ResultInactive=no
ResultActive=yes
No, I neither know nor care what it all does.

Next install Samba so I can network files to/from the PC
sudo apt install samba samba-common-bin smbclient -y
Edit the configuration file
sudo nano /etc/samba/smb.conf
below
workgroup = WORKGROUP
add
wins support = yes
comment out with ; the [homes] section header and following 6 lines right down to the next section
then add at the bottom (if you're using xrdp/RPC and nano just cut and stick it from here)
[cnc]
comment=Share folder with PC
path=/home/cnc
browseable=Yes
writeable=Yes
only guest=no
create mask=0777
directory mask=0777
public=no
save the file, generate a samba user called cnc with a password cnc using
sudo smbpasswd -a cnc
cnc
cnc
Now open \\Pi-CNC in the Windows Network explorer
expect to find a folder cnc
It will ask for credentials: cnc/cnc
don't forget to tick the 'Remember my credentials' box.
Drag the \\Pi-CNC folder onto your desktop for easy future access.

if you want to load the touch keyboard
sudo apt install onboard
Applications | Accessories | Onboard Settings
Layout: Full Keyboard
Theme: Model M

The screen I have needs more power so I need the Pi-5 1.6A option not the default 0.6A mode
see
https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#usb-boot-and-power-supplies
about half way down
run it
rpi-eeprom-config      to view the eeprom boot settings (works on Debian)
I got
[all]
BOOT_UART=1
POWER_OFF_ON_HALT=0
BOOT_ORDER=0xf461
      this is SD then NVMe boot order
I want to add
PSU_MAX_CURRENT=5000
USB_MAX_CURRENT_ENABLE=1
HOWEVER edit mode won't run on Debian (it complains it is a Pi4 for some reason)
so I plugged in a 'proper' Raspbrian Pi5 SD and it booted that
run
sudo -E rpi-eeprom-config --edit
this brings up nano, edit it, save it, wait for it to finish and
Remove the SD and repower to be back on the SSD.
That fixed it.



Mesa 7i95t setup

OK so what is this rather expensive and bulky Mesa 7i95t and why do I use it?
Convenience really.
The Raspberry Pi interface looked a bit fraught to me as, when I was first planning all this, I did not understand HAL or much about the way things worked. I was worried about getting a long way down the line and finding myself on a no-through-road situation. Knowing what I do now that might not be so true currently but I am certainly pleased with the Mesa and the level of support it gets in the LinuxCNC community.

So what does it offer?
It is a big 20K gate field programable gate array that bandies about numbers in the 100MHz zone.
The default field programable implementation provides:
Position encoders6
Servo/Stepper drivers6
Input pins24
Output pins6
Some serial port stuff2
I chose to use a non-default but quite standard load that swaps out the last servo/stepper driver for a PWM implementation so I can do an analogue spindle speed control (which you have probably already read about above).

Jumpers as I use it
W15DOWNUse IP address from EEPROM
W16UPie:10.10.10.10
W17UPAll P1 pins pulled up to 5V (how it came)
W18DOWN5V Breakout power off (default)
W21 W19 W13LEFTEncoder 0 single ended (for my TTL DRO)
W11 W9 W7LEFTEncoder 1 single ended
W5 W3 W1LEFTEncoder 2 single ended
W22 W20 W14LEFTEncoder 3 single ended (for my encoder wheel)
W12 W10 W8RIGHTEncoder 4 double ended (default)
W6 W4 W2LEFTEncoder 5 single ended for spindle speed

So problem 1: we need to connect it up.
Well the 5V is easy. I have 30A of the stuff available.
Networking is not so instantly obvious.
Well it is obvious.
The Mesa card plugs into the Pi with a 10cm cat6 jumper and the rest of the world uses WiFi.
However we need to explain that to the Pi...
Dual networking:
I want the Pi to be 192.168.1.220 on my wifi
and 10.10.10.11 on the Ethernet stubby

The default system seems not to do that so change to Network Manager
sudo apt install network-manager network-manager-gnome
This added a networking icon on the toolbar (a sort of bar graph thingie)
A reboot killed everything but a power off, wait, on made it better with a wifi connection.

However clicking the icon ended up with a "System policy prevents wi-fi scans" pop-up and a system hang when attempting to password it.

Applications | Settings | Advanced Network Configuration
I think I selected wired and + and selected ethernet...
Ethernet | Wired Connection 1 | gear icon bottom left
Ethernet tab
device: eth0 (should be already)
IPv4 settings
method: manual
address: 10.10.10.11 / 255.0.0.0

To get rid of that stupid lock you out message
sudo su
cd /etc/polkit-1/rules.d
nano 50-123.rules
polkit.addRule(function(action, subject) {
if(action.id == "org.freedesktop.NetworkManager.wifi.scan") {
return polkit.Result.YES;
}
});
save etc.
No, I haven't a clue what it does but it works.
You don't appear to be able to configure networking over the network, that makes sort of sense, so that must be done on the real screen et al.
Anyway it all seems to work now.


MesaCT

OK, so now we have a card with 5V and an ethernet connection we need to configure it so that LinuxCNC knows it is there and how to talk to it.
Well the official kit can do it but it's complicated and you need to attend to a lot of details. However a gentleman has stepped into the breach, understood and coded the solution to the problem and then wrapped it in a GUI for all us freeloaders to use. Use the forum. You'll meet him there. Smart guy and very helpful.

Download MesaCT to set it up

Starting from scratch...
sudo apt install python3-pyqt5 python3-packaging python3-distro zip git
git clone https://github.com/jethornton/mesact.git mesact
Make a desktop icon: Left button the desktop and Create Launcher
Name: MesaCT
Command: ./mesact
Working Directory: /home/cnc/mesact/mesact/src
Create (button bottom right)
Run it
documentation
https://gnipsel.com/linuxcnc/mesact/index.html

This is my configuration. It started as a minimum system to launch for test with no switches et al
I just kept pushing the 'Check Config' menu item to see what was missing
Then when things worked I kept adding stuff
This is where I ended up:

Machine tab:
Machine:
NigMill
Load this configuration at startup
Mesa Setup:
Board: 7i95T
IP address: 10.10.10.10 (assuming jumpers for: EEPROM: W15: down, W16: up)
Firmware tab:
It says 'not downloaded' so:
Select Download menu and Firmware and it does it.
Mesaflash tab
This offers several firmwares the default is 7i95t_d.bin so I verified
it and it matched. (deselect reselect to get display)
I changed this to get PWM outputs and so used: 7i95t_1pwmd.bin
6 Axes of Step and Direction
6 Encoder Input
1 Smart Serial Port
1 PWM (only on the PWM firmware)
24 Inputs
6 Outputs
P1 Daughter Card
Options
Step generators: 6
PWM generators: 1 (only on PWM firmware)
Encoders: 6
Settings tab:
GUI: Gmoccapy
Linear Units: Millimeters
Position Offset: Relative
Position Feedback: Actual
Maximum feed override: 1.0
Jog Slider Settings:
Minimum Linear Velocity: 0.0
Default Linear jog Velocity: 0.5
Maximum Linear Velocity: 1.0
Machine Settings: box on the right side
Maximum Linear Velocity: 10 (I'm working on this)
7i95T tab:
Drive 0 1 2
Speeds calculated on NEMA17 at 2000rpm (3000) NEMA23 at 1200rpm (1500)
Drive:012
Axis:XYZ
Scale: pulses per mm: 2mm per rev *4 *200800800400pulse/unit
Min limit:-328-124-206
Max limit:000
Max Velocity:151520units/second
Max Accel: >1sec to full speed151515
PID:
press 'Stepgen Values' for default PIDs
press 'Default Values' for Following Error values
Homing:
my homing is messy as my home switch is at the positive end of the bed
Home000
Home sequence012
Home offset0.50.50.5
Home Search Velocity555
Home Latch velocity-1-1-1
Home Final velocity111
all checkboxes clear
Stepgen:
My X and Y are TB6600 drivers and I assume the Z inputs are similar
Encoder
scale: -200
The negative limits are because my home switches are at the most positive end.
NB: I had to reverse the X and Z directions to make it match the DRO

Inputs (others will be defined around them but this keeps the wiring sane)
7X limitJoint 0 homeTB6-11
10Y limitJoint 1 homeTB6-16
13Z limitJoint 2 homeTB6-20

Outputs
0Spindle ONTB5-13
1Spindle CCWTB5-17
2SelectTB5-19Used for spindle power in spin.hal
3SelectTB5-21Not used yet
4SelectTB5-23Used for MPG lamp in spin.hal
5Motion EnableTB5-24Inverted in custom.hal and used to enable/disable the stepper drivers
TB-5 14,16,18,20,22 wired to 5V bus, TB-5 23 wired to 0V
NB: The invert doesn't seem to work. Set the flag manually.

Options tab:
Display tab:
Manual tool change:On Screen Prompt
Jog increments:.001mm .01mm, .1mm, 1mm, 10mm
Display seconds:2
HAL tab:
Custom HAL File
Post GUI HAL File
Halui User Interface
These are created if they don't exist or just offered to edit.

Don't forget to build the config and 'set load on start'.
You can only recover 'built' config data so don't exit without a build.

That builds or modifies these files
nigmill.ini
main.hal
io.hal
custom.hal
postgui.hal
tool.txt

Run the menu item Applications | CNC | LinuxCNC
Chose My configurations | NigMill | NigMill
and check the 'Create Desktop Shortcut'.
OK
The first time you launch it you have to 'Mark Executable.

If you don't have the card yet it configures OK but won't run.



Mesa Wiring

Click through for zoomable printable PDFs.





Wifi aerial

I discovered that the standard Pi-5 only works on WiFi with the driver box lid off. Apparently my 19 inch 3U steel case screens things much better than I expected. I found this surprising as the router was only about a meter and a half away. I ordered
the bits
to put a socket on the Pi to connect it to an aerial at the back of the case.

This involves soldering a surface mount 3x3mm socket to the Pi-5 PCB and moving another 0.6mm component so it is hardly a job for the faint hearted or the fumbly. This is a picture of the socket involved. Yes that is a standard 20mm UK penny it is sitting on. Sneeze and you've lost it.





And finally

So I clicked Home All on the touch screen and...





Pride goeth before destruction, and an haughty spirit before a fall.
Proverbs 16:18 KJV

So the wiring was virtually finished, I had written it all up and that was it. The hardware was now basically done. It was time to move the mill onto the bench so it could get its final software tweaks and start to earn its place in my workshop. I was pleased to say the least.

Hence I started to action my cunning plan to enable a 75 year old to reposition a machine tool that weighs more than he does into a confined space.
It all started OK. The
winch lifted the mill
to the required height and I pulled out the workmate it had sat on since I unboxed it and rolled in the platform I had built on the welding trolley. I lowered it gently and detached the winch. Then I started to manoeuvre the trolley into a position to slide the mill back onto the bench.

However the welding trolley then progressively collapsed, as if in slow motion, and finally my lovely milling machine slid off the platform and crashed to the floor. It appears the trolley was not quite as strong as I thought. Oh bother.

I grumbled for a bit (I didn't cry although later I did need to eat a whole 500ml pot of therapeutic ice cream) and then I messaged Joel (next door) and he was at home and happy to come round and help. We picked it off the floor and got it on the bench but there was rather a lot of damage. The Y control box was utterly scrapped with even the 5mm steel plate it was based on decidedly bent. There was also going to be a lot of 3D printing to do over. Sadly the X handle wobbled as you turned it so that was
bad news on that leadscrew. However I first invested my time in getting it all bolted down to the bench before starting on a total damage report. After all it's only metal and plastic. It can be fixed.<sigh>

So the remains of the X and Y driver boxes were gathered, the covers reprinted and the damaged bits inside replaced.
The bent Y-plate was percussively readjusted (I even got the creases out of the welding trolley).
The bent X leadscrew was improved and is almost straight.
Some redesigning and a lot of 3D printing was done (I had a list of details to change if I needed to remake things so I took the opportunity to include them into the cad files).
The wiring for the spindle wasn't really finished when I moved it, just hooked up, so that was done properly.
The damaged X and Y cable ends were remade.

Putting the clamping bolts for the Y leadscrew back in was annoyingly fiddly so I knocked up a
quick alignment tool
on the 3D printer to help to
align the far end
of the thread. It's in the archive as Y-tool. It was such a success that I made a similar
X-tool
to help align the other axis. The final version of that had the top of the hole sawn off so I could see past it to assure myself that the 'nut' was upright and then that I could get it out easily.

The DRO went back together remarkably painlessly although I admit I only roughed the gap to make sure it was close but never touched as the magnetic strip hadn't moved.

And then I discovered the real reason the Y gib was loose and wouldn't adjust properly. The casting it ran in was cracked and distorted. I confess I had gone round in a loop because nothing had looked obviously damaged and I tried shimming out the tapered gib but that made the fit better and the problem worse.

What is the picture?
This is the right hand end of the joint that slides in the Y direction, fore and aft viewed from the front. The grey is the base casting and what you see is the right hand side of a dovetail. The silver is the sliding part and the rhomboid thing is the end of the 'gib' that fills the gap between them to snug everything up so you get slide without wobble.
Gibs come in two sorts.
Simple parallel sided blocks
with a line of screws with locknuts to tighten things up or tapered gibs with an about 1% taper against a matching taper on the mating face so sliding the gib further through the joint tightens things. The round hole is for the bolt that moves the gib and there is another one on the far end so when they are both tightened the gib is locked in place.
You can just see the crack going right from the threaded hole and the bottom of the saddle is angled down lifting the top. The crack and distortion are only at the front hence my attempts to 'thicken' the gib made the rear end bind before the slop in the front was reduced.


First call was to email the supplier about
a replacement part
.
The second was to fit a 'normal' gib screw in the slide lock hole to take up the slack at the front to enable me to continue work fixing things.

I will continue writing here when I hear back.




By Nigel Hewitt