Raspberry Pi Sense HAT: a Simple Weather Station
In this article we have discovered the Sense HAT. Now let’s see how we can program it. In this article, we will see how to get data from the environmental sensors (temperature, pressure, humidity) to create a simple weather station.
The weather station is based on the reading of the environmental sensors. Fetching the value of environmental sensors is very simple. Just create a sense HAT object and get the value of sensors as follows:
from sense_hat import SenseHat sense = SenseHat() temperature = sense.get_temperature_from_humidity() humidity = sense.get_humidity() pressure = sense.get_pressure()
The temperature is in degrees celcius, the humidity is in percent and the pressure in millibars.
I coded a simple weather station demo with GeeXLab. The standalone demo can be downloaded here:
A thread is available HERE for any feedback or bug-report.
To launch the weather station, unzip the archive and start GeeXLab. The weather station demo will be automatically loaded. The source code (Python) of the weather station can be found in the weather_station_src/ folder.
The weather station demo is also available in the gl-21/rpi/sense_hat_python/weather_station_src/ folder of GeeXLab’s code sample pack.
The temperature / humidity sensor is located on the Sense HAT board and will display an higher value than the real one if the Sense HAT is directly connected to the GPIO connector of the Raspberry Pi.
For example, in my lab, the temperature is around 20°C and the temperature sensor value is around 30°C…
This wrong value is caused by the heat produced by the Raspberry Pi board. To fix this issue, I separated the Sense HAT from the RPi with cables (40-pin connector + 40-pin male-male 300mm jumper):
With that patch, the temperature is correct.