Caterpillars

Aim:

To monitor caterpillars bought from Insect Lore with timelapse and webcam as they grow and pupate.

UPDATE: The caterpillars are all now butterflies! Live webcam has stopped. You can catch up by watching the timelapse videos below.

Videos

The above webcam image was captured every minute. As well as being posted here, the images were saved and manually put into a timelapse sequence (30fps) using Openshot video editing software in Linux.

This video is of the first butterfly to emerge. It was FAST! It took less than a couple of minutes, so for the later video above I increased the capture rate to every 10s.

This video covers the last few days upto formation of chrysalides. The first caterpillar starts to pupate at about 1 minute in, the rest towards the 2-3 minute mark.

This is the video of the first couple of days timelapsed (30fps, original 1 frame per minute):

The python program that takes the pics, updates the webcam and turns on the IR LEDs:

import shutil
import time
import picamera
import datetime as dt
import RPi.GPIO as GPIO

#Set up the Pins. 23 & 24 each switch 3 IR LEDs
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)

#set up the camera
with picamera.PiCamera() as camera:
	camera.led = False
	camera.resolution = (640,480)
	camera.rotation = 270
	for filename in camera.capture_continuous('01caterpillar{counter:04d}.jpg'):

		#turn IR lights off
		GPIO.output(23,0)
		GPIO.output(24,0)

		print ('Captured %s' % filename)

		#copy latest picture to www for webcam
		shutil.copy(filename, "/var/www/images/caterpillars.jpg")
		print ('copied file to webcam')
		time.sleep(58)

                #add a timestamp to the picture 
                timestamp = dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                camera.annotate_text=(timestamp)

		#is it time to turn on the IR lights?
		start = dt.time(4, 30) 
		end = dt.time(23)
		currentTime = dt.datetime.now().time()

		if (start <= currentTime <= end):
			time.sleep(2) 
		else: 
			#turn IR lights on for next picture
	                GPIO.output(23, 1)
        	        GPIO.output(24, 1)
                	time.sleep(2)