Raspicam and motion

I got this idea to use Raspicam and motion. Then capture image?

K1rpiacam.py runs with python2, others with python3.

My innovations comes from:

Motion detect: A simple example of using the Raspberry Pi Camera Module and python picamera for motion detection · GitHub
Motion
http://kinograph.cc/

Raspberry pi community forums and countless others: Linux, and python, Adafruit (I use motorhat 2348, Adafruit-circuitpython-motorkit.)

Start DC1 and stepper.

While stepper is running, I use this:

K1rpiacam.py:

“”
#!/usr/bin/python

from picamera import PiCamera
import picamera.array
from time import sleep

threshold = 10 # How Much pixel changes
sensitivity = 100 # How many pixels change

def takeMotionImage(width, height):
with picamera.PiCamera() as camera:
time.sleep(1)
camera.resolution = (width, height)
with picamera.array.PiRGBArray(camera) as stream:
camera.exposure_mode = ‘auto’
camera.awb_mode = ‘auto’
camera.capture(stream, format=‘rgb’)
return stream.array

def scanMotion(width, height):
motionFound = False
data1 = takeMotionImage(width, height)
while not motionFound:
data2 = takeMotionImage(width, height)
diffCount = 0L;
for w in range(0, width):
for h in range(0, height):
# get the diff of the pixel. Conversion to int
# is required to avoid unsigned short overflow.
diff = abs(int(data1[h][w][1]) - int(data2[h][w][1]))
if diff > threshold:
diffCount += 1
if diffCount > sensitivity:
break;
if diffCount > sensitivity:
motionFound = True
else:
data2 = data1
return motionFound

def motionDetection():
print "Scanning for Motion threshold=%i sensitivity=%i… " % (threshold, sensitivity)
while True:
if scanMotion(224, 160):
print “Motion detected”

#if name == ‘main’:

try:

motionDetection()

finally:

print “Exiting Program”

from picamera import PiCamera
from time import sleep

camera = PiCamera()
camera.resolution = (1024,768)
camera.rotation = 180
camera.start_preview(alpha=200)

for i in range(15000):
sleep(1)
camera.capture(‘/home/pi/RUIJX/image%04d.jpg’ % i)
camera.stop_preview()
“”

DC1mot1

“”
from adafruit_motorkit import MotorKit
import time

kit = MotorKit(address=0x61)

kit.motor1.throttle = -1
“”

Stepper motor:

“”
from adafruit_motor import stepper
from adafruit_motorkit import MotorKit
import time

kit = MotorKit(address=0x61)
#kit.stepper2.release()

while True:

print ("Double coil steps")
for i in range(20):
    kit.stepper2.onestep(style=stepper.DOUBLE)
time.sleep (1)

“”

To release DC1:

“”
from adafruit_motorkit import MotorKit
import time

kit = MotorKit(address=0x61)

kit.motor1.throttle = -1
“”

To release Stepper:
“”
“”“Simple test for using adafruit_motorkit with a stepper motor”“”
from adafruit_motorkit import MotorKit

kit = MotorKit(address=0x61)

kit.stepper2.release()

“”
This seams to work, but as always, backlash got me. Stepper motor shaft was retired. Now I have to cerate something from inventory.

I use also 1. Nema 17 AC motor and one old inventory DC motor.

Raspberry pi 3B+, picamera
2 x 1 W Cool White LEDs, ADA518.

So the AC motor is pulling film and DC is pulsing and reel film to reel.

Thats it.