Raspberry Pi Weather Station Using Sense HAT and Python 3

I’m revisiting one of the first python projects that I started working on almost a year ago. I’ve learned a lot since that post and decided it was time to rewrite the original script in Python 3.

This project uses a Raspberry Pi and Sense HAT

I started out trying to modify my old scripts that were written in Python 2 and trying to write them in Python 3. After some tinkering around and tweaking of the code I decided to start fresh and try to write my code in a more modular form.

In this project 2 Python files are executed

weather.py

web_app.py

weather.py gets data from the sensors of the sense HAT and displays them on the 8×8 LED matrix. Depending on the temperature taken the LED screen background color changes lines 20-36 (Since the Sense HAT is placed directly atop the pi, the temperature’s are affected by the CPU temp of the pi). It then logs the data taken by the sensors. The next part of the script sets the orientation of the LED matrix by reading the acceleration data. Finally it prints the data taken to the LED matrix.

web_app.py takes the same data as weather.py but instead of displaying it on the LED matrix it creates a web server and displays it via the web using flask.

weather.html

weather.html is used with web_app.py to display Sense HAT data on port 5000 of the raspberry pi

I would like to add the ability to setup email alerts using the web interface. I currently have an email module setup to send emails, I just need to figure out how to set the alerts using the web interface.

Rewriting this script was very rewarding and I learned a lot along the way. I learned how to properly setup a requirements file and use flask. This blog post was very helpful in learning how to package Python. This project has been a lot of fun and I will continue to work on it and improve it.