Picammory Mark II
The Garden's Camera based on Raspberry Pi (with motion detection)
This project builds a waterproof high definition camera.
- Takes hourly full definition picture of the garden
- To create high speed movies of the garden over the years.
- See changes in the garden following different watering setting.
- Detects and records garden's intrusion within a noisy environment (trees, leaves, wind, sun, ...)
- Squirrel observation
Picammera includes the following capabilities:
- Capture one full size image every hour
- Mix of Python3 and C code for fast image processing
- Image capture: 100ms
- Image processing: 26ms
- Advanced motion detection algorithms for 5 stages:
- Moving Average of previous image (with low memory usage)
- Difference between moving average and current image
- Moving Average Mask to automatically remove noisy pixels
- Surface detection to convert adjacent pixels to surface (with very efficient algorithm)
- Surface processing to detect motion
- Continuous HD video recording in memory
- Save about 10s of video before the trigger event
- Upload movies on FTP server
- Automatic start at boot, and restart after a crash (restartd)
- Automatic conversion of h264 movies to mp4 for easy viewing on Mac/PC
- Bonjour to advertise services
- ASP for easy file sharing with Mac
An overview of the process to build the camera
The camera body is composed of aluminum body with good waterproofing and an excellent 2 axes orientation system.
The inside is very roomy. A platform on rail can be used to secure the circuit board.
The Raspberry Pi and all future components are placed on a platform (Styrene Sheets 0.080" tick), this way it is easy to insert and remove the Pi from the camera.
From a 12"x12" styrene sheet, we cut a band of 3.5" (90mm) large.
We bend the extremity of the sheet to a 90º angle. This will constitute the front that covers the cameras' body window. The bending is easily done by warming the styrene with a heat tool (like the Portasol 75-Watt Heat Tool)
A square hole is drilled in the middle of the component platform to handle the camera. We used a Dremel rotary tool with a 194 high Speed Cutter to create the preliminary square shaped hole. The square is then adjusted with a precision blade (like the X-ACTO Blade).
The Raspeberry is centered on the platform, with a distance, "comfortable" for the camera cable. We drill 4 holes with a No 43 drill, and create a female screw thread with a tap 4-40 NC.
Note: To avoid misplaced holes we test Raspberry Pi fitting after each drilling .
Screw the 4 Hex Standoff (Nylon, #4-40, 1/4" lenght).
Put the Raspberry on the standoff, and secure with 4 screw. Check if everything fits.
We need to cut the small part of the standoff screws that comes out of the styrene sheet, or it will prevent the styrene sheet later to touch the camera platform). Note: Another posibility to avoid cutting the standoff is to invert the order of creating the Raspberry attach and the camera platform, then drill the hole for the standoff through both platforms.
The Raspberry is set. We can now remove it and put it in a safe place until the final integration.
Camera platform on rail
The component platform is fixed on the top of the camera platform. The existing 8 holes cannot be used easily, they are in direct contact with the camera rail, no space for nut or screw head. It is probably possible to create a female screw thread in the existing platform hole, but because a "lot" of forces is needed to unclip the camera platform from the rail, we prefer to add some nuts here.
The camera platform is placed under the component platform, centred in width, but aligned to the extremity of the platform to limit traction on the component platform when unclipped from the camera.
The idea is to drill 6 holes. create a female thread plus 4 nuts at the extremity.
Usually it is not a good idea to assemble multiple pieces with female screw thread, difficult to make it right and tight all layers together. Both platforms should have holes without threads and nuts at the end to tight everything. But here plastic is malleable, and we expect to tap all the pieces at the same time, so it should be fine, and we get a better coupling by having more threads.
We using a drill No 43 and tap 4-40NC.
First drill the hole on the left side (border), then tap, and put bold and screw to maintain in position. Same for the opposite side in diagonal hole. Now we have all pieces tighten together, we can safely drill the 4 other holes.
The 6 screws in place on the component side.
Note: the screw heads are way lower than the Raspberry Pi on standoff.
The 6 screw with the 4 nuts on the rail side.
Waterproof Ethernet connector
The first version of the camera was weak on waterproofing at the external camera network connection. The second version use a Waterproof RJ45 Coupler
The existing hole in the camera body is 18.9mm and the coupler 25mm. We need a bigger hole. The camera box is constituted of aluminum 1.2mm. A Dremel rotary tool with a 194 high Speed Cutter can easily fix that.
The camera rail prevents a symmetrical expansion of the hole, the RJ45 couple will not fit. The hole needs to be shifted.
Before to remove some metal, let's draw carefully the part to remove. Here in black the part to remove, and red the extreme limit to not pass.
The big hole is finished.
The RJ45 coupler is designed to joint 2 ethernet cables, and assure the waterproofing on both sides. Because one side will be inside of already waterproof camera box, we can safely remove one side waterproofing.
We get an external camera network connector through a nice female to female RJ45 coupler, with the external side waterproof, and a low profile inside.
Power Over Ethernet (POE)
Power Over Ethernet (POE) and Passive POE
10Baes-T and 100Base-T needes only 4 wires, the others 4 wires are not used.
The passive PoE Injector uses the 4 remaining wire to provide power, grouping them by 2:
The Raspberry Pi needs 5V, but 5V cannot be transported over a long distance (voltage drop). Usually 24V or 48V is used.
Since the camera is not very far and we have CAT6 with 23 AWG wire, we opt for 12V DC. The DC/DC converter in the camera takes between 5 to 23v input to output 5V.
Passive PoE Injector
On the router side, we connect the “Passive PoE Injector/Splitter DC Connector” between the router and the network cable going to the camera. Connect a 12V DC power supply to the DC connector.
Passive PoE Splitter
The same cable can be used to extract the power, but the splitter is bulky, does not provide the micro USB connector the Raspberry Pi needs. This solution is too complex and bulky for the camera side.
Instead we can create a compact custom splitter.
We start with a 1 foot ethernet cable, we remove a band of the external sheath near one extremity.
Take the DC/DC Converter, Put a small Heat Shrink tubing on each power cable, and a bigger one on both. Solder the Blue with the DC/DC Converter Red . Solder the Brown with the DC/DC Converter Black .
Cover both power wires with the tubing and shrink them. Then the same for the bigger tubing over the two power wires. Small tubings are also put on the 4 remaining cut wires.
Finally, put a big tubing to cover all exposed wires.
On the other side of the DC/DC Converter, cut the provided connector to replace it with a micro USB connector.
Solder the red and black wires on the pin 1 and 5.
Note: the pin 1, 3, and 5 are really near of each other, to avoid soldering the pin 3, just cut it from the micro USB connector.
Add some glue (from a glue gun) on the micro USB pin and put on top a Heat Shrink tubing.
The final cable is compact and simple.
The ethernet cable in place.
Note: We initially just put the DC/DC converter under the component platform, later on we use a cable tie to attach the converter to the ethernet cable.
We finally use our little square hole to insert the camera
Note: Compare to the first version, the space between the sensor and raspberry pi permits to place the camera in the standard orientation.
Very simple and clean implementation, with a lot of space for future expansion.
Note: we removed the RGB LED and temperature sensor from the first version, they was not very useful.
Parts and Cost
|CPU||Raspberry Pi Model B+||1||$28.48||Amazon|
|Sensor||Raspberry PI 5MP Camera Board Module||1||$25.00||Newark|
|Camera Body||Outdoor Weatherproof Heavy Duty Aluminum CCTV Security Surveillance Camera Housing Mount Enclosure M57||1||$24.99||Amazon|
|Ethernet||AEAC Waterproof RJ45 Coupler, Female to Female Interface diameter 25mm||1||$14.99||Amazon|
|Power Supply||DC 12V 2A||1||$13.00|
|SD Card||Transcend 16 GB||1||$7.85||Amazon|
|DC/DC Converter||UBEC Input: 5-23v Output:5V 3a||1||$4.76||Amazon|
|Power part||Huacam HCP05 Passive PoE Injector/Splitter DC Connector||2 for $6.89||1||$3.45||Amazon|
|Board||Styrene Sheets - White - 12x12 0.08 Thick||4 for $10.99||1||$2.75||Amazon|
|Ethernet||Cat6 Ethernet Patch Cable 1 Foot||5 for $9.99||1||$2.00||Amazon|
|Screw||Nylon 6/6 Machine Screw, Plain Finish, Off-White, Pan Head, Slotted Drive, 1/4" Length, Fully Threaded, #4-40 Threads||100 for $5.13||10||$0.51||Amazon|
|Screw||Hex Standoff, Nylon, Male-Female, UNC Threads, Right Handed, Off-White, #4-40 Screw Size, 1/4" Length||100 for $10.98||4||$0.44||Amazon|
|USB connector||Micro USB Type A Male 5 Pin Connectors Jack||10 for $3.90||1||$0.39||Amazon|
|Screw||Nylon 6/6 Small Pattern Machine Screw Hex Nut, Off-White, #4-40 Thread Size, 1/4" Width Across Flats, 7/64" Thick||100 for $5.63||4||$0.23||Amazon|
|Heat Shrink tubing||1||$0.10|
Software Installation and Setup
A step by step installation
Setting Up the Raspberry Pi
To download and install Raspbian, follow the procedure from http://www.raspberrypi.org/downloads.
Note: at the writing, we used the Raw Images Raspbian, Release Date 2015-02-16
After putting the micro SD card in a USB reader, we run from the terminal something like:
diskutil list diskutil unmountDisk /dev/<disk# from diskutil> sudo dd if=path_of_your_image.img of=/dev/<disk# from diskutil> bs=1m
<!> Warning: giving a wrong device for '/dev/<disk# from diskutil>' can damage your computer, be extremely careful with 'dd' command.
Wait a LONG time!
Insert now the micro SD card in the Raspberry Pi.
Raspbian Initial Settings
Connect to the new Raspberry Pi computer, and start the initial configuration:
$ ssh pi@<ip address> password: raspberry $ sudo raspi-config
Modify the following item:
1 Expand Filesystem
2 Change User Password
4 Internationalisation Options
- I1 Change Locale (to adapt to your own locale)
- Remove en_GB.UTF-8 UTF-8
- Add en_US.UTF-8 UTF-8
- select ok
- Set default to "en_US.UTF-8"
- I2 Change Timezone (to adapt to your own timezone)
- Pacific Ocean
- I1 Change Locale (to adapt to your own locale)
5 Enable Camera
only step 5 is required. 1 and 2 are strongly suggested.
If raspi-config does not offert you to reboot, them manually reboot with:
$ sudo shutdown -r now
After rebooting, check if time and timezone are correct:
$ sudo apt-get update $ sudo apt-get upgrade $ sudo rpi-update
A reboot is needed to activate the new firmware
Install Netatalk & Bonjour
Netatalk is a freely-available Open Source AFP fileserver. With Netatalk, PiCammory is visible in MAC OS X Finder (thanks to Bonjour), you can copy file with Finder (AFP). Publish the existence of SSH is just to looks nice.
$ sudo apt-get install netatalk
Register ASP (File sharing with Mac)
$ sudo nano /etc/avahi/services/afpd.service <?xml version="1.0" standalone='no'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_afpovertcp._tcp</type> <port>548</port> </service> </service-group>
Register SSH (Remote Shell)
$ sudo nano /etc/avahi/services/ssh.service <?xml version="1.0" standalone='no'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_ssh._tcp</type> <port>22</port> </service> </service-group>
Restart the Avahi mDNS daemon:
$ sudo /etc/init.d/avahi-daemon restart
Now the Raspberry should be visible in the Finder (computer PiCammoryGarden), use your 'pi' account to connect.
Optionally you can install some tools to test Bonjour.
Browse for mDNS/DNS-SD services using the Avahi daemon
$ sudo apt-get install avahi-utils $ avahi-browse -a | grep PiCammoryGarden + eth0 IPv4 PiCammoryGarden Remote Disk Management local + eth0 IPv4 PiCammoryGarden SSH Remote Terminal local + eth0 IPv4 PiCammoryGarden Apple File Sharing local + eth0 IPv4 PiCammoryGarden [xx:xx:xx:xx:xx:xx] Workstation local
This package provides a pure Python interface to the Raspberry Pi camera module for Python 3.2 (or above).
$ sudo apt-get install python3-picamera
Install Python3 PIL
Python Imaging Library
$ sudo apt-get install python3-pip
$ sudo pip-3.2 install Pillow
Multimedia Framework for MPEG-4, VRML, X3D, SVG, LASeR ... http://gpac.wp.mines-telecom.fr
$ sudo apt-get install gpac
Download Picammory sources
for the last released version:
$ git clone https://github.com/pmermoz/picammory.git ~/picammory
or, for the current development version:
$ git clone https://github.com/pmermoz/picammory.git -b develop ~/picammory
Build the C source code
Note: This step is optional, Picammory will rebuild the C code at startup.
$ cd ~/picammory; python3 setup.py build_ext --inplace; cd ..
Create the log files folder
$ sudo mkdir /var/log/picammory $ sudo chown pi /var/log/picammory
Edit the configuration file
$ cp ~/picammory/picammory.ini_template ~/picammory/picammory.ini $ nano ~/picammory/picammory.ini
Modify the following entries:
| name | Name for your camera, this name is used to prefix filenames generated by the camera.
[smtp] | | Picammory send mail to inform of system status and detection events. |username|User name for your email account |password|Password for your email account |usetls|YES to use encrypted communication with the email server |server|Mail server Address and port (like 'smtp.mailserver.com:587') [email] || |recipient|Email address (or list of) for the recipient of alert |sender|Email address to identify this program (like 'GardenCam <email@example.com>') [ftp] || Picammory upload videos and pictures to an FTP server |username|FTP user name |password|FTP password |server|FTP server Address
Install the Automatic start at boot
Copy the boot script for automatic start at boot time:
$ sudo cp ~/picammory/etc/init.d/picammory /etc/init.d/
Make The Startup Script Executable
$ sudo chmod 755 /etc/init.d/picammory
Make The Script Run at Startup
$ sudo update-rc.d picammory defaults
Install the Automatic restart
Restartd is a daemon for checking running processes. It execute a script or a program if the process is not running anymore.
Note: Restartd can take up to 20s to restart a dead process.
$ sudo apt-get install restartd $ sudo nano /etc/restartd.conf picammory ".*picammorydaemon.py*" "service picammory restart"
Reboot the system
$ sudo shutdown -r now
Motion detection Algorithm