anicam

Concept


The idea for this  current version is to condense down the functions from the previous versions in to a single board that fits on top of the raspberry pi zero W.

I also wanted to reduce the cost and complexity of the previous versions to increase the reliability and make it easier to use.

 

Hardware


Board

The main board sits between the various components and the pi, and is populated with jst connectors to make fitting it all together easier.

I’ve been running a version of this board that I built with the excellent  protozero board : https://www.modmypi.com/raspberry-pi/prototyping-and-breakout-boards/prototyping-boards-1027/protozero-prototyping-board-for-pi-zero and thought I’d have a go at putting together a circuit diagram on fritzing.

A few clicks later I had the first version of the board ordered from aisler.net – this was a bit of a mess, mainly as I managed to use an odd relay template but after a bit of tinkering I had this version printed.

 

Circuit diagram (click to enlarge):

 

I.C.

The heart of the board is a L293D IC. I chose this as it can reverse the polarity of a signal which is necessary to control the IR filter over the camera lens. Further information here: http://garysshed.co.uk/wp/?p=664

Relay

The L293D has 2 channels and I have used the second channel to control the relay. This is handy as it allows the GPIO pins to control a 5v relay with minimum effort or additional components (just a diode to prevent feedback) and provides an element of protection to the pi.

5v relays are easy to get hold of and cheap, and the minimal components mean that I can include the relay on the main board and not have to rely on per built boards.

Light

The light is a 5v, 10W Infrared IR 840-850nm SMD LED unit.  It draws about 2A current so I’ve connected it to the USB battery supply via the relay to enable it to be switched.

Previously I’ve used a ring of LED’s but this brighter and doesn’t require a 12v supply so the whole assembly is smaller.

It gets very hot, so it may get an upgrade with a heat sink in the future.

Infra Red filter

This filter is designed for use with security cameras and consists of a small plastic element that is pulled in front of the camera lens to prevent infra red light getting through.

When it is deployed it gives a more natural colouration however when it is removed it picks the light reflected by the infra red lamp giving better vision in the dark.

It works by sending a 5v signal for a fraction of a second to the actuator – one way it moves in front of the lens and the other retracts it.

The polarity of the signal is handled by the L293D chip with the following outcomes:

Filter off
Chip pin Pi pin Signal
1A 16 LOW
1B 13 HIGH
1E 7 HIGH
Filter on
Chip pin Pi pin Signal
1A 16 HIGH
1B 13 LOW
1E 7 HIGH
Filter stop
Chip pin Pi pin Signal
1E 7 LOW

Buttons

The buttons are simple and cheap ones from mod-my-pi https://www.modmypi.com/raspberry-pi/sensors-1061/buttons-and-switches-1098/12mm-domed-push-button-6-pack/?search=buttons but they’re decent quality and a normally open (push to make) type. They are current limited with a 220? resistor and the pin is pulled down to negative on the board so it is simple to put any button or even an LDR or similar with a jst soldered to it.

There’s no protection on these and I managed to fry my old test pi by plugging in the 5v supply to the light on the first board (stupid mistake, but it had a broken camera connector anyway).

PIR sensor

I’ve used an inexpensive HC-SR501 PIR (passive infra red) detector  datasheet

5v is supplied to the module and when it detects movement, it sends a 3v signal through the yellow wire which is detected by the pi on pin 15

There are adjustments on the sensor for trigger time, sensitivity etc which can be altered however it is set up in a configuration that seems to work.

Software


Pikrellcam

http://billw2.github.io/pikrellcam/pikrellcam.html

Once again this does all of the heavy work to include the actual motion detection and video conversion. I’ve used the in built ability to add on a button to the main web interface that links to my own webpage which alters button size etc so  it’s a bit easier for kids with touchscreen devices to use.

  1. Status
  2. Current date & time
  3. Main screen
  4. Buttons

 

Detect

A program called “detect” is running which is started via cron at boot. This program is a loop that performs the following actions:

  • Waits for a trigger from the PIR then turns on the light;
  • Reads the pikrellcam pipe to see if the light or filter buttons have been pressed on the web page
  • Reads the 2 x buttons and performs the shutdown / restart wifi commands

Link to code:  HERE

Results


General

I’ve not been able to give it a proper test with animals yet -I don’t have any secure outside space to use it anymore and when I’ve put it out in other gardens nothing has been about at night (as its a bit cold). It works well in low light with early risers and curious children so performs as well as the previous version in terms of triggering.

