Digitizing my Beer Can Collection
Photo Studio Setup
Stepper Motor with a ULN2003APG controllerAukey HD Webcam
#!/usr/bin/env python from time import sleep, time import RPi.GPIO as GPIO import os import pygame import pygame.camera # GPIO pins to use for stepper pins = [ 24, 25, 8, 7 ] button = 11 # stepper sequences sequences = [[1,0,0,1], [1,0,0,0], [1,1,0,0], [0,1,0,0], [0,1,1,0], [0,0,1,0], [0,0,1,1], [0,0,0,1]] # global camera instance cam = None def setup(): """ initialize everythin """ global cam # use GPIO numbers GPIO.setmode(GPIO.BCM) # set up stepper pins for pin in pins: GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, 0) # set up button pin GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP) pygame.camera.init() camlist = pygame.camera.list_cameras() #Camera detected or not print "using camera %s" % camlist[0] cam = pygame.camera.Camera(camlist[0],(2048, 1080)) cam.start() cam.get_image() sleep(3) #wait for white balance cam.get_image() def sequence(seq): """ execute a single step sequence, eight of them make one step """ # set pins to correct sequence for idx, val in enumerate(seq): GPIO.output(pins[idx], val) # give it a bit to move sleep(0.005) # reset all pins to off for pin in pins: GPIO.output(pin, 0); def left(step): """ do this many steps to the left """ for i in range (step): for seq in sequences: sequence(seq) def right(step): """ do thi many steps to the right """ for i in range (step): for seq in reverse(sequences): sequence(seq) def run(): out = "out/%s" % time() os.mkdir(out) for x in range(8): # take picture cam.get_image() cam.get_image() img = cam.get_image() pygame.image.save(img, "%s/image%d.jpg" % (out, x)) print "saved %s/image%d.jpg" % (out, x) left(512/8) # turn an eigth setup() while True: run() while True: input_state = GPIO.input(button) if input_state == False: break sleep(0.2) GPIO.cleanup()




