May 182015
 
RasPiO Duino Cam

Around about this time three years ago, I bought and installed five EasyN pan-and-tilt ip cameras to keep an eye on various viewpoints of our houses in the UK and Poland. I think they were about £45 each on Amazon. They’re not too hard to set up and they work tolerably well. The main downside is that their resolution is only 640 x 480 pixels, which is not enough to read a car numberplate from across the street. It’s fairly poor resolution, but you can see something. The colours are a bit washed out too because there’s no infra-red filter.

Last summer, one of these cameras started going a bit ‘intermittent’. So this Easter, when we went to Poland, I had plans to replace it with one of my ‘old’ rev 2 model B Raspberry Pis, a RasPiO Duino, Pi Camera and two servos. The RasPiO Duino controls the servo positions, and the Pi controls the camera. Like any true hack, it uses what I had available at the time. In this case, I used an SD card case as camera mount (it’s a lovely hinge) and huge quantities of hot glue.

RasPiO Duino powered DuinoCam (note the SD-card box camera mount)

RasPiO Duino powered DuinoCam (note the SD card box camera mount)

How Do We Control It?

I set it all up and got it working, but there was a missing link in the chain. With the old ip cameras we had a browser-based user interface to control camera position and output. Well I wouldn’t know where to begin with a web UI, and that sort of thing doesn’t interest me either. So I thought about how else we could achieve our goal of being able to see what the weather is like in Poland and keep a general eye on things. At that point I thought…

Well we could get the DuinoCam to tweet a photo every hour, which would give us a nice snapshot of what’s happening. It would also alert us if the connection went down.

But then, in my mental meanderings, I had the “Eureka” moment…

What if we could actually control it by tweeting commands at it?

That ticked all my boxes…

  • I’d never done it before
  • I’d never heard of anyone else doing it before
  • I knew I could build on previous twitter app work I’d done
  • It was a great opportunity to use my own product to do something extremely cool

So I spent about 3 or 4 days on it, tweaking, fiddling, adding stuff (both hardware and software) and perfecting. The result is DuinoCam. It uses a pre-production “servo” variant of RasPiO Duino, but a standard RasPiO Duino could do the job in exactly the same way.

Here’s how the output compares with the EasyN…

Duino Cam output VS EasyN

Duino Cam output VS EasyN. Click to enlarge.

Note that the EasyN has no IR filter (for nocturnal use) hence the washed out colours. As you can see, the Duino Cam output is a massive improvement. The EasyN wasn’t usually quite as bad as it looks here with the sun shining straight at it.

Here’s a Video Walkround

How Does DuinoCam Work?

DuinoCam uses a RasPiO Duino to control the positions of the pan and tilt servos, which determine what the camera is pointing at.

RasPiO Duino - production version RasP.iO/duino

RasPiO Duino – production version RasP.iO/duino

There Must And Shall Be LEDs

LEDs on stripboard, held at correct angle with a ton of hot glue.

LEDs on stripboard, held at correct angle with a ton of hot glue.

There is also a bank of super-bright white LEDs for short-range night-time illumination. These are switched with the RasPiO Duino and a Darlington Array chip. (They’re powered from the same 5V source as the servos – which is separate from the Pi.)

The Duino also has a light sensor (LDR) and a temperature sensor (TMP-36) connected to two of its analog inputs. These are measured once per second and the results reported to the Pi via serial port.

An Arduino sketch drives all of those processes. Commands are received from a Python script on the Pi via the serial port.

So What Does The Pi Do?

The Pi runs a cron job every minute to scan the DuinoCam’s (locked) twitter feed with a Python script. (Cron is a mechanism for running things at specific times or on specific events). If it sees a new tweet from a pre-approved (and hard-coded) twitter ID, it examines the tweet, looking for the following #hashtag commands…

  • #1 – point camera at stairs/desk
  • #2 – point camera at default position
  • #3 – point camera at street
  • #4 – point camera at neighbours opposite
  • #lights_on – turn on LEDs
  • #lights_off – turn off LEDs
  • #photo – take a photo wherever the camera is now and tweet it
  • #video_on – start streaming video
  • #video_off – stop streaming video
  • #scan_str – a full range 180 degree video sweep with streaming
  • #scan_rec – a full range 180 degree video sweep, recorded, mp4ed & dropboxed, then local copy deleted
  • #hires – take a full resolution photo, upload it to dropbox, then delete the local copy

