Saturday, 15 June 2019

How to make a mini bird box monitor

It's all very well having a bird box camera that you can view on a PC/ipad/etc, I wanted an unobtrusive static monitor, so I made one

My little Elf Helpers demonstrating their bird box monitor

Some prerequisites....

  1. Bird box camera live streaming to your local network that can be viewed via a web-browser on a PC / ipad / other tablet computer.
  2. In my case I use Pikrellcam software running on a Raspberry Pi-equipped bird box with raspberry pi camera module (see a recent blog post on the nest that is showing on this ).
  3. In the picture above I've used a HyperPixel 4.0 screen from Pimoroni, which is plugged into a Raspberry Pi 3 Model A+, in a case to protect it.  Pimoroni have comprehensive setup instructions.

My normal way of monitoring this box on a PC using pikrellcam looks like this...


To get a minimal interface, you need to switch the Raspberry to 'kiosk mode'.  This means that when it boots up, it loads a specific website and removes extraneous stuff from the active window such as mouse cursors, scroll bars and distracting error messages.  This is the same approach that you get in applications such as photo booths, cash dispensers etc.

I modified a method from the  https://pimylifeup.com/raspberry-pi-kiosk/ website.  There are probably other ways of achieving the same end.  I'm also assuming that you're familiar with entering commands via SSH.  Google it if you don't know how.

Brief summary...

Make a file called kiosk.sh
nano /home/pi/kiosk.sh

Install dependencies
sudo apt-get install xdotool unclutter sed

Add this to the kiosk.sh file.  Substitute 'http://xxxurlToYourWebCam' with your local URL
#!/bin/bash

xset s noblank
xset s off
xset -dpms

unclutter -idle 0.5 -root &

sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/pi/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/pi/.config/chromium/Default/Preferences

/usr/bin/chromium-browser --noerrdialogs --disable-infobars --kiosk http://xxxurlToYourWebCam  &

Interestingly if you're doing his setup over SSH, if you run sh kiosk.sh from an SSH terminal window on another machine the kiosk wont start.  Probably as the active SSH session cant find a screen.  If you run it directly on the Pi with connected keyboard it works fine

Most of the following is copied verbatim from 'how to' the link above, with a couple of changes

Run script from command line using service file
sudo nano /lib/systemd/system/kiosk.service

Add the following text to this file:
Note that using the hyperpixel, this only works if 'Type=simple' is changed to 'Type=forking' (as suggested in the commentary at the end of the above article)
[Unit]
Description=Chromium Kiosk
Wants=graphical.target
After=graphical.target

[Service]
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/pi/.Xauthority
Type=forking
ExecStart=/bin/bash /home/pi/kiosk.sh
Restart=on-abort
User=pi
Group=pi

[Install]
WantedBy=graphical.target

Enable, then start the service
sudo systemctl enable kiosk.service
sudo systemctl start kiosk.service

Check status like this
sudo systemctl status kiosk.service

There's loads more detail on https://pimylifeup.com/raspberry-pi-kiosk/ but I've just listed the modified version I did to make it work.

One more thing....

There's some sort of bug/security procedure combo affecting the chrome web browser boot up time, such that it wont load chrome browser until it generate sufficient 'Entropy' in particular when there is no keyboard connected.  Seriously.  I think this has something to do with random number generation & cryptography and reflects how 'secure' the machine is.  Or something.

Anyway, the effect is that our kiosk wont load for several minutes after boot, which is a pain especially if you need to do a quick demo.

There's a solution detailed here:
https://www.raspberrypi.org/forums/viewtopic.php?t=237069
I'm not vouching for the relative safety or what it does (use at your own risk etc...)

sudo apt-get install haveged
sudo systemctl enable haveged
sudo systemctl start haveged

After all that I have a stand-alone Pi with screen that boots directly to my bird boxes webpage :)



Saturday, 1 June 2019

Dual camera birdbox 2019 update: Mistakes, Fixes, Bodges, nesting success and same year re-nesting

The dual camera bird box build started off back in 2016, and has been live since the 2017 Spring nesting season. It was my second Raspberry Pi-based birdbox, and my first attempt to combine a Raspberry pi camera module with a USB webcam on the same Raspberry pi mini-computer.  The system has video motion-capture, day + night illumination modes, an entrance hole activity logging mechanism, and also monitors temperature (?why not)...

Nearly fledging: My favourite picture of the 2019 season

This year (2019) is its first successful nesting season, seven great tit chicks fledged a few weeks ago, with another pair currently sitting on five eggs. I've had some requests on the Twitter about his box so this is an attempt to describe some of the modifications I've made over the last few years to fix various issues, and share some of the stuff I've learned along the way.

That's a 32mm entrance hole 

The Cameras

