element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi Projects
  • Products
  • Raspberry Pi
  • Raspberry Pi Projects
  • More
  • Cancel
Raspberry Pi Projects
Blog What's In The Box? PiFace PiCamera Prank - the Ultimate Raspi Bundle Continues
  • Blog
  • Documents
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: mazzmn
  • Date Created: 9 Mar 2014 11:28 PM Date Created
  • Views 865 views
  • Likes 0 likes
  • Comments 2 comments
  • python
  • piface_digital
  • rasberrypi
  • camera
  • raspberry_pi_projects
  • sensor
Related
Recommended

What's In The Box? PiFace PiCamera Prank - the Ultimate Raspi Bundle Continues

mazzmn
mazzmn
9 Mar 2014

Well, I've finished my main project for The Ultimate Raspberry Pi Bundle Road Trip, you can read about that here:

The Complete Channel One Temperature Monitor and Alarm Project - The Ultimate Raspberry Pi Bundle

But, that doesn't mean I'm done Road Trippin,

I still have a few more wonderful gadgets to test out....

In this post I'm go to explain how I used the Raspberry Pi, the PiFace Digital and the Raspberry Pi Camera to create a gadget that will catch sneaky people who  try to peek into packages when they're not supposed to.

 

image


What's in the Box?

For this project I'll hide a Pi, Camera and PiFace Digital inside a box, we'll use a magnetic switch to detect when the box opens and snap a picture of the snoop. A follow on for this project would be to send a text message (as I did on my previous project the Channel One Temperature Monitor) or twitter or instragram the image....but I'll leave that for another day.

 

Parts needed:

  • Raspberry Pi Model B (A would work as well, but a USB hub would be required)
  • PiFace DigitalPiFace Digital - Daughter Card / Expansion board for the Pi
  • Raspberry Pi Camera BoardRaspberry Pi Camera Board
  • Magnetic Proximity switch - I had this one from Jameco on hand
  • Optional LED - Breadboard and wires to act as an "on" indicator

 

The PiFace Digital:

The PiFace Digital is a shield designed to fit on the Rasberry Pi, and it adds many features to the Raspberry Pi including

  • 8 Digital Inputs
  • 8 Outputs
  • 8 LED indicators
  • 2 Relays
  • Works in Python, Scratch and C
  • There's even an emulator


Putting together the What's In the Box Project:

I'm going to skip the steps of installing Raspbian as I covered that in my previous project.

For this project I needed to:

  • Install the camera and some code it requires
  • Install code for the PiFace Digital and test it out
  • wire up the switch and LEDs
  • write the inTheBox.py script which runs everything.

 

Install and Configure the Camera:

Watch the video on the following page to see how the camera connects to the PiFace Digital

http://www.raspberrypi.org/camera

Be aware that the camera is sensitive to static electricity, the ribbon cable is fragile and the ribbon cable must be installed in the correct orientation

To operate the camera you need to

  • run sudo raspi-config to enable the camera
  • reboot

Now you'll be able to test the camera by running the command:

raspi-still -v -t image.jpg

This command will start the camera, show you a preview, prompt you on the commandline, when you press Enter the picture is snapped

There are many options and features available on the camera. It's worth it to take a look at the camera documentation found here


Installing the PiFace Digital:

Physically the PiFace Digital fits on easily, but since the Camera is part of this project, it would have been nice if there would have been more room for the ribbon cable. It seemed to work fine to run the cable under the shield, but I wasn't really happy about bending the cable that much.
For the software portion of the install, I thought a good place to get started on this project would be the piface getting started guide

The information on enabling SPI was good, but the instructions on installing the code and emulator used wget and were out of date. I eventually found the Install PiFace Software on the PiFace website and those instructions use apt-get and are up to date:

 

After installing the PiFace Digital code and Emulator (and rebooting) you can run a few things to test out the PiFace Digital

For example, test the PiFace built in LEDs with the following blink program

python3 /usr/share/doc/python3-pifacedigitalio/examples/blink.py

 

You can also test the switches virtually by running the PiFace Emulator

piface/scripts/piface-emulator

click on the Override Enable menu option

and now the virtual Output Pin buttons will operate the LEDs, even the real LEDs on the real board!

 

Code the inTheBox.py Script:

I wanted a program to monitor the door and then snap a picture when someone opened it. I thought it would be useful to have an external LED so I could optionally have a blinking indicator letting me know the box is "armed".

To accomplish this I used one of the 8 PiFace input ports to handle the magnetic proximity sensor. I used of the 8 output ports to power the LED.

I ran Fritzing to create a schematic, but sorry to so no PiFace ....But you can see the connections here:

image

 

The program is called inTheBox.py and here it is

 

 

#!/usr/bin/env python3
import pifacedigitalio
import pifacedigitalio as pfio
from time import sleep
import os  # os used to run camera commands

pfio.init(True,0,0)

pifacedigitalio = pifacedigitalio.PiFaceDigital()

while(True):
  pifacedigitalio.leds[1].toggle()
  print (pfio.digital_read(7))
  if (pfio.digital_read(7) is 0):  #wait till the box opens
    print ("Smile!")
    #TODO: get date and use as part of filename
    #todo: create thread to upload images and erase them, optionally twitter?
    os.system("raspistill -t 2000  -o image.jpg")
#    os.system("raspistill -t 1000 -n -o image.jpg") # no preview 1 second pause
  print (pfio.digital_read(0)) #read button S1
  if (pfio.digital_read(0)): # if button then quit
    pifacedigitalio.leds[1].turn_off()
    exit(0)
  sleep(1)

 

 

Here's a Video of the What's in the Box Project catching a snoopy Gnome in the act

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

  • Sign in to reply
  • mazzmn
    mazzmn over 11 years ago in reply to Former Member

    Thanks Ashley!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 11 years ago

    cool project I wish I had a raspberry piimage

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube