-
Notifications
You must be signed in to change notification settings - Fork 8
/
take_picture_and_email.py
97 lines (78 loc) · 2.21 KB
/
take_picture_and_email.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python
import os
import time
import random
import RPi.GPIO as GPIO
from send_gmail_attachment import sendMailWithAttachments
from lcd_display import lcd
def flash(d):
GPIO.output(11, False)
time.sleep(d)
GPIO.output(11, True)
time.sleep(d)
# use Pi board pin numbers with GPIO.BOARD
GPIO.cleanup()
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# see http://elinux.org/Rpi_Low-level_peripherals
# see http://pypi.python.org/pypi/RPi.GPIO
# initialise the lcd display
lcd1 = lcd()
lcd1.clear()
lcd1.display_string("Picture Taker", 1)
flash(0.2)
flash(0.2)
while True:
# Check camera is present
while not os.path.exists('/dev/video0'):
lcd1.display_string("No Camera", 2)
time.sleep(1.0)
lcd1.display_string("ready", 2)
go = not(GPIO.input(7))
stop = not(GPIO.input(12))
if go:
# wait for button release
while go:
go = not(GPIO.input(7))
print "taking picture"
lcd1.clear()
lcd1.display_string("taking picture", 2)
for x in range(2):
flash(0.2)
filename = "webcam%s.jpg" % (time.strftime('%d%b%H%M%S'))
pathname = "/home/pi/pictures/" + filename
command = "fswebcam -r 640x480 " + pathname
os.system(command)
if os.path.isfile(pathname):
print "picture ok"
lcd1.display_string("picture ok", 2)
flash(0.2)
time.sleep(0.5)
print "Emailing"
lcd1.display_string("emailing", 2)
sendMailWithAttachments( ["[email protected]"],
"Image from the Raspberry Pi",
"Someone took a picture.",
[pathname] )
lcd1.display_string("done", 2)
flash(0.2)
flash(0.2)
else:
print "picture failed"
lcd1.display_string("failed, sorry", 2)
flash(0.5)
time.sleep(0.5)
lcd1.display_string("Picture Taker", 1)
lcd1.display_string("ready", 2)
print "Done"
if stop:
print "goodbye"
lcd1.display_string("goodbye", 2)
flash(0.5)
lcd1.clear()
lcd1.backlight_off()
GPIO.cleanup()
exit()
time.sleep(0.1)