Let's Make Robots!

CNC machine v2.1 - aka "Valkyrie Reloaded"

Cuts shapes with better precision then me :D
tiny2313_stepper.brd22.52 KB
tiny2313_stepper.sch336.57 KB
serial_gcode.py_.txt730 bytes


 - the front 

 - the back

- left

- right

- the power unit

- and some closeups here and there



This is the second third version of a homemade CNC machine build using mostly off the shelve parts.

The first one aka "The beast" had a lot of precision issues due to play in most parts which in turn was caused by mostly bad cutting. Also one of the biggest problems was that when I have build it I did not think to allow later adjustments to be done. 

So this time almost every part of it allows for some adjustments. It is also easier to build due to the different design. 


I have been asked many times over why I did this below are a few possible answers:

- because I wanted to see if I can 

- because I like doing this kind of stuff

- because I think such a machine is useful

- because I want to use it to mill PCB's, I'm tired of messy etching, bad exposure, bad transfers ... etc

- because I also want to build some other stuff and I need precision

- because I learned a lot building it

- because maybe I can make some money out of it in the end 

- etc, etc ...

Technical details:

- 250 by 160 265 by 225 mm maximum work area

- 50 by 35 by 35 cm machine size (could sit on my desktop :))

- with the material I have tested (laminate wood pretty tough material) it can cut at around 80 to 100  100 - ? (must still find out maybe as high as 400) mm per minute

Construction materials:

The main material used is 16 mm MDF - I used about a square meter all together.

The rails are 10 by 20 mm aluminum corners used for ... I don't know for what but the margins are slanted at an angle - I used 3 meters of it.

The lead screws are standard M8 type threaded, nothing fancy - 3 meters.

The bearings used are two types because I did not have enough of them, but you can get away with ABEC7 bearings - 16 for the X-axis + 8 for Y-axis + 8 for Z-axis + 8 for the lead screws = 40 bearings.

The motors I used are 7.5 degrees per step, 24 volt, canstack stepper motors, the kind you should find in almost all older printers. 

The electronics used are all home build. The brain of the machine is an Arduino (the single sided version), and the motor drivers are created around Attiny 2313 paired with an l298. 

The wires used are CAT 5 pairs used for power, and pairs from an old SCSI flat cable for data. 

The screws used in the construction are standard M8 of different lengths and M6 screws to fix the rails.  


A. Lead screws

The design is as simple as it gets, it is all based on lead screw transmission.

I chose to use this kind of transmission because it has three advantages:

1. Force ratio is high - to move the nut along the screw the rotational force applied is low compared to the output. That allows the use of those small motors

2. Precision - even with the large step angles provided by the motors I still get pretty good sub millimeter precision: 76,8 steps/mm - good enough for my requirements for now at least.

3. Ease of implementation - you only need two bearings at the ends of the screw, two normal nuts to hold it in place, one long nut to move around. 

The linear rail system allows the axes to move freely along their axis and ensure there is no side load on the lead screws.

B. Rail system

On this machine the linear rails are using a different system as on the first version, inspired by the new version of the CNC machines created by the guy here. Obviously the new system is a lot easier to implement than the one before due to it's simplicity. The only drawback is that it requires a strange type of bearing called a V-groove bearing which comes with a V shaped groove along the center of the other housing. I could not find any of those, so I used a pair of normal bearings put side by side to create a small groove in the center.


The electronics of this thing are composed of two parts: the Arduino board and the motor boards.

The Arduino is just a standard single side board, not much to say about it, if you want to build your own see here.

The motor boards I designed myself, they are based on an Attiny 2313 and l298. You can find the schematics below.

I have built my own controller because I did not want to have a mess of wires around the machine from the Arduino to the drivers. This way I can control all 3 axis by using just two wires trough the I2C protocol. 


The software is divided in three parts: 

- pc side

- Arduino side

- motor controller side

On the pc side I'm using the excellent Inkscape to draw the shapes, and a plugin to convert them to G-Code coordonates. Then I'm using a simple python script to send the G-Code to the Arduino, over the serial link. 

On the Arduino I have a modified version of the code from the RepRap project (www.reprap.org), adapted to use I2C to command the motors instead of driving pins directly. 

On the motor controller side the software takes different commands trough I2C and executes them. 

Open source:

All code and driver schematics are available here:



Please ask for more info, I will add it, I do not have anything more on my mind now. 


Update 15-Aug-2009 - hit a wall ...

I clearly remember updating this page about 2 -3 weeks ago but I must have been drunk ... O.o


I was saying back then that I still have an issue, that sometimes the I2C bus seems to bail out causing the machine to stop working. 

I was finally able to do some testing last night  and I managed to replicate this "bug" and the conclusion is that it only happens when the machine is under load, i.e. cutting something.

The question remaining is: Why? Is it a power issue? Wiring issue ?

No idea ...  currently it uses a single 12 V rail from the ATX power source, I'm  thinking on rewiring this fellows power lines to use one rail for each motor.

Ideas anyone? 


Update 18-Aug-2009 - Here comes the source code


As promised I have made the source code available to the world. I do not like the way Drupal handles attachments (does not accept archives), so I decided to upload the code on GitHub. 

Git (http://git-scm.com/) on which GitHub is based is a very nice version control system and pretty easy to use. 

I have created a GitHub account, you can find my page here:


To download the source code as a ZIP or TAR archive you can click on the  "Download" button :)

For hardcore geeks install git and clone the code with: 

git clone git://github.com/TinHead/Valkyrie-CNC-source-code.git 

Have fun with it, clone it, fork it, patch it, optimize it ... eh write it in assembly if you wish.

Update 28-Sep-2009 - Some revelations

Lately I spent my time trying to understand the timers of the Attiny 2313.

While playing around with different PWM setups and frequencies I found out two things:

1. timers are not easy, but they are very useful beasts

2. why I could not get microstepping to work on the Valkyrie 

While  1 is pretty obvious, 2 requires some explanations:

- microstepping requires that you adjust the power on the motor windings  in such a way that a full step (say 100% an winding A and 100% in B) may be divided in multiple smaller steps.

- to achieve the above PWM has to be employed on the H-Bridge enable pins

- if PWM is employed  and you drive the motors at their nominal voltage you loose torque so microstepping is a no go, the stepper might microstep without load but not under load (the PWM frequency plays an important role here, higher frequencies tend to amplyfy the problem)

- so the solution to be able to microstep is to have the motors powered at a (much?) higher voltage than the nominal voltage and apply PWM with the right frequency (which sadly varies from motor to motor) to control the power.

 In my case the motors have an assumed  nominal voltage of 12v (based on datasheets of similar motors) and I'm driving them with 12v -> no microstepping possible. 

I have two options now:

- change the motors with 5v motors

- redesign the controllers to allow higher voltage input, the caps have to be replaced.

 PS: I know this stuff is nothing new, I'm practically reinventing the wheel, but this is what it takes for me to really "get it" :)

Update 25-Nov-2009 - All work and no play makes TH a dull boy

Long time no update, sorry got lost in todo stuff and never finished the todo stuff ... bah.

Things I managed to do:

1. Redesigned the motor driver with the following things in mind:

- used a ground plane to reduce some noise

- linked all inputs of the L298 to PWM capable pins on the Attiny 2313

- moved the enable inputs to non PWM pins because of the above

- the driver is designed with two layers now ... looks nicer but it is also harder to build

- replaced power and motor pins with screw connectors so it is easier  to connect the wires

- motor power is now independently routed so the driver has one power input with a voltage regulator for the logic and a separate one for the motor - on the logic power input you can use up to 12v (to be safe because the caps are 16V) on the motor up to around 40v.

- fixed a problem with the reset button in the schematic, now the reset works as it is supposed to. Before it would actually create a short, it worked but not really as it should have been.

- changed the diodes to schottky type, SB560 (not sure if they changed anything yet, but they do recommend them in the l298 datasheet)

- rearranged stuff around, I tried to follow the advices of B0SC0 on this, thanks B0SC0 :)

2. On the software side:

- found the problem with the Arduino code limiting the speed of movement (actually John_NY lead me up to this, thanks John)

- implemented full torque halfstepping on the driver trough PWM (still testing that) 

Things I did not managed to do (in random order):

- really get into XK-1 to use it instead of Arduino for the XMOS challenge  - needs lots of work I only got to blink a LED on it for now

- implement microstepping ... the short version is that it kind of works but totally unusable I think the torque loss is just to great or something, or a problem with my code.

- create two more new drivers to put them on the Valkyrie 

- implement home sensors on the axes to home the machine 

- work on the plastic extruder - still just an unclear recurring idea in my head

- squash the I2C lockup bug - but I have some ideas now

- other random stuff not related to Valkyrie

I will update the git repository with the new stuff soon, and also add the v1 controller re-designs by B0SC0 and John_NY in there.

Update 06-Dec-2009 - Bigger motors => bigger problems


So I finally got my hands on bigger motors with the kind help of a friend. 

These guys  are bipolar 1 Amp per coil 200 steps per revolution motors. Very cool Japanese motors. 

But there of course to use them I have to recreate the motor holders 'cause  those ones have a very different mount... 

Also driving two of them with one driver for the X-axis... seems risky to say the least, an early test proves that they can easily blow up my driver and melt the hell out of CAT5 type wires because of current draw. I'm now considering trying to use a really big radiator on the Xaxis driver, and if that fails building a special driver for the Xaxis with two L298's on it.

Looks like I will never get to finish porting the code to the XK-1 this year  ....


Update 20-Dec-2009 - Moving forwards to 2.1 (?)

So bigger motors are here (yey!) but not in use yet ... as usual I got side tracked with other stuff ...

The new ones need other mounts, and I just can't find an easy way to adapt the current mount for them. So I decided to delay mounting them, and go on using the old motors until I have a working machine which can do the mounts for me :) 

Had it too long on my TODO list: New Z axis, to really take advantage of the Y axis length. As it was it "eat" about 100 mm usable workarea, just by the sheer size of it so I was pondering for a long time to fix that. This actually happened this weekend because I broke the old axis. So I had to rebuild, and I gained the missing mm on the Y axis  :D

Also on my TODO was having some kind of home/eol sensors to make it easy to home the machine and stop it before destroying itself while trying to go further then possible. The drivers were designed with this in mind but I never got to try/test it. So today I finally got the drivers to respond back over I2C so they can yell "Hey I'm home already !" back to the Arduino. Which is very cool :D I'm going to implement this in the code ASAP.

One other thing waiting in my TODO is to try making an thermal plastic extruder as they have on the RepRap machine as a second tool for the Valkyrie, I was finally able to take a few steps in that direction. I played with a thermistor for the first time, and got it to show the room temperature properly, but not higher temperatures yet... I have no comparison to check it against.   

And finally it looks like I'm going to hit the limits of the Arduino  pretty soon with this project, I think reimplementing the extruder and the end stops will fill the rest of it up ... so I have to start working on the XMOS or get an Atmega 368 ... which I cannot seem to find locally ...

That's it for now, stay tuned .. 

 Update 21-Dec-2009 - Pythons

 There have been several requests for the python script I use to send the g-code over to the Arduino trough the serial connection. It requires python and pyserial installed to work.

Here we go:


import serial,sys,time
serial = serial.Serial('/dev/ttyS0', 19200, timeout=1)

def check_conn():
    if serial.readline().strip()=="ok":
        print "Connected"
        sys.exit("Serial connection could not be established")

