Saturday, April 30, 2011

Functioning Clock

I got the clock together and functioning today. It gets the data wirelessly over the Arduino Ethernet shield and wireless AP that I bought. The servos have been calibrated and it checks every minute for any new updates on the server and moves the hands to the proper location. There's still a long list of stuff to do before I consider it completed, but today really marks a milestone in the project.

Servo calibration

I'm working some more with the servos and with the gearing I have the servos will move the hands 540 degrees (1-1/2 turns). The Arduino servo class takes inputs between 0 and 180. On my clock, this translates to 3 o'clock position being 0, 12 o'clock as 90 and 9 o'clock as 180 going around clockwise.

I needed a method to make sure that each of the 5 servos:
  • start and end at the same positions
  • can reliably hit each of the 12 clock positions reliably
The first one is pretty easy. When attaching a Servo object to a pin you specify the minimum and maximum time (in us) that the servo will use. Most servos use 900us as a minimum and 2100us as a maximum. By altering this slightly for each servo I could get all the servos to start and end at the same position.

The second one was a little tougher. It turns out that a 10 degree Arduino input corresponds to one clock face position (30 degrees) for all the servos, but one servo would not reliably move to a position if the movement was too small (10 Arduino degrees). I wrote a subroutine in the Arduino code to take an offset factor defined for each servo (the first 4 are zero; servo5 uses an offset of 4) and the code causes the input value and goes a little farther to help push the servo to the desired position.

Here's an example of how it works: If the current position is 20, and we need to move to 30 the subroutine will actually move the servo to 34 for a couple seconds and then back to 30. If it's at 60 and we want to move to 50 the subroutine moves it to 46 for 2 seconds then to 50. It does this even for larger moves, and seems to work pretty well for this stubborn servo.

Friday, April 29, 2011

Wireless Bridge

I picked up a 3Com Wireless b/g access point off of Amazon for $20 used. I want the clock to get its data over the home wireless network and not have to run one more cable for this thing.

It took a bit of messing around with the access point to get it into a working bridge mode, but I did finally get it to work. Hooray! I can move the clock around the house now.

Wednesday, April 27, 2011

Alternative Drive Idea

Before I embarked on the build of the project I was torn between using servo motors or using stepper motors. I had originally opted for the servos because an Arduino can only control 2 steppers with the motor shield, and up to 3 with the EasyDriver Stepper controller. I need 5 motors, so each of these options were out and I went with servos instead.

After some frustration with the servos, I started to reconsider how I might control more steppers with the Arduino. I remembered back to my college days of basic circuit design and remembered a device called a demuxer that could control multiple output lines with fewer input lines triggered by a binary pattern. I checked out the EasyDriver again, and it has an "enable" pin that "enables" the board and the motor. If I could take 3 digital lines from the Arduino through a demux I should be able to control up to 8 stepper motors (each with their own EasyDriver).

I took down some notes (which I will add later) to detail more of this design, but unless my servo version complete craps itself I'm not going to ditch the current design. I've already sunk too much money in it to switch now. Maybe a version 2.0 later one will use steppers (or someone else can use this idea!)

Edit (5/2/2011): I found this chip (DM74LS138 8way demux) that could be used to switch up to 8 stepper motors with one Arduino. You could only control one motor at a time, but that should be fine for a clock. A counterpart 8-1 mux could also be incorporated to receive a location switch closure to make sure that the hands are where you think they are.

Some Servo Problems

I ran into some servo problems a while back that I haven't had time to try to fix. The first one turned out to be a programming error where I was using a byte data type to hold too much data. I'm finding that the C-like programming of the Arduino is very limited, and it's taking some getting used to from my experience with more fully featured Perl/PHP languages that I'm used to.

The second thing was that one of the servo motor brass gear shafts kept popping off the plastic servo output shaft. I fit the 1/4" o.d. brass tubing over the slightly less than 1/4" servo drive shaft by expanding the brass tubing slightly. The problem was that the alignment between the servo and the end of the brass tubing was off slightly causing the tube to "walk" off of the plastic shaft as it rotated. I took my micrometer and measured the vertical and horizontal variations from back to front on all the servos. Most of them were off my .02" at most (which is about the size of a mechanical pencil lead) and shouldn't be a problem, but the one in particular was off by .06" and was causing problems. I removed some rubber mounting bushings which allowed a little more wiggle on the servo mounting and now it's within the .02" variance as the others. So far, so good.

I also found that for large movements the servos did well, but for small adjustments (10 degrees in Arduino) it didn't always do well in repositioning. I thought that there might be too much friction in the gear shafts for the servo torque to overcome, so I tore everything apart again and applied a little oil to all the brass. It helped a bit, but still didn't solve the problem. Then I remembered that these servos are rated something like 5-7 volts, and I had been running them on 5 volts. After bumping up the power supply to 6 volts, everything seems to be in order.

