Introduction: Raspberry PI Rotary Time Lapse Rig.

Picture of Raspberry PI Rotary Time Lapse Rig.

So this instructable is about a time lapse rig. it started as a simple idea and then grew to what you see. Even if you don't want to build a time lapse rig some of the parts of this build may be of help to user's of the wonderful Raspberry PI.

  1. Raspberry pi with camera.
  2. GPIO outputs driving a 4 channel relay board (with optical isolation)
  3. GPIO outputs driving a 50 step stepper motor via a L298N drive board.
  4. Positive start via a optical slot detector on an input. (and logic level converter)
  5. Computer PSU used to drive all parts.

So lots of nice bits, which all show how useful the humble raspberry pi can be.

Step 1: Raspberry Pi With Camera.

Picture of Raspberry Pi With Camera.

So this is the easy bit. i have followed the raspberry PI's since they were released to the world 4 years ago, and the raspberry PI i have used for this project is a B+ model. Obviously you could use a 2B, or the latest PI 3.

The camera used is the Official raspberry pi camera, which if i am honest will be ok, but i would have liked to zoom in a bit more.

And the case i am using is very useful as it holds the camera in the top of the case and has slotted holes on the back to allow the PI to me mounted vertical on the lighting rig. I have hacked the case to allow the wires to connect to the GPIO, but you could use a proper ribbon cable to avoid this as there is a slot in the side of the case to allow the cable to come out.

Step 2: GPIO Outputs Driving a 4 Channel Relay Board (with Optical Isolation)

Picture of GPIO Outputs Driving a 4 Channel Relay Board (with Optical Isolation)

So on this project i needed to turn off and on lights so at this stage its important to realize that a raspberry PI can't drive much current on its GPIO. So to drive anything more than a simple LED you will need to use additional hardware. So i have used a relay board and the one i have chosen is a 4 channel board with an opto isolated input on each channel.

One thing that needs to be pointed out is that because the relay board uses opto isolators the board needs to be powered with 5 volts. so there are connections on the board for 5 volts and gnd. this 5 volts could come form the Raspberry PI, but i choose to use the 5 volts available from the stepper motor board, but if you do it this way then make sure you have a common gnd between all devices.

So far i have only used three of the four relays.

  1. One is used to switch colored "growing" leds.
  2. Another is used to switch half the camera lights on,
  3. And the other is for the second half of the camera lights.

The inputs for controlling the relays come straight from the GPIO.

Step 3: GPIO Outputs Driving a 50 Step Stepper Motor Via a L298N Drive Board.

Picture of GPIO Outputs Driving a 50 Step Stepper Motor Via a L298N Drive Board.

This was a good experiment for me as i had never tried driving a motor from a Raspberry PI before. So i had a look at the bits i had in my SHED, and came across a nice 50 step stepper motor, and a L298N driver board. I had never used these items but it turned out to be easy to do.

Also in the picture you should be able to see that i have used gears on the motor and the turntable shaft, and on the turntable shaft i have used a bearing in a aluminium block. Again this were all parts i had around my shed!

So this is really the first part of the build. I found a decent sized bit of 3/4" ply to use as the base and then a couple of bits of mahogany to use as motor bearers. You should be able to see in the pictures that i have firstly mounted the shaft bearing then with the shaft in place with the large plastic gear (56 teeth MOD1) i then positioned the stepper motor on the mahogany bearers. When i was happy with the mesh of the gears i drew around the bearers and screwed them down into place. The motor was then screwed into place but not tightly......... one screw was placed at the end of the slot so the motor couldn't move that way and the other screw was placed so i could use a little spring to put a bit of tension on the gears and eliminate backlash. This worked very well..... however the shaft only has one bearing at the bottom so two bits of pine were screw to the base and the top piece has a grove cut into the side to allow for the top part of the shaft to run in the grove and align the shaft. i hope that all makes sense and the pictures should help fill in any gaps in my description!

And lastly the wiring from the stepper motor to the L298N board. My stepper motor has 5 wires. i am not that familiar with stepper motors, but reading up on them and testing with a multi-meter mine has 4 coils arranged in pairs and the the common point in each pair is joined together. its hard to work out which pair is which with this configuration, but i think it doesnt really matter as long as you only turn one output on at any time and don't connect the common. you may have to play around with the sequence if the motor kind of goes forward then backwards and doesn't really turn, but that only involves playing with pin numbers.

To explain that a bit better you want the coils to run in the correct sequence I.E 1-2-3-4-1------ but since you don't know the correct order of the coils you might end up with 1-3-2-4-1 or 1-2-4-3-1 which will cause strange results. just play around with the connections or program to run the coils correctly. and if all else fails swop one wire from one output side of the L298N drive to the other side until it works correctly.

I haven't explained the gears, the big gear on the turntable shaft has 56 teeth and the gear on the motor has 28 so the motor has to run 100 steps for a full 360 degrees. i have chosen to take 25 pictures around the object so the motor will have to take 8 steps in between photos.

Step 4: Positive Start Via a Optical Slot Detector on an Input. (and Logic Level Converter)

Picture of Positive Start Via a Optical Slot Detector on an Input. (and Logic Level Converter)

To allow this time lapse to work well and consistently you need to make sure that the turntable always starts at the same point. to achieve this i have used a slot detector. this device has a IR diode on one side and a detector on the other side, when something enters the slot and obscures the gap you get a change of output. this will be used as a park indicator. At the end of each picture sequence the motor will be told to go one step back and then each time the slot will be checked. When the slot is interrupted then the motor will then move forwards to the start position.

There was a little problem with this device. it didn't like to run on the Raspberry PI's 3 volts, so for this to work correctly i had to use a logic level converter this allows the sensor to run on 5 volts and give out a logic 5 volt which is then converted to a 3 volt logic level by the converter. this protects the raspberry PI form the 5 volt logic level which could kill the GPIO?

The logic level converter is easy to use, it has a built in 3 volt regulator so needs a 5 Volt supply and GND. then you just feed it 5 volts logic on one side and get 3 volt logic the other. or vise versa. the one you see in the picture has 4 channels i am only using one.

Step 5: Computer PSU Used to Drive All Parts.

Picture of Computer PSU Used to Drive All Parts.

As this build started to grow so did the power requirements... so i thought the best solution was to get an old PC PSU. I have used these in the past for various job and it is very well suited to this task. I need 5 Volts for the raspberry pi and 12 Volts of the lights and stepper motor and the PC PSU has both those voltages with high current capacity.

But the question is how do you make the PSU unit work?? The simple answer is i don't know! so i googled it and found the answer. the power supply i have got, has a 20 pin connector and a 4 pin and the other connectors which go to the drives. To make this power supply work all you have to do it connect pin 14 (green) to ground (black) then with any luck the power supply will jump into life.

And thankfully that was it! it really wasn't that hard. So i checked the voltages (12 Volts and 5 Volts) and then connected the wires to the terminals blocks. I dont know how standard PSU's are but in my case......

  • Black is ground
  • Yellow is +12 Volts
  • Red is + 5 Volts

There are other colors but i am not bothered about them for this project.

Step 6: The Rest of the Hardware

Picture of The Rest of the Hardware

So the main build is bassed on a 3/4" plywood board and then i have added a substantial lighting tree made from off cuts of mahogany.

I wanted the pictures to all be taken with the same light, so i have added 8 LED lights to illuminate the object. In this way i should always get a good constant picture day or night.

Step 7: The Python Program and USB Storage.

Before i explain the bits of the program its worth just looking at how i am controlling the Raspberry PI. For a start i want to run the raspberry PI headless, so that's no keyboard mouse or monitor. so before i could achieve this i have had to plug in a USB WiFi dongle and configure the wireless password so it connects to my WiFi. then when i plug in the PSU the raspberry pi will boot up and i can connect to it via my windows computer using putty.

  1. Connect the power supply unit and let the PI boot up.
  2. Open up the router webpage using address in web browser. 192.168.1.1 is mine (on windows).
  3. Work out what connections you have and make a note of the PI's number.
  4. Open Putty and type in the number and connect.
  5. Log in using pi as name and raspberry as password.
  6. Then navigate to the correct file and run the program using "sudo python stepper01.py"
  7. Check it works by watching it park first and then take pictures.

And so on.

The program explained

1) set up the imports and GPIO pins and direction.

