Ricky Moorhouse

Blog

Measure sunlight with Raspberry Pi

For Christmas the girls gave me a Raspberry Pi, and for my first project I decided to try recording how bright the sunlight at our window is using an old Webcam.

raspberrypi

The basic idea is:

  1.  Capture a photo

  2. Analyse the brightness of the photo

  3. Log it (and eventually publish to cosm)

So first of all getting the webcam set up - My webcam is a Logitech Quickcam Express, which proved to work nicely with the Raspberry Pi, after plugging it in, it showed up straight away in the output to lsusb: ricky@pi ~ $ lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. Bus 001 Device 004: ID 046d:0840 Logitech, Inc. QuickCam Express

To get the photo from the webcam I used fswebcam which was simple to install (sudo apt-get install fswebcam) and use: fswebcam --no-banner -d /dev/video0 webcam.jpg The no-banner removes the default date and time at the bottom of the image, /dev/video0 is where the webcam appeared and webcam.jpg is the file to save the image to.

I found a python function to calculate the brightness of the image from StackExchange so put it all together and here is the python script I'm using:

<code class="language-python">
#!/usr/bin/python
import Image
import ImageStat
import math
import os
import datetime
os.system("fswebcam --no-banner --scale 50x50 -d /dev/video0 webcam.jpg")
im = Image.open("webcam.jpg")
stat = ImageStat.Stat(im)
r,g,b = stat.mean
brightness = math.sqrt(0.241*(r**2) + 0.691*(g**2) + 0.068*(b**2))
dt = datetime.datetime.now().strftime("%Y%m%d-%H:%M:%S")
data = '%s,%sn' % (dt, brightness)
open("brightness.csv", 'a').write(data)
</code>

It could be tidied up quite a bit and I'm sure there's a way to capture the image within Python without having to write it to disk first as well. My first days readings taken every 10 minutes look something like this: //

Gunwharf Fireworks

20121102-225824.jpg

Mini Great South Run

This morning I had fun doing the mini great south run with Abi, unfortunately RunKeeper crashed as we went through the start line but I think we did the 1.5k in roughly 11minutes. She had a great time and did it with a mixture of running at a good pace and then walking for a little bit until she saw too many people overtake, then she would pick up pace and dive through gaps in front of her. She enjoyed the stretch on grass much more than the road and path sections and was thrilled with her medal at the end.

20121027-174154.jpg

20121027-174204.jpg

20121027-174139.jpg

Bagel making

After seeing the bagel making on "The Great British Bake Off" the other night, I decided it would be fun to give it a go myself. So this evening using this recipe I did…

20120822-222649.jpg

Not quite as exciting as the ones they made on the programme, but they seemed to go well for a first attempt!

Dolbadarn Castle

[caption id="attachment_7453" align="aligncenter" width="300"] Sketch of Dolbadarn Castle, Wales[/caption]

Send out your light and your truth

Send out your light and your truth; let them lead me; let them bring me to your holy hill and to your dwelling!

Psalm 43:3

Tweeting Google Calendar reminders with Postmark

A while back I wrote my original script to tweet event reminders from Google Calendar and it's been through a couple of iterations since and been broken for a while. Well finally I got round to update it to use OAuth to connect to twitter using the twitteroauth library and switched to using Postmark Inbound for handling the incoming e-mail.

What you will need

Getting set up

Register a new twitter app from the Twitter Developer Site (making sure you sign in with the account you want the tweets to come from) - fill out all the necessary fields and click create. On the next page you should get the OAuth details (Consumer key and Consumer secret) and a section to generate your access token and access token secret, these all need putting into the section at the top of the script.

Install the script on your web hosting, along with the twitteroauth directory from  twitteroauth at GitHub. If you got to the script URL in a web browser you should see it post a , to your twitter account without any errors. (I need to add some testing code really!)

Set up a server in your Postmark account then go into the Settings page for that server and update the Inbound Hook to point to the full URL of the script on your server to point to your script for inbound emails. Make a note of the inbound e-mail address from the server tab of your settings as you will need this to forward the calendar reminders to.

Add your Inbound Email address as a forwarding address to your Gmail account. It will send a confirmation code to the address, which you can collect from the Inbound section of the Postmark interface

Create a filter in your gmail account to forward your calendar reminders to the Inbound Email address from your postmark account (Mine forwards anything from calendar.notifier@google.com).

Now everything should be in place to start sending reminders.  For each event in your calendar set up e-mail reminders for the number of days/hours before you want the reminder tweeted.  These should then appear something like this at twitter:

this afternoon at

Psalm 119:37

Turn my eyes from looking at worthless things; and give me life in your ways.

Psalm 119:37

Looking back on 2011

  • Greg and Poppy's wedding in February with the girls as bridesmaids.
  • My 30th birthday and combined birthday celebrations with my mum's 60th in the Cotswolds at the end of April.
  • Going to the London Men's Convention with Des and some of the men from church.
  • Starting to get into gardening and growing lots of tomatoes.
  • Holiday to Malta with Des where the girls swimming really took off greatly.
  • Our summer Hampshire pass, visiting some of the sites around - and especially our family trip to Basingstoke to visit Basing House and Milestones museum
  • Our lovely anniversary weekend in Torquay thanks to Anne and Des.
  • Abi starting school and her space party for her birthday
  • Visiting the Royal Landscape and meeting up with Linda and Dave on their way back to Canada

Merry Christmas