Sunday, January 18, 2015

71: My Pi as a Time Lapse Camera

I used raspistill taking 1 still per minute. Moved the JPEGs to my Mac and turned it into MP4 at 10fps. 450 minutes crunched to 45 seconds.

The .mov clip below is seriously down-sampled.

Noon to Sunset
Nothing much happening.

This command on the Pi took the stills:

  raspistill -w 1280 -h 720 -tl 60000 -o i%04d.jpg -t 28000000

(Having to time everything in milliseconds is tiresome.)

On my iMac this converted the stills to MP4/10 frames-per-second:

  ffmpeg -r 10 -i i%04d.jpg clip.mp4

I could have done this step on the Pi but it would have taken a lot longer. BTW: the video quality from this step was very good -- not like the above.

Saturday, January 10, 2015

70: PWM -- Another Reason to Front-end Your Pi with an Arduino

I just discovered the joys of Arduino PWM (pulse width modulation). Easy on my Nano, except for 1 GPIO pin is's a nasty kludge on the Pi. Ha! (I listed USB-connected source code for Pi and Arduino back in Post 66.)

BTW: PWM is useful for things like dimming LEDs. In my case, I wanted a user to notice differences in output of mini-motor vibrators (e.g., from Adafruit). You have 256 output levels: 0=none(OFF), 127=half, 255=full(ON).

P.S.: While Pi prices are pretty standardized, Arduino prices are all over the place. I've noted Internet-listed Nanos (my favorite model) at anywhere from over $30 down to $3.30 (no cable, soldering required, delivery from China).

Thursday, January 1, 2015

69: To Catch a Thief
(Raspberry Pi Security System)

My daughter's dog is an inveterate thief of any food left within even implausible reach. The previous time we dog-sat for him he managed to steal over a dozen home-made cookies. So I decided to catch him in the act using my Pi+camera+Python program. I have a (fairly) portable Pi system:
Notes on the configuration:
  • The 12,000mAh battery will power the Pi for about 10 hours. Unfortunately the battery can either charge or discharge but not both at once. Otherwise it would make a very nice UPS (uninterruptable power supply).
  • As shown, it has LED output, PIR and Pi camera input and a 7-segment display. On the side there is a Cat5 socket (provides 8 wires for remote sensors) and a pair of relay switches.
  • I use the speaker for text-to-speech output.
Anyway, I baited the kitchen counter with a piece of meat and set the porta-Pi aimed at the counter. On my first attempt my program just used the camera to detect motion. About once per second the Pi can take a grayscale 120x90 pixel image which the program compares pixel-by-pixel with the previous image. When more than an arbitrary number if pixels have changed by more than an arbitrary difference then the program takes a full-res image and saves it to the SD card filesystem.

This first test failed for 2 reasons: a) the dog ignored the bait; b) while we were away for about 3 hours the sun went under a cloud and back out about 100 times and my dumb program decided that each such change was "motion."

So, for my second try I added the PIR device -- logic as follows:

    IF the PIR detects motion AND the 2 camera images differ THEN store the high-res image.

This attempt failed too: at  a distance of about 12' the PIR didn't notice the 30-pound white dog (but he stole the meat).

I need a better motion detector.