Step 13: Programming

Now it's time to program the atmel. I used avr-gcc (a free compiler) to compile my code, and avrdude to burn it on to my chip.

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.
Operation to the echa sketch
would it be possible for you to mod an old printer one that runs on guide polls in order to virtually print things onto an etch a sketch... black and white images for example?
Do you mean that I'd print to the printer, but it would send the image to the etch-a-sketch instead? If I was going to do that, I wouldn't bother with a printer--I'd just write my own 'print driver' and send commands directly from a computer to the etch a sketch. There's a more fundamental problem, however, which is that an etch-a-sketch is a vector printer, not a raster printer. What that means is that etch-a-sketches are great at drawing paths, but not going through a drawing and saying "let's color this pixel white, the next pixel white, and the next one black." If you could modify and etch-a-sketch so that you could lift up the pen, it would be both much cooler as a vector drawer, and it would also be possible to use it to print images.
You know, you could probably take apart an etch-a-sketch and add a 3rd motor or servo or actuator or something that would lift the glass up and down. Although that aluminum dust gets over EVERYTHING! (I'd recommend respiratory protection)<br/><a rel="nofollow" href="http://www.howstuffworks.com/question317.htm">http://www.howstuffworks.com/question317.htm</a><br/>
I didn't just mean mod the printer i also meant to mod the printer drivers so it would understand printing constant line through vectors, and to not break the line and to stay on that track instead of printing line by line.
Well, there's not much similarity between vector and raster printers, so you might be better off writing your printer driver from scratch, especially since many drivers I know aren't open source. Writing a program in processing that would take a vector file and output the right set of serial command to the etch-a-sketch would be pretty easy.
long before windows i had a vector(called a plot ) printer that used inkpens .4 foot wide 12 foot long bed have to print each color one at a time ( then change the pen ) it was run from a BASIC program mostly had to do with PEEK/POKE commands .it would lift the pen but didn't have too. could make wonderful Blueprints,the hard part was the system running it did not have a VGA monitor altho did have a mouse think about how good that works
a mouse with out a monitor? that reminds me of the stupid keyboard error. "KEYBOARD NOT FOUND PRESS F12 TO CONTINUE" or some such nonsense.
the mouse lives on a large board on the front it has a little clear plastic tab with a crosshair. one corrner of the board is a "home "positition click that then click the icon wanting to input . if the mouse gets lost then take it to home , and it does. this was used to write fanuc programs to can for a cnc lathe. Fanuc is very close to basic type program using commands like basic peek/poke
oh that's cool, I'd never heard of that.
Thank you for the clarification.
Speaking of this, I'd like to see some one use this instructable to make a laser etching system, using a dvd burner diode and the etch a sketch guts. I'd like to do it my self, but I'm putting the idea out there cause I'm strapped for cash and parts.
where is the ground from the motor battery supposed to go?
would the pullup resistors be a different value if you used deifferent motors?
so pin 1, 16, and 9 are all connected to 5 volts?
I am in the process of doing something like this but making it r/c hopefully being able to make circles.
If it were to draw boobs.... Would they still turn out square?
is this some sort of zen koan?
4 C-cells to get 6V, or for life, liberty and the pursuit of amps?
wey-all, them amps don't hurt much, but dem L-293s need at least 6V on the power side to work well. Ja coulda useda four AAs, but dey'd just do dead fasta
L293D! Whee! Hey, were we ripping apart atoms before hair-chopping, or was that buzzer just really loud?
I built one at work a few years ago to test some code for an X-Y table we were retrofitting. I used stepper motors and a Trio CNC controller, a bit of overkill I know, but it worked pretty good. All of the parts eventually got donated to other projects after the fun wore off. I like the bracket you made for your motors; far superior to the jack leg job I did on mine:-) B.
i heart mars.
In a way, I think of mars as my mother. The way where I have a life-sized Mars doll I hug before going to sleep every night. On Saturdays, I dress up the doll in floral gowns!
I love those things, they're just plain awesome!
<a rel="nofollow" href="http://instruct1.cit.cornell.edu/courses/ee476/FinalProjects/s2004/jml66/EAS_final.htm#Design">http://instruct1.cit.cornell.edu/courses/ee476/FinalProjects/s2004/jml66/EAS_final.htm#Design</a><br/>
Awesome! It's pretty ironic that you post this now; my math theory professor was (for some reason or another) talking about automated etch-a-sketches at the end of last year.... I'm surprised I didn't get to see your etch-a-sketch when I visited MITERS a few weekends ago... I'll just have to ask Star to show me it next time I visit ;-) +!
I'm not sure if it's still around miters. I wouldn't be surprised if it's been put to other uses by now.

About This Instructable


39 favorites


Bio: here: http://www.artiswrong.com But really, I'm just this guy. For up-to-the-minute, action-packed updates on my life (and occasional drawings of tapeworms getting ... More »
More by prank: How to Draw Sweet 3D Graphics for LED cubes Make rad solar panels in minutes with a sweet desktop laminator Pixie, the world's most intense desk lamp
Add instructable to: