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:

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

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

And save this as I made it executable so I simply need to type ./ 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

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.


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