0

I want to use a picamera to take a picture when a light source sent to the camera is interrupted. So basically, I have one arduino(transmitter) sending a ON-OFF Keying(OOK) signal through an LED to a another arduino(receiver) with a phototransistor. Then when the light communication between the two Arduinos is disturbed, the arduino on the receiver side should send a message "Take a picture" to the raspberry pi through a USB connection. And when the raspberry pi receives the message "Take a picture" from arduion it should command the Picamera to take a picture.

I have managed to do the visible light communication between the two Arduinos using IDE. I have also managed to get the Arduino on the receiver side to communicate with the raspberry pi when the light communication is disturbed(sending "Take a picture") I have also manage to get the picamera taking a picture.

However, I am struggling combine my two codes on python. This is how I combined my codes;

import serial import RPi.GPIO as GPIO import time import picamera ser=serial.Serial("/dev/ttyACM0",9600) #change ACM number as found from ls /dev/tty/ACM* ser.baudrate=9600 def Blink(pin):

GPIO.output(pin,GPIO.HIGH)  
time.sleep(1)  
GPIO.output(pin,GPIO.LOW)  
time.sleep(1)  
return

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11, GPIO.OUT)

while True:

read_ser=ser.readline()
print(read_ser)
if(read_ser=="Take a picture"):
    #import picamera
    print("About to take a picture")
    with picamera.PiCamera() as camera:
            camera.resolution=(1280,720)
            camera.capture("/home/pi/Desktop/newimage.jpg")
            print("picture taked")

The camera does not take a picture when the light communication is disturbed. So, I believe the problem lies on line where I say if(read_ser=="Take a picture"): and downwards. Because the code does not work from there on wards. May you please assist me. Thanks in advance

  • all you need to do is take a photo when the lightsource gpio pin value goes low, so change if lumi > threshold: to if lumi < threshold: – Mohammad Ali Sep 28 '17 at 21:01
0

Have you looked at Motion? Latest version is on GitHub. An interruption in the light will be more than enough to suggest movement and trigger a photo.

0

Assuming the code from there will work, all you need to do is change the condition:

import numpy as np
import scipy.misc as spmisc

img = spmisc.imread(filename, flatten=True)
lumi = np.sum(img)
if lumi < threshold:
    # do something

Notice the change from:

if lumi > threshold:

to:

if lumi < threshold:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.