Friday, September 19, 2008

Home-made GPS for Nikon D300

Please read the next blog entry before building this circuit, as it details some important upgrades.

I'm in Ireland for a small vacation, having left Los Angeles (and indeed the US) permanently last week. I start my new job in Paris next week, so I'm enjoying the opportunity do do absolutely no work this week!

One small Nikon project I worked on before I left L.A., inspired by some other blogs, is a home-made GPS which connects to my D300. The GPS is based on a Globalsat BR-355 engine, which can be purchased cheaply on eBay ($25 - Sept. 2008), with a simple interface using two FET transistors and a couple of capacitors (bypass and reservoir) to ensure the signal is nice and clean.

The BR-355 outputs an RS232 serial datastream which carries NMEA-formatted position and time information at 4800 baud. Logic levels from the BR-355 are -5V for logic 1 and +5V for logic 0 (i.e. standard RS232 at 5V). The camera expects +5V CMOS signals, +5V for logic 1 and 0V for logic 0. The interface circuit therefore needs to be an inverter operating between +5V and 0V, which can deal with negative voltages at its input. Others have suggested a simple NPN-transistor with a diode clamp and a couple of resistors, which should work fine. I opted for an N-channel and P-channel MOSFET configured as a CMOS-like inverter. The basic circuit is show below:

Like real CMOS output stages, one of the transistors is fully on and the other fully off when the input is held at a fixed logic level. When the GPS voltage is -5V (logic 1), Q1 is on and Q2 off, so the output is held at the +5V rail. When the GPS is at +5V (logic 0) then Q1 is off and Q2 on, and the output is held at ground. No clamping diode is needed as the N-channel FET (Q2) can handle negative voltages on its gate. Current only flows through this circuit when it is switching from one logic level to another. At some cross-over voltage (between 0V and +5V) both transistors conduct equally and current flows between the rails. This happens only very briefly as the GPS voltage slews between its two states, but can give rise to spikes on the output line. The bypass and reservoir capacitors in the circuit eliminate these spikes (actually, in a circuit this simple only one of the capacitors is really needed, but it's good practice to put them both in). The voltage at which this cross-over occurs is dependent on the characteristics of the MOSFETs used - in a real CMOS gate the two transistors are built so that the switch over is half the rail voltage (+2.5V). With the two transistors shown the switch over is +1.8V, and the circuit uses approximately 1 microamps when fed from the NMEA datastream (compared with the 40-80 milliamps that the GPS itself consumes!).

The circuit and GPS board all fit nicely into a small project box.

The final thing that needs to be discussed is the connections to the GPS engine and to the camera. The BR-355 consists of a GPS engine in a nice molded enclosure with a magnet to attach it to a metal surface. To use the engine in this project I suggest that you extract it from its enclosure - you have to do some cutting to get the cable free. The GPS engine has a small 5-pin connector and comes with cable that you can cut to any length you desire. You can see in the photo above that I left about 2 inches. The wires on the GPS cable have the following functions:
  • RED - +5V supply to GPS,
  • BLACK - Supply ground,
  • GREEN - Serial data (NMEA stream) out of GPS,
  • WHITE - Serial data in to GPS - can be used to send commands to GPS board to change its configuration,
  • SILVER braid - Cable ground.
The BLACK, GREEN and RED should be wired to the connector labelled GPS in the circuit diagram (as pins 1,2,3). I also connected the SILVER braid to the ground point. I left the white wire unconnected as I suspect it is pulled-up internally to the correct voltage.

On the camera side, the D300 has a 10-pin multi-function connector which is used by various Nikon products, such as the MC-30 shutter release and the MC-35 serial converter (Nikon's device for use with GPSs etc.) You can also get this connector on various non-Nikon products, such as the cheap shutter releases that you can get on eBay, but it does not seem to be available through the major electronics outlets, such as Digikey.

Initially, in my desire to be thrifty, I got a couple of these cheap shutter-releases from China with the hopes of using one of them, as described in epicblog. The two I bought both had 10-pin connectors but to save money they use 4 full size, active pins in the connector, to which wires can be soldered and 6 small stud pins, which do not penetrate the plastic molding at the back and so cannot have wires attached. This necessitates dismantling the cable and moving the active pins to different positions and re-soldering the cable. In the process of removing some of the stud pins by pushing them through the plastic molding they broke off. It seems that (at least) the stud-pins are quite brittle - I tested this on some of them that I successfully removed. I decided that, rather than risking having a pin break in the connector on the camera (which would be a disaster!), I would not use the cheap connector at all.

The next cheapest way to get one is to bid on any of the Nikon MC-?? accessories that has one, as it seems that all these Nikon products have connectors with 10 active pins and a high quality 10-wire cable. I got a Nikon MC-22 on eBay for about $35 and chopped off the banana clips that were on the end, leaving just the beautiful 10-wire cable and 10-pin connector.

A diagram of the pins on the connector and table of the function of each pin, and the colour of the wire that corresponds to it on the MC-22 I purchased is shown below.

  1. RED - RX - serial data in to camera
  2. BROWN - Battery voltage (~6V) - on all the time
  3. GRAY - Regulated voltage (5V) - this voltage is powered when the camera meter is also on. The D300 can be configured to keep this powered on whenever a GPS datastream is detected, so that the GPS stays on.
  4. PURPLE - Release shutter - the Nikon shutter release (MC-30) shorts this to ground when the button is pushed all the way in.
  5. ORANGE - unknown
  6. YELLOW - Signal ground (to regulated supply)
  7. GREEN - Battery ground
  8. BLUE - TX - serial data out from camera.. does the D300 use this line?
  9. WHITE - Enable meter - MC-30 shorts this to ground when the button is pushed half way.
  10. BLACK - unknown
I connected the YELLOW, RED and GRAY wires to the three pins on the CAM connector (again as pins 1,2 and 3 respectively) in the circuit above. I strongly advise you to verify the function of each of the wires on any cable you want to use, as I cannot accept responsibility for any damage you do to to your camera by using the information in this post, I am simply reporting on what I did.

With everything connected, turn on the camera and set the "Auto meter off" option to OFF (in the GPS menu), so that the power to the GPS remains on all the time that the camera itself is switched on. You should see the GPS indicator flash and eventually stay lit, showing that the camera is receiving the datastream and the GPS has locked on.

That's enough for now. Next time some thoughts on how well the circuit works in real life, further refinements and some options for debugging the data stream with a DSO (if you have one!).

No comments: