**I'm going through and finishing a slew of old instructables I never published. I think I made this one sometime last year. Enjoy!
So, there I was, skipping class at MIT and hanging out at my favorite machine shop. While I was sitting in my favorite comfy chair, a flash of red shining from beneath a pile of books caught my eye.
"Aha!", I said, "What could that be?"
Further excavation yielded a classic red etch-a-sketch, perfectly preserved since Steve Cooke left it there twenty years ago.
I thought to myself, "I hold in my hands a perfect basis for a computer-controller vector drawer"
A maniacal grin crept across my face as I felt my plan grow to fruition inside my mind.
This, my friends, is the true story, complete with instructive pictures, of how a person such as yourself built a computer controlled etch a sketch. Sure, it's been done before. Now you can do it, too.
So, what are you waiting for? Skip a class and go build something!
Step 1: Overview
you're going to take an etch-a-sketch, pry off the knobs, put motors where the knobs once were, and then build a circuit that lets you control the motion of the etch-a-sketch from a computer
Step 2: First bit--figure out how to add the motors
You should be left with an etch-a-sketch with two metal nubs sticking up, each with a flat cut into it that used to mate with the hole in the knob.
Grab a calipers and measure the diameter of the metal nubs. Write it down somewhere.
Before you go on to the next step, play the song 'Neigborhood 1(tunnels)' by the Arcade Fire on your home entertainment and theater surround sound audio system and let its genius blow you away.
Step 3: Measure up the motors
Now, look around for an aluminum rod that's at least twice as big in diameter as the larger of the two shafts you found. You're going to use this to make a coupling between the motors and the nubs.
Step 4: Make the couplings (lathe time!)
For anyone interested, my stock was about a foot of 1" diameter aluminum.
Take your aluminum rod and mount it in a lathe. Find a drill bit that's a tiny bit smaller* than the smaller of the two shafts. Drill a hole in your stock for a little more than an inch. Now, find a drill bit a tiny bit smaller than the larger of the two shafts and drill that into your stock for 1/2"
Cut off inch you just machined. Make one more part the same way. While you're doing so, turn on the song 'Bottle up and Explode' by Elliott Smith.
- You're going to put setscrews into your couplings, so if the drill bits are the same size, or even a little larger than your shafts, it's OK.
Step 5: Put on a flat and drill some holes
I was feeling all fancy, so I used a mill. This just makes it easier to drill into.
Now, find a tap drill for an 8-32 screw and drill two holes in the coupling, about 1/4" from either end.
May I suggest the tune "Fake Palindromes" by Andrew Bird for this step?
Step 6: Tap the holes
While you're at it, take a look at your motor shafts. If there aren't flats, use a dremel or a bench grinder and add a flat on each shaft. This will help the setscrew hold the shaft in place.
"Take me to the Riot" off The Stars' new CD is a great song. In fact, the entire album is great--check it out.
Step 7: Check Out Your Couplings
So, this step isn't terribly thrilling, but listening to "Holy Calamity" by Handsome Boy Modeling School will make assembling motors much more fun.
Step 8: Stiffen Everything up.
Fortunately, I had used these motors for another project and I had made lots of nice waterjetted motor mounts(shown below). It's not a difficult part to make by hand--it's just a plate that goes on the front of the motor, with a hole for the motor shaft and three holes for mounting screws that screw into the motor. I can try to dig up my CAD file if anyone wants it, but the dimensions just took a few minutes with calipers to figure out. To make the mounting plate, I used 3/32" steel plate and there are four holes you have to drill.
I took a couple mounting plates and bolted them on to the motors. Then, I took the motors and put the couplings on them, coupling them to the etch-a-sketch. I grabbed a piece of 1" angle iron and measured out the distance between the two motor mounts, including the width of the mounts, and then cut my angle iron using a chopsaw.
Next, I rotated the motors and motor mounts so that the long parts of the motor mounts were both sticking off the etch-a-sketch, exactly parallel. I then put the angle iron over the overhanging part of the motor mounts, making sure that they were flush with the inside edge of the angle iron(the elucidating pictures below should illuminate your path through the darkness of confusion)
In retrospect, I didn't need to spend so much time making sure the motor mounts were parallel, but this made my finished product sexier.
Now that I had my angle iron lined up on my motor mounts, I grabbed a MIG welder and did a light tack weld on both motor mounts, where the mount overlapped with the angle iron. I didn't want to do a full weld with the motors still attached to the mounts for fear of heating up the motor too much and screwing up a bearing or winding.
Then, I valiantly uncoupled the motors from the etch-a-sketch and un-bolted the motors from the motor mounts, leaving me with the two motor mounts tacked onto the angle iron. I put some sturdier welds joining both mounts to the angle iron(see below) and casually slew a dragon that kept sticking its nose into the machine shop.
I sat atop the dragon carcass and admired my work(see below) while feasting on fresh dragonflesh--there's nothing like it!
Step 9: Painting
Rooting through the shop paint cabinet, I dug up Federal Safety Yellow and Flat Silver. They would have to do.
My fingers were also painted Federal Safety Yellow after this step. Everybody knew to stay away!
Step 10: It's time for a haircut
Step 11: Moving on to electronics
If you like, take a 9V battery and touch it to the terminals of each motor and watch them draw stuff on the etch-a-sketch screen. It's pretty cool, isn't it? Science is definitely happening.
The next steps of the instructable will explain how to hook up the etch-a-sketch to a microcontroller and program it to draw stuff.
The schematic below is frustrating to read. Hover your mouse over it and click the small italic 'i' at the bottom left corner. It should show the same frustrating image on a new page, but with a link to the original ~1000x1000 pixel image. Click the link, and the schematic should pop up with blinding clarity. Sorry about that.
As I mentioned at the start of the instructable, I used an Atmega48 micro. I used an stk500 to program it, and I breadboarded up an L293D motor driver, which I powered with a 6V battery pack. I kept the atmel on board the stk500.
If you haven't checked out the L293 chip, I highly suggest you do. It's called (somewhat irritatingly) a quad half-H chip. An H-bridge is a name for an electrical circuit that allows you to create a forward or backward potential difference across a load (i.e. drive a motor forward or backward). This gorgeous chip can handle up to .6A at 35V if you ask it nicely (heat sink the crap out of it) and control two different brushed motors simultaneously, or you could use it to drive one unipolar or bipolar stepper motor. I use them like they were candy. Circuit candy. That I put in my breadboards instead of gorging myself on their sweet silicony flavors.
If you're not familiar with atmel programming, may I suggest some of these fabulous instructables?
Step 12: Wire up your breadboard
If you're using an stk500, throw your mega48 into the green socket, and plug one of the 10-pin connectors into the portB header. Don't forget to wire the 5V and (more importantly) circuit grounds together. If you want to put the mega48 on the breadboard, that's fine, too. If I'm building a temporary circuit, I just like to use the stk so I don't have to wire up as much.
You'll also notice on the schematic that there are two power supplies, VCC and VDD. Vcc is the 5V supply that powers the atmega and the logic side of the L293 chip. There's another side of the L293 chip that deals with the power that actually goes to the motors, and it's a very good idea for these two power supplies to be separate. I used a pack of 4C cells to power the motors, and that lasted for three weeks of playing off and on with this thing.
Step 13: Programming
Unfortunately, I left my code behind on the shop computer when I moved out to LA at the beginning of the summer, and there's a possibility that the code is lost and gone forever. Rather than try to rewrite it(although I'll probably find a copy when I get back to LA in a few days--I'm in frisco now), I'll try to walk you through programming techniques you can use for this baby. Wouldn't you rather learn to fish than eat fish, anyway?
Here' s the basic theory behind the code:
Drawing is an open-loop process. The only way we have of knowing how far the etch-a-sketch has drawn is by figuring out how long we've been turning the motor at a constant speed. The problem, of course, is that the motors vary their speed based on the battery voltage, which could change from day to day. I could regulate the motor voltage, but I find that idea abhorrent and unnecessary. Instead I'll sit back and listen to the song 'Frankly, Mr Shankly' by the Smiths with a smug expression on my face.
To get around this, I pretend I'm drawing vector images (i.e. images that are composed of scalable lines and curves). I make a global variable in my code called scale, and if I had a function such as drawLine(angle, length), I would call it with an arbitrary number for length, say 3. Inside the function, I have code that says: Draw a line at the proper angle for 3*scale seconds
Does that make sense? Good.
Here are some basic functions:
void drawRight(unsigned char distance)
void drawLeft(unsigned char distance)
void drawUp(unsigned char distance)
void drawDown(unsigned char distance)
for those of you who don't want to write it, here's the wait function:
void wait(int time)
int count, count2;
for(count=0;count<1000;count++) //we're going to burn lots of cycles here.
OK, this ought to get you going. Play around with this code for a bit and draw lots of horizontal and vertical lines. Maybe a box. In the next section I'll talk to you about curves.
While you program, check out the indie label Kill Rock Stars. Next to Matador, it's one of my favorite labels. ok, cool.
Step 14: More programming(angles and curves)
and loop that for a while, but that'll never be all that smooth.
Wouldn't it be much cooler to run both motors at the same time, and run the vertical motor(in this case) half as fast as the vertical motor?
The way to do this is with PWM. For those of you who aren't familiar with this wonderful thing, PWM stands for "Pulse Width Modulation" and is a way of approximating a value between 0 and 1 in a digital circuit.
Here's a brief rundown:
Let's say I have a chip that can produce either 0 or 5 volts. This chip drives an electric motor, and I'd really like to run it at half speed, or 2.5 volts. I can't produce that voltage directly from my digital chip, but maybe if I output 0 volts for a while and then 5 volts for the same amount of time, the average output would be 2.5 volts. If I do this really slowly, the motor will jerk on and off, but if I switch between 0 and 5 volts really quickly, the motor will run smoothly. This is because the motor has a damping effect, and for some high frequency, can't respond as quickly as the signal is changing, effectively averaging the voltage across it. Hooray! Now I can control a motor's speed!
"If I want to produce a different voltage, say, 3 volts, I would just keep the signal at 5 volts for 3/5 of the time. 2 volts, 2/5 of the time. Ad nauseum"
OK, so practically, I'd like to write a PWM routine that can output a pwm wave to both motors simultaneously.
void pwm(unsigned char horizontal, unsigned char vertical, unsigned char horizontal_direction, unsigned char vertical_direction, int magnitude)
unsigned char count,output;
The angle you draw at (from the horizontal) will be pretty close to atan(vertical/horizontal).
Now you have a function that lets you specify the magnitude and direction of a drawn vector. This is the basic, fundamental component of any vector graphics renderer. Sweet!
Step 15: Delicious!
here are a few examples, though, to get you started:
//I use trig functions in this example, and you'll need to find some avr library that supports them
//or just whip up a table
double x,y,xp, yp, int mag;
unsigned char xval, yval;
unsigned char xdir,ydir;
Foster the dog wishes you good luck in your programming endeavors!
Valerie the dog suggests you listen to DJ Z-trip. Wait, that's not Valerie. That's me.
Step 16: Done!
Well, this instructable's done! I'm going to go and do something unwise now (see image).