0

I would like to use a Raspberry Pi camera to take a picture when a light source sent to the camera is interrupted. I have one Arduino (transmitter) sending an ON-OFF Keying (OOK) signal through an LED to a second Arduino (receiver) with a phototransistor. Then when the light communication between the two is disturbed, the receiver should send a "Take a picture" command to the Raspberry Pi through a USB serial connection. When the Raspberry Pi receives the "Take a picture" command from the connected Arduino it should 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 the "Take a picture" command). I have also managed to get the camera to take a picture. However, I am struggling to combine my two codes in 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, I believe the problem lies on the line if(read_ser=="Take a picture"): and onwards because the code does not work from there.

Can you please help me?

  • 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.