{"id":41883,"date":"2017-08-10T06:39:31","date_gmt":"2017-08-10T06:39:31","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=41883"},"modified":"2019-04-02T10:23:28","modified_gmt":"2019-04-02T10:23:28","slug":"guide-to-raspberry-pi-camera-v2-module","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/guide-to-raspberry-pi-camera-v2-module\/","title":{"rendered":"Guide to Raspberry Pi Camera V2 Module"},"content":{"rendered":"<p>This article is an introduction to the Raspberry Pi Camera V2 Module. It explains how to quickly get started with the camera: how to take photos and record video into a file.<!--more--><\/p>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-41958 \" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/5mp-1080p-720p-video-ov5647-sensor-mini-camera-raspberry-pi-2-model-b-board-e42ec945459a5eb9fefd8d8271494e9c.jpg?resize=251%2C251&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"251\" height=\"251\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/5mp-1080p-720p-video-ov5647-sensor-mini-camera-raspberry-pi-2-model-b-board-e42ec945459a5eb9fefd8d8271494e9c.jpg?w=400&amp;quality=100&amp;strip=all&amp;ssl=1 400w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/5mp-1080p-720p-video-ov5647-sensor-mini-camera-raspberry-pi-2-model-b-board-e42ec945459a5eb9fefd8d8271494e9c.jpg?resize=150%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/5mp-1080p-720p-video-ov5647-sensor-mini-camera-raspberry-pi-2-model-b-board-e42ec945459a5eb9fefd8d8271494e9c.jpg?resize=300%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/5mp-1080p-720p-video-ov5647-sensor-mini-camera-raspberry-pi-2-model-b-board-e42ec945459a5eb9fefd8d8271494e9c.jpg?resize=80%2C80&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/5mp-1080p-720p-video-ov5647-sensor-mini-camera-raspberry-pi-2-model-b-board-e42ec945459a5eb9fefd8d8271494e9c.jpg?resize=220%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 220w\" sizes=\"(max-width: 251px) 100vw, 251px\" \/><\/p>\n<p>We&#8217;ll cover the following topics:<\/p>\n<ul>\n<li>Raspberry Pi Camera V2 Module features<\/li>\n<li>Enable the Raspberry Pi Camera<\/li>\n<li>Connect the Camera<\/li>\n<li>Take photos with the camera<\/li>\n<li>Record video into a file<\/li>\n<\/ul>\n<p>Don&#8217;t have a Raspberry Pi yet? Check the <a href=\"https:\/\/makeradvisor.com\/best-raspberry-pi-3-starter-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">Best Raspberry Pi Starter Kits<\/a>.<\/p>\n<h2>Raspberry Pi Camera V2 Module features<\/h2>\n<p class=\"BodyFirst\"><span lang=\"EN-US\">The <a href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-camera-v2-module\/\" target=\"_blank\" rel=\"noopener noreferrer\">Raspberry Pi Camera V2 module<\/a> is very tiny and it looks like this:<\/span><\/p>\n<p><a href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-camera-v2-module\/\" target=\"_blank\" rel=\"noopener noreferrer\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter wp-image-41886\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/Rpicamerav2module.jpg?resize=577%2C292&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"577\" height=\"292\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/Rpicamerav2module.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/Rpicamerav2module.jpg?resize=300%2C152&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 577px) 100vw, 577px\" \/><\/a><\/p>\n<p class=\"BodyFirst\"><span lang=\"EN-US\">The Raspberry Pi Camera V2 features an 8 megapixel Sony IMX219 image sensor with fixed focus lens, it is capable of 3280\u00d72464 pixel static images and supports 1080p30, 720p60, and 640\u00d7480p90 video.<\/span><\/p>\n<p>The camera is compatible with all Raspberry Pi models.<\/p>\n<h2>Enable the Raspberry Pi Camera Module<\/h2>\n<p>To use the Raspberry Pi Camera module, you need to enable the camera software in your Raspberry Pi. In the Desktop environment, go to the <strong>Raspberry Pi Configuration<\/strong>\u00a0window under the <strong>Preferences<\/strong> menu, open the <strong>Interfaces<\/strong> tab and enable the <strong>Camera<\/strong> as shown in figure below.<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-41866\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/Figure-13-3.png?resize=508%2C429&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"508\" height=\"429\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/Figure-13-3.png?w=508&amp;quality=100&amp;strip=all&amp;ssl=1 508w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/Figure-13-3.png?resize=300%2C253&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 508px) 100vw, 508px\" \/><\/p>\n<p>Or, in the <strong>Terminal<\/strong> window, type the following command:<\/p>\n<pre>pi@raspberry:~ $ <strong>sudo raspi-config<\/strong><\/pre>\n<p>You should see the Raspberry Pi software configuration tool. Select the <strong>Interfacing Options<\/strong>:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-41873\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/Interfacing-options.png?resize=671%2C189&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"671\" height=\"189\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/Interfacing-options.png?w=959&amp;quality=100&amp;strip=all&amp;ssl=1 959w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/Interfacing-options.png?resize=300%2C84&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/Interfacing-options.png?resize=768%2C216&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 671px) 100vw, 671px\" \/><\/p>\n<p>Enable the camera and reboot your Pi:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-41874\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/enable-camera-raspi-config.png?resize=772%2C217&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"772\" height=\"217\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/enable-camera-raspi-config.png?w=960&amp;quality=100&amp;strip=all&amp;ssl=1 960w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/enable-camera-raspi-config.png?resize=300%2C84&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/enable-camera-raspi-config.png?resize=768%2C216&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 772px) 100vw, 772px\" \/><\/p>\n<h2>Connect the camera<\/h2>\n<p>Connecting the Raspberry Pi Camera Module is easy. With the Pi shutdown, connect the camera to the Pi CSI port as shown in the following figure. Make sure the camera is connected in the right orientation with the ribbon blue letters facing up as shown in the next figure.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-41868\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/connectcamera-1.jpg?resize=516%2C406&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"516\" height=\"406\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/connectcamera-1.jpg?w=516&amp;quality=100&amp;strip=all&amp;ssl=1 516w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/connectcamera-1.jpg?resize=300%2C236&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 516px) 100vw, 516px\" \/><\/p>\n<h2>Take photos with the camera<\/h2>\n<p>The easiest way to control the Raspberry Pi Camera is using the Python\u00a0<a href=\"http:\/\/picamera.readthedocs.io\/en\/latest\/\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>PiCamera<\/strong><\/a> package.<\/p>\n<p><strong>I recommend using\u00a0Python 3<\/strong> to run this script even though the PiCamera package supports Python 2. Create a new file called\u00a0<strong>take_photo.py<\/strong>:<\/p>\n<pre>pi@raspberrypi:~ $ <strong>nano take_photo.py<\/strong><\/pre>\n<p>Copy the following code to your newly created file:<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">from time import sleep\nfrom picamera import PiCamera\n\ncamera = PiCamera()\ncamera.resolution = (1024, 768)\ncamera.start_preview()\n\nsleep(2)\ncamera.capture('test_photo.jpg')\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/PiCamera\/take_photo.py\" target=\"_blank\">View raw code<\/a><\/p>\n<p>Press Ctrl+X to save your file, type Y and Enter.<\/p>\n<p>When you run the script:<\/p>\n<pre>pi@raspberrypi:~ $ <strong>python3 take_photo.py<\/strong><\/pre>\n<p>It takes a photo with the Raspberry Pi Camera and saves it with the\u00a0<strong>test_photo.jpg<\/strong> name:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-41915\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/test_photo.jpg?resize=600%2C450&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"600\" height=\"450\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/test_photo.jpg?w=600&amp;quality=100&amp;strip=all&amp;ssl=1 600w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/test_photo.jpg?resize=300%2C225&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/p>\n<h2>Recording video into a file<\/h2>\n<p>The next Python script also uses the <strong>PiCamera<\/strong> package to record video into a file.<\/p>\n<p>Create a new file called\u00a0<strong>record_video.py<\/strong>:<\/p>\n<pre>pi@raspberrypi:~ $ <strong>nano record_video.py<\/strong><\/pre>\n<p>Copy the following code to your newly created file:<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">import picamera\n\ncamera = picamera.PiCamera()\n\ncamera.resolution = (640, 480)\ncamera.start_recording('test_video.h264')\ncamera.wait_recording(5)\ncamera.stop_recording()\n\nprint('Finished recording')\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/PiCamera\/record_video.py\" target=\"_blank\">View raw code<\/a><\/p>\n<p>Press Ctrl+X to save your file, type Y and Enter.<\/p>\n<p>When you run the script:<\/p>\n<pre>pi@raspberrypi:~ $ <strong>python3 record_video.py<\/strong><\/pre>\n<p>It takes 5 seconds video with the Raspberry Pi Camera and saves it with the\u00a0<strong>test_video.h264<\/strong>\u00a0name.\u00a0You can modify the script to set the camera resolution and extend the video recording duration.<\/p>\n<p>To watch the video on Raspberry Pi with the Raspbian Desktop environment, you can use the <strong>omxplayer<\/strong> software.<\/p>\n<pre>pi@raspberrypi:~ $ <strong>omxplayer test_video.h264<\/strong><\/pre>\n<p>Here&#8217;s a screenshot of the recording:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-41914\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/image.png?resize=600%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"600\" height=\"443\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/image.png?w=600&amp;quality=100&amp;strip=all&amp;ssl=1 600w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/image.png?resize=300%2C222&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/p>\n<h2>Wrapping up<\/h2>\n<p>This post was a quick introduction guide to the Raspberry Pi Camera V2 Module and how to take photos and record video into a file.<\/p>\n<p>If you like this post, you&#8217;ll also like this project: <a href=\"https:\/\/randomnerdtutorials.com\/video-streaming-with-raspberry-pi-camera\/\">Video Streaming with the Raspberry Pi Camera<\/a>.<\/p>\n<p>We hope you&#8217;ve found this post useful.<\/p>\n<p>Thanks for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article is an introduction to the Raspberry Pi Camera V2 Module. It explains how to quickly get started with the camera: how to take photos and record video into &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Guide to Raspberry Pi Camera V2 Module\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/guide-to-raspberry-pi-camera-v2-module\/#more-41883\" aria-label=\"Read more about Guide to Raspberry Pi Camera V2 Module\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":41886,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301,269,264,289,268,190,192],"tags":[],"class_list":["post-41883","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-raspberrypi","category-guide-project","category-project","category-python","category-raspberry-pi-project","category-raspberry-pi","category-r-tutorials"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/08\/Rpicamerav2module.jpg?fit=700%2C354&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/41883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=41883"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/41883\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/41886"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=41883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=41883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=41883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}