From charlesreid1

Line 27: Line 27:
* python-picamera-docs
* python-picamera-docs


These packages were not, however, in the aptitude repositories for this OS:
===Can't use aptitude===
 
These packages were not in the aptitude repositories for this OS:


<pre>
<pre>
Line 63: Line 65:
apt-get install -y python-pip  
apt-get install -y python-pip  
</pre>
</pre>
===Using pip===


Now we should have pip, which will enable us install the Pi camera API:
Now we should have pip, which will enable us install the Pi camera API:


<pre>
<pre>
pip install python-picamera
pip install picamera
</pre>
</pre>
(I found this by googling the term "picamera" - one of the top results was the page for this library in the pip repository.)


=Scripting=
=Scripting=

Revision as of 18:24, 29 July 2016

Outline

For this project, I was replicating the Raspberry Pi timelapse setup from the RaspberryPi/Timelapse page.

Hardware

  • Raspberry Pi
  • Pi camera
  • Camera case
  • Network cable
  • Power cable

Setting up the Pi

To begin with, I installed a fresh Kali Linux arm image. I wanted to make sure I had installed the operating system correctly and that I could reach the Pi just fine. I connected the Pi directly to my laptop using a crossover cable. After connecting the two, I restarted both machines. They automatically picked link-local addresses at 169.254.X.Y, which I was able to use to SSH directly into the Pi.

This confirmed that I had everything working ok on the Pi.

Connecting to the Pi

The next step was to connect to the Pi over a network, so that the Pi would be able to download and install any necessary libraries. I started by modifying cmdline.txt on the SD card to manually set the Pi's IP address to 192.168.0.111. I then plugged the Pi into the network router, and was able to SSH into the machine at 192.168.0.111.

Installing Libraries

Once on the Pi, I needed to install some libraries. From my previous adventure at RaspberryPi/Timelapse I knew I needed a few libraries:

  • python-picamera
  • python-picamera-docs

Can't use aptitude

These packages were not in the aptitude repositories for this OS:

# apt-get install -y python-picamera python-picamera-docs
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-picamera
E: Unable to locate package python-picamera-docs

But that's ok, because we can use pip instead!

If this is a brand new Pi, you'll need to install some tools (not all necessary, but you'll need them sooner or later.) Start with screen, so you can run the installation process in the background:

apt-get install -y screen

Then install some utilities onto the Pi:

apt-get install -y vim aptitude

Next, install Python and tools for building stuff:

apt-get install -y python build-essential

Last, install pip:

apt-get install -y python-pip 

Using pip

Now we should have pip, which will enable us install the Pi camera API:

pip install picamera

(I found this by googling the term "picamera" - one of the top results was the page for this library in the pip repository.)

Scripting

To script taking a picture, use the following code, which loops forever, taking photos and marking them with timestamps:

# pic.py

import picamera
from datetime import datetime
import time

camera = picamera.PiCamera()

while True:

    prefix = datetime.strftime(datetime.now(),"photo_%Y%m%d-%H%M%S")
    filename = prefix+".jpg"

    camera.capture(filename)
    print "Saving photo to %s"%(filename)

    time.sleep(2)

Flags