Monday, 4 November 2019

Mini HDMI cable camera for nests in awkward places

This camera setup is designed to go into small spaces where my other setups would not fit

Its basically the same setup I use in my birdboxes, with a Raspberry Pi + Raspberry Pi v2 IR camera module + IR cut + some IR LEDs, with the addition of an adaptor which allows you to turn an HDMI cable into a camera cable extension.  I used a 3 meter HDMI cable (Amazon basics) as I wanted to get the camera into an otherwise inaccessible bit of the shed where a Treecreeper had been building a nest.

The HDMI cable adapter with the camera attached has a couple of spare cables in it, so I was also able to power four IR leds and switch an IR cut via the one HDMI cable.  The IR cut is the round black thing on top of the Raspberry Pi camera board that switches it from visible to IR light sensitive modes.

If I was to do this again I would add a few white LEDs that would switch on when the IR leds were off (it's possible do the IR on/vis off and vice versa  by using the same GPIO pin with NPN and PNP transistor combined).  As-is, having the IR cut is a bit superfluous since without the IR light it's pretty dark in there, and a 'day mode' doesn't see much without any visible light illumination - one for a future post (when I've modified it!).

You can get the HDMI adaptor direct from it's French maker via Tindie, or via UK all-round supplier of shiny must-haves Pimoroni (hint it's a bit cheaper to go direct to Tindie).

Here is a screen capture of the Treecreeper nest

The camera cable is poked through a gap in the shed structure into a void space created by the corner cladding on the outside.

Here is the bird bringing nesting material in...

This gives some idea of the length of the cable

I sort of threw together the perfboard sitting on top, so don't look too hard...  I've also used a longer than normal camera ribbon cable so that it comfortably reaches the HDMI adaptor.

I've enlarged it below to give show how the Pi end of the HDMI adaptor works.

Unfortunately our Treecreeper didn't get as far as egg laying, I can only assume that she found a preferable site elsewhere.  I do wonder if the bench saw in the shed put her off.... But it does mean that I've now got a mini camera for tricky places for next year...

Saturday, 2 November 2019

Birdbox camera dashboard now with live weather data

I added a live weather widget to my grafana birdbox camera monitoring dashboard, in case I can't be bothered to look out of the window.

Dark Sky weather data 
I did an earlier post that described getting my camera feeds into this setup here.
I used info on Michael Green's blog post here as inspiration for my setup.

This is the updated version, not a lot going on apart from the wind rattling the windows...

The weather bit is in the top left corner, it pulls weather data from an online weather visualisation app called Dark Sky.  It's added via a short piece of modifiable html code into an iframe panel on the grafana dashboard that runs in a docker container on a Raspberry pi.  It was a bit of a pain to get running , so I'm going to document it in case anyone else wants to do this.
Note that the 'accelerometer' style graphs are populated by a temperature and humidity sensor in one of the bird boxes themselves.

Steps / considerations
I'm running grafana version v6.3.6 in a docker container on a Raspberry pi.  If you go to the grafana website you'll see a darksky plugin that can also be used... I didn't go that route, instead opted for (what I thought) would be simpler, namely adding a short bit of html to a text panel in html mode (see my original post on this) , this proved not to be the case...  The iframe embed method is described in this helpful blog post.

In theory, you just add the iframe html into a new grafana panel and set it to txt/html mode.
It's quite configurable, e.g. the colour of the text and background/font used and temperature units used - I'm in the UK so have set it to degrees celsius.
You'll need to substitute the XXXX and YYYY for your latitude and longitude so that the weather data is relevant to your location.  I sourced my location via this handy postcode to lat/long converter

<iframe id="forecast_embed" frameborder="0" height="245" width="100%" bgColor="transparent" src="//

The fiddly bit.

So in theory its as simple as dropping in a bit of html - no it isnt...
There's a configuration option that needs to be changed, otherwise an ifram wont render, and you just get a string of text.  In the grafana server admin screen, if you scroll down to the [panels] section there is a setting called 'disable_sanitise_html = false', this needs to be changed to ' = true' or your iframe wont load.  You would think that changing it directly here would be possible?  ...but it isn't

Note - I've updated it in my version.  the default is 'false'
How to fix it depends on how you're running garafana.  If you've installed grafana locally, then you just need to directly edit the grafani.ini file, which is located in /etc/grafana/grafana.ini.

In my case I've set it up in a docker container which makes editing the file a bit more tricky- editing it directly does not work either but I'll describe the process as its handy to know how to connect to a running docker container and modify ts contents:

SSH into the Rassberry pi running Docker, and by definition your grafana container
Find the container ID of the grafana container
docker container ls -a

