Raspberry Pi Camera – Basic Motion Detection

Here’s a very basic method for implementing motion detection using a Raspberry Pi and camera.

This script works by taking an image and comparing it to the last significant image taken – if the images differ by 10% (this can be configured to suit your environment), the new image will be saved.

The idea here is that images are only stored when a significant change has been detected. The image comparison algorithm has been taken from Rosetta Code.

Continue reading “Raspberry Pi Camera – Basic Motion Detection”

Raspberry Pi Camera Live Streaming

I recently bought a Camera Module for the Raspberry Pi. One of the main reasons for getting one was to see if I could set up a live stream from the camera that would be accessible from a web browser or mobile device – partly because it seemed like an interesting project, and partly so I can keep an eye on our dog while I’m away from the house.

It turned out that this was very achievable, but it does require quite a bit of configuration to get things working. I thought I’d document my process here, in the hope that my experiences might help anyone else trying to get a live stream up and running from their Raspberry Pi.

I’m using the following software to enable the live stream:

  • Raspbian
  • FFmpeg
  • libx264
  • nginx with rtmp
  • Safari (OS X or iOS)

Assuming that you have a Raspbian installation up & running, I’ll run through the configuration of the other items below.

Continue reading “Raspberry Pi Camera Live Streaming”

Tweeting Raspberry Pi info – part 2

I’ve made some small changes to the startup script published here:

  • Moved all of the configuration variables to the top of the script.
  • Added the interfaces variable to configure with network interfaces should be checked for and included in the Tweet. By default, eth0 and wlan0 are defined, but you can change these as required.
  • If an interface is not found, the function will return an error message rather than failing on the exception.

The updated version is available from the GitHub repository.

Tweeting Raspberry Pi Info at Startup

I’ve spent a bit of time over the last few months setting up my Raspberry Pi collection. I now have 3 devices running between my home and my office with a variety of services, including Internet Radio streaming, XBMC, file shares, web and chat servers, and so on.

Two of these Raspberry’s are running full-time without a monitor, which sometimes causes a problem – what happens when the IP address changes? Without a monitor attached, it can be difficult figuring out what the IP address of the Raspberry is. Obviously I can have a static IP address on my home network, but the work network is a different story (without going to a lot more trouble, anyway).

So, here’s a small Python script that runs when the Raspberry starts up, and sends me a direct message over Twitter with the Raspberry’s current hostname, and the IP addresses for eth0 and wlan0.

twitter
An example of a direct message generated when the Raspberry Pi boots.

The script uses Python and the Tweepy library for accessing the Twitter API. I’ve also used the get_ip_address() as published here.

Installation & Usage

You  can get the current version of the script from GitHub. Before using the script, you will need to make a few changes.

First, you will need a separate Twitter account for the Raspberry script to use. Once created, follow these instructions to install Tweepy and generate the secret keys you will need for the Twitter API.

Update startup.py and populate the CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY and ACCESS_SECRET with the values that have been generated for your account. You will also need to set the to_user value to be your Twitter @username. Once you’ve entered these values, you can run the script. This should send you a Twitter DM similar to the one pictured above.

Running the script at startup

The exact details may vary depending on which distribution you use – in my case, I’m using Raspbian – to run this script at startup, simply add the following line to your /etc/rc.local file:

#Send Startup Tweet
/path/to/startup.py

Also make sure to chmod 755 the script to ensure it is executable. Now, each time the Raspberry boots up, it will DM you with the hostname and IP address information.