PCB

  • fritzing is really easy to use and handy for drawing up the circuit diagram.
  • It’s simple to turn the diagram in to a pcb, but you need to be careful with component choice to make sure they are easy / cheap to get.
  • Aisler are quick and  cheap  – 3 identical boards cost approx £20 which is less than buying the prototype boards. It’s also fun to get Emails from Felix keeping you updated on progress.

Lamp

  • The lamp gets REALLY hot! Not so bad when it is on sporadically outside but running for long periods wil require a heat sink.
  • The top line of emitters failed on my first lamp during testing. This could be down to getting hot, defective lamp or mishandling (it was messed about with a lot).
  • the lamp is an 840-850nm version which works well with the pi camera. I’ve since bought 3 x smaller (3W) ones at 740nm, 850nm & 940nm to test out which is best.

Power

I’ve used an easyacc 10400mAh power supply – link which works fantastically in normal operation, giving a good 10 to 12 hours of power for both the pizero and lamp.
It’s got 2 connections – 1A & 2.1A with the lamp requiring all of the 2amp supply to function correctly.
The only issue with the power supply is its size. It’s pretty small for its output however it is now the largest component in the whole setup, so it dictates the overall box required.

Internal access

There is nothing more irritating than the insides of the camera flapping about and disconnecting so I’ve screwed everything down in this version. All worked beautifully until I needed to get to the sd card and had to unscrew and disconnect the board so I’ve bought an SD card extender which should do the trick.

The battery is now easily accessible via a flap in the bottom of the birdbox and the connections, while fiddly to put in, are nice and stable.

Pictures


Old version

The is the original version with the ring of IR LED’s and the main control board with separate ones for the relay and the filter control. Not shown are the 9v battery to power the light (supposed to be 12v but needed the space!),2 buttons  and the main powerpack.

New version

The is the new version with the pi zero attached to the back and all of the elements connected. The usb plug goes to the 2.1A output from the battery with the pi powered by the 1A output (lead not shown). It is a considerable saving in space & complexity over the old version with fewer areas to break.

Comparision

This picture shows the evolution of the camera board:

  1. simple version for pi V1 to break out the gpio pins. Very bulky and needed the wires kept falling off of the pins.
  2. this version is again for the pi V1 but introduced a couple of buttons on the board
  3. the final pi V1 board with pins that allowed the various elements (relays, buttons etc) to be positioned in more convenient places.
  4. Explorer phat version that I just couldn’t get to work well enough. It was excellent for the filter switching but the relay control needed a bit more oomph (or a better programmer!)
  5. The populated and working previous version.
  6. prototype of the new board constructed on an excellent protozero board. Loads of messy wires and my crummy soldering underneath so plenty of points of failure.
  7. PCB version 1 – i managed to mess up the relay type and didn’t want to use expensive ones so moved on to the current version.
  8. Current version, populated and unpopulated.
  9. Current version fully connected.

Housing

Group shot of the cameras, from left to right:

  • Handheld version – as described on previous posts.
  • The current trailam. The lamp is in the top and camera below., the pir is now fitted under the camera (not shown in this pic) and the buttons are inside.
    Stupidly I ended up putting the smallest version of the trailcam in the biggest box I had! In reality it could easily fit in the smallest box with space to spare.
  • normal colour trailcam. This is just pikrellcam and an old camera and pi model A used in daylight.
  • old version – this has got the big light around the camera and the PIR in the little window. The button is cunningly positioned behind the door.

Code


Custom index page

The Anicam is controlled with a custom php page that uses the feed from pikrelcam.

 

<?php
//ini_set('display_errors',1);
//ini_set('display_startup_errors',1);
//error_reporting(-1);

require_once(dirname(__FILE__) . '/config.php');
include_once(dirname(__FILE__) . '/config-user.php');
include_once(dirname(__FILE__) . '/config-defaults.php');

