This project was inspired by the “Reverse Geocache Puzzle Box“, an idea that has been duplicated a few times. For Christmas this year, I drew my brother-in-law, Scott. I know that he appreciates hand-made gifts, and my idea of hand make 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. When it’s time shut the system down, the controller can turn the power off. The circuit I found was listed on this forum. It was an O.K. start, but left something to be desired. 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 PIC 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.
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 16×2 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.
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.
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.
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 accepts latitude and longitude in the form of radians, does a little trigonometry magic, and away you go!
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.
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.
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.
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.
Here you can see the LCD module installed in the case. It was a tight fit. In additing 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.
I traced the outline of the display part of the LCD module. I used this to mask out the clear part.
As you can see the bezel is hidden. Unfortunately, some of the red paint leaked behind the masking tape.
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.
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.
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.
Now, you can hook a fingernail onto the wire. Pull to enable, push to disable. This also prevents from attempts being wasted during shipping.
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.