I've been asked about how I'm using the GPIO pins to control the shutter.

A good tutorial on how to wire optoisolators can be found here. For astrophotography we don't usually need to control focus, but if you do, there are units available with two optoisolators built in. I'm actually using this board , but I don't recommend it. I was required to use power from the camera (by leaving the focus pin off) in order for the transistors on the board to work. The method in the first link is easier and better.

You can then use the /sys/class/gpio interface to control the pins. For example, I'm using pin 23 for the shutter. The following code will control the pins and includes the needed exposeSensor and closeShutter functions needed in the script I posted earlier.

# Set GPIO path
GPIO_PATH="/sys/class/gpio"

# Define Pins
SHUTTER=23
FOCUS=24

# This is backwards because of the board I'm using.  
# You likely want to swap values here.
ON=0
OFF=1


# Function to export a pin if not already exported
exportPin() {
  if [[ ! -e $GPIO_PATH/gpio$1 ]]
  then
    gpio export "$1" out
  fi
}

# Function to change state of a pin
setState() {
  echo $2 > $GPIO_PATH/gpio$1/value
}

# Function to expose for for a given number of seconds.
exposeSensor() {
  setState $SHUTTER $ON
  sleep $1
  setState $SHUTTER $OFF
}

# Function to close the shutter.
closeShutter() {
  setState $SHUTTER $OFF
}


# Export pins and set initial state.
exportPin $SHUTTER
setState $SHUTTER $OFF

exportPin $FOCUS
setState $FOCUS $OFF

By the way, audio header cables used on old CDROM drives have the right pin spacing for the raspberry PI. :)

Read More...