Reverse Geocache


Finished puzzle box

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.

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 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.

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.

Latitude/Longitude distance equation (r means radians)

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!

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

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

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

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

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.

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

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

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

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

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

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

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

, , , ,

  1. #1 by Russ on December 31, 2010 - 2:28 pm

    Awesome job! Beautiful workmanship.

  2. #2 by hpux735 on December 31, 2010 - 2:49 pm

    @Russ
    Thanks!
    I really like yours, also.

  3. #3 by machinegeek on December 31, 2010 - 5:59 pm

    Which specific PIC did you use?

  4. #4 by hpux735 on December 31, 2010 - 6:15 pm

    @machinegeek
    Good question… It was an 18F2539 at 4Mhz. B.t.w., using the Hi-Tech lite C18 compiler, this program took 98% of the available code space on the device.

  5. #5 by hpux735 on December 31, 2010 - 6:20 pm

    Also, maybe it’s a good idea to include the compile line for Hi-Tech C18:

    picc18 –chip=18f2539 -DXTAL_FREQ=4MHZ –runtime=+plib main.c delay.c

  6. #6 by Brett_cgb on January 2, 2011 - 12:24 pm

    A fun project – I may do this someday. I’ve already done the Timer ticks (0.5ms, 1ms and 5ms) and servo pulse width timing in a current projects (up to 8 servos). This is absolutely stable – no servo chatter.

    A couple thoughts regarding the PIC Code:

    1) I’d urge you to consider using interrupts for various events (Timers and USART).
    For delays, count the timer interrupt, clear the TMR2IF flag, then exit the interrupt. (Consider using TMR2/PR2 – does not require reloading if configured correctly, but automatically generates consistent timer ticks.)
    For the USART, read RCREG, store byte in a buffer, then exit the ISR.
    Process both events in main code as needed.

    2) Sending servo pulses faster than 50Hz (1 pulse each 20ms) doesn’t improve servo performance – the servo just draws more current.

    3) Consider using Timer interrupts for servo pulse width timing.
    In main code, start the servo pulse based on the TMR2 interrupt count, preload TMR1 with pulse duration, enable TMR1, clear TMR1IF and set TMR1IE.
    End the servo pulse based on TMR1 interrupt (poll first in ISR). After the pulse, disable TMR1 and/or clear TMR1IE.

    Regarding the circuit:

    4) R4 and D2 may not be required – remove/open circuit. D1 can be shorted.

  7. #7 by Brett_cgb on January 2, 2011 - 12:41 pm

    When the PIC shuts down, all I/O pins DO go to tristate mode. Consider what the circuit would do if the PIC were to disappear when in reset or power-down modes.

    With that in mind, reduce R10 to 1k, reduce R3 to 10k, move R3 to between R10 and Q1 base (R10 pulls RC4 to ground). Q1 is driven with the full RC4 output instead of being divided by R3 & R10.

  8. #8 by ups on January 6, 2011 - 1:29 pm

    What GPS module did you use?

  9. #9 by hpux735 on January 6, 2011 - 1:40 pm

    It was eBay item number 180581292221

(will not be published)

Please complete this capcha. I get almost 1000 spam comments a day! * Time limit is exhausted. Please reload CAPTCHA.