Python RaspberryPi Steppers Etch-A-Sketch
Last month, at PYPTUG PyHack workshop, we did a lot of stuff with motors. DC, servos, H bridges, PWM and steppers.
It was a very dense 3 hours. We covered a lot, and it was a lot of fun. I've already posted about the 2 bit H bridge, and I'll post some more articles covering some of the other aspects (steampunk DJ gear, anyone?)
But let us get back to steppers for a moment. Steppers are interesting, but just looking at them step one way, then the other, is not exactly exciting. Well, for most folks, anyway.
Silver screenI've been keeping quiet for about a month on the last piece of the workshop. The reason is that I had a talk at the local IEEE chapter, and I was going to let that project go around the room for a live demo (that's right, battery powered), so I didn't want to kill the surprise too much (and it turned out to be a full house). Well, I gave the talk, so I can finally detail this project.
|LCD? Not quite...|
Pi-A-Sketch is a friendly Raspberry Pi in a raspberry colored case. The case is also housing an 8 channel darlington array.
It is powered by a Kodak Lithium battery pack. I was able to pick one up for a meager $6. It is small and low capacity, but it is perfect to power this setup.
It runs Raspbian. It auto logins at boot and start a Python script (roughly 150 lines of Python - I will do a step by step code review in a follow up post). The code is both a program and a module. It can be imported in python or ipython and thus we have an interactive session with the monitor.
Ah yes. the Pi-A-Sketch is connected to its "monitor" in a very mechanical way...
The pictures tell the bulk of the story, it is deceptively simple:
|The Pi drives a pair of stepper motors|
|These stepper motors control the knobs of an Etch-A-Sketch|
|Each stepper is tied to each other to prevent rotation|
The shaft of the Etch-A-Sketch, once we remove the knob, is the same diameter as the shaft of the stepper motors I chose. They are extremely cheap, but have enough torque due to a 64:1 built-in gearbox. They have no trouble doing their job.
With both side keyed, I coupled them with a hollow plastic tube, and filled the key with some hot glue. Good enough.
Walking the lineHorizontal is easy, just turn one knob. Vertical line? same thing. What about diagonals? Anything else?
On the above screenshot, not only are we doing some straight lines, but we are drawing circles. C.I.R.C.L.E.S. Yes, that.
Have you ever tried drawing circles on an Etch-A-Sketch???? Impossible. But, hey, a little Raspberry Pi, and what do you know!
It's trickyThere were a few challenges. For one thing, there is hysteresis to deal with. This is particularly an issue when drawing a circle due to slop when changing direction on an axis. Also, most algorithms are designed to work with a bitmap display. The Etch-A-Sketch is quite definitely not a framebuffer...
In our next episode we'll see how the Python code resolves some of these problems. And we will see how we can use the module to draw lines and circles, and you'll get a refresher on some of Bresenham's work (thank you Jack)... the line algorithm and the midpoint circle algorithm.
What's funny is that he initially started with plotters, but these algorithms are using a bitmap, yet we will reconvert these to be used with an X-Y plotter like interface (delta vs coordinates). Talk about going full circle.
In the interim, I have to get a few minutes to upload the video of the Pi-A-Sketch in operation...