Wednesday, 22 July 2015

Bat Detector Overhaul: Logging Bat Data

I have to admit to being a lazy person, so even the effort of standing in the garden pointing my bat detector at the sky is too much for me.

It can also be a bit boring. Especially when its 11pm and I'm not seeing (let alone detecting) any bats!

So the next step is to leave the bat detector outside unattended and try to log any activity on a computer.

Since I need a digital input, and I don't want to leave my laptop laying on the grass, the next best option is a Raspberry Pi. The Pi may not be the best option for data logging in the field, as it is over complex and requires too much power (I could use a Picaxe and EEPROM on less than 10% of a Pi supply current).

But for testing ideas its great, because I can quickly knock up a simple test app in Gambas and have it recording data within a few hours.

What's the big idea

First a confession. In my last post I said the high frequency to audio divider was dividing by 8.

CH1 is the detected signal, CH2 is the divide by 16 audio signal

On closer examination I find that I'm using pin 6 on the cmos 4024 which divides by 16. This means that the audio frequencies are half those previously quoted. So at some point I'll re-work the filter calculations and probably make a few simple changes.

The Pi logger needs to sample the output from the divider fast enough to ensure we can count transitions from low to high. To make life a little easier, I decided to use the "divide by 32" output from the 4024.

By counting high and low states, and then dividing by the sample time, we can get an indication of frequency. In my Gambas test program I just use a For loop which counts the number of times the signal changes state during 100,000 loops. A complete cycle consists of 2 state changes (e.g. low-to-high and high-to-low).

On a PiB2 running my test program in the Gambas IDE, each time through the loop took approx 3us (300ms approx for 100,000 loops).

This code uses the wiringPi library to monitor input 4 (physical pin 16)

I display detected frequency, peak detected frequency, sample start time, end time and total sampling time.

The rest of the ReadFrequency() function looks like this:-

To log data, I call a log routine whenever a frequency > 20kHz is detected. So each record in my CSV log file consists of the date, time and frequency.

Connection to Pi

I have added another 3.5mm Jack socket to the bat detector box and wired it to the cmos 4024 pin 5 (divide by 32 output) via a 100k resistor. The resistor limits the current into the Pi gpio input, giving a level of about 3Volts.

Now I can hang the detector out through a window and connect a long screened cable from the bat detector to Pi pins 16 (input 4) and 6 (0 Volts).

We just need a few dry nights so that I can test it!

No comments:

Post a Comment