So, with the help of Realizator, I'm back up and running!
If you want to use the Python files I created, here's a step by step guide to get it running:
Step 1: Wire up the two pins, GPIO 004 for the button and one of the GROUND pins, I used Board Pin 9.
Step 2. Power up the StereoPi and make the file system writeable:
Step 3. Create the trigger_photo.py file:
Code: Select all
sudo nano /opt/StereoPi/scripts/trigger_photo.py
Once opened and ready for editing, paste the following code in there:
Code: Select all
# Nabbed from Stereomaton and Modified by TechDevTom/Tom Southworth
#!/usr/bin/env python
# Import necessary libraries
import RPi.GPIO as GPIO
import os
from time import sleep
# Set up the Trigger Pin which will trigger the taking of Photos
triggerPin = 4
# Set the GPIO Board mode to BCM, so it uses GPIO number reference not Pin number reference
GPIO.setmode (GPIO.BCM)
# Set the triggerPin to be an input and for its internal resistor to be initially HIGH
GPIO.setup(triggerPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Infinitely Loop
while True:
# Wait for a change in the triggerPin
GPIO.wait_for_edge(triggerPin, GPIO.FALLING)
# Say cheese!
print ('cheese!')
# Create a system call to run the Python based python_make_photo.py script
os.system('python /opt/StereoPi/scripts/python_make_photo.py')
# Sleep for a second while the photo is taken
sleep(1)
Exit the file when code is pasted and saved.
Step 4. Create the python_make_photo.py file:
Code: Select all
sudo nano /opt/StereoPi/scripts/python_make_photo.py
Once opened and ready for editing, paste the following code in there:
Code: Select all
# PHP version Nabbed from Realizator/StereoPi and Modified into Python by TechDevTom/Tom Southworth
#!/usr/bin/env python
# Import necessary libraries
import io
import os
from datetime import datetime
# Declare file paths
filename = 'stereoImage_' + datetime.now().strftime('%d%m%Y-%H%M%S') + '.jpg'
storagepath = '/media/DCIM/'
configpath = '/opt/StereoPi/config.conf'
# Load Config File
with open (configpath) as file_object:
config_strings = file_object.readlines()
# Parse Config File into an array
config = {}
for line in config_strings:
temp = str(line).split('=')
temp[0] = temp[0].rstrip()
temp[1] = temp[1].rstrip()
config.update ( {temp[0] : temp[1]} )
# Stop raspidvid from streaming
os.system ('killall -q raspivid')
# Determine raspistill settings
if config['video_mode'] == '3D':
VIDEOMODE = ' -3d sbs '
else:
VIDEOMODE = ''
if config['up_down'] == '1':
UPDOWN = ' -vf -hf '
else:
UPDOWN = ''
if config['swapcams'] == '1':
SWAPCAMS = ' -cs 1 '
else:
SWAPCAMS = ''
if config['photo_resolution'] == 'V1-full-size':
PHOTO_RESOLUTION = ' -w 5184 -h 1944 '
elif config['photo_resolution'] == 'V2-full-size':
PHOTO_RESOLUTION = ' -w 6560 -h 2464 '
else:
PHOTO_RESOLUTION = ''
# Print the information related to the raspistill command
print ('videomode: ' + VIDEOMODE)
print ('updown: ' + UPDOWN)
print ('swapcams: ' + SWAPCAMS)
print ('photoresolution: ' + PHOTO_RESOLUTION)
# Take the photo with raspistill
os.system ('raspistill -n -t 500 -awb sun ' + VIDEOMODE + UPDOWN + SWAPCAMS + PHOTO_RESOLUTION + ' -o ' + storagepath + filename)
os.system ('sudo sync')
print (filename)
Exit the file when code is pasted and saved.
Step 5. Make both python files executable:
Code: Select all
sudo chmod +x /opt/StereoPi/scripts/trigger_photo.py
Code: Select all
sudo chmod +x /opt/StereoPi/scripts/python_make_photo.py
Step 6. Add the call to execute trigger_photo.py on start up to the run.sh file:
Once opened and ready for editing, add the following two lines:
# Adding in the ability to Trigger the taking of Photos via Python (USER ADDED)
python ./scripts/trigger_photo.py &
Notice the (USER ADDED) on the comment, it's just to help me find it later on amongst all the other calls. Now save and close the file.
Step 7. Power off your StereoPi and unplug your Wi-Fi/Ethernet cable, so that the StereoPi has no internet access.
Step 8. Power up your StereoPi, and make the connection between the GPIO 004 pin and the GROUND pin as mentioned in Step 1. This should take a photo and add it to your photo records on the StereoPi. Take more than one photo if you like! A red LED lights up on the StereoPi board when a photo is being taken.
Step 9. Power off your StereoPi, plug in your Wi-Fi/Ethernet cable, so that the StereoPi has internet access again.
Step 10. Power on your StereoPi one last time, and connect to the SLP Web Interface's records section on a different machine. Type in either
http://stereopi.local/records/ or IPADDRESS/records/, where IPADDRESS is the IP Address of your StereoPi. This should take you to the collection of photos that your StereoPi has taken and stored for you. The photos you took in Step 8 should be here. If not, something has gone wrong!
Hope this helps people who might want to take the photo making ability that comes with the StereoPi and extend it using Python
The python_make_photo.py is pretty much a Python version of the make_photo.php that comes with the StereoPi, with a few minor Python based adjustments.
Let me know if you use it and what you do with it