Servo Controlled Time-Lapse Camera

For our HAB mission, we created a servo controlled camera running on a RasPi Zero and using β˜’CHIPs to control/drive a servo.

IntermediateFull instructions provided2 hours3,604
Servo Controlled Time-Lapse Camera

Things used in this project

Hardware components

Raspberry Pi Zero
Raspberry Pi Zero
Get the newer version that has a camera interface. And make sure you got a Micro-USB cable to connect the Pi to your computer
×1
BR03
XinaBox BR03
×1
XinaBox OC05 - Servo Driver
×1
XC10
XinaBox XC10
×1
MD01
XinaBox MD01
Really just a spacer to mount the servo on, so very optional.
×1
Camera Module
Raspberry Pi Camera Module
Remember to get the narrower flat cable that fits the RasPi Zero
×1
3.7v LiPo battery (generic)
×1
Servos (Tower Pro MG996R)
Any small servo with standard 2.54 mm 3 pin header cable, and mounting gear (nuts/bolts, rubber bands, cable ties, glue, or what ever is your preference)
×1

Software apps and online services

Raspberry Pi Raspbian Lite
balena Etcher
XinaBox OC05 Servo Driver

Story

Read more

Code

servo.py

Python
from __future__ import division
import time
from datetime import datetime 
import rpOC05
import picamera

pwm = rpOC05.PCA9685()

servo_min = 150  # Min pulse length out of 4096
servo_max = 500  # Max pulse length out of 4096
i = servo_max + 10
chan = 8
filename = 'frames/frame-%s.jpg'
pwm.set_pwm_freq(50)
# signal ready with a wave
pwm.set_pwm(chan, 0, servo_min)
time.sleep(1)
pwm.set_pwm(chan, 0, servo_max)
time.sleep(1)

print('Time-Lapse Running...')
while True:
  if i > servo_max:
    i = servo_min      
                        
  pwm.set_pwm(chan, 0, i)
  with picamera.PiCamera(resolution=(1920,1080)) as cam:
    ts = str(datetime.utcnow())
    cam.capture(filename % ts,quality=90,thumbnail=None)
  # time-lapse interval in seconds.
  time.sleep(0.1)
  i += 1

Credits

Comments