function time_lapse_period()
{
$tl_status = "../../.pikrellcam/timelapse.status";
$f = fopen($tl_status, 'r');
$tl_period = 1;
if ($f)
{
$input = fgets($f);
$input = fgets($f);
sscanf($input, "%d", $tl_period);
fclose($f);
}
return $tl_period;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo TITLE_STRING; ?></title>

<script src="js-css/jquery.min.js"></script>
<link rel="stylesheet" href="js-css/pikrellcam.css" />
<script src="js-css/pikrellcam.js"></script>
<script src="js-css/expandable-panels.js"></script>
<link rel="stylesheet" href="js-css/expandable-panels.css" />
</head>

<?php
if (isset($_GET["hide_audio"]))
{
$show_audio_controls = "no";
config_user_save();
}
if (isset($_GET["show_audio"]))
{
$show_audio_controls = "yes";
config_user_save();
}

echo "<body background=\"$background_image\" onload=\"mjpeg_start();\">";
echo "<div class=\"text-center\">";
echo "<div class='text-shadow-large'>";
echo TITLE_STRING;
echo "</div></div>";
echo "<div class=\"text-center\" style=\"color: $default_text_color; font-size: 1.4em;\">";
echo "<img id=\"mjpeg_image\"
alt=\"No preview jpeg. Is pikrellcam running? Click: System->Start\"
style=\"border:4px groove silver;\"
onclick=\"image_expand_toggle();\"
></div>";

echo "<div class=\"text-center top-margin\">";

?>

<input type="image" src="images/bigstop.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="fifo_command('record off')"
>
<input type="image" src="images/bigpause.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="fifo_command('pause')"
>
<input type="image" src="images/bigrecord.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="fifo_command('record on')"
>
<input type="image" src="images/bigtakestill.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="fifo_command('still')"
>
<input type="image" src="images/bigmotion.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="fifo_command('motion_enable toggle')"
>
<input type="image" src="images/mainmenu.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="location.href='index.php'"
>
<br>
<input type="image" src="images/lampon.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="fifo_command('lampon')"
>
<input type="image" src="images/lampoff.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="fifo_command('lampoff')"
>
<input type="image" src="images/filteron.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="fifo_command('filteron')"
>
<input type="image" src="images/filteroff.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="fifo_command('filteroff')"
>
<input type="image" src="images/videos.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="location.href='media-archive.php?mode=media&type=videos'"
>
<input type="image" src="images/stills.png"
style="vertical-align: bottom; margin-left:9px; margin-right:0px;"
width="100" height="100"
onclick="location.href='media-archive.php?mode=media&type=stills'"
>
</div>

<div id="container" class="top-margin">


<?php
if (file_exists("custom.php"))
{
include 'custom.php';
}
?>
</div>
</body>
</html>

 

This page basically hijacks the pikrellcam pipe and sends its own information through it to the python program.

6 thoughts on “anicam”

  1. I like this, I’ve done something similar, but for a nest box rather than a trail cam at the moment – one day I’ll have time to blog it….. I particularly like what you’ve done with pikrellcam, would you be able to post your modified index.php file? I have yet to figure out how to trigger an IR cut on/off direct from the pikrelcam webpage, looks like you’ve already figured it out….
    If you can find it, can you post a link to the ir cut you’ve used? I had to dremel the mount off both of mine in order to make the pi cam fit… it takes such a long time for those things to come from china.com that it would help to know which ones work better. Mine had a narrower opening… Thanks, and keep up the good work!

    1. Hi Chris.
      I got the filter from ebay seller “inperius” a year ago, and it was described as “20/22MM Hole Distance F1.2 CS IR-CUT Dual Filter Switcher For CCTV CMOS/AHD/IPC”. They don’t seem to be selling them currently but hopefully the description will take you to an alternative with the large aperture – as you say, the tube ones with the smaller, longer mounting restrict the view.

      The IR filter works by either sending a message down the pipe to the main program or has cron running a script to turn on or off at specific times – I’ve not figured out how to get it switched by pikrelcam at dawn / dusk. I’m not too worried about it as in practice I take mine out at night and bring it back in the morning to charge it but I can see how it would be really helpful for your birdboxes.

      I’ll put together a page about the index file in a bit. It really just hijacks the pikrelcam tube so you might be able to adapt it to work with your more efficient looking flask method.

      Thanks for taking the time to comment!

      1. For the dawn/dusk bits I tried a program called ‘sun wait’ with no success, but have got the python module pyephem to work nicely:
        http://rhodesmill.org/pyephem/
        The flask thing is useful but I haven’t had time to do much more with it, I would rather have all the controls in one place with the video stream. Incorporating the video stream onto a flask website would be interesting….
        Looking forward to your index.php code 😉

        1. pyephem looks interesting – thanks!
          I’ve added the code to the bottom of the main article, beneath the pictures under a new heading “code” ->” custom index page”.
          From the pikrellcam information it looks like you’ll need to call it something beginnnig with “custom-” so that it won’t get deleted or replaced when pikrellcam is updated.
          Hopefully you’ll find something in this that will work for you 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.