Pages

Navitron

2016-01-13

Hello Sense HAT

Yesterday I bought one of the wonderful Sense HAT boards from element14.com. The Sense HAT provides an 8x8 LED maxtrix display, accelerometer, gyroscope, magnetometer, air pressure sensor, temperature sensor and air pressure sensor, as well as a small joystick.  Basically a bundle of sensors that plug in directly to the GPIO pins on your Raspberry Pi. They are well worth purchasing should you wish to upgrade your Pi.  I would like to set up a data- logging weather station, however I have only had time for a brief experiment with the features so far.

Follow link for buying options.


Setting up is very easy: the board just plugs straight in and the online instructions are very easy to follow. I suggest you download the Sense HAT Python API or you wont get very far with Sense HAT.

Listed in this post are two of my 'hello world' programs.

Space Invader


I am your father...
This program creates a space invader tile on the LED matrix display and flashes the colours.

# Displays a space invader on the LED panel
# and flashes the colours a bit
import time
from sense_hat import SenseHat

def getInvader():
    return [
            O, O, X, X, X, X, O, O,
            O, X, X, X, X, X, X, O,
            X, X, O, X, X, O, X, X,
            X, X, X, X, X, X, X, X,
            X, X, X, X, X, X, X, X,
            O, X, X, O, O, X, X, O,
            O, X, X, O, O, X, X, O,
            O, X, O, O, O, O, X, O
            ]

sense = SenseHat()

while True:
    for r in range(255, 0,-5):
        for b in range(0, 255,5):
            X = [r, 0, 0]
            O = [0, 0, b]
         
            sense.set_pixels( getInvader() )
            time.sleep(0.1)




Thermometer


Displaying a scrolling display of the sensor outputs.
This program simply displays a continuous scrolling readout of the temperature and air pressure. The colour of the display depends on the current air temperature.

# Displays the temperature and pressure
# on the LED panel
import time
from sense_hat import SenseHat

sense = SenseHat()

while True:
    # find temp in celsius
    t = sense.get_temperature_from_humidity()
    # find temp in fahrenheit
    f = ((t/5)*9)+32
    # find pressure in mb
    p = int(sense.get_pressure())
    # find display colour
    # this depends on the current tremperature
    if t<12:
        myCol = [ 0, 200, 230 ] # a cold colour
    elif t<22:
        myCol = [ 0, 220, 0 ] # a neutral colour
    elif t<29:
        myCol = [ 200, 100, 0 ] # a warm colour
    else:
        myCol = [250, 0, 0 ] # very hot colour
    #display message
    sense.show_message( str((int(t*10))/10)+"C   "+str((int(f*10))/10)+"F    "+str(p)+"mb", text_colour=myCol)
    time.sleep(0.5)


Sense HAT reading the wrong temperature

One problem: the temperature sensor is positioned on the board so that it is directly above your Raspberry Pi processor. This means that it picks up the ambient air temperature as well as some of the heat from the processor. Positioning the Pi vertically along its widest edge alleviates some of this problem due to better convection however not altogether.

I do not have a decent thermometer to test the callibration, however I suspect that the Pi can become inaccurate by 12 degrees Celsius or greater.

The manufacturers make no apologies for this.

One solution is to make a heuristic algorithm (a fudge-y guess) at the temperature, however this is not very satisfactory.

Another solution will be to position the Sense HAT further away from the motherboard using a 40 pin ribbon cable and GPIO cobbler. I have a 20cm cable currently with the Royal Mail (along with some blu-tak). I'll let you know how I get on with this.

Still awake? That's all for now, but try these...
More Raspberry Pi adventures.
More programming things.
Something completely different.

#raspberrypi #senseHAT

No comments:

Post a Comment