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