def send_line(line):
    print "Sending "+line
    response = serial.readline()
    while not response:
        response = serial.readline()

def main():
        filename = sys.argv[1]
    except IndexError:
        print "Usage: serial_gcode filename"
        g_code = open(filename, 'r').readlines()
    except IOError:
        print "An error occured opening the file "+filename
    for line in g_code:

if __name__ == "__main__":


And attached above http://letsmakerobots.com/files/serial_gcode.py_.txt, please remove the .txt ending.

Have fun !


Update - 04 Jan 2010 -Valkyrie Reloaded


The last two days I worked on and off on the Valkyrie slowly putting it back together.

I mounted the new Z, got the motors mounted. I got the drivers checked, fixed and running.

I'm running the motors at around 30V now (give or take 5V) and with the help of the redesigned drivers, I'm running them in a so called "full torque half stepping" mode (at least it seems to work) see here for info on that: 


I still have to re adjust the axis, right now I have problems with both X and Y, Z seems fine, I will do that tomorrow with a fresh mind. 

I moved the drivers off of the machine to avoid EMF as much as possible, will run tests ASAP to see if I still get lockups on the I2C bus. 

So basically I have the machine back online, I hope I will be able to start doing useful stuff with it soon.

12 - January - 2010 - 2.1 is here aka "Valkyrie Reloaded"

Check out the new video for now, I will update the rest in the

following days.  



19 - Jan - 2010 - Video for Oddbot


Hi all,

Since China gouvernment seems to protect it's people form bad things like youtube, OddBot is unable to see any of my youtube videos.

So here you go Oddbot a download link:


Let me know if it works.


17 - Feb - 2010

Brain: We must prepare for tomorrow night.
Pinky: Why? What are we going to do tomorrow night?
Brain: The same thing we do every night, Pinky - try to take over the world!

Long time no update, well I didn't have much to say really. The machine is more or less done and more or less working ;) My biggest problem is still having the time to actually do stuff with it. 

So here is some random stuff on my TODO/WIP list:

- implement G02/G03 in the Arduino while keeping the Atmega168 - done needs testing 

- trying to get the code written by Triffid Hunter which is here: http://github.com/triffid/ATmega-Skeleton/tree/master/mendel/ to work with my I2C controllers - previous commit worked to some degree, last one does not work at all, the author is still heavily developing on it. But it shows a lot of promise and cool features.

- thinking on the next generation of the driver - a few choices here not sure which to go for:

a. keep it I2C based but add l297 on to take care of the stepping and currents (got 4 of l297 I might as well give it a shot)

b. drop I2C, use step/direction/enable with l297 - standard Reprap but keep the Arduino controlling the beast  

c. drop I2C,  use step/direction/enable with l297,drop Arduino, use parallel port and EMC2 directly to do all nasty G-code processing part

d. drop I2C,  use step/direction/enable with l297, keep Arduino but do G-code processing on PC and send only stepping commands to Arduino. (This one would be future proof too)

e. keep I2C, add l297, keep Arduino but do G-code processing on PC and send only stepping commands to Arduino. (This one would be future proof also)

- working on the Valkyrie 3.0 which should have the following features (draft):

  • CAD designed
  • Open Source - all files including G-code for parts will be available
  • Self replicating - yes you got that right, all structural parts will be designed in a way which will allow an existing machine to cut them for another
  • More precise - parts will not be manufactured as before
  • Light weight yet sturdy (well we'll see about light weight)
  • Larger cutting area, yet same size or even smaller
  • NEMA17 200 steps per revolution motors 
  • New drivers or electronics altogether
  • Home/EOL sensors are a must 
  • ... and some other stuff

- working on the software side a lot

- working on a nice control panel for the machine 

- thinking on creating a website for this project so I do not flood LMR :)

03 - Mar - 2010 - Every time you think you have it all nicely working - disaster strikes :P