Camera 1 (SIDE): This is a Microsoft LifeCam Cinema usb webcam.  It can only see in visible light - I used one of these in my first birdbox (side-view-box, 2016).  A motion-jpeg (mjpeg) network video stream from this webcam is picked up by a remote PC running iCatcher CCTV software.  iCatcher isn't able to include audio from this source.

Camera 2 (TOP): This is a Raspberry Pi v2 Infra-Red (IR) camera positioned above the nest space.  An IR-cut module sits between the camera and the main nesting chamber and switches it between IR (night/dark) and visible light sensitivity (day/lit) .  A motion capture application called pikrellcam uses this camera, with the videos saved directly to the same networked PC mentioned above.  Camera-1 (the webcam) has a handy built-in microphone that pikrellcam cleverly uses, adding sound to the captured video from camera 2.

Camera 1 (Side) fits into height-adjustable slots.  Entrance hole is on the Left of this pic

The entrance hole has two IR beams that once broken record the event to a file.  Based on the order of breaking it's possible to work out whether the bird is coming or going.  I added a visual indicator to check this is working, the video below shows the outer then inner beams being triggered whilst I balance precariously up a ladder...


The Brain: This is a Raspberry pi model B+.  It's powered over a single cat5 network cable run of approx 150 meters using power-over ethernet (PoE),  which also connects it to my home network.

Yes, I know the wiring is a mess...
Practicalities of video review
The side camera can be reviewed directly via iCatcher console on a remote PC, or via a webpage using any network connected device.  Exporting video / screengrabs from iCatcher is a pain in the proverbials.

iCatcher Console with Camera-1 as source (USB webcam.  Visible light only.  No audio)

The top camera (Raspberry Pi cam) can be reviewed in a web browser on any network-connected device.  Exporting video / images is really easy and can be downloaded directly via a web browser.

