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

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:



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:
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:
if diffCount > sensitivity:
motionFound = True
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’:




print “Exiting Program”

from picamera import PiCamera
from time import sleep

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

for i in range(15000):
camera.capture(’/home/pi/RUIJX/image%04d.jpg’ % i)


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)

while True:

print ("Double coil steps")
for i in range(20):
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)


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.