Sunday evening I finished surgery on the v2 drivers to get them to work with Step / Enable / Direction signals instead of I2C (see here on why it took me all weekend). The code was 90% written but I was too tired to do any good about it so I decided to just mount the drivers back in the box and wire them up and leave software/testing for Monday.

That was a very bad decision since I ended up somehow with the motor power connections inverted and on Monday morning when I powered the thing up without checking, all L298's on the drivers were instantly killed ... not even some blue smoke :P

Good thing I tested without the Tiny's plugged in though or else I would have killed any hope to machine the PCB's for the V3 drivers. 

Anyway I replaced the burned l298's this morning so probably tonight I'll have a live Valkyrie lurking around. 

On the software side of things I have multiple firmware choices to play with on the Arduino. My old code does not work anymore since it used I2C, which has to be removed now and replaced with functions to do the step signals. While that isn't hard to do really, I have found several alternatives which provide some extra features or are simply better written:

1. The most complete candidate seems to be the one written by Chris Meighan (yes he did write his own firmware besides that nice java control panel) for which the only release ever done is to be found here . Note that it will not compile straight up and requires fixes here and there to fit on the Arduino, I got it to compile and fit but I still need to do some testing so I will not post it yet.

2. Triffid_Hunter has been writing on a very nice c only replacement for the Arduino 5D firmware, but currently it is in a fairly unstable stage.   

3. grbl  is another c only implementation, haven't played with it yet cause may goal now is to have acceleration in the movements and it does not provide any. But it might be the most stable code.

4. this  one also seems cool, not tested yet.

Of course I can always start hacking on my own and take the best out of the above with credits to their respective owners, but it might not be necessary for now.



09 - Mar - 2010 - It's alive :)

Fixed the drivers yeah!


Acceleration Arduino firmware seems to do nicely, but it is not what I hoped PCB milling is a no go as it would take forever...

As I'm going to Spain I'm trying to finish the new design of V3, maybe I'll have it ready until then.

Here is a quick preview:


















Still a lot to think and work on it, but I think it is coming up nicely :D 

02 - Apr - 2010 - Done!

This is it ! The Valkyrie 2.1 is officially done! It is doing it's job as well as possible considering it's birth :)


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
TinHead -- would an upgrade to a 328 from a 168 help?  I think you might be able to drop in the upgrade and change the Arduino.exe settings.  Of course it would be a good idea to see whether there is an option in Arduino.exe to upgrade using the type of board you have.  A "Boarduino" clone would be relatively easy to build compared to a full Sanguino (Adafruit has the schematics at http://www.ladyada.net/make/boarduino/ and http://www.ladyada.net/make/boarduino/download.html).  The only catch is that you don't have an Auto-Reset function (there are instructions to enable it, but if you enable it the Boarduino will not immediately start the sketch after upload, so it is a trade-off).   Just another option if you upgrade to a bigger Arduino.  --John

The limits of the Arduino based on the AtMega 168, which is what I have, are hit if I try adding some more stuff in the current code which like the original extruder code (I'm thinking on having an extruder just like the RepRap one on the machine for 3d printing, but that is still a long way to get done). I know about the Sanguino and the RepRap guys did too since they switchced to using it currently, but I would have to build a Sanguino myself because I don't like to buy such things :) which I probably will eventually.

On a sidenote the AtMega 168 is not the problem, if the code were written in pure avr-c without the bloat of the Arduino and the floating point calculations, a lot more could be achieved with it ... but the Arduino way is very confortable for low quality programmer like myself. 

I'm not intending to switch for now anyway, what you read about was of trying to use the Xmos instead because of the challenge they have, and also because it can run 8 threads in parallel. But that is just another thing in my never ending TODO list ...

Currently I'm trying to do a first real project using the machine, namely PCB milling, but I only got to do some early tests .... maybe the next weekend...

Cool you like it and have fun building it :) Post some pictures I'd like to see your design. 

Now to your questions:

