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.

 

Previous posts:

[Pi IoT] Plant Health Camera #6 - Putting the slave Pi to work

[Pi IoT] Plant Health Camera #5 - OpenCV

[Pi IoT] Plant Health Camera #4 - Putting the parts together

[Pi IoT] Plant Health Camera #3 - First steps

[Pi IoT] Plant Health Camera #2 - Unboxing

[Pi IoT] Plant Health Camera #1 - Application

 

Intro

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.

Hardware setup

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.

Pi-GPIO-connections.png

 

Software

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

 

slave_camera.py:

 

#!/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.

stay tuned.