Connect to the container as root
docker exec -it <container-name> bash

To edit the grafana.ini file, you'll need to install a txt editor inside the docker container first
apt-get update
apt-get install nano

Then edit the file in nano, updating the disable_sanitise_html = false to true
nano /etc/grafana/grafana.ini

Save the file, exit the container.

SO.. that should fix it?  WRONG.  The config screen in the web interface as described above will still show this setting as = false.  Loads of forums recommend restarting the docker container, which has not effect either.  Running the command 'service grafana-server restart' within the docker container also has not effect.

The solution..
The trick is to pass 'disable_sanitise_html = true' to a docker image as an environmental variable at the point that a docker image is spun up into a container.  To make this work, I committed my existing grafana container back to an image file (this is essentially making a backup/snapshot of a container),  then re-launched the new local image file with the environmental variable added:

#run newly saved image file with environmental variable set
docker run -d -p 3000:3000 -e GF_PANELS_DISABLE_SANITIZE_HTML=true  grafana:1_Nov

Note that I wanted to keep my modification to the stock docker image for my modified version of grafana.  If you want to apply it to the stock grafana image on then use this command to spin up a new container:

#or add environmental variable option to the image on docker hub:
docker run -d --name=grafana -p 3000:3000 -e GF_PANELS_DISABLE_SANITIZE_HTML=true grafana/grafana:6.3.6

I've squished the DarkSky iframe down a bit on my dashboard, if you make it bigger within its grafana panel, you get this which has some pretty cool animated effects too

Sunday, 20 October 2019

Birdbox camera dashboard + environmental monitoring

I made a CCTV-type monitoring screen to present multiple birdbox cameras together + environmental monitoring data, using a Grafana / Docker container on a Raspberry pi...

The screenshot below shows all five of my currently active bird boxes.  The foot in the top Left box  belongs to a blue tit that spends quite a lot of time in there the moment (roosts too).  The temperature graph and widgets are populated by a temp + humidity sensor in the bottom R box that logs to its own internal environment every minute - the data really is an in-box box environment monitor.

EDIT Nov 2019: New blog post describing addition of web-sourced weather data to grafana

Prerequisites.. quite a lot of groundwork.  This project relies on various stuff already existing:

(1) Multiple birdbox camera streams
Most of mine use Raspberry Pi ZeroW mini computers + v2 camera modules running motion capture & streaming software called pikrellcam.  The top L one is a motion jpeg stream from a webcam on an early first raspberry pi model that has been going strong since 2014, the camera window could do with a clean though, our early evening roosting blue tit is present in this one:

(2) Some environmental data.
The aim is to present environmental data relevant to to the camera feeds.  The bottom R bird box has a sensor that logs its internal temp & humidity every minute to a mysql database, and is used to populate the temperature plot:

Temperature plot over time, current humidity and temps also showing

Equally there are plenty of free sources of weather data that could be used to provide a feed - it would be fun to see what the weather is locally too.

(3) A 'video dashboard'
The main point of this post.  The dashboard runs on the newest model from the Raspberry pi foundation, the Model 4B (4Gb ram version).  This has faster wired networking, more ram available, and generally more processing ooph.  I would NOT advocate putting one in a bird box unless you're planning on keeping roosting birds warm over the winter.  Mine sits 'headless' (ie with no monitor/keyboard etc) in the lounge behind the TV.  I've set it up with fixed IP address (wired, not wireless), and is accessed via SSH from a laptop.  I'm not going into detail for that as there are countless 'how-to's' out there.  Lets call this machine 'Hub-Pi'.

Hub-Pi setup as follows

Docker provides a seamless(ish) way of running 'OS-level virtualization software in packages called containers'.  Basically there are a lot of freely available pre-configured software 'images' that allow rapid deployment of software without having to fiddle about with setup.  I've used a Docker image of a dashboard application called Grafana.

Install Docker on Hub-Pi:  I used the guide on this site, up to the bit about 'swarming' (ignore from then).

Docker works by first downloading a specified image.  It then creates a live 'container' from that which is what you 'do stuff with'.  The 'docker run...' command specifies how the resulting container is configured.  If a container is deleted then all configuration data within the container is lost and you need to re-create a container from the original image and loose all your work in the process.  You can 'commit' a container back to a fresh image at any time,  again Google is your friend.

Install Grafana Docker image: Docker images are supposed to run on any hardware running Docker... sort of.  A base image is built with respect to the architecture of the CPU of the machine it runs on.  This basically means that Raspberry Pis are different to PCs (Arm vs  AMD64).  I'm not totally clear on the difference, but an image built for one may not work on the other.  Many images are built for both CPU architecture and Docker intuitively picks the right one to run.  Mostly.

