Thursday, January 16, 2014

Raspberry Pi as a Northern light forcast device - PiAurora




Raspberry Pi as a Northern light forcast device - PiAurora

Aurora is a beautiful natural light display in the sky particularly in the high latitudes.It is caused by the collision of energetic charged particles with atoms in the high altitude atmosphere. The prediction of viewing aurora is based on Geomagnetic Activity-The Kp Index (you can read more here )

Based on the geo magnetic latitude,the Kp index should be above a certain value to view the aurora (apart from local weather conditions :) like clouds )
You can check the geo magnetic latitude and the minimum Kp value needed by clicking here (NOAA).

Current extent and position of the auroral oval can be viewed below

from http://www.swpc.noaa.gov/

Here is a simple Northern light (Aurora Borealis) warning (alert - if i miss it i feel bad so i wrote warning :)) device based on a Raspberry Pi. Basically it connects to noaa.org to get the Kp values and if the predicted value goes above a set limit, it powers on an led connected to the GPIO pin of the Raspberry Pi. To make it simple only one led is used with a green color ( i used one of the channel in an RGB module).

To give some visual effects 'like' the Aurora, a pulse width modulation is used with varying intensities. This is achieved by using the servoblaster project, which provides an efficient (DMA based) way to produce PWM with minimal cpu usage. I just placed a waterbottle in front of the led to get a nice visual effect!

The forcast on Pi works by a pythonscript which check the current kp value with the threshhold value and triggers the lights

See it in action below



Partial code which parse the kp value from noaa is given below. Linked it with servoblaster and used a cronjob to check the kp values every 30minutes/1hr. If you have any trouble in completing the stuff, post it as a comment. Until then the rest of the code is kept as an exercise to keep the interest on coding with pi and python :-)

#!/usr/bin/env python

import sys

import urllib

import re

import io    

from StringIO import StringIO

def getLine(data, line_no):

    buffer = StringIO(data)

    for i in range(line_no - 1):

        try:

            next(buffer)

        except StopIteration:

            return '' #Reached EOF



    try:

        return next(buffer)

    except StopIteration:

        return '' #Reached EOF



url = 'http://www.swpc.noaa.gov/wingkp/wingkp_list.txt'

u = urllib.urlopen(url)

txt = u.read()

u.close()

temp = StringIO(txt)

count_lines = len(temp.readlines())

lineE = getLine(txt,count_lines-1)

lineE.split()

elements=re.findall("[-+]?\d*\.\d+|\d+", lineE)

kp=elements[len( elements)-1]

print kp

2 comments:

  1. Pretty cool! runnning the rgb strip with added weather data may be an alternate possibility

    ReplyDelete
    Replies
    1. Thanks for the comment. I have a plan for that, but need to add some driving circuits for the strip (couple of transistors) and at this time i tried to make a quick and lazy alerter :) I actually run the pi as an xbmc system and just attached the rgb module and kept a waterbottle on top so that when kp index goes high it gives a noticeable flashes in the room (used some strong green led which gets projected every where in the room!)

      Delete