Software

Camera/motor control

I use the Raspian distro on my Raspberry Pi.

I installed Python, WiringPI and WiringPI-Python - a good write up on setting this up can be found here:

http://www.sirmc.net/view/9001/

Next, I export the pins I will be using. I need two pins as outputs, so in a shell I type:

      gpio export 18 out
      gpio export 23 out


Now I can play around with pin 18 and 23.

Next, I write a python script to allow me to input exposure time, interval and number of shots. Here it is:

import wiringpi #get wiringpi-python
from time import sleep
io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_SYS)
triggerpin = 18 #set my pins
motorpin = 23
io.pinMode(triggerpin,io.OUTPUT)
io.pinMode(motorpin,io.OUTPUT)
wiringpi.pinMode(triggerpin,1)
wiringpi.pinMode(motorpin,1)
exposure = input('exposure time: ') # pick exposure, interval and number of shots
interval = input('interval: ')
shots = input('number of shots: ')
motor = 72.8/shots
print 'begin'
while shots != 0: # loop through actions until complete
io.digitalWrite(triggerpin,io.HIGH)
sleep(exposure)
io.digitalWrite(triggerpin,io.LOW)
sleep(0.5)
io.digitalWrite(motorpin,io.HIGH)
sleep(motor)
io.digitalWrite(motorpin,io.LOW)
sleep(interval)
shots = shots-1
print shots

You may notice the motor time is 72.8 / number of shots - this means I can select a number of shots and the Pi works out the motor times needed to run the length of the track.

I save this to a file named 'timelapse.py'.

To make this easier to run in the field, I create a bash script to export the pins then run the python script:

#! /bin/bash
gpio export 18 out
gpio export 23 out
python timelapse.py

And save this as t.sh. I made it executable so I simply need to type ./t.sh in a shell to get things up and running.

Talking to the Pi


I needed a way to control the Pi out in the field where there are no other computers to SSH into the Pi. I have an Android phone, so the obvious solution for me was to create a bluetooth network that would allow me to use SSH to run the scripts.

I bought a bluetooth dongle (a cheap Tecknik brand nano one from Tescos did the trick) and set this up to use the IP 192.168.50.1.

See my update below - I now use an ad-hoc wifi network for communication, which seems a more stable solution.

Once paired with my phone I can then SSH into the Pi using the ConnectBot app.

Update

Well. my phone died on new years eve, so I've been downgraded to an older android device. This one wouldn't talk to the Pi through bluetooth, so instead I set up an ad-hoc wifi network to connect the phone.

This was straight forward enough - I edited /etc/network/interfaces and added the following:

    iface wlan0 inet static
        address 192.168.2.1
        netmask 255.255.255.0
        wireless-mode ad-hoc
        wireless-channel 5
        wireless-essid pi
    auto wlan0



I also installed Screen on the Pi - this allows a session to run after SSH is disconnected so I can walk away from the rig whilst it still runs the last command I gave it.
Comments