On writing this, the most recent Grafana image is 6.4.3.  The Arm (is for Raspberry pi) version is somehow broken, so I had to revert back to version 6.3.6, which runs fine.  The Docker command to pull down the right Grafana image and create a Docker container that runs it is...

docker run -d --name=grafana -p 3000:3000 grafana/grafana:6.3.6

If you omit the :6.3.6 bit you'll get the current image which may be fixed in a future version, but didi not work for me.

This command is saying:

  1. Pull down the v6.3.6 of the Grafana image from DOckerHub.
  2. Run it (make container) and forward port 3000 to the host computers port 3000.
  3. Assuming the container runs, if you navigate to the Pi's IP address in a web browser that you fixed earlier, using port 3000 (http://HubPiIPaddressHere:3000), if its connected to a screen & keyboard use localhost:3000 directly then you get to the Grafana main login screen where you can assign a new password
Addition of camera feeds to Grafana
To make a camera feed in Grafana, got to..
Add Panel, then choose 'Text' from the visualisation options.
Based on the two types of video feds that I currently have, I edited the text in html mode as shown below.

My network video streams are of two flavours:
(1) Using webcams to generate a motion JPEG (MJPEG) stream, add the following to the html:
<img src="http://XXX.XXX.X.XX:YYY/?action=stream">
where XXX.XXX.X.XX is the IP address of the remote source and YYYY is the port it streams from

(2) Using Raspberry Pi v2 camera modules and pikrellcam software, add the following to the html:
<a href="http://XXX.XXX.X.XX" target="_blank"/a>
<img src="http://XXX.XXX.X.XX/mjpeg_stream.php"">
Where XXX.XXX.X.XX -  the IP address of the remote Pi running pikrellcam.  This also adds a convenient hyperlink to the video in the dashboard to the main pikrellcam page for that camera where motion captured video can be reviewed.

Once a video feed is added you can manually drag it about and resize it to fit your screen. Simple.

Potential developments...
This is an early version.  I plan to add in local weather data, e.g. from  I have entrance hole activity counter on one of my boxes (soon three), so it would be good to see a plot of activity associated with each video feed too.

UPDATE Nov 2019: see a new post which discribes the addition of a live weather feed

Saturday, 21 September 2019

Bird box activity counter v3: Build, detect & log activity

I've built entrance hole detectors into two existing bird boxes, lets call those counter versions 1 + 2.
This year, the v.2 counter box had two consecutive Great Tit nesting sessions, 8 chicks fledgling in total (7 and 1).  With the data it records, it can generate informative visuals like this one that shows daily counts of 'in events' for nesting sessions 1 and 2.  Can you work out which was the more successful 2019 brood?

Nest box activity for two consecutive nesting sessions in Spring 2019

I re-visited this from an earlier version (v1), this post describes version 3.  It uses the same principle as a commercial product from Schwegler that displays a local count - their product doesn't do anything else and will set you back approx £65.

Commercial counter displayed on the of the box front

My detector uses a pair of infrared (IR) beams & detectors that are offset from each other giving an 'outer' and an 'inner' beam.  A bird coming in will break the outer beam before the inner one and vice versa for a bird exiting the box.  Beam disruption events are logged to a text file on the integral  Raspberry pi Zero W which also runs video motion capture software, controls the lighting etc.

By having two detectors, its possible to differentiate between 'in' vs 'out' events.  Sensor noise such as a bird popping its head in from the outside or a spider jumping up and down on one IR LED can be ignored.  This is better than a 'one beam' approach that would produce noisy data that would be impossible to clean.

My design is an evolved version of a project in the 'Raspberry Pi projects' book by Robinson & Cook.  Don't buy the book for this project as it uses obsolete hardware (something called a 'PiFace', I used that in my v1 counter from 2014), the python code is chock full of mistakes, the code also isn't available to download on the publisher's website.

I reckon my v3 version is simpler to do and I've fixed the code side of things too 😏

Parts / equipment
2x 5mm IR LEDs buy here
2x IR phototransistor QSE113 buy here
Some 0.25 watt resistors: 1x 100ohm, 2x 1k ohm, 2x 10k ohm
Small piece of stripboard (grandly(!) referred to as the 'interface board' below)
1.6mm / 2.4mm heat shrink tubing
Wire.. I buy one roll of black 2 core firework shooting wire every few years, and a box of ethernet cable provides virtually endless colour-coded twisted pairs of low gauge wire.
Raspberry pi Zero W + power source

