This week I was traveling again, so unfortunately I didn't have much time to work on the project.
Therefore I will share my thoughts on how to synchronize the two cameras.
In the previous post I explained how the two cameras are combined, using the master and slave Pi. Here I will show how the two Pi's are connected hardware wise, and how the two images are taken simultaneously from the two systems.
The power for the Pi B+ comes from the Pi 3's header block, as shown in the image below.
I wrote some python code which will run on the slave system. It will wait for a trigger pulse on GPIO 23 and then take an image and save it on the share as described in the previous post. The master system will output the trigger on GPIO 18.
Below is the python code which runs on the slave system, it is based on an example I found on the internet (camera - Problems triggering via GPIO - Raspberry Pi Stack Exchange).
If not done already rip.gpio needs to be installed:
sudo apt-get install python-dev python-rpi.gpio
#!/usr/bin/python import RPi.GPIO as GPIO import socket import time import picamera # PiCamera Setup camera = picamera.PiCamera() camera.ISO = 100 image_num = 1 ready = 1 # GPIO Setup GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) # Begin Loop try: while True: if GPIO.input(23): camera.capture('/home/pi/planthealthcam/slave_image.jpg') print('input from master on gpio 23, Picture taken!') ready = 1 image_num += 1 time.sleep(3) except KeyboardInterrupt: # trap a CTRL+C keyboard interrupt GPIO.cleanup() # resets all GPIO ports used by this program
In order to start this script on every boot, I added it to /etc/rc.local:
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi python /home/pi/planthealthcam/slave_camera.py & exit 0
In a following post I will describe the python code on the master system.