What is it?The Raspberry Pi Camera is a small and cheap add on module that allows you to take images and HD video input to projects such as security systems, logging in or even time lapse photography, all for the little price of £16
The installation and setting up of the Pi Camera can be found here. This page will focus on the use of the Python camera module and taking a picture.
1. Installing the ModuleInstallation is simple:
In the LX Terminal type: sudo apt-get upgrade sudo apt-get update then apt-get install python-picamera or apt-get install python3-picamera You are ready to shoot! 2. Simple Code to send a Basic EmailTo get started with the code is very simple, open IDLE or start a new Python program
import smtplib #This is Gmail’s Email server details server = smtplib.SMTP('smtp.gmail.com', 587) #Identifies the features of the email server server.ehlo() #A method of upgrading plain text connection to an encrypted one server.starttls() #Identifies the features of the email server server.ehlo() #message is the variable where you enter the content of you email message = "Enter your message here" #Use server.login to log into Gmail’s server.login("your_email_address_here", "your_password_here") #Use server.sendmail to send the Email server.sendmail("your_email_address_here", "their_adresss", message) |
Send an E-mail3. Take a Selfie!Taking a picture with Python is very simple and can be achieved in a few lines of code. The picture can be previewed using the code, camera.start_preview() and to take a picture use camera.capture('eggs.jpg'). Where eggs is replaced with the name you wish to call the file. Open Python and create the the function below.
import time import picamera def take_a_selfie(): with picamera.PiCamera() as camera: camera.start_preview() time.sleep(2) camera.capture('eggs.jpg') take_a_selfie() Further information can be found at Picamera site 4. Emailing a PictureLast part is to attach the Image to an email, this requires a different set of Python modules but is fairly simple t achieve. The program makes use of MIME, which stands for Multipurpose Internet Mail Extensions (MIME) it is an Internet standard that extends the format of email to support such as Text in character sets other than ASCII non-text attachments, for example images, pdf and others.
The code is much the same as in part 2 makes use a of definition to craete a list of email subject, the message and the attachment: def mail(to, subject, text, attach): msg = MIMEMultipart()
|
- Home
- Python
- Ras Pi
-
Pi Hardware
- Pi-Hacks
-
Pi-Hacks 2
- The Joker
- Hologram Machine
- Google Vision: Camera Tell
- Yoda Tweets
- Pi Phone
- Darth Beats
- Twitter Keyword Finder
- Crimbo Lights Hack
- Xmas Elf
- Halloween 2016
- Halloween Hack 2015
- Socrative Zombie
- Voice Translation
- The Blue-Who Finder
- GPIO, Twitter
- Pi Chat Bot >
- PiGlow & Email
- Pibrella Alarm System
- SMS with Python >
- Pi-Hacks 3
- Minecraft
- Computing
- Contact Me
- Random Hacks