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.


To help get wildlife counts we have been using the SkyIPCam500W as a wildlife camera.

Since it is not an outdoor camera we built a weather housing.

Details on the camera:
aicn500w

The neat thing about this camera is that it has a built in web server. It has built in motion detection with triggers. Those triggers can be set to ftp a still to a server whenever its triggered. It also has a built in time trigger. So it is possible to say email or ftp a still every so often.

I wanted the server on my local network to poll the camera once per minute and save a photo for each day. I wrote shell scripts to do that. During my reasearch on the camera I found some special URLs that allow you to interact with the camera.

Some of special urls: (assuming everything is setup as the default)

To get one jpeg image from camera:
lynx -auth=admin:admin -source http://192.168.1.240/cgi/jpg/image.cgi >image.jpg

To save the video stream:
lynx -source -auth=admin:admin http://192.168.1.240/cgi/mjpg/mjpeg.cgi >video.mjpeg

To change the brightness/contrast and osd:

wget –http-user=admin –http-passwd=admin “http://192.168.1.240/admin/camera.cgi?brightness=100&contrast=80&osd_enable=1″ -O /dev/null

I just posted the project page for my
Cheap Generic LED Sequencer that I designed for Professor Conrad.

It is based on the ATTiny84 Chip. But I’m sure it would work with the ATTiny44 or ATTiny24.

The neat thing about this one is I have 8 pre-programmed sequences and they are selectable by jumpers or switches.

Not really a snow day but it was finally cold enough and the humidity was low enough in Spicewood, TX to make a little snow. We don’t have the snow makers like the ones on snowathome.com (Although I’m sure we will some day.) So we used a paint sprayer filled with water attached to an air compressor.

The temperature was about 29° and 51% humidity.

Since most of the projects I work on with Atmel are USB based the first thing I do is load AVRUSBBoot on a chip. Once the bootloader is on the chip you can re-program it by setting a jumper on your circuit and using the avrusbboot command line interface. (Example: avrusbboot ./filename.hex)

But how to get the bootloader on the chip in the first place? Easy. Buy a AVRISPMkII from an Atmel distributor. It comes with the necessary hardware and software to program chips. Then the question becomes: If I have a programmer why would I need a bootloader? I guess the answer is: convenience. Once a circuit is built with usb support, which is only 4 wires, it is easy enough to put a jumper on and use the bootloader. When I order a new batch of chips I could put them all on the programmer and load the bootloader all at once.

The downside to the usb bootloader is that it requires a 12Mhz crystal to be attached to the chip. (I primarily use Atmega8 chips.)

Although I have never used one there is a possibility of using a serial port or parallel port programmer built out of very few, cheap components.

There is a good overview of all the methods of programming an avr at ladyada.net.

One of the greatest beginning tutorials I have found for Atmel programming is the I Make Projects article called “A Quickstart Tutorial for ATMEL AVR Microcontrollers.” If you are just starting buy a couple Attiny45 chips and follow that.

Warning: To get a bootloader to work with usb you have to change fuse settings. It is easy to “brick” a chip if you give it the wrong fuse settings. Especially changing the clock and re-assigning the reset line. (Reset is needed to activate the In Circuit Programming.) Read, re-read, and triple read before reprogramming fuses. Look at RSTDISBL, SPIEN, and CKSEL.

When I prep an Atmega8 for use with the avrusbboot program I use Hight fuse @ C0 Low Fuse @ 9F and locks set to EF. As soon as you hit the button to program these fuses it will absoulutely need that 12Mhz crystal on pins 9 and 10 with the 27pf capacitors. Or you wont be able to talk to the chip again.

An online fuse calculator for avr chips.

Now that I have my quick protoboard together it allows me to take other people’s projects and put them together really quickly. Today I built the USB-LED-Fader. Since the hard parts were already done it took about 5 minutes to add the 4 resistors and LEDs to a breadboard. Then another 5 minutes to compile and upload the firmware using the bootloader.

Then I spent about an hour playing with the different LED patterns. This is a really fun project. I can see tons of potential for different status lights. Tie a cpu meter to one of the lights… the faster it flashes the more cpu is being used. One LED for email status. One for network traffic. And finally one for server status.

(The photo from the atmega8 development board shows this project on the breadboard.)

Last night I stared building a atmega8 development board. Tonight I finished it.

I got tired of building the same circuit over and over; so I made a generic board that I could slap onto a breadboard and quickly try out projects. It also allows me to rapidly prototype something new.

I based the board on AVRUSBBoot. The only thing I changed was the programming pin. I moved it to PD7. This allowed me to put PB* and PC* on the plug side of the board.