For the box:
Plywood (front of bird box): 1x 18mm piece and 2x 3mm pieces
30mm flat drill bit for the entrance hole
Router with a narrow cutter for the cable runs, e.g. this 3.2mm one.

The idea is to create a plywood sandwich for the v3 counter, with the 18mm ply between two 3mm pieces.  In contrast, v1 and v2 used more layers of plywood and was more fiddly to make.

How to make this....
Start off by clamping the three plywood pieces together.  Drill the entrance hole through all three ( I use a 30mm hole) then put the inner and outer 3mm plywood pieces to one side.
Drill 4 small 'guide holes' through the inner 18mm piece only, in approx a square (ish) arrangement around the entrance hole.  Use these as guide to route a diagonal channel on either side.  The channels need to intersect the guide holes   You want an 'X' shape  with one / and \ channel cut on each side, some of these guide holes will also double up as cable conduits.  Cut a couple of cable channels for the LED and phototransducer as shown below.  Its important that the cable channels are not full thickness.

Cut a recessed chamber on the 'outer' face of the 18mm ply piece that is deep enough to fit a small piece of stripboard (no smaller than 8 holes along the top, 10 on the side).  Drill another small hole through the ply in the recess that connects to a channel that runs up to the top of the inner face.  Power and GPIO connections to the Raspberry Pi come out via this route to the Pi in the top of the bird box.

Routing channels for the phototransistor and LEDs is a bit fiddly, here's a closeup of my efforts.  Any over cut/gappy bit around the detector can be filled with blu-tac or wood filler.

Before making the 'Interface board' I prototyped it out to make sure it worked

Breadboard fiddling
The resistors are as follows:
1) 100 ohm for the in-parallel LED circuit (220 ohm may also be okay)
2) 10k ohm pull up resistor to 5V for the transistor collector
3) 1k ohm resistor for the transistor collector GPIO connection

A handy hint for making stuff with IR LEDs: You cant see when they're on, however if you point a digital camera (with a screen on it) at them, then the camera can see it.

The breadboard prototype evolved into this shrunk down version on stripboard:

'Interface' resistor board

I use 2 core cable to wire the phototransistor emitter and collector legs as shown above, and a couple of twisted pair wires from a piece of ethernet cable for the LEDs, using different colour twisted pair wires for each LEDs - this make is easier to tell them apart.  I'm in the habit of using the stripy one of the pair for the + and the solid colour for the - pole (helps avoid soldering stuff in-situ the wrong way around).

Wire the transistors and LEDs cables first, then slot them into their routed channels and solder in-situ to the prepared interface board as shown above.

There are 4 connections to be made coming off the interface board: (1)5v and (2) ground [GND] (3) GPIO_1 for inner beam, (4) GPIO_2 for outer beam connections.  For the 5V and GND I use two core cable again, and coloured twisted pair for the GPIOs - as before, having a stripy one and solid coloured one for the GPIO connections helps you tell which is which.

How you inerface this with your raspberry pi is up to you, these 4 wires can be connected directly to the appropriate GPIO pins.  In my boxes, the 5V and GND will connect direct to the recom switching regulator (R-78B5.0-1.5) that drops the box's 12v feed to 5v. 

In this setup the IR LEDs are 'always on'.  I cant forsee a situation where I may need to turn them off but you could alternatively wire the LEDs via a second GPIO for power and power them on/off programatically.

The python script writes a single line to a log file if one of the beams transitions from broken to whole or vice versa.

The logfile logic is as follows:  BEAM,STATE,event time
Outer beam = 1; Inner beam = 2
Whole = 1; Broken =0

In this excerpt from the log, a bird has come into the box:
Outer beam broken, event_time
Inner beam broken, event_time
Outer beam whole, event_time
Inner beam whole, event_time

### recordBird_v3 starting up at:21 Sep 2019 09:47:35.990
1,0,21 Sep 2019 09:48:04.100
2,0,21 Sep 2019 09:48:04.446
1,1,21 Sep 2019 09:48:05.180
2,1,21 Sep 2019 09:48:05.228

The python script '' that records this is detailed below.
On my 'to do' list is to modify this to record to a database rather than a static text file. 
Having this recorded to a database opens up the possibility of connecting remotely to this box and directly querying its on-board database.

The 'log to file' version is below.  I'll write up the graphing functions in another post...

import RPi.GPIO as GPIO
from time import sleep
import time
import datetime

# Change log
# 16/09/19 updated for zerocam 7

GPIO.setmode(GPIO.BCM)          #use BCM pin numbering system

whichBirdcam = 'zerocam7'

#file used to log entrance actions
OpenEntrancelogFile= open(EntrancelogFile,  'a', 0)