import math
import time import datetime as dt
import RPi.GPIO as GPIO
import os import sys
# to run this program
# open terminal and nagigate to the directory then type "sudo python stepper01.py"
# this will run the program
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(4 , GPIO.OUT)
GPIO.setup(17 , GPIO.OUT)
GPIO.setup(27 , GPIO.OUT)
GPIO.setup(22 , GPIO.OUT)
GPIO.setup(26, GPIO.OUT)
GPIO.setup(19, GPIO.OUT)
GPIO.setup(10 , GPIO.IN)

2) start main program (routine)
make sure the lights are off. initalise the counter check the usb stick and reverse up stepper motor to park.

GPIO.output(26, False)
GPIO.output(19, False)
F = 0
checkMedia()
checkSlot()

Start main routine.
3) Log the start time, Turn on lights, check USB stick, take 25 pictures, move motor each time.

while True:
 startTime = time.time()
 GPIO.output(26, True)
 time.sleep(1)
 GPIO.output(19, True)
 time.sleep(1)
 checkMedia()
 for B in range(0, 25):
  for x in range(0,2):
   rotate(0,1,0,0)
   rotate(0,0,1,0)
   rotate(0,0,0,1)
   rotate(1,0,0,0)
  takePicture(B)

4) Then increment the photo file name counter, reverse up and park, turn off the lights, work out the delay time and sleep until the next photos.
 F = F + 1
 checkSlot()
 GPIO.output(26, False)
 time.sleep(1)
 GPIO.output(19, False)
 time.sleep(1)
 endTime = time.time()
 totalTime = endTime - startTime
 delayTime = 600 - totalTime
 #15 minutes would be 900
 #10 minutes would be 600
 time.sleep(delayTime)

5) Now lets look at the stepper motor section...

def rotate(ln1,ln2,ln3,ln4):
 AllZero()
 if ln1 == 1:
  GPIO.output(4, True)
 else:
  GPIO.output(4, False)
 if ln2 == 1:
  GPIO.output(17, True)
 else:
  GPIO.output(17, False)
 if ln3 == 1:
  GPIO.output(22, True)
 else:
  GPIO.output(22, False)
 if ln4 == 1:
  GPIO.output(27, True)
 else:
  GPIO.output(27, False)
 timeSleep1()
 AllZero()


6) This is the section that parks the table.

def checkSlot():
 g = 1
 while g==1:
  rotate(1,0,0,0)
  if GPIO.input(10)==0:
   resetStart()
   g=0
   return
  rotate(0,0,0,1)
  if GPIO.input(10)==0:
   resetStart()
   g=0
   return
  rotate(0,0,1,0)
  if GPIO.input(10)==0:
   resetStart()
   g=0
   return
  rotate(0,1,0,0)
  if GPIO.input(10)==0:
   resetStart()
   g=0
   return

7) This is the last section to look at. The whole program is in the files.

def takePicture(fileNumber):
 y = str(F)
 filename = ("pic_")+str(B)+("_")+y+(".jpg")
 print (filename)
 partA=("/media/pi/KINGSTON/Photos/Photo")
 partB=str(B)
 os.chdir(partA + partB)
 command = ("sudo raspistill -t 200 -n -o ")
 os.system(command + filename)
 os.chdir("/home/pi")

Comments

bigme (author)2016-03-15

That's quite an impressive rig! How do you go about stitching your 20+ rotational photos in to one 360 image? I've tried using a turntable and shooting with a DSLR on a tripod but using Photoshop to create a gif but that is labor intensive. I am wondering if you've come across an alternative?

mr_fid (author)bigme2016-03-15

That's a good question.......

each photo is named and stored in a different folder, so i copied 1 from each folder and added them to the movie as a series of pictures, then select them all on the film strip and condense the time. Then when i am happy with the time, i copied it and pasted to the end? that's not a very good description but i guess it depends on what software you use? i use but do not endorse Serif MoviePlus X6. its cheap but doesn't do all i want it to do?

About This Instructable

1,931views

29favorites

License:

Bio: I love making things. I have for as long as I can remember liked to make stuff. Now days I have two kids (Thomas and ... More »
More by mr_fid:Simple Quadcopter, Basic Tools Only.HoverboardSignal Generator Build.
Add instructable to: