{"id":273,"date":"2017-05-03T01:08:49","date_gmt":"2017-05-03T05:08:49","guid":{"rendered":"http:\/\/teakdata.com\/blog\/?p=273"},"modified":"2017-05-03T01:11:33","modified_gmt":"2017-05-03T05:11:33","slug":"create-photo-camera-using-raspberry-pi-zero","status":"publish","type":"post","link":"https:\/\/teakdata.com\/blog\/create-photo-camera-using-raspberry-pi-zero\/","title":{"rendered":"Create your own photo camera using Raspberry Pi Zero"},"content":{"rendered":"<p>This project provides instructions how to create a\u00a0very simple photo camera using Raspberry Pi Zero.<\/p>\n<div id=\"attachment_274\" style=\"width: 484px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/05\/IMG_4479-Edit.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-274\" class=\"wp-image-274 size-large\" src=\"http:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/05\/IMG_4479-Edit-1024x768.jpg\" alt=\"DIY Photo Camera using Raspberry Pi\" width=\"474\" height=\"356\" srcset=\"https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/05\/IMG_4479-Edit-1024x768.jpg 1024w, https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/05\/IMG_4479-Edit-300x225.jpg 300w, https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/05\/IMG_4479-Edit-768x576.jpg 768w, https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/05\/IMG_4479-Edit.jpg 1200w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/a><p id=\"caption-attachment-274\" class=\"wp-caption-text\">DIY Photo Camera using Raspberry Pi<\/p><\/div>\n<h2>Required Materials<\/h2>\n<ul>\n<li>Raspberry Pi Zero (you can use also other models, update the case accordingly) \u00a0<a href=\"https:\/\/www.raspberrypi.org\/products\/pi-zero-w\/\">https:\/\/www.raspberrypi.org\/products\/pi-zero-w\/<\/a><\/li>\n<li>Pi Camera\u00a0<a href=\"https:\/\/www.raspberrypi.org\/products\/camera-module-v2\/\">https:\/\/www.raspberrypi.org\/products\/camera-module-v2\/<\/a><\/li>\n<li>Raspberry Pi Case\u00a0<a href=\"https:\/\/www.raspberrypi.org\/products\/raspberry-pi-zero-case\/\">https:\/\/www.raspberrypi.org\/products\/raspberry-pi-zero-case\/<\/a><\/li>\n<li>Break-away pins (Raspberry Pi Zero does not come with i\/o pins)\u00a0<a href=\"https:\/\/www.adafruit.com\/product\/2822\">https:\/\/www.adafruit.com\/product\/2822<\/a><\/li>\n<li>Jumper wires\u00a0<a href=\"https:\/\/www.adafruit.com\/product\/266\">https:\/\/www.adafruit.com\/product\/266<\/a><\/li>\n<li>LED<a href=\"https:\/\/www.sparkfun.com\/products\/10632\">\u00a0https:\/\/www.sparkfun.com\/products\/10632<\/a><\/li>\n<li>Resistor 330 \u2126\u00a0<a href=\"https:\/\/www.sparkfun.com\/products\/8377\">https:\/\/www.sparkfun.com\/products\/8377\u00a0<\/a><\/li>\n<li>Momentary Push Button\u00a0<a href=\"https:\/\/www.sparkfun.com\/products\/9190\">https:\/\/www.sparkfun.com\/products\/9190<\/a><\/li>\n<li>Soldering iron (for model zero, pinout not attached)<\/li>\n<li>Battery pack\/charger<\/li>\n<\/ul>\n<h2>Hardware setup<\/h2>\n<div id=\"attachment_283\" style=\"width: 484px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/05\/IMG_4477-Edit.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-283\" class=\"wp-image-283 size-large\" src=\"http:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/05\/IMG_4477-Edit-1024x768.jpg\" alt=\"DIY Photo Camera using Raspberry Pi\" width=\"474\" height=\"356\" srcset=\"https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/05\/IMG_4477-Edit-1024x768.jpg 1024w, https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/05\/IMG_4477-Edit-300x225.jpg 300w, https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/05\/IMG_4477-Edit-768x576.jpg 768w, https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/05\/IMG_4477-Edit.jpg 1200w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/a><p id=\"caption-attachment-283\" class=\"wp-caption-text\">DIY Photo Camera using Raspberry Pi<\/p><\/div>\n<h3>Raspberry Pi Pinout<\/h3>\n<ul>\n<li>pinout <a href=\"https:\/\/pinout.xyz\/\">https:\/\/pinout.xyz\/<\/a><\/li>\n<li>in this project using pin GND, BCM 18, BCM 17<\/li>\n<\/ul>\n<h3>Step 1 &#8211; Attach Break-away pins on Raspberry Pi Zero<\/h3>\n<h3>Step 2 &#8211; Solder the wires on LED, resistor and Push Button<\/h3>\n<h3>Step 3 &#8211; Connect the LED on Raspberry Pi<\/h3>\n<ul>\n<li>using pin (GND and BCM 18)<\/li>\n<li>GND: <a href=\"https:\/\/pinout.xyz\/pinout\/ground\">https:\/\/pinout.xyz\/pinout\/ground<\/a><\/li>\n<li>BCM 18: <a href=\"https:\/\/pinout.xyz\/pinout\/pin12_gpio18\">https:\/\/pinout.xyz\/pinout\/pin12_gpio18<\/a><\/li>\n<li>Test pins:<\/li>\n<\/ul>\n<pre><code>python led.py to test led<\/code><\/pre>\n<h4>led.py script<\/h4>\n<pre class=\"p1\"><span class=\"s1\">import RPi.GPIO as GPIO<\/span>\r\n<span class=\"s1\">import time<\/span>\r\n<span class=\"s1\">\r\nGPIO.setmode(GPIO.BCM)<\/span>\r\n<span class=\"s1\">GPIO.setwarnings(False)<\/span>\r\n\r\n<span class=\"s1\">GPIO.setup(18,GPIO.OUT)<\/span>\r\n<span class=\"s1\">print \"LED on\"<\/span>\r\n<span class=\"s1\">GPIO.output(18,GPIO.HIGH)<\/span>\r\n<span class=\"s1\">time.sleep(1)<\/span>\r\n<span class=\"s1\">print \"LED off\"<\/span>\r\n<span class=\"s1\">GPIO.output(18,GPIO.LOW)<\/span><\/pre>\n<h3>Step 4 &#8211; Connect the Push Button on Raspberry Pi<\/h3>\n<ul>\n<li>using pin (GND and BCM 17)<\/li>\n<li>GND: <a href=\"https:\/\/pinout.xyz\/pinout\/ground\">https:\/\/pinout.xyz\/pinout\/ground<\/a><\/li>\n<li>BCM 17: <a href=\"https:\/\/pinout.xyz\/pinout\/pin11_gpio17\">https:\/\/pinout.xyz\/pinout\/pin11_gpio17<\/a><\/li>\n<li>Test button:<\/li>\n<\/ul>\n<pre><code>python button.py<\/code><\/pre>\n<h4>button.py script<\/h4>\n<pre class=\"p1\"><span class=\"s1\">import<span class=\"Apple-converted-space\">\u00a0 <\/span>RPi.GPIO as GPIO<\/span>\r\n<span class=\"s1\">import time<\/span>\r\n\r\n<span class=\"s1\">GPIO.setmode(GPIO.BCM)<\/span>\r\n<span class=\"s1\">GPIO.setup(17, GPIO.IN,pull_up_down=GPIO.PUD_UP)<\/span>\r\n\r\n<span class=\"s1\">while True:<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>inputValue = GPIO.input(17)<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>if (inputValue == False):<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>print(\"Button press \")<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>time.sleep(0.3)<\/span><\/pre>\n<h2>Software Setup<\/h2>\n<p>(see git repository below for full source code)<\/p>\n<h3>Take a picture<\/h3>\n<ul>\n<li>Take a picture into the current folder (resolution 800&#215;600)<\/li>\n<\/ul>\n<pre><code>raspistill -t 1 -w 800 -h 600 -o {imgName}<\/code><\/pre>\n<h3><a id=\"user-content-full-script\" class=\"anchor\" href=\"https:\/\/github.com\/smarcu\/ddl-cam#full-script\"><\/a>Full script<\/h3>\n<ul>\n<li>ddl-cam.py script monitors the button state, takes a picture and turns the led on during shot time.<\/li>\n<li>pictures are taken in the same folder where you run the scripts<\/li>\n<li>you can copy the files from remote machine using scp<\/li>\n<li>example, copy all jpg files from 192.168.1.15 (your current raspberry pi ip) to your current folder<\/li>\n<\/ul>\n<pre><code>scp pi@192.168.1.15:\/home\/pi\/ddl-cam\/*.jpg .<\/code><\/pre>\n<h3>ddl-cam.py script<\/h3>\n<pre class=\"p1\"><span class=\"s1\">import RPi.GPIO as GPIO<\/span>\r\n<span class=\"s1\">import time<\/span>\r\n<span class=\"s1\">import subprocess<\/span>\r\n\r\n<span class=\"s1\">GPIO.setmode(GPIO.BCM)<\/span>\r\n<span class=\"s1\">GPIO.setwarnings(False)<\/span>\r\n\r\n<span class=\"s1\"># LED PIN<\/span>\r\n<span class=\"s1\">LED_PIN = 18<\/span>\r\n<span class=\"s1\">GPIO.setup(LED_PIN, GPIO.OUT)<\/span>\r\n\r\n<span class=\"s1\"># BUTTON PIN<\/span>\r\n<span class=\"s1\">BUTTON_PIN = 17<\/span>\r\n<span class=\"s1\">GPIO.setup(BUTTON_PIN, GPIO.IN,pull_up_down=GPIO.PUD_UP)<\/span>\r\n\r\n<span class=\"s1\">def led( state ): <\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>print \"LED state \", state<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>if state == True:<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>GPIO.output(LED_PIN, GPIO.HIGH)<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>else:<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>GPIO.output(LED_PIN, GPIO.LOW)<\/span>\r\n\r\n<span class=\"s1\">def takePicture():<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>imgName<span class=\"Apple-converted-space\">\u00a0 <\/span>= \"ddcam-\" + time.strftime(\"%Y%m%d-%H%M%S\") + \".jpg\"<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>print \"Take Picture! \", imgName<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>subprocess.call([\"raspistill\", \"-t\", \"1\", \"-w\", \"800\", \"-h\", \"600\", \"-o\", imgName])<\/span>\r\n\r\n<span class=\"s1\"># monitor button<\/span>\r\n<span class=\"s1\">while True:<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>inputValue = GPIO.input(BUTTON_PIN)<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>if (inputValue == False):<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>print(\"Button press \")<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>led (True)<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>takePicture()<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>time.sleep(1);<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>led (False)<\/span>\r\n<span class=\"s1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>time.sleep(0.8)<\/span><\/pre>\n<h3>Git Repository<\/h3>\n<p>You can find full source code and instructions on the git repository:\u00a0<a href=\"https:\/\/github.com\/smarcu\/ddl-cam\">https:\/\/github.com\/smarcu\/ddl-cam<\/a><\/p>\n<p>Clone the repo on your raspberry pi:<\/p>\n<pre>git clone https:\/\/github.com\/smarcu\/ddl-cam.git<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This project provides instructions how to create a\u00a0very simple photo camera using Raspberry Pi Zero. Required Materials Raspberry Pi Zero (you can use also other models, update the case accordingly) \u00a0https:\/\/www.raspberrypi.org\/products\/pi-zero-w\/ Pi Camera\u00a0https:\/\/www.raspberrypi.org\/products\/camera-module-v2\/ Raspberry&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":274,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12,40,10],"tags":[],"class_list":["post-273","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-daniel-dad-laboratories","category-education","category-linux","category-python","category-raspberrypi"],"_links":{"self":[{"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/posts\/273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/comments?post=273"}],"version-history":[{"count":9,"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/posts\/273\/revisions"}],"predecessor-version":[{"id":284,"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/posts\/273\/revisions\/284"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/media\/274"}],"wp:attachment":[{"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/media?parent=273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/categories?post=273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/tags?post=273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}