Control your old film camera with a Raspberry Pi

Adding the GPS Receiver

The next step is to make the USB GPS receiver work with Raspberry Pi. As described in the "Getting GPSd to work with Python and Threading" blog [4] article, enabling the GPS receiver is a matter of installing the gpsd and gpsd-clients packages:

sudo apt-get install gpsd gpsd-clients

To make sure the connected GPS receiver (Figure 3) is detected and working properly, run the cgps utility to view the received GPS data. To obtain the current latitude, longitude, and time values, you can use a modified version of the Python script described in the blog [4]  – after all, you don't need to reinvent the wheel. The modified script (Listing 3) does away with the while loop and adds the time.sleep(15) statement, which gives the GPS receiver time to get the satellite lock and receive GPS data. Another addition is the code block that writes the received values to the gpsdata.txt file.

Figure 3: Film SLR camera and a GPS receiver hooked up to a Raspberry Pi.

Listing 3 Script

01 #! /usr/bin/python
02 import os
03 from gps import *
04 from time import *
05 import time
06 import threading
07 gpsd = None
08 class GpsPoller(threading.Thread):
09   def __init__(self):
10     threading.Thread.__init__(self)
11     global gpsd
12     gpsd = gps(mode=WATCH_ENABLE)
13     self.current_value = None
14     self.running = True
15   def run(self):
16     global gpsd
17     while gpsp.running:
19 if __name__ == '__main__':
20   gpsp = GpsPoller()
21   gpsp.start()
22   time.sleep(15)
23   os.system('clear')
24   print 'latitude    ' , gpsd.fix.latitude
25   print 'longitude   ' , gpsd.fix.longitude
26   print 'time utc    ' , gpsd.fix.time
27   f = open('gpsdata.txt', 'a')
28   coord = str(gpsd.fix.latitude) + '\t' + str(gpsd.fix.longitude) + '\t', str(gpsd.fix.time) + '\n'
29   f.write(coord)
30   f.close()
31   gpsp.running = False
32   gpsp.join()

Because running the scripts that trigger the shutter and save GPS data manually is not very practical, you might want to add two buttons to GPIO pins 17 and 23, and add yet another simple Python script (Listing 4). This way, you can use one button to trigger the shutter and the other one to save GPS data.

Listing 4 Script

01 #!/usr/bin/env python
02 from time import sleep
03 import RPi.GPIO as GPIO
04 GPIO.setmode(GPIO.BCM)
05 GPIO.setwarnings(False)
06 GPIO.setup(17, GPIO.IN)
07 GPIO.setup(23, GPIO.IN)
08 GPIO.setup(25, GPIO.OUT)
09 while True:
10   if GPIO.input(17):
11     execfile("")
12   if GPIO.input(23):
13     GPIO.output(25, True)
14     sleep(0.5)
15     GPIO.output(25, False)

Finally, you should configure Raspberry Pi to run the script automatically. To do this, open the inittab file in the nano text editor and modify the 1:2345:respawn:/sbin/getty --noclear 38400 tty1 line as follows:

1:2345:respawn:/sbin/getty --autologin pi --noclear 38400 tty1

Then, add the sudo ./ line to the .bash_profile file, and you are good to go.

Final Word

Using a Raspberry Pi and a handful of electronic components, you can teach your vintage SLR camera a few new tricks. With a bit of creative thinking and a dash of coding, you can make Raspberry Pi work with older gadgets, too, so if you are looking for a Raspberry Pi project for a rainy weekend, you don't need to buy LEDs, motors, and other peripherals. Instead, you might find inspiration in a box of old hardware, saving some money and lessening the impact on the environment. Putting discarded devices and components to some interesting uses lets you breathe new life into them.


  1. gpsd compatibility table:
  2. 2N2222 transistor Wikipedia article:
  3. Sunrise and sunset photo calculator:
  4. Getting GPSd to work with Python and Threading:

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content