From charlesreid1

 
(32 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Outline=
=Outline: Raspbian=


For this project, I was replicating the Raspberry Pi timelapse setup from the [[RaspberryPi/Timelapse]] page.
The issue with using Kali was, the use of the camera required onboard video libraries that did not come bundled with Kali. These were also not in the aptitude repositories, and I had no luck installing them. So for the camera project I decided to go with Raspbian and not sink any more time into getting Kali to work with camera hardware.
 
pi/raspberry


==Hardware==
==Hardware==
Line 19: Line 21:
==Connecting to 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.
I connected the Pi to a router, set a fixed IP address on the boot line of cmdline.txt on the memory card's boot sector, and plugged it into my home router. I then fired up the Pi.


==Installing Libraries==
SSH to 192.168.0.111 confirmed I was able to remotely reach the Pi. The Pi was also able to successfully reach the gateway and the outside internet.


Once on the Pi, I needed to install some libraries. From my previous adventure at [[RaspberryPi/Timelapse]] I knew I needed a few libraries:
==Installing stuff==
* python-picamera
* python-picamera-docs


===Can't use aptitude===
Get busy installing stuff:


These packages were not in the aptitude repositories for this OS:
<pre>
apt-get install -y screen
screen
</pre>
 
In the new screen window:


<pre>
<pre>
# apt-get install -y python-picamera python-picamera-docs
apt-get install -y vim aptitude
Reading package lists... Done
apt-get install -y python build-essential
Building dependency tree
apt-get install -y python-pip
Reading state information... Done
E: Unable to locate package python-picamera
E: Unable to locate package python-picamera-docs
</pre>
</pre>


But that's ok, because we can use pip instead!
This doesn't do much - most everything here is already installed.


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:
Now install the pi camera library (should also be already installed):


<pre>
<pre>
apt-get install -y screen
pip install picamera
</pre>
</pre>


Then install some utilities onto the Pi:
Now one last thing to do before testing the camera is to enable the boot flag that lets you use the camera (disabled by default).
 
Run <code>raspi-config</code> and pick the camera menu item (number 6). Choose to enable the camera. Save changes, and you'll be asked to reboot the Pi. Reboot the Pi. Now you can try out the camera.


<pre>
==Testing Picamera==
apt-get install -y vim aptitude
</pre>


Next, install Python and tools for building stuff:
Open python and try to import the picamera library:


<pre>
<pre>
apt-get install -y python build-essential
import picamera
</pre>
</pre>


Last, install pip:
Now try capturing your first photo:


<pre>
<pre>
apt-get install -y python-pip
import picamera
camera = picamera.PiCamera()
camera.capture('helloworld.jpg')
</pre>
</pre>


===Using pip===
Woo hoo! Works perfect!


Now we should have pip, which will enable us install the Pi camera API:
===Problems out of nowhere===


<pre>
Suddenly, out of nowhere, just when I had finished rigging the wireless and the zip ties and the camera box, everything failed. The camera would no longer respond. Hardware connection problem. Tear it all apart.
pip install picamera
</pre>


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


<pre>
The problems that came out of nowhere turned out to be connection problems with the flat yellow plate on the front of the camera face. I had to re-seat that plate snugly. After that, the camera worked fine.
# pip install picamera
Collecting picamera
  Downloading picamera-1.12.tar.gz (109kB)
    100% |████████████████████████████████| 112kB 680kB/s
Building wheels for collected packages: picamera
  Running setup.py bdist_wheel for picamera ... done
  Stored in directory: /root/.cache/pip/wheels/ec/7e/4f/ff55e2d9ee8377f0452e7f03822c3ee914c8c75a9cb9f57642
Successfully built picamera
Installing collected packages: picamera
Successfully installed picamera-1.12
</pre>


===Errors with libmmal===
===Testing with crossover cable===


I saw errors coming from missing libmmal files when I tried to import the picamera library. The following Python code imports the picamera library:
Connected Pi and laptop with crossover cable, set Pi IP to 169.254.111.111, tested local ssh to Pi - PASSED


<pre>
Connected Pi and laptop with crossover cable, same IP, tested capturing photo from Pi camera - PASSED
import picamera
</pre>


This failed with the following error message:
===Testing with Wireless===


<pre>
Wireless, 192.168.0.X, test whether we can connect to the wireless - PASSED
Traceback (most recent call last):
  File "lapse.py", line 3, in <module>
    import picamera
  File "/usr/local/lib/python2.7/dist-packages/picamera/__init__.py", line 72, in <module>
    from picamera.exc import (
  File "/usr/local/lib/python2.7/dist-packages/picamera/exc.py", line 41, in <module>
    import picamera.mmal as mmal
  File "/usr/local/lib/python2.7/dist-packages/picamera/mmal.py", line 47, in <module>
    _lib = ct.CDLL('libmmal.so')
  File "/usr/lib/python2.7/ctypes/__init__.py", line 362, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libmmal.so: cannot open shared object file: No such file or directory
</pre>


After some googling, I discovered that <code>libmmal.so</code> is supposed to reside in <code>/opt/vc</code>, which is where the Raspberry Pi stores its VideoCore API files. More information here: [http://elinux.org/Raspberry_Pi_VideoCore_APIs]
Wireless, 192.168.0.X, test whether we can auto-MAGIC-ally connect to the wireless on boot - PASSED


The source code for building this library is available on Github here: https://github.com/raspberrypi/firmware/tree/master/opt/vc
Wireless, 192.168.0.X, test whether we can plug in on other side of house, SSH in, start/finish photo capture, run HTTP server - PASSED


Precompiled binaries of these libraries are available here: https://github.com/raspberrypi/firmware/tree/master/hardfp/opt/vc
Wireless, 192.168.0.X, test whether we can capture photos, with everything taped into position - PASSED


Check out a copy of this repo from the Raspberry Pi with Kali on it (takes a while):
Wireless, 192.168.0.X, test whether we can run a time lapse test - PASSED


<pre>
==Final Arrangement for Timelapse 2==
git clone https://github.com/raspberrypi/firmware.git
</pre>


===Alternate route: install raspi-config===
The final arrangement of parts for the first timelapse was hacky and definitely would not have held together more than 24 hours. Here are photos of the Pi on the balcony. I used some packing tape (should have used duct tape, but I didn't have a fresh roll) to create a "sheet". I wrapped that around the Pi, the cabling for the camera, and the balcony rail.


Even though it is intended for Raspbian, we can try using the raspi-config utility, which is what Raspbian users use to enable the camera module on their Raspberry Pi. It is not available on ours because we installed our own operating system.
[[Image:PiBalcony3.jpg|500px]]


The .deb file for the raspi-config utility is difficult to find, but the link to all the release versions listed by date going back about 5 years are available online here: http://archive.raspberrypi.org/debian/pool/main/r/raspi-config/
[[Image:PiBalcony2.jpg|500px]]


From there, you copy the link to the .deb installer file, and download it to the Pi:
[[Image:PiBalcony1.jpg|500px]]


<pre>
This whole arrangement was made super awkward by the camera cable. It was wide, inflexible, hard to twist (and had to be twisted at least once given the way it came out of the case), but the real challenge was that if it was tugged too hard, the yellow plate on the front of the camera would pop off, and the entire assembly would have to be un-taped and disassembled to push the plate back onto the board, reassembled, re-taped, etc.
wget http://archive.raspberrypi.org/debian/pool/main/r/raspi-config/raspi-config_20160527_all.deb
</pre>


To install the contents of a deb file, use the <code>dpkg</code> utility with the <code>-i</code> flag, for install.
[[Image:PiDesk1.jpg|500px]]


=Scripting=
=Scripting=
==Taking photos==


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


</pre>
</pre>
==Processing photos==
While the full details are over at the [[Timelapse/Processing]] page, here's a quick taste of what collating a bunch of images together looks like.
Assuming you have all the images you want in a pile in one directory, we want to rename them in order so that they have the same name as before, but with the suffix _0001,0002,0003, etc.
=Successful Capture=
Notes on what the successful capture looks like, and links to pages/notes on processing timelapse photos.
=Notes=
==Timelapse 2 Notes==
Running my first timelapse, I didn't bother doing any calculations to see how long I could run based on available disk space - I just ran at a frequency of 1 photo per 2 seconds and let it run all night. It maxed out the SD card after about 6 hours.
Results and notes from this script/timelapse:
* Dislike case of Raspberry Pi 3
* Tape job was very perilously perched after a night of sitting - need mechanical security, not just tape and balance (ZIP TIES and/or LASHING)
What to keep the same:
* Camera worked ok
* Mini SD card worked ok
* Kali operating system worked ok, connected to wireless ok, hosted files ok, transferred data ok
* Power cable situation worked ok
What to change for next timelapse:
* More HD space
* No red light
* Case for Pi - loose top makes it awkward to do anything with it, forced camera angle is awkward too
* Need a swiveling plate or platform or boom
* Up/down angle of camera was difficult to control
For Next Design:
* Make it reusable across other types of camera and sensor platforms
* What other kinds of cameras might we be using
* What other kinds of control systems
* Generic mounting brackets, mechanical connections, on a platform would be good. Screws/bolts/etc.
* Way of positioning platform using railing.
What to change eventually:
* Adjustable frequency and more sophistication in script
* Motor control of plate or device to control angles and motion
* Image processing (vivid, contrast, hue, blur, tilt shift)
==Processing timelapse photos==
For notes on processing timelapse photos, see [[Timelapse/Processing]] page.
Notes on time-lapse photography in general at the [[Timelapse]] page.
==Next timelapse==
For planning notes for Timelapse 3, see: [[RaspberryPi/Timelapse3]]


=Flags=
=Flags=
{{TimelapseFlag}}


{{PiFlag}}
{{PiFlag}}

Latest revision as of 16:55, 14 August 2016

Outline: Raspbian

The issue with using Kali was, the use of the camera required onboard video libraries that did not come bundled with Kali. These were also not in the aptitude repositories, and I had no luck installing them. So for the camera project I decided to go with Raspbian and not sink any more time into getting Kali to work with camera hardware.

pi/raspberry

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

I connected the Pi to a router, set a fixed IP address on the boot line of cmdline.txt on the memory card's boot sector, and plugged it into my home router. I then fired up the Pi.

SSH to 192.168.0.111 confirmed I was able to remotely reach the Pi. The Pi was also able to successfully reach the gateway and the outside internet.

Installing stuff

Get busy installing stuff:

apt-get install -y screen
screen

In the new screen window:

apt-get install -y vim aptitude
apt-get install -y python build-essential
apt-get install -y python-pip

This doesn't do much - most everything here is already installed.

Now install the pi camera library (should also be already installed):

pip install picamera

Now one last thing to do before testing the camera is to enable the boot flag that lets you use the camera (disabled by default).

Run raspi-config and pick the camera menu item (number 6). Choose to enable the camera. Save changes, and you'll be asked to reboot the Pi. Reboot the Pi. Now you can try out the camera.

Testing Picamera

Open python and try to import the picamera library:

import picamera

Now try capturing your first photo:

import picamera
camera = picamera.PiCamera()
camera.capture('helloworld.jpg')

Woo hoo! Works perfect!

Problems out of nowhere

Suddenly, out of nowhere, just when I had finished rigging the wireless and the zip ties and the camera box, everything failed. The camera would no longer respond. Hardware connection problem. Tear it all apart.

Resolution of problems out of nowhere

The problems that came out of nowhere turned out to be connection problems with the flat yellow plate on the front of the camera face. I had to re-seat that plate snugly. After that, the camera worked fine.

Testing with crossover cable

Connected Pi and laptop with crossover cable, set Pi IP to 169.254.111.111, tested local ssh to Pi - PASSED

Connected Pi and laptop with crossover cable, same IP, tested capturing photo from Pi camera - PASSED

Testing with Wireless

Wireless, 192.168.0.X, test whether we can connect to the wireless - PASSED

Wireless, 192.168.0.X, test whether we can auto-MAGIC-ally connect to the wireless on boot - PASSED

Wireless, 192.168.0.X, test whether we can plug in on other side of house, SSH in, start/finish photo capture, run HTTP server - PASSED

Wireless, 192.168.0.X, test whether we can capture photos, with everything taped into position - PASSED

Wireless, 192.168.0.X, test whether we can run a time lapse test - PASSED

Final Arrangement for Timelapse 2

The final arrangement of parts for the first timelapse was hacky and definitely would not have held together more than 24 hours. Here are photos of the Pi on the balcony. I used some packing tape (should have used duct tape, but I didn't have a fresh roll) to create a "sheet". I wrapped that around the Pi, the cabling for the camera, and the balcony rail.

PiBalcony3.jpg

PiBalcony2.jpg

PiBalcony1.jpg

This whole arrangement was made super awkward by the camera cable. It was wide, inflexible, hard to twist (and had to be twisted at least once given the way it came out of the case), but the real challenge was that if it was tugged too hard, the yellow plate on the front of the camera would pop off, and the entire assembly would have to be un-taped and disassembled to push the plate back onto the board, reassembled, re-taped, etc.

PiDesk1.jpg

Scripting

Taking photos

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)

Processing photos

While the full details are over at the Timelapse/Processing page, here's a quick taste of what collating a bunch of images together looks like.

Assuming you have all the images you want in a pile in one directory, we want to rename them in order so that they have the same name as before, but with the suffix _0001,0002,0003, etc.

Successful Capture

Notes on what the successful capture looks like, and links to pages/notes on processing timelapse photos.

Notes

Timelapse 2 Notes

Running my first timelapse, I didn't bother doing any calculations to see how long I could run based on available disk space - I just ran at a frequency of 1 photo per 2 seconds and let it run all night. It maxed out the SD card after about 6 hours.

Results and notes from this script/timelapse:

  • Dislike case of Raspberry Pi 3
  • Tape job was very perilously perched after a night of sitting - need mechanical security, not just tape and balance (ZIP TIES and/or LASHING)

What to keep the same:

  • Camera worked ok
  • Mini SD card worked ok
  • Kali operating system worked ok, connected to wireless ok, hosted files ok, transferred data ok
  • Power cable situation worked ok

What to change for next timelapse:

  • More HD space
  • No red light
  • Case for Pi - loose top makes it awkward to do anything with it, forced camera angle is awkward too
  • Need a swiveling plate or platform or boom
  • Up/down angle of camera was difficult to control

For Next Design:

  • Make it reusable across other types of camera and sensor platforms
  • What other kinds of cameras might we be using
  • What other kinds of control systems
  • Generic mounting brackets, mechanical connections, on a platform would be good. Screws/bolts/etc.
  • Way of positioning platform using railing.

What to change eventually:

  • Adjustable frequency and more sophistication in script
  • Motor control of plate or device to control angles and motion
  • Image processing (vivid, contrast, hue, blur, tilt shift)

Processing timelapse photos

For notes on processing timelapse photos, see Timelapse/Processing page.

Notes on time-lapse photography in general at the Timelapse page.

Next timelapse

For planning notes for Timelapse 3, see: RaspberryPi/Timelapse3

Flags