In today's lab, we will be working with the Sense Hat module on the Raspberry Pi to read environmental sensor data and display it in our Flask web app.
Read the Sense Hat documentation for built in methods
Read data through one or more sensors on the module
Display sensor data visually through the module or app
The Internet of things (IoT) is a network of devices that range from sensors to software and other technologies that are all connected to the Internet. They "talk" to each other to gather, analyze, and share data. This allows for the creation of amazing projects, from smart mirrors to wearable heath monitors.
The Sense Hat module is an add-on board that you can attach to the top of your Raspberry Pi. It attaches to the GPIO (General Purpose Input/Output) pins on the Pi.
It contains:
An 8x8 RGB LED matrix
A 5 button joystick
Gyroscope
Accelerometer
Magnetometer
Temperature sensor
Barometric pressure sensor
Humidity sensor
The Sense Hat contains multiple sensors that can detect environmental data, such as temperature, humidity, etc. The API provides multiple functions that we can call to retrieve specific sensor data.
Example:
from sense_hat import SenseHat
sense = SenseHat()
temp = sense.get_temperature()
print("Temperature: %s C" % temp)
# alternatives
print(sense.temp)
print(sense.temperature)
Data can be passed to the Sense Hat module to be displayed visually on the LED matrix. To set the color of each pixel, the API provides a set_pixels function that can be called. The color values of the pixels are stored in a tuple.
from sense_hat import SenseHat
sense = SenseHat()
X = (255, 0, 0) # Red
O = (255, 255, 255) # White
question_mark = [
O, O, O, X, X, O, O, O,
O, O, X, O, O, X, O, O,
O, O, O, O, O, X, O, O,
O, O, O, O, X, O, O, O,
O, O, O, X, O, O, O, O,
O, O, O, X, O, O, O, O,
O, O, O, O, O, O, O, O,
O, O, O, X, O, O, O, O
]
sense.set_pixels(question_mark)