Tuesday, December 17, 2013

Eyeball Details: Electrical

How to have fun at the hardware store:

1. Go to the hardware store looking for something out of which to make robot legs.
2. Find nothing but an absurdly long piece of PVC conduit, but hey, you could make a lot of robot legs out of it and it's only 3 bucks.
3. Take conduit to the front counter and try not to hit anything important with it.  (The lady at the counter asks, "Is that yours?")
4. Wonder if you'll have to walk home because conduit is so long.  End up barely fitting it inside your tiny Honda by bending it all the way around the inner passenger side and back seat.

Maybe I should have asked them to cut it in half for me.  Turns out that hardware stores will do that kind of thing sometimes.  Oh well.

Anyway, that's for another project later.  Got to finish with the eyeball first!

If you remember from the last post, the eyeball is driven by two unipolar stepper motors, which needed to be independently controlled to provide the eyeball with two degrees of freedom of rotation. The motors are controlled by an ATTiny85 microcontroller, which only has five IO pins (six if you re-purpose the reset as an IO pin). This meant that driving each coil tap of both motors with a separate IO pin was unacceptable. Fortunately, there's an existing stepper motor control circuit design that allows the motors to be controlled with only two wires:

I was first introduced to this highly useful circuit by a page on the Imperial College of London web site, but it has since been taken down, and I found myself without a reference for the circuit when I needed it. I think I can credit this site for helping me rediscover the circuit. Note that there is a separate connection for the motor power voltage, which is allowed to be higher than the logic voltage. In this project I didn't want to power the motors with more than 5V, so I just tied the two power connections together.

The control circuit is small enough that I was able to squeeze the drivers for both motors onto a single small square of proto-board. The other board in the eyeball holds the (socketed) ATTiny, a voltage regulator with its capacitors, and a switch. That's it!


I used an Arduino Leonardo to program the ATTiny85. The availability of this technique was a major driver of my decision to use an Atmel microcontroller for this project. I've always been deeply frustrated by the fact that affordable microcontrollers often seem impossible to program without purchasing an expensive dedicated programmer board, or building a homebrew programming circuit that itself requires a programmable chip (leading to a chicken-or-egg problem, unless you know somebody who already has a programmer). I have some old Freescales whose datasheet included a programming circuit that I was able to build myself, but they're essentially obsolete now, and I needed a new solution. An Arduino board costs $25 or less, is friendly with various microcontrollers in the Atmel family, and can be used for other things besides just programming other chips. Woah!  Shockingly, there were no compatibility problems with my computer, and though the process of getting the Arduino set up for programming wasn't as straightforward as it could be, everything worked the first time I tried it. I used the instructions given here and here.

Software for the microcontroller was written in Arduino's high-level code language. I didn't use any pre-existing stepper motor libraries. Creating a loop to generate the correct pulses on the control lines was easy enough, and seemed quicker and cleaner than trying to use somebody else's library. Once I had code for turning each motor in either direction, I created an outer loop that would perform one “move” per iteration. At the beginning of each “move,” several pseudo-random numbers are generated and used to decide the length of the move, which of the two motors will be active, and which direction each active motor will turn.

The development time for this project was less than one month (including the planning phase).

Eyeball budget (electrical systems)
1.75 inch square proto board X 2: $2.49
4AA Battery holder X 1: $2.49
ATTiny85-20PU X 1: $1.29
8-pin DIP socket X 1: $0.19
Darlington transistor array (ULN2003A) X 2: $0.44
1K resistor X 8: $0.16
12V Zener diode X 2: $0.04
Pin headers (6 pins): $0.19
Wires and connectors: free salvage
5V regulator (MC7805CT): free salvage
Switch: free salvage
Capacitors: free salvage
Electrical total: $4.80

Does anyone else find it ironic that the circuit boards and battery holder are the most expensive things on this list??

Project total: $12.04


The Arduino cost $21.95, but since it's only the programmer, I'm treating it as a piece of equipment rather than part of the project.

Until the next cycle,
Jenny

Sunday, December 8, 2013

Eyeball Details: Mechanical

I said I would give some more details of how the mechanical eyeball works, so here we go.

The design uses two motors, enough to turn the eyeball forward or backward around two different axes of rotation. At first I considered driving it with a “reverse mouse wheel” setup, in which each motor turns a roller that touches one side of the ball. But when I sat down with my materials and actually started thinking about how I would mount the motors, I started liking this idea less and less. For this movement to work properly, the rollers need to be held against the ball with enough pressure that they won't slip, but not so much that the whole thing binds up and stops turning … not a big problem if you have a well-constructed housing to hold everything together, but I had cardboard and ice pop sticks to work with. You can only make things so precise with those materials. Okay, not very precise at all, usually.
Anatomy of the human eye.  By Patrick J. Lynch, medical
illustrator, and C. Carl Jaffe, MD, cardiologist, via
Wikimedia Commons.

Thinking about how my own eyeball works, I thought of connecting strings to four points around the ball to act as “muscles.” But muscles can only pull, not push, and I didn't want to be doubling the number of motors needed. I wound a pair of strings around each motor shaft so that when the shaft turns, one string loosens as the other tightens … so a single motor can drive a differential pair of “muscles.” The motor shafts are made from ballpoint pens, and the plastic is soft enough that I could poke holes in the shafts and thread the strings through them. This arrangement seems far more reliable than the reverse mouse wheel drive. If the shaft turns, the eyeball moves, even if things have (ahem) shifted around a bit inside the housing; there's no need to worry about rollers slipping. When the eyeball was undergoing its major demonstration (at work on Halloween), I discovered a couple of minor problems. One of the strings got snagged on a protruding piece of wire and had to be manually disentangled, and another frayed through because it was routed around one of the ice pop sticks and was rubbing against it constantly. I think I can avoid this in the next design iteration with more durable strings (perhaps a polymer monofilament line instead of embroidery thread) and more care given to string routing and possible snag points.

I actually went to several stores trying to get a ball that would work for this project. Originally I wanted one without holes. It also needed to be hollow so I could put a camera inside some future version, and needed a fairly smooth, rigid surface so it could turn easily in the cradle. The only ball I could find that met the other requirements and was about the right size was a wiffle ball, so I had to live with the holes. Then I decided to use the muscle drive, and the holes turned out to be very fortunate, since they made it easy to attach the strings to the ball. This wiffle ball was a one-dollar party favor that came with a little rubber ball that holds flashing LEDs inside … not useful for my purposes, but it doesn't hurt anything. The only problem was the seam where the two halves of the ball were joined together. It wanted to catch on the edge of the cradle when the ball was turned. I solved that problem by filling the crack at the seam with superglue, then vigorously sanding all around the circumference of the ball until the seam was smooth.

The motors I used are six-wire unipolar stepper motors, model #PF35T-48L4. They're fairly precise, easy to control, and have an appropriate torque-speed balance for this project. (I.e. no gearboxes were needed. Phew.)

Closeup of one of the motors and the ball cradle.
There isn't too much to say about the housing, which is really just a junky prototype until I get the tools to make something better. The cradle that holds the ball is made of two cardboard rings of different diameters, separated with pieces of foam. I covered them with part of a smooth plastic bag so that the rough edges of the cardboard would not impede the ball from turning. Wire hoops at the four corners of the cradle guide the strings so that they pull the ball in the right directions. More ball point pen pieces support the cradle above the base. The motors and the ends of the motor shafts are held in place with the ice pop sticks and tongue depressors, which go all the way through the base and the lid to hold everything together. I joined all the pieces with bent paperclip wire or pieces of narrow plastic acting like cotter pins, because I've learned that glue is not to be trusted. (Some strong glue is fine to keep things from wiggling around, but never expect it to bear a load.)

I'll go into the electronics and software in another post.

Eyeball budget (mechanical systems)
Stepper motor* (PF35T-48L4) X 2: $3.50
Wiffle ball X 1:                                 $1.00
Everything else: probably <                 $.25
Total:                                               $4.75

* This model doesn't seem to be available any more, at least not in hobbyist quantities. If you're looking for an extremely cheap stepper motor, the best replacement I can find is this.

Until the next cycle,
Jenny