Jones23
Posts: 4
Joined: Mon May 11, 2015 5:41 pm

where to start

Mon May 11, 2015 6:15 pm

Hi,
Please help, as part of a college project I am trying to use the RPi B+ to take a photo when triggered by a pir sensor. I have practically zero experience with using a Pi and not sure of many things :)
Where do I start? how do I open a file to save the code onto so it doesn't disappear when I turn it off? is there a viewer on the RPi that will show the pic taken? Basically im lost as to how to best start this and need some advice for a dummy. If anyone can advise me that would be amazing.
Does anyone know if there is somewhere i can go and meet some experts in person?

any advice would be greatly appreciated
K jones

User avatar
B.Goode
Posts: 8926
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: where to start

Mon May 11, 2015 8:32 pm

The Raspberry Pi Foundation project here - https://www.raspberrypi.org/learning/parent-detector/ - has a lot in common with what you want to achieve. From the same source there are loads of other Getting Started resources here: https://www.raspberrypi.org/help/

For help in person, look out via the Community Pages for a Raspberry Jam in your area, or look out for other similar activities such as CoderDojo or Hackspaces.

gordon77
Posts: 4253
Joined: Sun Aug 05, 2012 3:12 pm

Re: where to start

Wed May 13, 2015 1:57 pm

Try this...assuming you've got to the stage of trying to write some Python software..

Code: Select all

import RPi.GPIO as GPIO
import os
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO_PIR = 7  # pin 26
GPIO.setup(GPIO_PIR,GPIO.IN)

print "  Press Ctrl & C to Quit"

try:
   
   while GPIO.input(GPIO_PIR)==1:
       Motion = 0
   print "  Ready"
   
   Motion = 0
   
   while True :
      if GPIO.input(GPIO_PIR)==1:
         if Motion == 0:
            print "  Motion detected!"
            path = "raspistill -n -o photo.jpg"
            os.system (path)
            Motion = 1
         
      else:
         if Motion == 1:
            print "  Clear "
            Motion = 0
         

except KeyboardInterrupt:
  print "  Quit"
It assumes you have a PIR detector wired to pin26 (GPIO7), and a Pi camera installed.

Jones23
Posts: 4
Joined: Mon May 11, 2015 5:41 pm

Re: where to start

Wed May 13, 2015 5:38 pm

Thanks, Ive used the parent detector and have made a file that with the PIR triggering the camera. I now know how to recall each video file taken as it shows. Im unsure how to change the settings so I can dictate the length of time of the video. I can follow instruction but really have little understanding of writing code with python or anything else. Ultimately I want the video to send an email and/or send the video to a viewer on an iPhone. Is this possible? I'm just trying to read through all the resources but losing lots of time if looking in the wrong place so any help advice again really appreciated. Really looking to meet with someone if possible im in bucks, uk and will check again on the forums for a jam.
Cheers guys


Jones23
Posts: 4
Joined: Mon May 11, 2015 5:41 pm

Re: where to start

Wed May 13, 2015 7:40 pm

Thanks Gordon,
Im happy with the basic functions of the camera now. Can I not adjust the code ive got from the parent detector. It appears to be by default a 5 sec video so I just change this don't I? but I cant see where it is in the code
Once that's done I want to send it to a viewer on my iPhone or as an email/sms whichever is easier. Ive read the html link regarding sending emails but I didn't understand what I was reading. I need a human teacher I think! :oops:

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: where to start

Wed May 13, 2015 7:43 pm

I recommend reading a brief tutorial on Python, to get the works of it and Linux, before you delve into it all here. It will make life so much easier!

For the iPhone part, you could make your own app with sockets (which I did which takes way more time) or send an email which would be the easiest.
There are 10 types of people: those who understand binary and those who don't.

User avatar
B.Goode
Posts: 8926
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: where to start

Wed May 13, 2015 8:06 pm

Jones23 wrote:Thanks Gordon,
Im happy with the basic functions of the camera now. Can I not adjust the code ive got from the parent detector. It appears to be by default a 5 sec video so I just change this don't I? but I cant see where it is in the code
https://picamera.readthedocs.org/en/rel ... -to-a-file

I need a human teacher I think!
Since this is a college project, don't you have one already?

gordon77
Posts: 4253
Joined: Sun Aug 05, 2012 3:12 pm

Re: where to start

Wed May 13, 2015 8:11 pm

Jones23 wrote:Thanks Gordon,
Im happy with the basic functions of the camera now. Can I not adjust the code ive got from the parent detector. It appears to be by default a 5 sec video so I just change this don't I? but I cant see where it is in the code
Once that's done I want to send it to a viewer on my iPhone or as an email/sms whichever is easier. Ive read the html link regarding sending emails but I didn't understand what I was reading. I need a human teacher I think! :oops:
If l'd read the links provided l'd have seen you are using picamera!

Other responders have sent links to the picamera docs where you'll see how to set the length of the video

Gordon

Return to “Beginners”