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.

I'm not even sure if you program the AtTiny or does it "read the code from arduino" without any program inside it, but I can't find any guide to program it from your description. And how do I want to connect the motor controller board to my arduino mega? Which arduino pins to where?

... and while your questions are (mis?)leading me into thinking you did not blink your LED yet, here are the answers:

1. The tiny2313 is a microcontroller and it needs to be programmed ... yes no magic there

2. Use the source Lucke ... you can define whatever pins you need in there

And 3 most important: read the whole post dude, Valkyrie is gone for good for some time now, Phoenix is the cool stuff :D

Why, oh why, are you asking your question here?


Please post your question as its own forum post.

TinHead, I have started building my machine. Hopefully I'll finish it over the weekend. If not, I'll get back to it after 3 days of work. See it here:


http://letsmakerobots.com/node/8089  link seems vaporized..

As you mentioned the use of steel would be better, maybe stainless steel angles?.


I thin next time I ll go with this kind of rail..

deserve a try.

good wok mate.

I had a try with the rail system you are using, well it worked ...  but I had many troubles with it because I lack the tools to do the cuts correctly and precise. See here http://letsmakerobots.com/node/8089 

The rail system I'm using now is easier to implement but it has it's own issues. To get real good sturdiness and reliability the rails must be made of steel not aluminium.

I think I have found a solution as a mix of both ways, I just applied it on the Y and Z axis, it remains to be seen how well it performs.  

Thank you very much! :D

i like how you have diferent types of boards, one sided, double sided ETC :D hopefully these will be the last boards i etch lol :P

props on making such an awsome machine! 

Arm yourself with patience, money and good tools, you will require all of them. 

10x for the props, I think I'll start working on a new machine soon, this time it will have building instructions, and I might be able to provide kits for people who want them.