This is a handy little function I’ve used a few times to calculate the aspect ratio of an image or video. Simply give it the width and height and it’ll give you the aspect ratio.
Last night I packaged everything up in the trail camera lunch box and gave it the first outdoors test. The first thing it captured was this little guy!
I think there may still be a few things to sort out. The PIR sensor may not be very sensitive or the code may not be 100% functioning correctly (though it seemed to be in all other tests I ran indoors), as the videoing stopped before I would have thought it should. However, as the very first thing it captured was the hedgehog I am very pleased with the result!
One thing I’ve always wanted to do with my Raspberry Pi was to build a trail camera, and when the Pi Zero was released with a camera port I thought that it was about time I stopped wanting to do it and actually just do it.
It took a while to get parts delivered from various places, but eventually in the last week or so I have finally built a trail camera. I’ll probably post more about that at a later date, but the most intriguing part for me was the programming…
Most of the trail cameras I had seen on the internet that people had built would either take a photo when a PIR sensor was triggered or would take just time lapse photos all night. Neither of these solutions really appealed to me. What I wanted was a video, and more than that I didn’t just want a video to record for a few seconds and stop. I wanted it to keep recording as long as there was movement triggered by a PIR.
In the end I came up with quite a nice small solution using Python and I’ve put it up on GitHub so feel free to fork and use or improve.
What I like about my solution is that when the PIR is triggered it will start recording for a definable number of seconds. If the PIR is triggered within that time it’ll just extend the record time by that many seconds again, and so on and so on until the PIR hasn’t been triggered for at least that many seconds at which point the recording will end.
Easy to use and exactly what I wanted. So feel free to grab my trailcam phython script on GitHub.
Yesterday I was starting a small, very stand-alone project that required a pretty dynamic interface. I decided to put together the components using ReactJS but as it was essentially just one JSX file that I had I didn’t want to have to set up a gulp file, babelrc file, and whatever new-fangled build process the young kids are in to these days.
I thought about not using JSX syntax, but I think it adds a level of readability to the code and will make it easier for myself and others to maintain longer term, and besides which, I had already writing the JSX part and didn’t want to redo the work. Thankfully, though, it’s really easy to use Babel from the command line to do the conversion,.
First, install the required npm modules (I did this globally so that I could use it anywhere on the cli, not just in the specific project):
A while ago now (back in February!) I did a talk about writing an extension using Zephir to interact with the RaspberryPi’s GPIO. The extension itself wraps around the wiringPi library and it makes it really easy to write PHP scripts that send output and gather input from the GPIO.
Here are the slides (use left/right arrow keys to navigate):
Just a quick note to say that my thumbnail and VTT creator for JW Player, a script to help extract thumbnails from a video and present them in JW Player a a toolbar preview, has now got the ability to be included in your project via composer. Just use:
composer require amnuts/jwplayer-thumbnail-preview-generator
If you want, you can also browse for it on Packagist.
I’ve pushed a few changes to phpiwire can now use the PWM functions in wiringPi. You can use either the hardware PWM pins or any of the GPIOs by using software PWM. A couple new examples of how to do this have also been added to the repository.
With software PWM comes the requirement to include pthreads, so that’s also linked when you compile the zephir extension.
I’d recommend you do a full clean first before compiling with:
zephir fullclean zephir install
I’ve just arrived back from the inaugural PHP South Coast Conference. It was a really great event that seemed to go without a hitch, had a fantastic range of speakers and a nice bunch of people that attended. So first of all, a really big thank you! to PHP Hampshire, BrightonPHP and PHP Dorset for putting on a top-notch event – you really wouldn’t have known it was their first one as everything seemed so professional! Continue reading “PHP South Coast 2015”
So it’s been a while since my lightening talk on Zephir and I realized I hadn’t really done anything to try to learn it a little more in-depth. Coincidentally, I was recently going through a drawer and realized that one of my Raspberry Pi’s was in there just begging to be put to some use (seriously, I could practically hear it weep). So I thought that the only thing to do was to attempt to write an extension using Zephir so that I could control the GPIO via PHP. I mean, isn’t it obvious? Continue reading “Phpiwire: a PHP extension (written using Zephir) for controlling the Raspberry Pi GPIO”
Yesterday I was one of four people to do a lightning talk at BrightonPHP. As anyone who knows me; I hate public speaking with a passion. Anything over, say, four people (usually including me) and I just like to sit there quietly and not say much. But encouraged by @coderabbi’s Wisdom as a Service talk he did at BrightonPHP in February (read: told at the train station by coderabbi that I had to do a talk) and the fact that it was a lightning talk so I didn’t actually have to speak that long, I presented a very brief, high-level overview of Zephir.
If you think any of this is inaccurate, needs tweaking, etc., then please let me know and I’ll happily update it accordingly.
Well done also to Rich, Rowan and Tristan for their very informative talks on joind.in, xml/json and selenium (respectively)… Although I’m the only one that didn’t get an applause after their talk, so you’re all dead to me. 😛