Experimenting with the Raspberry Pi Sense HAT


[ad_1]

The Opensource.com team has been fascinated by the Raspberry Pi Sense HAT, a low-cost addon for the Raspberry Pi that enables astronauts and citizen scientists alike to easily collect measurements from a variety of sensors to conduct science experiments or just have fun.

So we decided to try one out ourselves. We grabbed a side room at our offices in Red Hat Tower and spent an hour or two learning what it can do.

First step, attaching the device. Easy enough!

sense-hat-attached.jpg

Then, it was time to try out some of the functionality. The Raspberry Pi Sense HAT provides a variety of ways for testing out interactivity and sensing the environment, including electronics for:

  • Accelerometer (movement)
  • Barometer (pressure)
  • Gyroscope (rotation)
  • Hygrometer (humidity)
  • Joystick (basic input)
  • LED matrix (basic output)
  • Magnetometer (direction)
  • Thermometer (temperature)

Experiments

We got started by testing out the humidity and temperature sensors. After borrowing and slightly modifying some code from Ben Nuttall’s GitHub repository, we were able to display a graph of the humidity in our room on screen the Sense HAT’s screen.

from sense_hat import SenseHat
 
sense = SenseHat()
 
while True:
    humidity = sense.humidity
    humidity_value = 64 * humidity / 100
    print(humidity)

A further extension of this code let us display the results on the Sense HAT’s tiny screen, but with several of us gathered in the room, it was simply easier to display the output of our terminal window on the room’s projector. Next, we tested the accelerometer.

Using the Creative Commons instructions on the Raspberry Pi, we designed a Magic 8 Ball. Except my team wasn’t content with the default responses, and instead, decided to make it a Magic 8 Ball that answers questions the way that I do.

import random
import time
from sense_hat import SenseHat
 
sh = SenseHat()
 
sh.show_message("Ask a question & shake", scroll_speed=(0.06))
time.sleep(3)
 
replies = ['No.',
	   'That is a great question...',
	   'It depends...',
	   'Actually it is complicated...',
	   'Let me think about that.'
        ]
 
while True:
    x, y, z = sh.get_accelerometer_raw().values()
 
    x = abs(x)
    y = abs(y)
    z = abs(z)
 
if x > 2 or y > 2 or z > 2 :
    sh.show_message(random.choice(replies))
else:
    sh.clear()

Unfortunatley for me, that worked too.

What’s next?

Now that we’ve learned to use the Sense Hat, what’s next? Sure, it’s a fun toy, but it’s also a working scientific instrument. Why not try out some ‘real’ science? Here are some of the projects we hope to try out next.

  • Testing the humidity every few milliseconds is fun, but not all that useful. Let’s build a data logger to record the humidity over time to a file, so we know how damp (or not) the air in our office is over the course of a week.
  • Next, let’s take the concept and extend it a little further. Using the thermometer just as we did the humidity meter, let’s use a little Python to have our Raspberry Pi tweet at us when the conference room gets too cool for taste, to remind us to bring a sweater!
  • Ever wonder how ‘active’ you are at your desk, as you figet and shift your weight around throughout the day? Why not use the accelerometer and a chair-mounted Pi to figure out just how many times you move across your workday?

Have you tried experimenting with the Raspberry Pi Sense HAT? What have you built with it? Let us know in the comments below!

[ad_2]

Source link

,

Leave a Reply