Reverse Geocache

Finished puzzle box

Finished puzzle box

This project was inspired by the "Reverse Geocache PuzzleBox", an idea that has been duplicated a few times. For our yule "secret santa" this year, I drew my brother-in-law, Scott. I know that he appreciates hand-made gifts, and my idea of hand-made is almost always electronics related. I thought for a while about a gift I could give that was hand-made, but appropriate to his interests. While I wouldn't say he's interested in Geocaching, per se, but I know he will appreciate the destination.

That said, I began by designing the electronics. In the original puzzle box, the designer used a commercial Pololu "soft" switch and an Arduino. I decided to make everything custom, including a custom soft power switch. When I say soft power switch, I mean a button you press to turn the system on, but when it's time to turn the power off, the microcontroller can essentially "kill itself".

The circuit I found was listed on this forum. It was an O.K. start, but left something to be desired. To start, the given resistor values were all wrong for my application; I think it was intended for a lower current applications, and the servo powering the latch draws a lot of power, relatively speaking. Also, I'm not sure whether it it was an error on my part, but when the microcontroller shuts down, the output pins go into "high impedance" mode, as if they're disconnected. I had to add another resistor from the control wire to ground to hold it low while the system is off, otherwise it would never shut down. In the future, I think I'll approach it another way.

Reverse Geocache schematic

Reverse Geocache schematic

The remainder of the circuit is pretty straightforward. There is a connector for the GPS, servo, programming header, and LCD. I decided to use the 4-bit interface to the LCD to save some pins. I designed a PCB from the schematic with home-fabrication in mind. While I don't think the through-hole construction is necessary for homebuilding, it's easier for some people. I caution you that the sparkfun outline for the 16x2 LCD isn't quite right. The mounting holes didn't line up. Also, I didn't have the pins for the servo correct, I had to move them around on the connector (5v and Ground are reversed). Finally, another error in the design was that I didn't notice until after I made the PCB that the 4-bit interface to the LCD is on pins D3-D7, not D0-D1. I used a few wires to bridge over to those pins to fix it.

Reverse Geocache PCB

Reverse Geocache PCB

Once the design was complete, I made the board using the toner transfer method and etched it using ferric chloride. I've refined my toner transfer technique recently, and I've been having really good luck. I'll write a post about it soon. Drilling and assembling the PCB was otherwise unremarkable.

Prototyping and programming

It took a few days to program the microcontroller and test the electronics.There was one significant stumbling block that wasted an entire day. Hopefully google indexes this so other people don't have the same pain I did. Here it is: If you're having trouble with the USART on a PIC microcontroller, whether you're using PICC, Microchip C, or Assembler, the Overrun flag stops the USART dead in it's tracks. I recommend that every time you poll the port, check the flag and reset it. This is likely the problem if you can receive 2 bytes, then nothing. Also, the transmitter will continue working.

\( d = \arcsin\left(\sqrt{\sin(\frac{lat1_r-lat2_r}{2}})\right)^2+\cos(lat1_r)\cos(lat2_r)\left(\sin\left(\frac{lon1_r-lon2_r}{2}\right)\right)^2 \)

In the above equation, the \(r\) subscript indicates radians, and returns the distance in nautical miles.

This was the first time I used floating point math on a microcontroller, and I have to say I was a little impressed. I use the distance equations from the aviation formulary. I think it is an interesting equation because it's so trigonometric! It makes sense when you think about it, but fascinating, just the same.

Clasp design

Clasp design

With the code finished, I focused on the enclosure. I started with a weird suitcase-looking wooden box from the crafts store. Then, I measured it carefully and designed the clasp. The main idea is that there is a rotating disk with a notch cut in it. The screw fits within this notch and holds the lid closed.

Clasp

Clasp

With the measurements derived from the dimensional drawing, I drew a few circles. The inner one is the diameter of the servo control arm shaft, the next circle out is the location of the screw. The last circle is the desired maximum outside diameter. Using these circles as a guide I drew the clasp. The tongue has a little bulge to make sure you can't wiggle it open. I drew it over until it was nice and dark, then traced it onto a notepad sheet. I cut this out and traced it to light-ply. My Dremel with an end-mill made short work of cutting it out.

Completed clasp and pin

Completed clasp and pin

Clasp tolerances

Clasp tolerances

As you can see, the final tolerances are really tight. I'm very happy with this mechanism. In fact, later in the process, I accidentally locked the box with bad software. Luckily, the hinge is screwed on from the back and I could remove them. However, the clasp was so tight, I still took several minutes to open it.

Measuring the LCD

Measuring the LCD

With the clasp done, I moved on to the LCD. In this case, I measured it and traced it onto the lid. There are two rectangles. One is the location of the mounting holes, and the inner is the outline of the black LCD frame.

LCD Module test fitting

LCD Module test fitting

Here you can see the LCD module installed in the case. It was a tight fit. In addition to cutting and drilling the case, I cut some acrylic to use as a window. I've been trying to figure out how to hide that ugly black bezel for a while, now.

Acrylic window

Acrylic window

I traced the outline of the display part of the LCD module. I used this to mask out the clear part.

LCD Window

LCD Window

As you can see the bezel is hidden. Unfortunately, some of the red paint leaked behind the masking tape.

Controller assembly

Controller assembly

This is an image nearing final assembly. I use 4-40 hardware through the front of the lid. On the back side of the LCD I installed a nylon and steel washer, then a standoff. On the Standoff threads, there is a nut on the top and bottom of the mainboard. These are to set the spacing of the LCD and mainboard and hold the package securely.

Mainboard installation

Mainboard installation

With the mainboard installed, the GPS was installed. I just used double-sided foam tape. It is behind the lid, and the satellite signal simply travels through the lid. It looks nice and still works great. The wood is so thin, in fact, that the light from the LEDs shines through it.

Arm switch

Arm switch

Going back to the problems I was having with the soft power switch, I noticed that when I left the battery plugged in over night it drained somewhat. It's kinda cheap, but I had to hack-on a power switch in addition to the pushbutton. I use an ancient RC airplane trick where you stick a control rod through the wall to access a switch on the inside.

Power switch outside

Power switch outside

Now, you can hook a fingernail onto the wire. Pull to enable, push to disable.This also prevents from attempts being wasted during shipping.

Final programming

Final programming

This is an image of the final time I programmed the controller. Complete with the puzzle coordinates! It was important to remember to not let the lid close unintentionally, as the target almost 1000 miles from here!

A note about the provided code. It isn't high quality. It's a little embarrassing, but I did it in a hurry.

Resources

code.zip

Eagle files


1584 Words

2010-12-31T12:39:44