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,

No comments:

Post a Comment