Showing posts with label drilling. Show all posts
Showing posts with label drilling. Show all posts

Friday, 21 June 2013

CNC testing with Mach3

It has taken a bit of trial and error and a good, old-fashioned, low-tech method of validating our CNC setup, but we're thrilled to see that it finally looks like it's working.

To begin with, we placed a pen (instead of a drill) in the z-axis and fiddled with the motor tuning settings in Mach3. We had no idea how many turns per unit (i.e. millimetre) we needed, so went with a default of 200 (assuming that the steppers were 200 steps/rev). The grid it plotted looked like we'd used inches instead of millimetres - the gaps between the dots were massive!

To simplify things, we replaced our grid with a row of three dots, using the g-code

G0 Z0
G0 X0 Y0
G0 Z2
G0 Z0
G0 X10 Y0
G0 Z2
G0 Z0
G0 X20 Y0
G0 Z2
G0 Z0


to draw a row of three dots on a sheet of paper. We checked our Mach3 settings and confirmed that we had, indeed, set the default units to mm and not inches. After measuring with a steel rule, we confirmed that the dots were not actually an inch apart either.

So we were pretty sure that the machine was set up for millimetres (but not 100% convinced) but had no idea of the leadscrew pitch. Inspired by Steve's coding method - where if something works but not quite, you keep applying multipliers and choosing different numbers until it's close enough - we set to work changing the values in the Mach3 settings. Firstly by reducing the steps per millimetre down to 100.

This time, the spacing between the dots looked better, but we were now about 12mm apart, not 10.
Reducing the steps per millimetre to 90 brought the dots too close together, but it seems that 95 is the magic number for our machine:


Each dot was perfectly 10mm apart - exactly as the g-code described.


(the pattern of dots in this photo shows a grid supposedly drawn at 0.1" pitch, but at 100 steps per mm, our machine drew them slightly too far apart. Repeating this later, at 95 steps per mm, resulted in a perfect 0.1" grid)

Thursday, 20 June 2013

SVG to g-code. Now we're getting there!

Using a different coloured dot as our origin marker works perfectly!


And the great thing is, by changing the multiplier (at the minute we're using 25.4/90 to convert an image at 90dpi into millimetres) we can output our g-code in any units that the cnc machine requires.

One thing we have noticed, however, is that there's no real control over the order of the dots - the svg file appears to write them in the order they were drawn on the screen. That's fine for a simple example like this, but could be a bit of a nightmare when importing files from other applications.

The generated g-code (obviously) follows the drawing order of the svg file, which may not necessarily by the most efficient path between points.

By following the points in our svg file exactly, we would end up with a drilling pattern something like this:
So the last little bit of our project to do now, is to add in some path optimisations. We've already done something similar in the past, with our miniature CNC drill, so it shouldn't be a major problem.
Because our CNC is pretty accurate this time (the miniature one had loads of backlash because of the super-cheap stepper motors) we should be able to implement a "move to nearest point" routine to reduce the amount of time the drill head spends travelling from one point to the next (and hopefully reduce the overall drilling time for each entire board).

Tuesday, 9 April 2013

Preparing for small scale production of PCBs

For a number of years, we've been thinking about the future of production and manufacturing. While everyone else seems to be "scaling up" and embracing globalisation, perhaps we're been a little perverse in going the other way. Or maybe we're just "ahead of the curve" and everyone else will be wrestling with the logistics of having stuff made in China, a good three or four weeks away, and shipping stuff half way around the globe, in order to save a few pence-per-unit in production costs.

Here at Nerd Towers we really do believe that the future in manufacturing could (if not should) be through a series of cottage industries. With access to tools like laser cutters, 3d printers, open source electronics, and funding platforms such as indiegogo and Kickstarter, there's no reason why we can't all be making and manufacturing at home. Online retail platforms like eBay, etsy and tindie are perfect for selling products "on demand" - if you're confident you can make a product as it's required, you can start selling without the need to carry lots of stock, or have warehouses full of products tying up all your money. Yet for a lot of physical products, the first thing anyone does when they hit their funding target (on sites like Kickstarter and indiegogo) is to "tool up" and get stuff made in China.

What if we could all become designer, manufacturer, distributor and retailer all in one?
Sure that takes a lot of effort - but running your own business was always going to be that way. The current phenomenon of "drop shipping" - i.e. your customers order from you and you get your supplier to ship directly to them - is just an example of acting as a middle-man, creaming a slice from the profit and letting everyone else do the work. A nice idea - but unsustainable: not everyone can be a middle-man. Someone somewhere has to do some work. So why don't we do that work, bring manufacturing back in-house and provide opportunities for people to work for themselves, from home?

Maybe it's just a pipe dream. But we're determined to give it a try!

Having seen the incredible success of the boardgame Dreadball - something we'd never even heard of until a few weeks ago - we're looking to use a boardgame as a product to try this idea out. In fact, we're building a board for this very board game, with a view to producing manufacturing methods that anyone can use at home to make similar products.

Each board will make use of about 40 "modules", arranged to make a playing surface. If we were building this as a one off, that would mean lots of press-n-peel or maybe even a few hours with some car paint and a laser cutter. But what if we needed to make three or four of these things? What if we needed to manufacture 100+ pcbs?

The easy answer is to draw the layout as gerber files and send off to China, wait four or five weeks and assemble when they arrive. But that goes against the grain of "just in time manufacturing". What if our customers want their gaming boards in under the six weeks it would take? We need to be able to make our own PCBs - quickly and easily (note, cheaply is not the main concern here. Of course price is a consideration, but shouldn't be the driving force).

Now what if we could make large numbers of PCBs quickly? We've already tried CNC milling and drilling PCBs (messy) press-n-peel (expensive and can be sometimes problematic) and laser-etching (slow and inconsistent). One approach we haven't yet looked at - but still used in a large number of semi-automatic manufacturers - is silkscreen printing. Here's a video explaining the whole process:


With screen printing, on a small scale, we could print single- or double-sided boards and modify our CNC drilling machine to drill them afterwards (we'd need to use rivets for through-hole vias to avoid having to go down the whole electro-plating route).

As ever, we're looking for a desktop rather than a workshop-sized solution. So we're after making a small screen printing press, capable of printing up to eurocard size (160mm x 100mm). Our drill already handles eurocard sized boards pretty well, so we'd also need a UV exposure box, suitable for exposing eurocard sized boards.

Of course, in the real world, we'd scale all this up and have A3 or even A2 sized silkscreens, massive sheets of copper board and panellise all our PCB designs. But then we're back with the problems of industrialisation - keeping large stocks of large sheets of copper board is a headache in itself. Storing all the equipment when not in use (we're not looking to build a PCB factory here, more a desktop method of producing lots of PCBs quickly) and having lots of materials hanging around the place is the exact opposite of what we're trying to achieve.

If cottage industry style manufacturing is going to be successful, we need to keep it desktop-sized. After all, it's only once printers become desktop sized that we had the home desktop published revolution in the late 80s, early 90s. It's only since 3d printing has become desktop-sized that we've seen the boom in RepRap and similar 3d printing technologies. Likewise, if home-base manufacturing is to be successful, it needs to be something that can be put got out, used, and put away again - to clear the dining room table in time for tea!



Saturday, 9 March 2013

Linear rails for possible CNC?

A few weeks ago, at one of our Thursday BuildBrighton meetings, Matt suggested another cnc machine idea.   We've already completed one - a pcb drilling machine - and while the mechanics and software side of things were pretty good (for a £30+ cnc) the quality of the stepper motors was always a little suspect!

These cheap little stepper motors are all over the internet (and despite being rated at 5v as this one is, we found running them at 7v-9v the minimum, else they stall really really easily, but they can handle being driven hard at up to 12v. Beyond that, we've no idea - we didn't want to intentionally burn one out!)


What's not immediately apparent from this photo is that the shaft is actually offset from the centre:


And that's because, inside, there's a load of internal gearing which gives these little motors a pretty decent amount of torque for such a small package. In fact, the motors we had were geared by 1:64 on a 1/64 stepper motor - meaning they required 4096 steps for one complete revolution. By the sounds of things, perfect for ultra-tiny movements, and therefore precision accuracy.

Unfortunately, the internal gearing comes with a price - backlash!
When you send up to 100 step pulses to these motors, they can either move a great distance (depending on the size of the cog the motor is turning of course!) or they may not move at all, as all the slack in the cogs is taken up. This can be compensated for, a little, in software, but it's not ideal. So a while back, when some cheap steppers came up on eBay, we got hold of three decent motors and waited for the opportunity to present itself...


As often happens, when eating pizza and talking rubbish at BuildBrighton, discussions soon got around to making another cnc machine - this time with a multiple head attachment, for doing solder paste spotting as well as pick and place for SMT components. We already had the stepper motors, we've got access to equipment for cutting frames, inside of messing about with cheap-and-ok, we thought if we're going to do it, we'll make a pretty decent spec machine this time. And that means linear rails....

This morning, Mr Postie dropped off another peculiar looking package at Nerd Towers, covered in hieroglyphics from the Far East and we tore into it:


Yay! 12mm linear rails. Perfect for any decent-sized cnc machine (up to about A3 cutting bed size we reckon, certainly more than enough for up to A4). They're actually quite chunky but in a reassuring way. The mounting holes are already tapped, ready to take an M5 bolt.



Check out those tiny little ball bearings! These rails (we've got six) are going to be perfect, at least for our X/Y axis on the next CNC machine (whatever that is, whenever it gets made). They're actually quite big for a z-axis, unless Matt has ideas about making a massive monster-sized machine.......

Friday, 21 September 2012

CNC drilling machine - FINISHED!

With the new path finding routines in our CNC drilling software, and changes to the firmware to allow the user to manually jog the drill head up and down to get more precise alignment during initial set-up, we're finally happy to say that our cheapo CNC drilling machine is finally complete.
Or at least, complete to a state that we're happy to release for anyone else to have a go at making their own.

The last little part of the test was making sure that the machine could drill a PCB even when placed on the cutting bed at an angle. Here's a video showing exactly that:


The drilling is accurate enough for us now (there's still a little bit of play in the x-axis, but we seem to have done enough to remove/reduce any play in the y axis, even when the bed still needs to travel up-and-down in order to correct for the board being at an angle)

Here's the final board, as drilled in the video:


The holes on the bottom-right-hand edge may not be absolutely bang on, but they're good enough to make the board usable, and are about as accurate as you could get by drilling the board by hand. The photo seems to emphasise the amount of drift - it's probably less than 0.5mm away from the centre of the hole.

Having successfully completed a cnc drill test, we put the machine away!


We reckon our machine fulfills all the criteria set in the CNC drill challenge.

  • You can load NC compatible drill files to operate the machine
  • It cost less than £50 to build, completely from scratch with new (no salvaged) parts
  • It's accurate to within 0.5mm (despite the dodgy cheapo stepper motors)
  • The footprint is less than a sheet of A4 (in storage mode, it's about 210mm x 160mm)


It's been a long (and sometimes painful) journey, but it feels great to finally complete a project, not just to a point where it's working, but to be able to compare it to a list of criteria drawn up at the start, and to be able to tick every one off the list!

Along the way we were introduced to brushless motors and their servo-protocol control boards, created our own stepper motor control boards and our own USB-based protocol for moving them, and proved that rack-and-pinion gearing can be used just as successfully for CNCs as belt drives and leadscrews.

If we were to do the whole thing again?
Probably it'd look pretty similar. Maybe instead of a travelled bed-on-wheels we might use rails (similar to the x-axis) because there is a lot of play in the y-axis. But then again maybe not?

Any improvements?
Of course. Better stepper motors would be a great start. When energised, a stepper motor should have no movement in it at all - our steppers have 1mm-2mm of play because of the internal gearing. But then again, this does give us simple movement commands - no messing about with micro-stepping or any of that tricky stuff! We love the simplicity of the rack-and-pinion approach: belt-drives and leadscrews may be more popular, but we reckon we'd stick with ours.

The custom software is enough to make the device usable, but the protocol for sending x- and y- axis values is so simple that allow anyone else can write their own controller software. The latest firmware not only allows you to set a the number of steps to move in both x- and y- axes, but you can also now provide a "ratio" (for every three steps in x, move one in y for example). This means that if a vector line is broken down into enough parts, the machine could be modified to do simple milling - an idea that Justin from BuildBrighton is already working on!

Saturday, 15 September 2012

CNC software update

One of the main problems with getting absolute accuracy with our CNC drilling machine is overcoming backlash. We've loads of it. Not only between the cogs and the gears on our gantries, but inside the cheap little stepper motors too. Because the motors themselves are geared down inside, there's loads of backlash/slack on the actual motor spindle - and that's before any slack we introduce with our plastic push-fit rack-and-pinion arrangement to drive the axes.

All that said, we're still getting pretty good results, by compensating for backlash whenever we change direction in each axis (for example, whenever the x-axis gantry is travelling left-to-right, and we need to reverse it, to move right-to-left, we add in an extra number of steps to the move command, to take up any slack in the system).

Looking over our software, the "move-to-nearest-point" may make pretty efficient use of time, but because of the number of times we change direction over the course of drilling a board, there are plenty of opportunities for backlash/slack to affect our accuracy.

We've changed our driver software to use calculate different paths now.
Previously, it started at one point and simply picked the nearest undrilled point to the current location:


Now, we're going to move the head to the top-left-most point on the board, and drill them in a strict left-to-right, top-to-bottom sequence:


Although not shown on the screenshot, we're also planning on "overshooting" any point when moving the gantry from right-to-left, before moving to the correct location. The reason?

Doing things this way, we should help reduce (if not eliminate) backlash/slack in the y-axis, since the bed will only ever be travelling in the top-to-bottom direction. By overshooting each point when travelling from right-to-left, we're also ensuring that every hole is approached from the top-left corner so the system should be tight when travelling from top-left to bottom-right.

Hopefully this will help reduce the amount of backlash in the system, and produce a more accurate drilling action.

That's the theory taken care of.
The software is almost ready for testing.
There's only one thing left to do - and that's try it out!

CNC drill - more testing

Another Thursday, another post-Midnight testing session at BuildBrighton - this time we're trying to handle play in our cnc drilling machine which is still causing some of our boards to be drilling slightly off.
We managed to get the drill head spinning the right way, and slow down the servo movement (rather than just ram the drill bit into the cutting board at full speed) and it's certainly helped.

Here's the latest test board fresh off the cnc:


We started in the top right hand corner. Around the centre of the board, the drill isn't quite 100% bang on, but is about as accurate as we usually get when drilling these things by hand, with a little Dremel and snake-head attachment, so it should be good enough.

The three holes at the bottom left of the board were totally way out with the printed PCB, but did actually marry up with the on-screen display


So either the PCB layout has changed between printing our test boards onto paper (not impossible) or the software is reading the dxf/nc drill file incorrectly and putting the holes for the transistor at the bottom-right corner in the wrong place!
It shouldn't take a massive amount of work to find out what went wrong and why, and maybe even tighten up some of the inaccuracies around some of the holes.

At the minute, our path-finding is still doing "nearest-non-drilled-hole"


Given that we start in the top-right hand corner, the y-axis travels "downwards" for a total of nine holes, while the x-axis moves left to hit hole 5 and then right onto hole 6 (the x-axis doesn't change in order to then drill holes 7,8 and 9). At hole 10 the y-axis moves in the opposite direction (upwards) and it's around the centre holes that there's a lot of backwards and forwards movements. It's also around these centre holes that we're seeing most inaccuracies.

The next plan is to alter the path-finding in the software so that it starts at the top of the board, and only ever travels in one direction on the y-axis. This should eliminate any backlash in at least one axis and hopefully give us a level of accuracy that we'd be happy to live with, and then we can get on with the exciting stuff like publishing it all online for everyone else to have a go with!

EDIT: Do'h. We were indeed using two different boards for testing! Here's a screenshot of the PCB layout used to load the holes into our CNC. Note how the transistor in the bottom right hand corner has moved down in relation to the rest of the board. If we had printed this board and drilled it, it's looking quite likely that we'd have had a successful test much earlier on!


Sunday, 9 September 2012

CNC drill actually drilling!

Another late night on Thursday at BuildBrighton and another leap forward in progress with our mini CNC drilling machine. This time we actually got a drill bit attached to the RC brushless motor and set it spinning. Because the RC motor requires 12v and we're running our (so-called) 5v motors at 7.5v (at 5v they have no torque at all and stall very easily) we've got a couple of different power supplies running - and a dedicated Arduino board cobbled together to give the RC controller a few commands at boot up to get it spinning.
You can see in the video below that the start-up sequence is quite convoluted!


The laser dot is far too bright to be of any use, so we might just lose that in future development. But we managed to load an nc drill file (and a dxf output from ExpressPCB) into our software and get the machine to drill the pads.

The ultimate test is, of course, to place a printed PCB onto the drill and have it drill out the pre-printed pads. We did this with a printed sheet of paper and the results were pretty encouraging (though not 100% accurate)


Starting in the top-right hand corner, things progressed well for the first few holes. As we got towards the centre of the board, there's a bit of drift which is recovered during the last few holes in the bottom left corner.
Despite these holes looking massively out-of-place on the photo, they're still within about 1mm of the target point - a pretty impressive resolution, considering the hardware used!

There are a few possible explanations for this drift, although it's probably due to a combination of:


  • The servo rams the drilling bit into the board at full speed. This can sometimes cause the bed to move slightly at the start or the end of a drilling stroke. We need to slow down the speed of the servo descent.
  • The anti-backlash routine in software contains some values we just made up that seemed to work! We may need to calculate these values a little more accurately than typing some random numbers and checking the results by eye
  • The drift in the holes is difficult to explain in terms of x- or y- axis since the drilling head travels in all directions (up, down, left, right). We could alter the software so that the bed only every travels in one direction (we could split the board up into rows, and drill each row one at a time, moving the bed in one direction only, while the gantry is allowed to move both left and right). This would make the drilling action less efficient, but would eliminate (or drastically reduce) any backlash in at least one axis.


With these changes in mind, it can't be long before we've a working CNC drilling machine and can post all the files and diagrams online for others to share!


EDIT: At the Mini MakerFaire the following Saturday, one passer-by pointed out that our drill bit was actually spinning the wrong way! We reversed the spin direciton, and the drilling action was much smoother, caused fewer jumps on the travelling y-axis and created lovely little piles of sawdust around each hole drilled. It seems that previously we were just burning our way through the board!

Sunday, 2 September 2012

Repeatability - the holy grail of CNC

After getting our CNC running, we've spent a bit of time trying to work out the auto-calibration on our machine. The idea is that you select two opposite corners on the board, and the software works out the scaling and rotation (given that you may have plonked the PCB down at any old angle).

The rotation part of this works really well, but scaling has been a bit of a problem.
It seems that unless you are absolutely accurate with placing the drill head in the dead centre of each dot at the start, the scaling quickly goes to pot! Any tiny slight mis-alignment during the set-up stage is magnified and repeated many times over when the CNC tries to draw/drill the board.

Also, we struggled quite a bit with consistency.
Whether or not the scaling was correct, it should at least have been consistent - but this is something we had trouble with for a while. Until Robot Steve pointed out that the backlash in our stepper motors was massive! Because the motors themselves are geared down, there's quite a bit of play in the motor assembly. Although 2mm-3mm doesn't sound like a great distance, when you're working to keep a cumulative error over thousands of steps to less than 1mm, it's a massive amount of play.

The answer we came up with is as quick and dirty as it is cheap. Simply put, software compensation for backlash (or play or slop or whatever you call it) means keeping track of which direction each motor is spinning and when it changes direction, adding in a few extra steps to take up the slack first.

How we determine the number of steps required could involve some serious calculations about gear pitch, tooth count, complex trigonometry and more. So we used the SteveCode approach and just tried different numbers until it looked about right.


To reduce any error introduced by badly calibrating the machine, we also added in a fixed constant value for "scaling" - so for testing, where we're not concerned about rotation, we can have the machine plot a series of points from an NC drill file, without having to go through the calibration process every time.

All this seemed to work pretty well.
The last addition to the software is the ability to parse DXF files for hole placement - allowing us to draw a PCB in ExpressPCB and export to dxf, then import the dxf directly into our software as if they were NC drill files.


In ExpressPCB we drew a grid of holes, starting at 10,10, each 5mm apart then exported the layout as a dxf mecahnical drawing


The final dxf file is ready to load into our CNC software which it converts into an NC drill file during import. The NC drill file is then loaded just like any other and drawn on screen


This time we don't bother with calibration (we've already set the backlash and scaling values on the settings screen earlier) and set the machine drawing/drilling:



The key to getting a working CNC is repeatability. And in this case, we've got a brilliant, working, repeatable output! And here's our (second run) drawing being measured up for accuracy:


The input file (ExpressPCB exported dxf) had a grid of 4x4 holes, placed 5mm apart.
The centre points of each hole drawn with our felt-tipped pen are consistently within about 0.3mm which means we've met just about all of the criteria for the BuildBrighton CNC drilling machine challenge:

Less than £50 total build cost? Check (will publish full parts list shortly)
When put away, the total footprint does not exceed an A4 sheet (297mm x 210mm)
Ability to drill up to 80mm x 100m half-eurocard sized boards? Tick
All components are easily accessible from a variety of sources, such as eBay or Amazon marketplace.

The only part we've not actually proved yet is the drilling a 1mm hole inside a 2mm pad.
This is the same as drilling to within 1mm accuracy, and we've proved we can do that, with our cardboard printed output. So all that's left to do is make a collet for the brushless motor and connect a 1mm drill bit - then actually drill some boards!






Saturday, 1 September 2012

CNC drawing and drilling

Tonight we got the z-axis (drill up/down) servo working and managed a full test using a felt-tipped pen in place of a drilling head. The test was almost a complete success!
Ok, not entirely, but pretty much there, except for a bit of tweaking...


There's still the small issue of backlash to compensate for (the motors have a massive amount of "slop" in them, meaning they get less accurate each time you change direction with them).

Instead of a "traditional" cnc controller, we built our own PIC-based board, which doesn't use g-code but rather accepts an x- and y- co-ordinate (distance to travel in each axis, counted in steps) and a "go" command, then moves from point-to-point. At the end of travel, when the machine sends back a "arrived at point" signal to the PC, we send a "peck" command to perform the drilling action (this will be modified with an actual cutting head).

The results were pretty impressive, even in this rough-and-ready form. Here's the input file:


And the actual output drawn on the cnc machine:


You can see the output is pretty similar. Where some of the dots don't line up exactly, we can see how this relates to one (or either) axis changing direction - this is where the backlash compensation needs to be implemented, to keep these turns as tight as possible.

Hopefully we just need to do a little bit of tweaking to get a 100% accurate output from an NC drill file. But for a first-run test, it's very encouraging. Obviously replacing the steppers (with better/more expensive ones) and introducing a belt rather than rack-and-pinion should give us a bit more accuracy - but this flies in the face of the original design brief, to make the machine as simple (and as cheaply) as possible. So we'll do a little more work on this design to see how tight we can get it before exploring alternatives....

Friday, 31 August 2012

CNC drilling machine - testing everything

This is one of the most exciting blog posts for a while. After working on the CNC drilling machine as part of the BuildBrighton £50 CNC challenge for a few weeks, we're actually at the point of putting software, hardware, nc drill parsing and motor controller all together and actually trying to cut a PCB.

Actually, we don't have the drill part running yet - but this test shows actual movement, and we've used a laser dot in place of a drill head. But it shows a (sort-of) working CNC machine....


Instead of jumping in at the deep end and trying to draw a complex PCB (the printed pattern on the paper) we started off with a simple square. But as you can see from the video, we deliberately drew (and mounted) the square on an angle, to simulate mounting a PCB on the cutting bed on a wonky angle.

The software takes care of the rotation and follows the dots.
The first few seconds of the video show the machine being calibrated - the software prompts you to place the cutting head over a hole, record this location, then move the head to a second hole. This is what you see as the head travels diagonally across the board at the start (and the slight delay in the finer movement is us changing some parameters on the PC to reduce the jog step size).

The software then works out the cutting path (in this case, a simple down-across-up type pattern) and sets the motors spinning!

It's interesting to note that the cutting head doesn't necessarily follow the "lines" between the dots (if the dots were on the corners of a square for example), since it is a point-to-point machine, rather than a line follower. We'll try to demonstrate this more clearly in a later post.
But for now, sit back and enjoy our first CNC test.

It's not bad. It's not perfect - we need to take out any backlash in the gears (the motors themselves have quite a bit of "slop" on the spindle because of the internal gearing) to get greater accuracy but as an initial test - and particularly the handling of skewed boards - we're quite pleased with progress so far!

Next time we hope to actually cut (or maybe just draw felt-pen dots on) something.....

Wednesday, 29 August 2012

CNC motor testing via USB

There's an often held belief that you can't do CNCs without a parallel port on your PC and cleverly timed move instructions. That may have been the case back in the day, but we've had the nineties guys, USB is all the rage!

So we're building a USB CNC controller board.
We're quite lucky that these cheap little 5V 28BYJ48 steppers have already been stepped down. They're supposed to be 1/64 but inside they're geared down again. There are loads of places all over the internet which say that they're stepped down again by 1/32 - meaning you need 64 * 32 = 2048 steps for one complete revolution.

If that's the case, we should be able to get pretty precise movement, even with a massive gear/cog riding on the shaft, and without having to bother with the complexities of micro-stepping. There's only one way to be sure - and that's spin one around and count the steps!

In-keeping with our NC drill software, we're looking to build a USB controller which we can give a number of steps and have the motor(s) play out those steps. We've no idea at the minute how many steps we may need to move up to (depending on how many steps per revolution these motors actually need) so we've allowed for a 4-byte value to be sent to our trusty 18F2455 PIC microcontroller.

We're using (as ever) a generic HID device interface and sending data in 8 byte packets.
  • The first byte (byte zero) is our "command byte".
  • If the value is one, it's a command to set the x motor step count
  • If the value is two, it's a command to set the y motor step count
  • The second, third, fourth and fifth bytes make up our 4-byte value (0-2,147,483,647)
  • The sixth byte (byte 5) is a direction - one is anit-clockwise, zero (or any other value) clockwise.

After sending the x-axis step count (or the y) the controller board stops all motor activity (since if the motors are spinning when new values come in, the x- and y- axis will go out of alignment with each other, as the earlier axis will be ahead of the later one).

Only once the command byte 254 is sent do the motors actually spin up.
For as long as the x/y step count has a value greater than zero, the motor(s) are given a signal to move them onto the next step. The step-count value is decreased by one each time one of the axis motors steps. Once both motors have a step-count value of zero, a flag is set to tell the PC that the motors have stopped spinning and the head is now in it's correct position.

Here's a video of some early testing:


What's happening here? Thanks to the autofocus on our camera-phone it's not too clear - but if you squint and stand back from the monitor you might see:

Firstly, the command byte (7th byte) is given the value 1 (set x motor step count), along with the second byte (from the right) set to 16. Since our x count is a 4-byte value, we're setting it to 16*256 = 4096.
We repeat these values with the command byte set to value 2 (set y motor step count) then clear the buffer and send the command value 254 to get the motors spinning.

Giving our control board a value of 4096 makes the motor complete one full rotation.
So there we have it. Our stepper motor has a 1/64 step angle, geared down, not by 1/32 as some other forums suggest, but a full 1/64 again. 64 * 64 = 4096 so this is the number of steps required for a full rotation.

The video then skips back to a blurry laptop screen, where we enter the same values, but this time setting byte 4 to 1. This is the direction byte. When this is set to one, the motor spins in the opposite direction.

All in all, we've had quite a successful evening - we've got both axis motors spinning from a custom-built PIC-based USB (HID device) board and some software which we can talk to the board with and get predictable results. Now we just need to remember how to work with Timer1 to create a 20m/s interrupt on the PIC and we can use this to send servo commands for the z-axis (drill up, drill down and motor speed).

Tomorrow is another BuildBrighton open evening.
There's even a slim chance that after the beers and pizza, we might actually get something working......

NC drill file format - origin is bottom left

So far we've been working with screen co-ordinates, with the origin (0,0) at the top left. But when reading/parsing NC drill files, the origin seems to follow cartesian co-ordinates with the origin in the bottom left (like you get when drawing a graph on a piece of paper).

So a quick hack later and our software now starts with the dot nearest the bottom-left-hand corner of the board


It then prompts to move the drilling head to the top-right-hand corner hole


And calculates a cutting path from the current hole (the top-right) back, not necessarily to the origin, but in a way that passes through each hole.


When the cutting head reaches point A, the general rule to follow is "move to the nearest undrilled dot". If we were doing this job manually, we'd probably go from point A to point E, continue working up the board, then move to the left and work our way back down again.

But that doesn't actually follow the "move to the nearest dot" rule. From point A, the nearest dot is point B, so that's the path that's taken. Now at point B, point E is still further away than one of the other, non-drilled, points. So the head moves to point C instead. When it gets to point D, however, the nearest undrilled hole is point E, so the cutting head moves there and continues in a more predictable pattern.

We could probably "iron out" these peculiar movement patterns by looking ahead more than one hole at a time, but that's an awful lot of work for something that we've not even tested yet! For now, we'll live with a few quirks until we've seen it actually drill a PCB board!


Tuesday, 28 August 2012

CNC drilling software development

Ever used Mach3 for your CNC machine? Or RouteOut? Or one of those other CNC applications with a myriad of settings so that it can support any type of CNC machine?

If you've ever bought a second-hand CNC machine off eBay or tried to build one from salvaged parts, you know how difficult it is to work out (or guess at) the settings to make it work. Sometimes you end up shoving numbers in and keep tweaking until the actual output sort-of matches the drawing files you give it.

Well not any more....

Not only has Robot Steve redefined simple CNC design, with his awesome push-fit chassis, but this custom-written software is designed to do away with CNC-hardware-related headaches. Simply load a file, manually move to head to a start position (origin), move the head to a second position, then hit go.

At the minute the software can read NC drill files.
Here's the app reading a drill file generated from an Eagle PCB


After calculating the scale and rotation for each point (at the minute we're just working on scale, having just read in an nc drill file) the software runs through each point, creating a "cutting path"


At first, something appears to have gone wrong down the left-hand side. But on further inspection, the software is actually following the simple rule "move to the nearest hole that hasn't been drilled yet".
Because we set the origin to the top-left-most hole then travel to the bottom-right-most hole, the cutting head  should be at the bottom right of our PCB.
From here, it starts with the rule "move to the nearest point" then marks it as "drilled" when it gets there.
Repeating for only holes that haven't been drilled creates the cutting path above.


Monday, 27 August 2012

CNC drilling machine first test (x- and z- axis)

After a successful couple of hours at the nerd cupboard, we managed to get Steve's CNC design working in two axes. The test board simply uses buttons to turn a connected stepper motor clockwise and anticlockwise (we've yet to finish our controller software) but proves the concept of moving a drilling head across a gantry and performing a plunge-and-drill operation.



Exhilarating stuff!
We're particularly pleased with the dual-servo control: the first servo is actually an RC motor controller and sets the drilling spindle spinning. Then the z-axis servo plunges the drill head, pauses, and retracts the head, before stopping the drill spindle. (In code we "detach" the z-axis servo so that it is only powered for as long as is required.)

Surely it's only a matter of time before the y-axis (cutting bed) is in place and we're ready to try out some custom software to drill our first board!

CNC drilling software (open source?)

We're still not 100% au fait with the requirements for open source, GNU licences and all that kind of stuff - does everything in the chain have to be open source? Can we use our preferred PIC microcontrollers to make a USB device when the Microchip software and USB libraries are not open source? Does it really matter?

We're blundering ahead with our software, but have hit upon two potential problems - and hopefully workable answers to them:

The first is converting the NC drill file units (mm or inches) into steps on our CNC machine.
Since a big part of our design process is to make the machine easily repeated and built from spare parts (salvaged printers are a great place to get hold of cheap steppers) we're trying to work from the assumption that the end user knows nothing (or very little) about their hardware.

Rather than have the user enter all kinds of values to describe their hardware (or worse still, guess at them) we thought we'd have a simple manual calibration routine at the start of the software. Simply put, the user loads their pre-printed/etched PCB onto the cutting bed and moves the drill head above the top-left-most hole (the software will highlight one if there are multiple possibilities). This will form the origin (co-ordinate point 0,0) for our cutting routine(s).

The software will then find the bottom-right-most hole (furthest away from the origin) in the drill file, highlight it and prompt the user to move the drill head (maybe using the computer keyboard's arrow keys or similar) above this second hole. Using these two co-ordinates we can calculate two vitally important things: scale and rotation.

In the NC drill file we have co-ordinates for every point on the board. Using pythagoras theorum (a^2 = b^2 + c^2) we can calculate the distance R1 between the top-left and bottom-right points. On our actual PCB, this represents the same distances between the same two points. The only difference is the units used to measure this distance.

In the same way the same distance can be described in imperial (inches) and metric (millimetres) by multiplying one set of values by a constant, we can do the same to convert inches or millimetres in the NC drill files into steps on the CNC machine. Let's pretend both images (above) are exactly the same size. Let's say the distance R1 is measured in millimetres, but we want the same distance R2 in inches. We know that 1 inch = 2.54cm and 1cm=10mm. So we can easily compare R1 (mm) with R2 (inches) by multiplying R2 by 25.4 (or dividing R1 by 2.54 to get R2, the same distance in inches).

We don't know what this constant value is to convert our NC drill measurements (mm/inches) into number of steps, but we can calculate R2, the distance the drill head travelled between two points, in terms of steps. Knowing the value of R1 (in, say, mm) and the distance of R2 in steps allows us to calculate the scale between the two. Scale = R2/R1

The great thing about using the first hole as our origin point is that it doesn't actually matter at this stage whether or not the PCB board on the CNC machine is dead square. If the PCB board were not aligned exactly squarely, the difference between these two distances would be exactly the same, since they both describe the radius of a circle with it's centre point at the origin

 So now we've worked out the scale (the constant to multiply our NC drill hole positions by to convert distances in mm/inches into number of stepper motor steps) we now need to work out the rotation of the PCB on the cutting bed

Even if the PCB on the cutting bed were badly skewed, the ratio (scaling) between R1 and R2 would be the same. We know the location of the bottom-right-most hole from the origin according to our NC drill file, and we know the distance of the same hole on the actual PCB in terms of number of steps travelled in both the x and y axis. What we need to do is calculate by how much the PCB has been rotated.

One way to do this is to calculate the angle (from the origin) of the diagonal in the NC drill file (the larger of the three angles above) then calculate the angle from the origin of the current position of the drilling head.
Since we know the position of the cutting head from the origin in terms of steps (we count the number of steps moved in both the x- and y- axes) we can calculate this angle (the green diagonal) quite easily.

Using simple trigonometry:



If we rotate the bottom triangle 90 degrees clockwise, we can see that we've described a right angled triangle, where the adjacent side is the number of steps travelled in the y axis, the opposite side is the number of steps travelled in the x-axis, so tanA = stepsY / stepsX

From here we can calculate the angle of the position of the drilling head from the origin.
Using the same principles, and with the values from the NC drill files, we can calculate the angle between the bottom-right-most hole and the origin (top-right-most hole). The opposite side of this triangle is the difference between the x co-ordinates of the two holes and the adjacent side is the difference between the y co-ordinates of the two holes, so tanA = (y1-y2) / (x1-x2)

Knowing these two angles, we can subtract one from the other to calculate by how much the PCB has been rotated on the cutting bed. Now we know the scaling AND rotation, we can simply apply these to every point in the NC drill file, to get the number of steps needed to move in both the x- and y- directions to reach in point on the actual PCB on the cutting bed.

Apply rotation to a co-ordinate point can be acheived by using a rotation matrix:



What this scary looking equation boils down to is - the coordinates (x',y') of the point (x,y) after rotation are:
x' = (x * cosA) - (y * sinA)
y' = (x * sinA) + (y * cosA)

Given that we know x and y (from the NC drill file) and we've calculated the rotation of the PCB on the cutting bed, we can work out:

xSteps = ( (x * cosA) - (y * sinA) ) * scaling
ySteps = ( (x * sinA) + (y * cosA) ) * scaling

where x and y are the co-ordinates given in the NC drill file.
And all without knowing how many teeth are on the CNC belt, how many steps the motors turn per full revolution or any of that other junk, nor without any headaches lining up the PCB to get it absolutely square and accurate on the cutting bed.

In theory, this provides a really nice and easy to use - if not entirely easy to understand for everyone - way of drilling every hole on the PCB, from an NC drill file, given the user has manually located two holes on the board.

Software design requirements for CNC drill machine

Robot Steve's late entry into the BuildBrighton CNC Drilling Machine competition has in some ways spurred us on and in others caused things to grind to a halt. In some ways, seeing such a simple, usable design has us wondering whether it's worth continuing with our little laser-cut caddy. The main difference between our approach and Matt's CNC monster was simply scale and cost:

Matt came up with a solid (though possibly over-engineered) design using linear bearings, rods and bolts by the bucketload, expensive steppers and belts - basically blowing the budget to create the best CNC type machine he could manage.
We stuck to the cheap-as-possible, easy to replicate route, but possibly at the cost of accuracy (we still don't know if our design will actually create a working, functional CNC machine!)

Steve's design fits nicely in the middle.
With 3d printed parts, built from a 3d CAD-based design, he can see his prototype working (virtually) before cutting or casting a single piece of plastic! Yet with minimum part count and easy push-fit construction, there's no need to worry about bolting plastics edge-to-edge and trying to get everything square. It's a great design.

So is it worth continuing with a slightly shonky design, knowing that eventually we'll probably adopt another in the near future? We'll leave that question, and spend our time constructively on the one aspect that no-one seems to have addressed just yet: software.

The budget allows for the complete build - including driver board/electronics and controlling software.
The easiest approach would be to get a MACH3 compatible driver board, hook up the steppers and run everything through some milling software like MACH3. But this is an expensive way of going about things, so we reckon custom software is the way to go.

Also, we're not drilling or milling blank material. Our PCBs with either already be etched, or have tracks and traces already marked on them, ready for etching. So before we start any drilling, we have to make sure our boards are perfectly lined up to begin with.

In something like mach3 we could do this by moving the drill head to a known position and placing the board underneath it, then moving the head to a second (known) position and rotating the board until this second point fits under the head. With the board in place, we could lock it down and start the cnc running.
MACH3 also has a myriad of settings, belt-tooth size, leadscrew adjustment values - all things which make it quite complicated and daunting to the untrained user. For our software we want:


  • Minimum settings screens - we don't care how big your stepper motor is, the tooth pitch, degrees per step and so on. The software should work with a wide range of machines without any complicated maths/physics calculations!


  • Auto-alignment - placing a PCB exactly squarely on the cutting bed is going to be difficult enough. Cutting the sides square is hard - knowing that you've placed one edge exactly squarely can be hit-and-miss, and if your edges aren't exactly true and straight, getting the whole thing to line up is almost impossible!


  • Auto-scaling for different measurement units - NC drill files are commonly described in imperial (inches) but there is software that uses (and an NC drill command for using) metric (millimetres). The software should be able to handle mm and inches without the need to re-calculate the drill position data in the NC drill file.

We're not worried about making everything open source, complying with GNU licences and all that - we're just looking to create some software that just works (in Windows at least) using whichever tools do the job. Of course, details of how the software is created will be explained, should anyone wish to re-create their own, but we're not ruling out any specific technologies just because it's not "open source" or GNU-a-like or anything like that!

Sunday, 26 August 2012

Late entry to the BuildBrighton CNC drill machine challenge

It's a bit late - though not as late as our actual machines are for being ready (they should have been drilling PCBs in time for last August's BuildBrighton Guitar Stompbox Workshop) - but we've had an exciting last-minute entry from Robot Steve.


Steve's taken the simplicity of our design but coupled it with the super-low cost option (and ease of construction) of a 3D printed solution. We think it looks amazing.


Using a servo for the drill plunge, this design keeps things about as simple as they possibly can be. The rails are structural as well as functional (carrying the carriage for the x/z axes) and the tiny steppers are mounted directly onto the moving parts. Rather than mess about with linear bearings, Steve has gone for the simpler (and cheaper) design used in many inkjet printers - greased rails and precision cut nylon blocks sliding along them!


We think the best thing about this design is the relatively low part count. Once you take away the cutting bed (a piece of cheap acrylic or some mdf) and the rails, you're left with a handful of cheaply produced 3d printed parts.


Steve sent over some early prototype photos. It actually looks better in real life!


Wednesday, 22 August 2012

Miniature CNC drilling machine x-axis carriage

We've had a bit of mixed success at Nerd Towers tonight.
Firstly, we wanted to get our x-axis working on the miniature drilling CNC machine. The y-axis (bed) is easy enough - it's just a plastic bed set on top of an Ikea drawer runner. The x-axis is altogether more difficult, as it's a gantry-based axis (to keep the size/footprint down).

In the spirit of making everything as cheaply and as repeatable as possible, we're using the same rack-and-pinion approach for our x-axis as we have done on the y.
Simply put, a long toothed edge will run along the top of the gantry, and the stepper motor mounted on top of the moving carriage will pull the carriage along by rotating a cog/pulley along the tooth-edged strip.

We've decided on this approach as once the parts are designed and proven to work, anyone with access to a laser cutter should be able to make the same thing from our drawings.
The only thing is, we've drawn most of the CNC by eye - so have no idea how far away from the rails or toothed edge our carriage is going to be. So the first thought was to make an adjustable carriage:


At the bottom of the picture you can see the side section of our carriage. By adjusting the bolts. the stepper motor (mounted on the top of the carriage section) could be moved closer to and further away from the toothed edge running along the top.
After bolting all this together, we found that not one single piece of this carriage had been designed properly so we started the whole thing again, this time with a slightly different approach - "guesstioneering"

It's a term coined one night at BuildBrighton and fits this approach perfectly.
Basically we make something based on a best guess, then whittle things down until they fit.....


This second carriage (in blue) was designed entirely by eye and with no reference to our frame! (if the frame doesn't fit, we can always tweak that, and the carriage together, until they line up and mesh together nicely!)
In this instance, the small cog on top of the stepper motor is neither high enough, nor close enough (laterally) to the toothed edge running along the top.
Instead of messing about measuring and re-measuring and cutting and re-cutting, we just decided to make our toothed edge have a bit more play in it. The idea being that we line it up with the carriage in place and just fix it down!

As we were cutting a new toothed section, we decided to go for a double-sided piece, with the cog on the stepper motor sitting between two rails. Hopefully, this will stop the motor from pushing away from the toothed edge and skipping steps....


The only thing now, of course, is that we need to make our gantry stands about 3mm higher and a little wider on one side (so they're asymmetrical) so that this new piece doesn't look like it's been cobbled together and just shoved on as an afterthought. (it has, but there's no need to advertise the fact!)


This new carriage moves along the rails quite nicely.
There's not much play and hopefully this double-rail approach will eliminate this altogether. Here's a quick photo to show the actual size of the gantry. It's really quite small -


So there we have it. A nice sliding gantry with a stepper motor mounted onto it. It's not quite working under it's own steam just yet, but we can't help but feel that we're getting a little bit closer!
Here's how the final thing will sort-of look in place over the y-axis bed. We may even go crazy and lose the lump of scrap wood for a nice piece of red acrylic. That's the kind of colour scheme that would make Robot Steve have a fit



Sunday, 12 August 2012

ExpressPCB to NC Drill files

As part of the CNC drilling machine challenge, one of the things we have to be able to do is parse NC drill files. The idea being that using an industry standard file format makes the machine compatible with a much wider range of PCB layout software.

One of the problems we have is that Eagle sucks.
Yes, that's quite an inflammatory comment but, compared to ExpressPCB, we've seen loads of people have trouble with Eagle-drawn circuit boards.

The first thing is those stupid lozenge shaped pads. And the default hole size seems to be too small. And the pads are ridiculously small. And when you've finally etched your board and drilled it, it's all too easy to ruin a pad because your 1mm drill bit has ripped up all but the tiniest thread of copper left around the pad (right-most-pad, below). One slight wobble with the drill or mis-aligned pad and the whole board can be ruined!


Over at Nerd Towers, we defy convention and refuse to get drawn in to the everyone-uses-Eagle-so-we-must argument. Although it's less of an ideological standpoint and more to do with the fact that it's just so complicated to use when no-one has ever shown you how!

Our tool of choice is ExpressPCB. It's not only free but it's simple to use.
For the hardcore gerber-loving geek crowd, the very things we laud it for may well be it's Achilles Heel too - but it is very simple to use and you can get a PCB thrown together very quickly, all with 2mm pads with 1mm holes (ok, the default is 0.89mm but what's a tenth of a millimetre between friends?). No worring about mirroring, or not mirroring, or which-do-I-mirror before printing for toner transfer - just draw on the top (red) layer and print it out!

To produce PCBs for etching, we usually print to a virtual printer, such as CutePDF and make a PDF file for editing in Inkscape but one thing we recently discovered was the "export to DXF" option


This is quite exciting, as it allows us to generate a file which can be parsed and turned into a drill file. The export to dxf option in ExpressPCB can send just the pad data to a single drawing. Simply loop through the text-based dxf file, find all instances of CIRCLE and write the co-ordinates out to a NC Drill compatible file format!

After a cursory glance at the generated dxf file we can see all our pad data quite easily:


Every pad is a circle entity so we fiddled with a few values and loaded the resulting dxf into Inkscape until we found which entries corresponded to the X and Y co-ordinates. Ultimately it is these values that we'll be interested in to create our own NC drill file.

(comments in the above image were added one we'd identified which values did what, they were not present in the original, generated dxf)

To try out our idea, we picked a circle and set the X/Y to zero and the radius to 4
Interestingly, Inkscape does not position circles from their centrepoint, but from the bottom left corner of the shape. So we expected to see our shape at -4,-4


Inkscape seems to include the stroke (shape outline) width in the X/Y co-ordinates for each shape. So we reduced the stroke width and indeed the X/Y co-ordinates updated accordingly.


We can only assume that with a stroke width of zero, the shape would indeed line up to -4,-4 and thus prove that the values we changed in our dxf file were indeed the correct x,y and radius values.
With this in mind, we're off to write a simple script to convert metric x/y value pairs into an NC Drill file.....