If one or more of these commands are found, they are executed. Servo and LED control sends a serial message to the Duino, camera commands are executed on the Pi itself.

DuinoCam twitter output

DuinoCam twitter output


Another cron job reads and stores the current room temperature (TMP-36 sensor) and light levels (LDR) every 10 minutes using a Python script to read the Duino’s serial output.

Another cron job runs once an hour, on the hour (0600-1900). It first moves the camera to our chosen “default” position (in case we’ve been fiddling with it and left it in the wrong position), then takes and tweets a photo and the most recent temperature and light level information. (It usually takes about 17 seconds to achieve all that.)

So all we have to do is look at the twitter feed.

If we need to go “live” (which we find we really don’t since we now get a tweeted status photo every hour) we can switch on streaming and watch the stream with VLC on any device that can run it.

Streaming Relies On A Good Uplink, What If…

Streaming isn’t all that good on our Polish connection though because the uplink is not very fast. It took me 26 hours to upload the (4Gb) RasPiO Duino assembly video from there. So I decided to implement the same sort of dropbox upload that I used for RasPiCamcorder 2. This gives you the option to get high quality video without needing good bandwidth, as long as you can wait about 10-15 minutes for your results.

I Want High Res Photos Too

No problem! I also added the facility to dropbox upload a high resolution photo. Sometimes you just need a really good look…

Full Resolution shot with registration plate magnified

Full Resolution shot with registration plate magnified – click for full res

Turn on LEDs for a night-time reading

Turn on LEDs for a night-time reading

What About Lights?

You may have noticed the weather station in the default view showing the car above. This has a remote temperature sensor in the basement. If we want to see the basement temperature in the dark (well you might, WJDK) we can flip the LEDs on with a #lights_on tweet, then get a photo either tweeted #photo or dropboxed #hires

Will You Share The Code?

Yes, I intend to share the code and write the whole thing up some time within the next few months. I’ve been rather busy lately getting the RasPiO Duino KickStarter rewards out the door. We’re nearly done with those. Once we are, the RasPiO Duino will go on general sale. Click here to find out when that will be.

  9 Responses to “Twitter-controlled RasPiO Duino based Pan and Tilt, Tweeting, DropBoxing, Raspberry Pi Security Camera”

  1. Lovely project Alex, Polish & polished. The use of an SD-card-case as a camera hinge is very clever :-)

    I guess you could also hook up a motor to the ‘Duino and have it automatically close your blinds at night, even when you’re not at home? (although you’d obviously need some kind of limit switch / detector)

    • Thanks Andrew. Could do the blinds thing. That would enter the realms of “catch fire if it goes wrong” which would be a breach of rule 1. But yes. I was already thinking of hooking it up to a relay and 12V desk lamp (breaking into the 12V circuit would be safe enough, but I don’t want to mess with 230V).

  2. Hiding the twitter account identity, could you post a “control tweet” example?
    Thanks,
    Ben

    • Hi Benoit, there were three examples in the video, but any tweet from the right account and at the right account containing one of the hashtag commands would execute that command. e.g.

      @ZgierzHouse #1 #lights_on #hires

      Would move the camera to position 1, switch on the LED lights, take a Full resolution photo and upload it to Dropbox.

  3. I am curious to know how in your cron job that runs every minute to read the DuinoCam’s twitter feed knows that a tweet is “new”. Twitter doesn’t seem to have the concept of “read flag” for tweets. Do you store the tweet ID of downloaded tweets and check to see if it hasn’t seen the tweet before?

  4. maybe try pi-blaster + motinioneye
    https://github.com/yanoschik/PiPan_Cam

  5. Hi Alex,

    Are you planning to post the code for this brilliant project soon?

    Thanks

    Jim

Leave a Reply