1. For the tiny you need to set the lfuse to FF  that all what is needed (to work with the external crystal 16 Mhz).

2. There is a motor test ideed both in the arduino and in the driver code ... eh I don't know if that works anymore anyway. Let me check on that and I'll let you know. 

 Thanks for the suggestion, good thing I understand german fairly well :D Danke shön, I'll check it out. 


i can't believe i am about to build a cnc machine because of your build and your link to buildyourcnc.com.

this type of linear rails realy simplifies the mechanical aspect of the machine, i think alignment becomes easier too.

here is a source for v groove bearings:


Have fun building it :) Make sure you have the right tools for the job.

The v-groove bearings will reduce the number of used bearings with 16, but at 9 bucks per piece I don't think it is worth.

only have to edit the reprap code deleting al the extruder comands, variables etc, then hit compile and the arduino GUI will tell toy what elese is mising............


i did it and worked well....... in my case edited the "do step" in order to make it work on my stepper drivers.....(thanks carlos...)  

Thank John_NY for your answer.
Your explanation is very useful for me:)

I will try to find a motor at the local flea market, first.
Then try to find it online.

But, I'm sure I'll get the motor here.
I just do not have time to find out :)

Thanks for datasheet too. Very detail information there.
Trying to understand... That is too advance for me :)

I found stepper motor with 1.8 degree from old machine (200 steps... wow)

Can I use that motor?
Which code to modify?




I'm hoping to use some similar motors with 200 steps/rotation.  One thing you'll have to change is the Arduino code -- the "parameters.h" file.  The "steps per millimeter" will be determined by the pitch of your lead screws and the resolution of your motor.  With half-stepping, there are 400 steps per rotation.  If you have an M8-1.25 lead screw and half-stepping, there are 400 steps per 1.25 mm or 360 steps per millimeter.  "X motor steps" will be 400.

One problem I encountered was that the stepper motors burned out my L298N IC.  The resistance of the motor coils were measured with a multimeter to be 1.4ohms; Ohm's law says that at 24V/1.4ohms = 17Amps of draw (unless the L298N limits the current somehow).  I didn't have a heat sink on it, and I should have probably started at 12V instead of 24V, and I may have wanted to try putting some current-limiting resistors in the line to start with, or at least comparing my circuit with something like the "EZ Driver" Stepper Driver to see whether there are any extra components to handle big motors.  I'm going to be trying to wrap my head around this problem before I try burning another stepper driver.  You may do better if you know what you're doing (I'm just copying from the smart kids or making it up as I go along).

I did mean the HobbyCNC EZ Driver.  The EZ Driver and the Probotics SideStep driver both feature "current limiting".  Why is that important?  Without current limiting, Ohm's law says my motors (24V & 1.4Ohms) will draw 17Amps/coil (34Amps).  The L298 does have the ability to current-limit, but it involves the "Sense" pins (Sense A and Sense B), and I think the motor driver must be able to read these pins.  TinHead has researched this better than I have, I think, and even investigated how to use the Sense pins in his driver design.  

Regarding the driver, I haven't built anything better just yet.  I plan to spend my spare moments before next weekend reviewing TinHead's notes on the L298 sense problem (I think the problem was that the ATTINY has no analog inputs), and perhaps evaluating a few different driver options that support current-limiting.  If you are designing a Valkyrie CNC, you may want to stick with the little motors (like Minebea PM-42 motors), since the Valkyrie driver (the August 12th 2009 design) does not limit the current and the L298 may fail on bigger motors.

Update: I've seen on the data sheet that the L298N sense pins should be pulled down for current limiting (but for some example circuits they are connected to the driver controller IC as well).  So is controlling current as easy as pulling down the sense pins?  Doesn't the Valkyrie driver pull down the Sense pins (1&15) already? Research to follow, collaboration welcome.

Update: 5xL297 controllers (one spare) would cost $56 at Mouser!  That's not an option for this machine.