On the right hand side of the board I brought all the PortC and PortB pins as well as + and GND to a row of header pins.

The important thing about this board to me is that it is USB powered and based. I don’t need to hook up a programmer, I just use the bootloader and usb to update the software on the chip.

My header looks like this:

  1. PC5
  2. PC4
  3. PC3
  4. PC2
  5. PC1
  6. PC0
  7. GND
  8. PB0
  9. VCC
  10. PB5
  11. PB4
  12. PB3
  13. PB2
  14. PB1

Last night I showed my “Hallucination Generation” device at the The Robot Group meeting and many people asked me how the device could cause visual hallucinations. I have a theory about that.

First in normal people speak. Sensory overload in your eyes makes you see stuff.

Now in geek speak. The phenomenon of pareidolia, which is a type of apophenia, is the brain’s (dis)ability to see patterns where none exist. When the UBHG device flashes lights in the eyes it causes retinal fatigue. As the duration of exposure and frequency changes, the amount of noise coming from the cones and rods increases. The brain does its best to interpret the noise. Depending on the viewer’s natural tendency of pareidolia, what the brain interprets can range from just a flashing light to religious icons. Most see patterns like checkerboards, spirals, and triangles.

The next logical question is: Why use Alpha, Beta, Delta, and Theta waves as the basis for the frequency of flashing? I guess the best answer is: Why not? They seem to work fairly well. I do want to make a future version where each of the four frequencies can be tuned to what works best for my body’s specific nature.

Introducing the Unfocused Brain Hallucination Generation device. A Trance Machine based on visual stimulation.

In ancient times people used what is known as the Psychomantium to talk with the spirits. Nostradamus used one to tell the future. In the 1960’s Brian Gysin and Ian Sommerville created the Dreammachine. Recently pioneer Mitch Altman gave us the Brain Machine in Make: Volume 10.

All of these devices try to bring us to a heightened state of consciousness where we can achieve our full potential commune with the universe and see the future.

My device does one thing and one thing only. Makes you see trippy stuff.

I’ve built a Psychomantium. I built the Brain Machine. What I learned was that playing with your visual processing can make you see stuff.

The Brain Machine makes you see really neat stuff. Stuff like I used to see in the old days staring into a Circle K cup held over a strobe light. I tried the Brain Machine without the sound and it seemed to make me have hallucinations as well as with the sound. Plus certain transitions, like from theta to delta, made really neat visuals.

Getting bored quickly and wanting to just have the transition visual effects I made my own. This one has buttons. It allows you to switch from one state to another at will. It allowed me to find out what worked best for me.

This is just the start of my path down the visual stimulator trance machine path. I plan on making one that I can tune to which ever frequencies in each range work best for me. Then I plan on making one where I can easily store programs of different patterns and play them back. Possibly as a USB device. I have even thought about making one that will fill a whole room with light so that the patterns can be given to me while sleeping.

This is going to be fun. 8)

Like I said in my last post I have been working on some tools for writer brainstorming. The first one was the “article title writer” at TheWritersSecret.com. Next is a one for brainstorming movie titles. I call it “Movie Brain”.

The tech behind it:

It is written in JavaScript. That way the work of sorting through the data is done by the client machine instead of the server. JavaScript also has some pretty decent string handling abilities.

I collected over 11,000 titles from the WikiPedia list of movies. These are stored by category and are processed into usable data using a combination of awk, grep, and php scripting. For example:

cat horror_words.txt | awk '1==1 {printf("\"%s\",\n",tolower($2));}' | sort | uniq >movies_all.js

The engine uses a very simple template technique. Examples:
“() meets (2).” The parenthesis would be replaced by two different random words. “Boy meets Bacon.”
“The {} and the ()” The brackets would be replaced by a random amount of random words and the parenthesis would be replaced by a single word. “The egg substitute and the curmudgeon.”
“[]: {}” Here the [] means a year. “2012: Pirates Invade”

The last piece of tech was a fun part. When you generate the random list of movies you can see what they would look like with your standard coming soon movie title over a black screen. Just click on one and see what I mean. It uses JavaScript and CSS to generate and animated the title. For a time I had added zooming in on the title but I didn’t like how much processor it hogged.

I also used a technique for the coming soon generator, to keep it all client side, that I had never used before. A couple days ago a friend asked if it were possible to do forms without a server. Apparently it is possible if you are using method GET. You can just have JavaScript parse the URL to read the data.

While writing the JavaScript I found a wonderful resource JavaScript equivalents for PHP functions.

Next Page »