Pages

Saturday, November 21, 2015

Ancient laptop with Puppy Linux

The burglar that "visited" our house a couple of weeks ago took our laptops and tablets. Luckily our desktops were left alone (probably to heavy). Also a very old IBM Thinkpad T40 was left behind. The burglar probably thought it didn't have any value. That was a bit of luck for me because with a little effort this 12 year old laptop is still very usable. After all these years the only thing that failed in this laptop was the battery. Everything else is still in excellent condition. These Thinkpads were (are?) very sturdy. On top of that they are very modular. Almost every component is easy accessible with just a screw driver. Very different from modern laptops that are almost impossible to open without special equipment.

The twelve years old IBM Thinkpad T40. Is it worth reviving it?
With a 1.4GHz Pentium M inside the T40 is, I suspect, hardly faster than the Raspberry Pi 2. I therefore needed an Operating System that isn't a burden for this hardware. Since Windows XP isn't an option anymore I looked at Linux and decided to give Puppy Linux 5.7 Slacko a spin.

Puppy Linux is very small and it loads into the ramdisk and is therefore very zippy , even on old machines. Installing it on the Thinkpad T40 was easy. It recognized all hardware even the wifi (which can be a problem with other distro's). Unfortunately I can't use the wifi chip inside the T40 because the WPA2 security protocol that I use in my network is unknown to this chip. This was easily solved with a wifi USB-stick.

Now I'm typing this blog from the T40. Firefox (version 17 ESR) works fine. I can access Google+, Youtube and other sites without problems although the rendering of some sites isn't perfect. With Geany I can create html/css pages and code Python. Wordprocessing is done with Abiword and spreadsheets with Gnumeric.

Do I want my laptops and tablets back? Of course but in the mean time I thank Barry Kauler and Co for this wonderful distro.

Puppy Linux Slacko 5.7 runs fine on this very old laptop.

Typing my blog on the T40 without a problem.

Wednesday, November 18, 2015

Plywood housing for the homemade security camera

In the last two weeks I have built a Raspberry Pi security camera. For the time being I used a crude housing made out of MDF. This was ok for testing purposes but now I wanted something more permanent. Something that I could attach to my window frame and that is able to pan and tilt to get the best angle at my backyard. I could buy of camera housing such as the ModMyPi Nwazet Pi Camera or buy a dummy camera and build the security camera in it. However building it myself would be more fun. I decided on a housing made out of plywood since it is cheap, strong and durable.

The Raspberry Pi security camera keeping an eye on my backyard.

The housing is rectangular box that nevertheless looks like a camera due to the round placeholder of the camera. I used 1/2 inch thick plywood for the body of the housing and 1/4 inch thick plywood for the lid and bottom plate. The camera module is placed between two pieces of plywood, that keep it in place. The two pieces are tight together with two machine screws. I used spacers to prevent the module from being squeezed when tightening the machine screws.

Housing of the security camera
The front of the housing lifted showing the Raspbery Pi B mounted on the 1/4 inch plywood bottom.  
The camera module is easily removed from the front.

I left an opening in the camera housing to have easy access to the micro-USB connector and the SD-card.
the Raspberry Pi camera module between two pieces of 1/4 inch plywood kept together with two machine screws.
The camera housing is connected to a plywood frame that enables me to pan and tilt it. The frame is also made out of 1/2 inch thick plywood. The three pieces are glued together and two 1/4 inch machine screws (one on the top of the housing and one on the bottom) connect the frame with the housing. Two wing nuts are used to tighten the camera enabling the camera to pan. The frame is connected to the wall with cylindrical piece of wood (from a broom stick). Two pieces of plywood at the end of this pieces of wood enable the camera to tilt (see image below).

The finished security camera. The mount will be fitted to our window frame. The camera can be panned and tilted to get the best view of my backyard.

With the housing and mount complete my Raspberry Pi security camera is finished. Motion has been very stable on the Pi. I haven't had a crash or malfunction in three weeks. And thanks to crontab the camera doesn't need a lot of maintenance. Is there something left to be desired? Yes. The camera is not usable at night (I need the NoIr camera and IR lights for that) and I have false positives e.g. when it rains (the raindrops on the window are causing this) other than that I'm pleased with the result.

Friday, November 13, 2015

Raspberry Pi security camera, first experience

Introduction

(EDIT: updated on 4 May 2018). Last week I wrote about the Raspberry Pi, the camera module and Motion acting as a security camera. I've been testing my Raspberry Pi security camera for a week now and the results are satisfying although there are also some problems. I think much of the success of the camera comes down to finding the best settings of the /etc/motion.conf file of Motion for a given scenario. The motion.conf file enables you to setup the Motion program. Everything from camera settings to motion detection can be changed in this file.

Image from a motion video. If someone (in this case my son) is entering our backyard it is perfectly recorded by Motion.

Threshold

I want my security camera to record anyone entering my backyard but this sounds easier than it is. If the threshold parameter in motion.conf is too low all kinds of events are recorded that are completely irrelevant. E.g. on a rainy day raindrops falling on the window are recorded. With higher threshold values I might miss something relevant. After experimenting with different values of the threshold I found that a value of 1500 works best in my case.

Lens flare

On a sunny day bright sunlight can fall onto the camera lens causing lens flare. This reduced contrast and color saturation (see image below). More importantly the Motion program detect changes in lens flare as motion and records them. I think problem can easily be solved with some kind of lens hood.

Lens flare caused by sunlight reducing contrast and color saturation.

Night

A whole different problem is motion detection at night. My camera, the regular Raspberry Pi camera module, is just not up to this task. For detection at night I'll need the NoIR Pi camera. This camera has no infrared filter. As a consequence colours at daylight look odd but you're able to record at night, but only with infrared light illuminating the subjects. Several add-on boards for the NoIR Pi camera are on the market that do just that. These boards fit right over the camera module.

The regular Raspberry Pi camera module is useless at night.

Proper file permissions

I created a directory /home/pi/Camera on the Raspberry Pi. I want all my video files to be stored in this place however before Motion is able to do this I had to change the permissions. Motion (the program) creates it's own user motion so this user needs proper permission in the home/pi/Camera folder (that is created by the user pi). To do this I first changed the group ownership of the folder:
chgrp motion /home/pi/Camera
And next give the group the proper permission:
chmod g+rwx /home/pi/Camera 

Scheduled tasks

The number of motion video's that are stored on the Pi increase rapidly over the days. My backyard is quiet but not that quiet (not to mention the false positive that I described above). Since the Raspberry Pi stores the files on an SD card I will easily run out of storage space. So I need a method to remove the files automatically e.g after five days. Cron is perfect for this since it let me schedule commands or scripts periodically. I wrote a shell script that removes avi files created by Motion older than five days and added this to my crontab file to be executed daily. The key command in this script is:
find /home/pi/Camera -mtime +5 -name "*.avi" -exec rm {} \;
This shell script is then added to the crontab. With crontab -e the crontab file can be edited. If you're looking for a good article on Cron and how to create a scheduled task look here.

Copying files to a PC

Whenever I want to check the motion files (e.g after one day) I copy them to my iMac using scp from the OSX terminal and then created a playlist in VLC by dragging all the files into it. The harvest of that one day is then displayed.
scp pi@192.168.178.27:Camera/*.avi to/destination/folder

What's next

Next I'll test the security camera further until I'm satisfied with the settings and build a proper housing for the camera. Possibly I will switch from the regular camera module to the NoIR camera.

Saturday, November 7, 2015

Homemade security camera with a Raspberry Pi

Introduction

(EDIT: updated on 4 May 2018) One week ago we've had a burglar in our house. Of course I immediately started improving the security of our home. After improving the usual stuff I felt the need for some kind of security camera. This camera could provide me a good view of the backyard which is a very quiet place and therefore preferred by burglars. Because I like to make things myself I thought it was a good idea to use a Raspberry Pi and it's camera module. I used them in the past for time lapse video's of scenery but I hadn't used it much lately.

The goal that I had set was a camera that detects and records motion and that I could access through our local network preferably a browser. I also wanted the camera to give decent images by day and night.


Hardware.

The heart of the system is a Raspberry Pi model B with the Raspberry camera module (5MP). Furthermore I use an Edimax dongle for my WiFi connection and a micro-USB power supply (1A). Initially I use an MDF case that I made to fit the camera and the Pi. It isn't pretty but it protects both the camera and the Pi. If everything works as planned I probably built it into a dummy camera such as this one or may make a wooden enclosure myself.

Initially I had some problems connecting to the Pi through SSH. I discovered that this was caused by the Edimax dongle (8192cu WiFi chip) that apparently goes into sleep mode after a period of inactivity. This was solved with a command line fix that disables power saving (see here on page 17 how to fix this).

Raspberry Pi B and camera module in an MDF enclosure.

Software

On top of Raspbian (I installed Wheezy with Desktop but nowadays I'd suggest using Stretch Lite) I installed Motion. Motion is a Linux program that monitors the video signal from camera's and, very important to me, is able to detect motion. Motion is widely used and there is plenty of good information on it on the internet. A simple tutorial how to install Motion specifically on the Raspberry Pi and get it to work with the Raspberry camera module can be found on here (go to step 7 for software installation). However Motion has far more possibilities and it is worthwhile to explore these once you start using it.

Configuring and testing the system

Motion can support multiple camera's but I'll stick to one camera for now. Configuration of Motion for the Raspberry Pi and it's camera module is done in the /etc/motion.conf file (not in the /etc/motion/motion.conf file). There is a very good YouTube tutorial on configuring Motion for Linux here and here. At this point I made only a few changes to the motion.conf file such as camera width and height, directory where the video is stored on the Pi and some camera specific variables.

The camera works great. The image quality is good and the system appears to be stable. I can open a stream of the security camera in my browser by entering the URL of the Raspberry Pi and the selected port (default 8081). My motion files are stored as avi's on the Raspberry Pi. I can play them with VLC media player on my iMac. Next I'll experiment with the settings of Motion (e.g. sensitivity of motion detection, resolution of the camera), test in under different circumstances (indoor, outdoor, night and day) and build a proper housing for the security camera.

It doesn't look pretty but the security camera works great.