Using an Atmega8 2x ULN2803’s and a “Magic Screen” device I made a CNC 2 axis machine.

CNC Magic Screen Machine Project Page

A few weeks ago I started this project knowing almost nothing about CNC, steppers, or controlling them w/ a microcontroller. I have learned so much in that short time and have a lot more to learn.

I chose to do a version of etch-cnc because it looked really simple. In that version it was an open-loop controller and just used 2 uln2803‘s to control 2 steppers. These steppers were driven by the parallel port on a pc using Axis in EMC2.

Steppers are super easy to control. The unipolar ones that a friend gave me have 4 coils. You give them voltage on 1 coil and it snaps to that coil. Give power to the next one and it moves clockwise or counterclockwise depending on the order. This is called a stepping sequence. If you know the stepping sequence for a motor, good. If not it is easy to figure it out.

Next is trying to get a computer to talk to a stepper. Since the steppers I was using were rated at 24V and can draw a considerable amount of current, I learned that you need a driver chip to help handle the current. That is where the uln2803 comes in. It has 8 channels of a “darlington array.” Each channel on the chip can handle 500ma. Following the example from etch-cnc I combined 2 channels for each step.

My first experiment was hooking up a ATMega8 and just having it send step pulses. It worked with only a handful lines of code. Now the fun part. Hook it up to a machine running EMC2 software w/ the parallel port driver. It turned out not so fun. Based on what I saw on the etch-cnc page it looked like you could have EMC2 send the step pulses over the port using pins 2-10. That is not how it works.

It works by using the parallel port to send step and direction. Example X axis uses pin 2 to indicate step and pin 3 to indicate direction. So every time the computer wants the stepper to step it puts a short pulse on pin 2 and sets the pin3 high or low depending on the direction it wants it to go. Easy enough to solve. I put the ATMega8 back in the loop. Connected 4 ports to the motor. Connected pin 2 to one of the interrupt pins and pin 3 to one of the portD pins. Then wrote a little ‘C’ code that setup the interrupts and told it that each time a rising edge interrupt happens to read the status of direction and do a step in that direction. The steps are done round-robin style.

Great, now after running the EMC2 config generator I could actually get it to step forward and backward w/ the software. Now I just added the code and wiring to do one more stepper for Y axis.

Then I did a config for a 2 axis machine. Well that didn’t work. Most of the g-code files included as samples expected a 3 axis mill. So I just told it that it was a 3 axis mill. I just ignore the stuff for the 3rd axis.

Now I started Axis (the program that outputs g-code to the parallel port in EMC2) and hit run. When axis starts it loads a little default file of g-code. It did not work as I expected. Then I noticed a comment in that default file that said that that file was not good for milling. So I loaded the spiral sample g-code and hit run. Worked perfectly. Almost.

I had to figure out the lead screw ratios and maximum step rates and such to make what was on the screen come out to the machine. Through a little trial and error I got it pretty close and the settings I used are on the Project Page.

I presented what I had to The Robot Group.

Next I started the cleanup to make the project presentable. I re-did the breadboard onto a soldier type board. I used the “ATMEGA8 Development Kit” by ProtoStack. This is the first time I used a pre-prepared board for an ATMega8 project. This board made it unbelievably simple for me to wire the project up and make it permanent. The board has many features that helped make it go faster. The first of which is that the ATMega8 has some pins scattered around and not in sequence. This board brings them all out away from the chip and puts them in order ie. PC0…PC7 all in one little row.

In the past I had always transferred my projects to perf-board w/ plated holes using bus wire to make all the connections on the back. It is difficult because the ATMega8 needs 2 sets of power to the chip… and for some reason they are reversed on either side of the chip. It is frustrating. But by using the ATMega8 Development kit I didn’t have to worry about any of that. The board has 2 really nice power planes and all the reversing directions have been taken care of for me. A few other features of the board that were helpful to the project were: Large prototyping area. Since I am using 2 unl2803 chips I needed the room. Built in reset button. I have a POST in the software and just hitting a button to run it is nicer than plugging and unplugging. Built in ISP programming header so I can change the chips brain.

Since I wanted to learn about CNC from the is project, part of the equation is Going from idea to output. The whole CAD/CAM thing. For the demo I did at the robot group I wanted to take the group logo and put it on the magic screen. I loaded the logo as a bitmap into Inkscape and traced it by hand keeping in mind that the CNC MSM cannot lift the pen. So I had to trace it in one continuous path. I exported it to dxf using “Better DXF” plugin for inkscape. Then converted the dxf to g-code using “Über DXF2GCODE.”

The last thing I did for the project was take the whole prototype to a friend who is really good at making cases more elegant. He trimmed it down, painted it, and reduced some of the wooden parts to get the final version of the setup.

The CNC Magic Screen Machine Project Page has a video and some shots of the prototype.
Also see more description of the building of the machine.

Thanks again to all the people who helped me w/ this project, Nyssa, Paul, Vern, Bob, and Rick.