Tuesday 29 December 2015

BirdBox2016: the role of the Picaxe

As 2015 gives way to a new year, so its time to ready those bird boxes for the coming nesting season.

My original 2014 Raspberry Pi box remains unchanged, although it will be sited higher than previous years, this time maybe 3 metres up the trunk of our Canadian Maple.

But last years (2015) Picaxe + Pi box has undergone a few more changes, so maybe this is a good time to mention them.

System Overview

The electronics in this bird box includes a RaspiCam, a Raspberry Pi and a Picaxe. The system can take photos, stream & record good quality video, capture high frame rate (slow-motion) video, and also capture low quality video triggered by movement within the box.

Raw data from the system can easily be presented using LibreOffice

Additional information provided by this system includes an estimation of bird visits and chick feeding rate. This data can be saved, manually pasted into a spreadsheet application, manipulated and presented.

The system is wifi enabled and battery powered.

The role of the Picaxe

The reason for the Picaxe is basically to extend battery life. Since the battery has a 12Ahr rating and the system typically draws between 120 -150mA:-

12Ahr/120mA = 100hrs
12Ahr/150mA = 80hrs

...so the battery will need recharging after 80-100hrs of continuous operation.

The 08m2 Picaxe monitors the entrance to the bird box via an optical sensor. When the beam is broken, the Picaxe turns on the supply to the Raspberry Pi. The system then boots and is ready to stream or capture video.

When the action stops (i.e. the optical sensor is no longer being triggered) the system continues to run for a short time, typically 20minutes, and then the Picaxe turns off the Raspberry Pi supply. This approach can extend the period between recharging by days or even weeks.

The ADC input on the Picaxe is used to measure the battery voltage. From the manufacturers information we can get an idea of battery voltage vs state of charge. I have also carried out my own tests on the two batteries that I have.

Lead-acid batteries don't like being fully discharged, so I've set a lower limit of approximately 11.9Volts (80% discharge). When the battery voltage drops below this limit, the Picaxe will no longer turn on the system. Most of the time I will recharge the battery before it falls to this level, so this is a kind of safety net.

During normal operation, the measured voltage is sent from Picaxe to Pi via a serial link.

In order to improve both resolution and repeatability, the Picaxe 10bit ADC takes 20 readings and passes the sum of these readings to the Pi. The only exception to this is the single reading taken to determine if the battery voltage is too low for normal operation.

Calibration is simply performed by adjusting a calibration factor in the Pi [Gambas] software, so the system readings agree with my digital volt meter.

The user interface (written in Gambas) is only viewable remotely, via VNC

The Gambas user screen shows:-

 battery voltage (sum-of-picaxe-readings) status

The Battery % reading is just calculated from run-time based upon typical system current, which seemed to provide a pretty good estimation of battery state during last season.

The final circuit

The final change to this years bird box circuit is the addition of a 10k pull-up resistor from Pi gpio pin 8 to the permanent 5Volt supply.

For those who are "spooked" by any mention of "gpio" and "5V" in the same paragraph, here is an explanation;

The reason for this resistor is that when the Pi is not powered, the output on pin 8 is 0V, which results in Picaxe pin 2 going high. So when the battery is first connected to the circuit, the Picaxe goes into program mode and (naturally) my program does not run.

The pull-up resistor supplies enough current when the Pi is off to provide a high logic level to the driver, and the Picaxe pin 2 is driven low. Thus the Picaxe can start and run its program. But note that the voltage at the Pi gpio pin 8 is only 2Volts.

The current flowing in this resistor is:-

(5V-2V)/10k =300microamps

...so not a danger to the Pi gpio.

When the Pi is powered, the gpio output will either be low (0V) or high (3.3V). In either condition the current will be much lower than the 15mA rating for a single gpio output. (Further info about mixing voltage levels here).

The complete circuit (see earlier posts for a better understanding of this circuit)

For other related posts, click on the "BirdBox" tab at the top of the page.

The Picaxe code

The Picaxe program is simple, with only around 50 lines of code.

No comments:

Post a Comment