Sunday 18 January 2015

BirdBox2015: Picaxe controller details

Progress has been slow due to other commitments, and a heavy bout of man-flu.


But I've been testing the Picaxe powered controller with a RaspberryPi and it works just as I had hoped.


This low power controller may even be a useful building block for other battery-powered application.

The prototype controller board sits on top of the RaspberryPi model A+ connected via 26 of the 40 pin header, with a single plastic threaded pillar for additional support.

Testing the controller with detector & RaspberryPi A+


I can see now that the controller strip board should have been slightly larger, because I could not attach the pillar in exactly the right place (i.e. it needed to be one hole further out towards the edge). However, I may use this prototype anyway, as it works, and I just don't have the time to build mark II.

So the final circuit diagram looks like this:-



As I have soldered the Picaxe (rather than use a dil socket) I've also included the two resistors required for programming the device. This means I just have to temporarily tack 3 wires to a 3.5mm jack socket if I need to reprogram.

IC1e and the associated 10k pull-up resistor are probably not necessary (I only thought about this after writing this post on mixing voltage levels). However there are a few spare drivers in the 16 pin ULN2003 chip, so not a problem.

The current draw for BirdBox2014 was about 20mA with the 555 timer controller powered, but the RaspberryPi off. For the new Picaxe controller it is just 11mA, with 8mA of this is due to the box activity detector.

This makes me think that the controller could be used for other battery powered applications. For long periods when the RaspberryPi is not needed, the battery drain is negligible.

The only issue is boot time; for last years box using Raspbian Wheezy, the boot-to-application time was 45 seconds. This time around I'm using Raspbian Jessie, and for some reason it takes 60 seconds to boot...I need to try tuning this.

The code


The Picaxe code is simple.

'****************************************************************************************
'BirdBoxPi2015 controller
'--------------------------
'This Picaxe 08M2 program controls the BirdBox power supply.
'When triggered by the activity sensor, the power is turned on for 90 seconds.
'If RPi boots into application and starts kicking the Picaxe, power is maintained.
'If RPi stops kicking, the Picaxe sends a shutdown signal within 90 seconds.
'After a further 30 seconds, RPi power is switched off.
'There is then a 5 seconds delay before the Picaxe can be re-triggered and power
' can be re-applied to the RPi.
'
'SteveDee
'Jan 2015
'*****************************************************************************************
'
'byte b0 is used as a loopcounter
'byte b1 is used for bit values: bit8 & 9 hold input values, bit10 is a kick flag


input C.1        'Picaxe pin 6    trigger
input C.2        'Picaxe pin 5    kick Pi
output C.0        'Picaxe pin 7    Power control
output C.4        'Picaxe pin 3    Shutdown signal

main:
        let bit8 = pinC.1
        if bit8 = 1 then    'trigger detected
            for b0 = 0 to 180    'Power hold-up time in 1/2 second steps
                high C.0
                pause 500
                let bit9 = pinC.2    'kicked by Pi
                if bit10 = 0 then
                    if bit9 = 1 then    '0 to 1 step change
                        bit10 = 1    'positive going kick
                    endif
                else
                    if bit9 = 0 then
                        bit10 = 0    'clear kick flag
                        b0 = 0        'reset power hold-up time
                    endif
                endif
            next b0
            high C.4
            let b0 = 0
            for b0 = 1 to 30    'RPi shutdown (over-run) time in seconds
                high C.4
                pause 1000
            next b0
            low C.4        'end shutdown signal
            low C.0        'power-down Pi
            pause 5000    'wait at least 5s before power can be turned back onto Pi
        endif
        goto main


The only problem I had was due to not reading the Picaxe documentation properly the first time. You can use memory bits, bytes & words, but of cause you can't use a bit contained inside a byte you are already using for something else....Doh!...Man-Flu rots your brain!

For example:-
word: w0
...contains bytes: b0, b1
...and bits: bit0, bit1,....bit15

More to do


I still need to hack the new camera (i.e. replace the lens and lens mount) and install all the software and scripts to the Pi and hope they are compatible with Jessie.

Oh, and I probably need to build a new bird box, as I don't think I can adapt any of my existing stock.

No comments:

Post a Comment