This project is submitted for

Description

The landscape is vanishing around us. From the Amazon jungle to the vacant lot across the street, the natural habitat is replaced by man-made structures. Pyball ("Raspberry Pi Eyeball") is a tool for keeping track of what's happening to the world around us. Recording the changing environment in time-lapse form lets you play back what happen, making it easy for people to understand how your environment is changing right out from under you.

The current Pyball hardware is off-the-shelf from Adafruit. A Ras-Pi 2, Ras-Pi camera, power supply, WiFi dongle, & weatherproof case. The hardware is inexpensive enough (about $100 USD) that it's cost-effective to deploy.

Most of the work will eventually be in the software; scripts for time-lapse recording, uploading results, and ultimately detecting and focusing in on "interesting" events the Pyball is witness to.

Details

Hardware to buy

Almost all of the hardware for the Pyball is available off the shelf at Adafruit. Feel free to shop around though; these are generic items and you might find better prices at Amazon or one of the big-time suppliers like Mouser, Digi-Key, etc.

Here's the list:

Raspberry Pi 2 Model B

It's worth spending the extra $5-10 to get the upgraded Pi 2, Model B. It has substantially more compute horsepower, which will come into play for analyzing the images on the fly or sending video.

Raspberry Pi Camera

USB WiFi

If your mounting location has acccess to hard-wired Ethernet, this isn't necessary. If your Pyball is mounted some distance from a WiFi station, getting a WiFi adapter with a long antenna makes a substantial improvement in the connection.

5V 2A Micro-USB power supply.

You'll want the 2A version to make sure the Pi has enough juice to run the peripherals (camera & WiFi). Adafruit specs the power supplys up a bit (5.1V) to account for power loss in the cord. Not a bad idea.

Case

I used the Adafruit weatherproof case, but really, look at where you'll be mounting it. If you can see what you want from an office window, you might not need a case at all.

These are available for cheap from Amazon. You'll want at least 16G to have working space for your captured data. Even 16G is still less than $10.

All tolled, the hardware runs about USD$100.

Software Setup

The Raspberry Pi comes without any software or boot media. Installing Raspbian is just the first step of many for getting the system put together. I installed Raspbian (vs. NOOBS) because I'm not experimenting with any other OS configuration.

For the first Raspbian boot-up, plug the Pi into a screen and keyboard. You'll be presented with a dialog to install various system components. You'll want to add ssh support, for remote access, and definitely enable the camera drivers and configuration.

My router requires the hardware MAC (media access control) address for authentication. To get these, use the command:

The hex numbers give the hardware addresses; eth0 is the wired address and wlan0 is for the WiFi. Note: I learned the hard way the Rasp Pi can't easily support two network connections. If you're using WiFi, unplug the Ethernet cable, and vise-versa.

You'll need to set up new users. You should add whatever user you choose to the "sudoers" list, so the adminstrative command sudo is available:

$ sudo bash
# cat >> /etc/sudoers eyeball ALL=(ALL) NOPASSWD: ALL
^D

To make sure you're running the latest software:

$ sudo apt-get update
$ sudo apt-get upgrade

To set your time zone (important for this project):

$ sudo cp /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

(Substitute your favorite time-zone city for Los_Angeles, use ls /usr/share/zoneinfo/*/* to see the full list)

To make sure enough USB power is available to drive the Wifi, add the line

max_usb_current=1

to the file /boot/config.txt and reboot the Pi.

The camera fails if the user taking the picture isn't a member of the video group. Fix this with

$ sudo usermod -G video <username>
$ sudo usermod -G video www-data

The second line is to make sure the web server can access the video hardware. Note: May need to do the second step after installing the apache2 web server; see below.

Finally, I removed some software I had no use for (Scratch, a toy programming language & Supercollider, an audio tool):

Hardware Setup

Once you've collected the items from the shopping list (under "Components") the configuration of the hardware largely depends on where it's deployed. If you have a comfortable office or home window overlooking what you want to watch, you may be able to get away with something a simple as duct taping...

Project Logs

Rather than continue to struggle with the lousy low-light performance of the RasPi camera, I bought a purpose-built security camera, the D-Link DCS-942L (also sold as the "Cloud Camera 1200").

This camera is an Ethernet/WiFi device; although I found its WiFi reception so lousy I had to cable it to hardwired Ethernet. It gracefully supports both. This Camera has a smart web server running on it. Among other functions, it can FTP clips and stills to another computer when it detects motion in a pre-selected area of view. So I use this feature to upload captured motion clips to a PyBall, and use the PyBall as a web server to conveniently display what it's seen. The home page displays a live video feed, and the Events page displays a thumbnail collection of all of the motion-detection clips it's captured.

I have a sub-repo posted on Github with the components for this web server. It's very basic and clunky right now, but if you're proficient with Linux you should be able to get it to work.

We live in a neighborhood that's pretty quiet around Halloween, but we leave a bowl of candy out just in case. And it's always empty by the time we get home.

So, who was taking the candy?

I tried to set up a Pyball to find out. This was done in a hurry, so my hacked together image-difference algorithm was not sophisticated. It just captures two images a second apart, finds the difference of the two images, and computes the mean of the RMS of the differences. In Python, using the PIL library, this is:

In reasonable light this seemed to work OK. But when I deployed it to watch the candy bowl I ran into some unexpected problems.

The default low light performance of the RasPi camera is terrible. I think the only way to get anything useful when the light drops to a lower level is to manually control the shutter speed/ISO of the camera (run raspistill and look under "Image parameter commands").

Having a decoration full of LED lights really threw the camera for a loop. Because the cheap decoration didn't bother to rectify the power to the LEDs, they blink at 30Hz. Depending on when the shutter snapped, this seemed to wildly throw off the camera exposure, and cause a lot of false positives in my simple motion detection.

I'll be looking into more sophisticated algorithms, both for exposure control and motion detection.

So here's the one photo that sort of worked (though the contrast was massively boosted in Photoshop)

Just updated with more details about the hardware configuration. In particular, updating the WiFi adapter to a model with a longer antenna solved communications problems with the base station 80 feet away.

I wanted to get an initial Pyball up as soon as possible, to record some environmental destruction happening across the street. Meanwhile, I have another set of hardware on order (Ras-pi + camera) I can use as a test platform. Once the software is cleaned up & tested there, I'll post it on Github.