TeCoEd (Teaching Computing Education)
  • Home
    • Freelance
    • Book
    • Downloading
  • Python
    • Learn Python >
      • Python Modules
    • PyGame Zero
    • Python Programs >
      • Higher or Lower
      • Magic Calculator
      • Password Checker
      • Python Pit
    • What's News App
    • Pixels to Cells
    • Python Mosaics
    • Python OCR
    • L-1-AM
    • Web Scraping >
      • Scraping Trains
    • Weather App
    • Snakes and Windows
    • Python Web Server >
      • Flask
    • Python Picks
  • Raspberry Pi
    • All About the Pi
    • Getting Started
    • Remote Desktop and VNC
    • Static IP Address
    • Sonic Pi >
      • 3.14
    • Twitter Feed >
      • Tweepy
    • Android & Pi >
      • Advanced Apps
      • Odds
    • A.I on the the Pi
    • CRON
    • Pick Your Own
  • Pi Hardware
    • Pi HATS >
      • Sense Hat Hacks
      • AstroPi HAT
      • Unicorn-HAT >
        • Unicorn Alphabet Disco
        • Uni Codes / Programs
      • Skywriter
      • Piano HAT
    • STS Pi
    • Pi Camera >
      • Pi-Cam, Python & Email >
        • Time Lapse
      • Pi Noir
    • Pipsta >
      • Flask, Input & Printers
    • Raspberry Pi Power >
      • Energenie IR power
    • Pibrella
    • Distance Sensor
    • LCD Screen
    • Pi-Tooth
    • Robot Arm
    • PiGlow
    • PiFM
    • Accelerometer
    • PiFace >
      • Installing PiFace >
        • Python Commands
  • Pi-Hacks
    • Drone Hacks
    • Pi Glue Gun Hack
    • Blinkt!
    • Sonic Pixels
    • R2D2
    • Get to the chopper
    • Astro Bird
    • Twitter Translator
    • Hacking a Robot
    • Nature_Box >
      • Best Nature Photos
    • Wearable Tech >
      • Project New York
      • P.N.Y Part 2 Health
      • P.N.Y Part 3 Games
      • P.N.Y Part 4 Translation
    • Dino-Tweet
    • Other Links
  • 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 >
      • Dictionary Definitions
    • PiGlow & Email
    • Pibrella Alarm System
    • SMS with Python >
      • Spooking a Mobile
  • Pi-Hacks 3
    • David Bowie
    • Lamp Prank >
      • TEST
    • Yoda FM
    • Retro Player
    • LED Pixel Art
    • TARDIS
    • Battleships
    • LED Board
    • Night Vision
    • Enviro+ Weather
  • Minecraft
    • Minecraft API
    • Minecraft Sweeper
    • PiGlove: Minecraft Power Up
    • Minecraft Photo-booth
    • Rendering Pixels
    • Speed Cube
    • Lucky Dip
  • Computing
    • Why Computing?
    • Can You Compute
    • micro:bit
    • Coding Resources
    • Learn to Code >
      • Coding with iPads
      • Apps Creation Tools
      • sKratchInn
      • Sound Editing
    • Cheat Sheets
    • Theory
    • HOUR OF CODING
    • BEBRAS Computing Challange
    • Computer Facts
    • Free Software and Links
  • Contact Me

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 
Pi Cam
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 Module


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


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



3. 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 Picture


Last 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()

Send an Email with Attachment
File Size: 1 kb
File Type: py
Download File

Copyright 2020 TeCoEd @dan_aldred