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?