Skip to content

Instantly share code, notes, and snippets.

@KonradIT
Forked from cooncesean/script.py
Created January 13, 2014 21:22
Show Gist options
  • Save KonradIT/8408417 to your computer and use it in GitHub Desktop.
Save KonradIT/8408417 to your computer and use it in GitHub Desktop.
"""
This program interfaces with the GoPro camera and records footage for a
set amount period of time defined by the optional `--seconds` arg.
"""
import argparse
import time
import serial
parser = argparse.ArgumentParser(description='Captures video from GoPro for set number of seconds.')
parser.add_argument(
'--seconds',
dest='seconds',
type=int,
default=5,
help='The number of seconds you want the video to record for.'
)
args = parser.parse_args()
# Open a serial connection to the GoPro
ser = serial.Serial('/dev/tty.usbserial-A7WA8RME', 9600, timeout=1)
print 'Serial connection opened'
PIN_OUTPUT = 'ATO2\r'
PIN_HIGH = 'ATS2\r'
PIN_LOW = 'ATC2\r'
# Initialize the connection mechanics of the output from the PC to the GoPro.
ser.write(PIN_OUTPUT) # Sets the adapter output pin to an 'output'
ser.write(PIN_HIGH) # Turns the output to the GoPro camera to the 'high' state (its default state)
print 'Configured output pin'
time.sleep(1)
# 1. Power Camera On
# Once the correct serial port has been determined and the output has been set to the
# high 'default' state, you are ready to send commands to the camera.
ser.write(PIN_LOW) # Set the state to low
time.sleep(1)
ser.write(PIN_HIGH) # Re-set the state to high
print 'Camera is powered ON'
# 2. Record for X seconds
seconds = args.seconds
print 'Start recording: %d seconds' % seconds
time.sleep(seconds)
print 'Stopped recording'
# CAMERA NEEDS TO BE IN 1-BUTTON MODE AND IT WILL START RECORDING UNTIL IT IS TURNED OFF
# http://www.youtube.com/watch?v=3a3876GHNO0
# 3. Power Camera Off
# Set the state to low for 5 seconds and reset to high
print 'Preparing to turn camera off'
ser.write(PIN_LOW) # Set the state to low
time.sleep(5)
ser.write(PIN_HIGH) # Re-set the state to high
print 'Camera is off'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment