Tweets from a Dragon

I’ve started the prep work on the “DragonCam” project – a monitoring system for Andrew’s Bearded Dragon, Summer. This weekend, I did the basic setup on a new Raspberry Pi B+ (love the new board design!) to get just enough working that we can start prototyping as a family. (When teaching others, I prefer a “quickstart” mode where they can see immediate results, then I can go back later to show the underlying work it too to get to that point…)


The setup work completed so far:

After moving the camera around for the best view, I settle on the fancy mounting solution below – first with the camera module taped to the glass – then later I found a small tripod and used it to move the camera back about 6 inches from the glass. Obviously, we will need something better – but this works for now 🙂

IMG_2149     IMG_2150     IMG_2151

This hardware and software setup allowed me to merge  example code from and example code from picamera to take a picture once every 5 minutes and uploaded it to Summer’s new twitter account 🙂


Here’s the quick bit of mashed-up example code:

import tweepy
from datetime import datetime
import time
import picamera

with picamera.PiCamera() as camera:
    camera.resolution = (1024, 768)

   # Consumer keys and access tokens, used for OAuth
    consumer_key = [removed]
    consumer_secret = [removed]
    access_token = [removed]
    access_token_secret = [removed]

    # OAuth process, using the keys and tokens
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    # Creation of the actual interface, using authentication
    api = tweepy.API(auth)

    for filename in camera.capture_continuous('/home/pi/dragoncam/img_{timestamp:%Y-%m-%d-%H-%M}.jpg'):
        print('Captured %s' % filename)
        print('Uploading to twitter...')
        # Send the tweet with photo
        i =
        status = 'DragonCam auto-tweet: ' + i.strftime('%Y/%m/%d %H:%M:%S') 
        filename = filename.encode('UTF-8')
            api.update_with_media(filename, status = status)
            print('Done. Sleeping for 5 min.')
        except tweepy.error.TweepError:
            print('Tweep Error. Sleeping for 30 sec.')
        print("About to capture...")

We’ve got lots of fun features planned – follow Summer on twitter & stay tuned!

About Ian Cole