Pikrellcam with Camera-2 as source (Raspberry Pi v2 IR camera+IR cut (day mode)_white LEDs on.  WITH Audio

Design evolution, 2017 to now (May 2019)

2017: The Bird Box went up in April.  No birds came in all year with just the occasional wasp and spider triggering video capture (pikrellcam).  The entrance hole had logged some attempts that were probably birds popping a head in, so assuming  that the hole was too small, I enlarged it from 20mm to 32mm over the Winter.  This wasn't as simple as just drilling the hole bigger as the entrance hole IR activity detector beams needed moving to accommodate a bigger hole.  The 'glass partition' between the side camera and the main nesting chamber kept getting dusty and it also created an annoying reflection of the side camera (which could essentially 'see itself'), so I replaced it for a half height plywood partition that the camera could see over, giving it an unimpeded view into the box, as well as allowing its microphone do a better job.



This box did do some useful work that season - Using a programme called ffmpeg, I used it to transcode a video feed from a separate, less-powerful Raspberry pi/usb webcam combo on a Robin nest and live-stream the result to YouTube.

2018: The enlarged entrance hole meant birds were coming in periodically, probably looking for food.  The default lighting remained on 'night mode' (just infra-red) as I thought the birds would be put off by the visible light LEDs.   I also hadn't got round to making the day-night switching happen automatically.

By April we had a pair of great tits bringing in moss.    I had the 'bright' idea of making the white leds come on when movement was detected by pikrellcam software to improve the daylight video capture... bad idea.  What I actually ended up with was a system that kept switching from night to day mode whenever a bird came in.  I think that the 'thunk' of the IR cut module switching between modes freaked them out so they nested in a neighbour's box instead.  That was the end of Spring 2018 nesting.

THIS YEAR.. 2019: A great tit pair started making visits from early March this year.  Nest building started 10 March, nine eggs laid and eight hatched on approx 17 April.  The last one fledged two weeks ago 7:50am on Sunday 5th May.  Unfortunately I missed them hatching as the PC where the videos are saved had crashed and I was away on holiday.

I also got around to fixing the day/night transition as described in this post, so lights come on at sunrise and off at dusk (switch to IR mode).

A selection of images / videos from nesting session 1

Cropped-in still image from camera 2.  Lighting aided by south-facing window on RHS of this image

Feeding False Black Widow Spider
Difficulty swallowing another false black widow spider

The next image is a screen-grab from a top camera video.  These are really easy to make using vlc media player.

An explosion of Great Tits

This is the male on the day the last chick fledged.  He's looking a bit battered

Scruffy male adult after the chicks all fledged

So... I though that was it for this season, which was timely as we were just about running out of disk space on the PC that stores the captured video.  I removed the remains of the deceased chick, and in the process broke the night illumination mode...

This one didn't make it :(
I switched from motion capture to timelapse on the last couple of days (pikrelcam makes this easy).  I converted this to a timelapse using Adobe Lightroom then converted it to a manageable size in vlc.  The dead chick above sadly passed away during this period which is evident particularly in the overnight section...



Poo-cam?
Daylight-sensitivity / video quality from the top down camera had dropped considerably over the previous year.  With no physical partition, the chicks were able to have a lovely time jumping up and down and pooing on the the side camera too.......Leaving a 'poo-obscured cam in the day, cant see anything at night' bird box.

Surprise 2nd nesting
...But 5 days later, another Great tit pair have moved in (Fri 17 May) and re-built the nest.  I've never had two back to back nests in the same box before.

And who miss, are you? this is the second female re-building the nest
So, poo-cam, poor lighting an degraded image quality will never do, so I removed the top camera section and cleaned the mess off the side camera that you can see in the picture above.

Top camera modifications... New Daylight LEDs / IR cut replacement
The Raspberry pi camera has poor low light sensitivity so I wanted to improve the lighting.  I swopped some of the existing 5mm LEDs for some LED panels from Pimoroni- I've used these in four other bird boxes I built this year see here.  They give a nice even illumination, avoiding the spotlight effect you get with 5mm LEDs.  You can see my original attempt to avoid spotlighting with the original 5mm leds by pointing them up towards a white background, but they don't really make enough light for the Raspberry Pi camera which has fairly awful low light sensitivity which isn't surprising given that its lens aperture is a couple of mm.

New LED panels on underside of top section

 I also swopped the IR cut for a new one (see this post) as the old one had fogged up.

2019 2nd nesting, updated performance...
Our five eggs have yet to hatch, the image quality is much better:

Cropped down to show detail.  I like the symmetry in this one
I'm using a python module called ephem to trigger the day to night lights-off at sunset, however she's usually tucked up 1 to 1.5 hrs before then.  Here you can see aside camera view before the upgrades (or cleaning the webcam...)

Female number two turning in for the night
The new pair has a different male
Male number 1 was looking very shabby at the end of the the last nesting session.
This clip shows make number 2 feeding female number 2 while she's incubating her five eggs, he's not scruffy, so Ithink that he's a different bird.  Can't say much about her though.


More to come... when this lot hatch


Sunday, 27 January 2019

LED backlights for birdbox illumination

All my birdboxes have Infrared (IR) and white light illumination, using 5mm LEDs.  The IR ones that I use give nice diffuse lighting, however the  white light ones tend to give a 'spotlight' effect.  I spotted these LED backlights recently from Pimoroni and once installed, they give a nice diffuse 'daylight' effect:

Underside of roof camera insert.  The circular black thing is an IR-cut module.

This year's new small bird boxes are equipped with two each.  They are wired in parallel to 5V with a 50 ohm resistor for each one, as well as another 50/100/200 ohm resistors between the ground and the uln2003 i/c transistor that is used to switch them for low/med/and blinding light levels.  Default is medium.

This picture shows the underside of the roof 'insert' for this small birdbox.  To the top and bottom are 5 IR LEDs in total.  These are wired in parallel, the only resistors are between the ground and the uln2003 (same arrangement as above there).  100 ohm seems the sweet spot.


The IR LED setting is still a bit spotty for my liking.. but I haven't found an IR led panel.... 
Last year's version of this used 4 IR LEDs, on in each corner, leaving a dim bit in the middle... which is exactly where all the action is... I fixed this this time by adding a fifth LED that points a the middle specifically.  The camera is rotated by 90 degrees to include the entrance hole in the image as well.  A 3mm green led indicator is added via one of the GPIOs (+10k ohm resistor) so that if I cant connect to it, it's obvious from the ground that there is/isn't power.



The diffuse white LED is an improvement on a previous version of this that uses 5mm white LEDs:

Nasty spotlighting in a previous version of the 2019 build, will be re-made with LED panel...

This is the business side of things:


Apart form the modifications described above, it's exactly the same setup as last season's box: Raspberry pi ZeroW (wifi), 8 MPixel v2 IR camera, IR-cut module. 5mm IR LEDs and White led panel (updated).  Illumination has high, medium and low (mood lighting) options.  Power is via 12v to 5v step-down. 

Video capture uses pikrellcam.  Video / image captures are stored locally, and can be archived off to a separate PC via wifi.  Local video storage overwrites if space drops under 20%.  This version uses the 'Lite' version of Raspian, so there is 13Gb available on the 16Gb micro SD card.  Based on last year's nesting activity that is good for approx 1 day of before a review is needed.  The prototyping board sitting on top of the Raspberry pi zero W is wired as described in this post (minus the rat-nest of wires for the LEDs...)

Sound...
I wanted to add a microphone this year, but had real trouble getting a USB microphone adaptor working without noise interference.  The semicircular thing poking out the micro USB socket is a microphone, but its a fairly poor one.  I will probably not turn it on in practice... ironically a usb webcam I had spare gave flawless audio, but there was no way to fit it in and it seemed a bit silly to use an additional webcam as a microphone anyway...