#function to return the current time, formatted as
# e.g. 13 Jun 2013 :: 572
def getFormattedTime():
    now =
    return now.strftime("%d %b %Y %H:%M:%S.") + str(int(round(now.microsecond/1000.0)))

#generate and record an event to file
def logEntranceEvent(sensor, state):
    OpenEntrancelogFile.write(str(sensor) + "," + str(state) + "," + getFormattedTime() + "\n")

#setup GPIOs

detect_OUTER = 22 #6    #set GPIO pin for Outer photransducer (input)
detect_INNER = 23 #12    #set GPIO pin for Inner photransducer (input)

print 'detect_OUTER = ' + str(detect_OUTER)
print 'detect_INNER = ' + str(detect_INNER)


#WHOLE = 1

# setup GPIO pins:
GPIO.setup(detect_OUTER, GPIO.IN)   #set Outer GPIO Phototransducer as input
GPIO.setup(detect_INNER, GPIO.IN)   #set Inner GPIO Phototransducer as input

#indicate the point the program started in the log
OpenEntrancelogFile.write("### recordBird_v3 starting up at:" + getFormattedTime() + "\n")
print "============================================"
print whichBirdcam.upper() + ": Starting up entrance hole counter script..."
sleep (0.5)

#Set initial state of WasBroken for both beams:
OUTER_WasBroken = False
INNER_WasBroken = False

# LED status check
# LEDstate= GPIO.input(detect_INNER)

print ""
print "detect_OUTER status = " + str(GPIO.input(detect_OUTER))
print "detect_INNER status = " + str(GPIO.input(detect_INNER))
print ""

#When the detector          'sees' IR led, the detector pin is 0/LOW/False
#When the detector does not 'see ' IR led, the detector pin is 1/HIGH/True

def checkStatus():
    if GPIO.input(detect_OUTER):  #if OUTER detector does not see IR led, print error, GPIO.input = HIGH
        print "OUTER beam detect failure!, status = " +str(GPIO.input(detect_OUTER))
        print "OUTER beam detect - passed :) | Status = "+str(GPIO.input(detect_OUTER))

    if GPIO.input(detect_INNER):  #if INNER detector does not see IR led, print error, GPIO.input = HIGH
        print "INNER beam detect failure!, status = " +str(GPIO.input(detect_INNER))
        print "INNER beam detect - passed :) | Status = "+str(GPIO.input(detect_INNER))
        print "============================================"
        print ""

def status2():

    print "============================================"
    print "OUTER_IsWhole = "+str(OUTER_IsWhole)
    print "OUTER_WasBroken = "+str(OUTER_WasBroken)
    print ""
    print "INNER_IsWhole = "+str(INNER_IsWhole)
    print "INNER_WasBroken = "+str(INNER_WasBroken)
    print "============================================"
    print ""


# (x,y)
#  x=beam   (1=Outer,2=inner)
#  y=state  (1=Whole,0=Broken)

while (True):
    OUTER_IsWhole = (GPIO.input(detect_OUTER) == 0)  #read current state of beam
    INNER_IsWhole = (GPIO.input(detect_INNER) == 0)  #read current state of beam

    if (not OUTER_IsWhole and not OUTER_WasBroken): #if OUTER beam is broken [FALSE], and OUTER_WasBroken=FALSE (ie default value)
        OUTER_WasBroken = True
        print "(OUTER,Broken)"+ getFormattedTime()

    if (OUTER_IsWhole and OUTER_WasBroken): #if Outer beam is whole [TRUE] and OUTER_WasBroken=TRUE
        OUTER_WasBroken = False
        print "(OUTER,Whole)"+ getFormattedTime()

    if (not INNER_IsWhole and not INNER_WasBroken): #if INNER beam is broken [FALSE], and INNER_WasBroken=FALSE (ie default value)
        INNER_WasBroken = True
        print "(INNER,Broken)"+ getFormattedTime()

    if (INNER_IsWhole and INNER_WasBroken): #if INNER beam is whole [TRUE] and INNER_WasBroken=TRUE
        INNER_WasBroken = False
        print "(INNER,Whole)"+ getFormattedTime()


Here is a 'production version' of this being setup.  I swapped out the camera unit from an existing box.  You can see the IR leds in this camera - the're invisible to humans/birds

2x entrance hole IR beams - Digital camera view only!

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 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
nano /home/pi/

Install dependencies
sudo apt-get install xdotool unclutter sed

Add this to the file.  Substitute 'http://xxxurlToYourWebCam' with your local URL

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 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)
Description=Chromium Kiosk

ExecStart=/bin/bash /home/pi/


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 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:
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...

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...)

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...