I wrote a quick program to help me calibrate the servo motors to the various clock positions. I plan to do this initially with altering the low and high PWM values for the servos. The factory recommendation is between 900 and 2100 milliseconds, but each servo is a little different (gotta love analog!) By altering these values slightly I can get the servo start and end positions very close to each other. The next step will be to validate the intermediate positions and see if additional adjustment factors are needed to get each servo to reliable move to each of the 12 clock positions.

Wednesday, April 13, 2011

Adding some error checking

I figured that it would be nice for the Arduino to be able to indicate that there was a problem without having to have it connected to a PC. I added a single LED to an unused pin and created a routine to blink it on and off based on an error condition. Works pretty well.

Well enough to tell me that for some reason the Arduino w/ Ethernet shield doesn't like to work without being plugged into USB as well as the external power. It could be that my power supply isn't clean enough or enough voltage to operate everything at once. More investigation is needed. I was hoping to only have a single power cord for this clock.

Tuesday, April 12, 2011

Positioning Code and First Breakage

Tonight I was able to work on some of the positioning code for the clock. Yesterday I was able to get all 12 positions working, but the servos allow for up to 540 degrees of movement in the configuration I have. I want the hands to randomly move to the location if more than one direction is possible. I was able to do just that right before one of the drive shafts came off the servo. I'll have to repair it to get back on track. It does concern me that these may come off fairly easy. I don't want to glue them to the servo, but I may have to find an alternative to pressure fitting them.

Monday, April 11, 2011

First Arduino Clock Code

Tonight I hooked up the possibly completed clock movement to the Arduino and started to assemble the network fetching code with the servo movement code to actually make the clock be a clock.

I think I have the twelve locations that I want the clock to have. I chose all of the locations mentioned in the book along with a few of my own to round out twelve.

It turns out that the 30 degrees between clock points is almost exactly 10 degrees in the Arduino servo code when using these sail-winch servos. With the gearing I have in the clock I get a little more than 540 degrees out of each servo. I will eventually add some code that will make the servo move in the most optimum direction to get to the location. That'll have to be part of LOTS of other optimizing I will need to do to polish this thing up.

For now, I have a paper dial with the 12 locations and small zip ties for each of the five hands. Here's a sample pic:

Sunday, April 10, 2011

Movement Almost Finished

I was able to run by the hobby shop after church today to pick up more servo mounting screws, and I was able to get the last of the servos mounted on the backplane.

I also was able to complete the nested shafts for the hands of the clock. I had 5 sizes of brass tubing that all nested nicely into each other, but all my gears have 1/4" holes. I had to cut small spacers of each of the necessary sizes to make the small diameter shafts fit snugly with each drive gear. Here's a pick of the finished hand shafts:


I used 5 min epoxy to glue the brass tubing together. I know that most glues won't work on metal (it's non-porous). Epoxy should do the trick. It's not like any part of this clock requires lots of torque or has lots of pressure on it.

I was able to attach the brass drive shafts to the servos by expanding the tubing slightly and pressing them onto the plastic shaft of the servo. So far, it's holding well and aligns perfectly.

Here's some more pics of the finished mechanism:




Saturday, April 9, 2011

Build Started

I stopped by the hobby shop on Friday and picked up some more hardware to work on the Whereabouts clock. I've been working with Sketchup to model the clock in 3D before I start cutting brass tubing and plywood. I was able to model the servos and gears and got a good top-view of the mechanism. I printed it out in full scale and was able to use my drill press to drill the 6 holes for each servo shaft and the center shaft. I then used the scroll saw to open up the holes in one piece of plywood to make the holes where the servos mount.

For the brass tubing I was planning on using a regular tubing cutter, as the guy at themagicclock.com had used, but I must say it was a dismal failure. I knew that the cutter would leave a bit of a lip on the inside of the tubing that would need to be filed off, but it actually resized the end of the tube slightly smaller where the next smaller tube would no longer fit. I quickly abandoned the tubing cutter and went with a Dremel tool fitted with a cutting wheel and griding stone. I was able to make quick cuts through the tubing without having to resize it after each cut.

After a full day's work on it I have 4 of the 5 servos mounted to the back piece of plywood. I have all the brass bushings for the axles on the front plywood, but these will need to be glued in later. I don't have the nested center tube completed for the hands yet, but I was able to successfully stack all 5 center gears and the individual servo gear on their own axle. I even plugged them into the Arduino running the same little servo test from a previous post and they all work just fine!

Here's a picture of the progress I've made so far: