Raspberry Pi Desktop Weather Display Using OpenWeatherMap and PyGame
by SwordfishEngineering in Circuits > Raspberry Pi
174 Views, 4 Favorites, 0 Comments
Raspberry Pi Desktop Weather Display Using OpenWeatherMap and PyGame
I've wanted to create a desktop weather display for some time, so I decided to use my (limited) knowledge of PyGame to build a simple one that still looks pretty good.
Supplies
- Raspberry Pi 3b
- 7" 800x480 Screen
- Short HDMI Cable
- Keyboard & Mouse
- (optional) 3D Printer
Setup OpenWeatherMap API
The first thing we need to do is get an API key from OpenWeatherMap.
NOTE: It can take around 24 hours from signing up with OpenWeatherMap to activate an API key.
All you need to do is sign up or login to here. Once you're logged in, go to the "API Keys" tab to view your key, which will be a long string of letters and numbers. Keep this key in mind for the future when we get to the Python program.
Setup Your Raspberry Pi
Download the latest Raspberry Pi OS to your Raspberry Pi. Here's a good tutorial on how to setup your Raspberry Pi. I used a Raspberry Pi 3b, but you can probably utilize any Raspberry Pi you desire. You will need an internet connection to communicate with the API.
(Optional) Build Screen Stand
My 7" screen came with a simple little stand, but I still decided to design and 3d print a stand for myself. You can utilize any screen holder you desire, all that matters is that you're able to connect the screen to the Raspberry Pi.
If you do utilize my stand, you will need a 3mm screw set with nuts. Also, I accidentally designed my stand upside down, so follow this tutorial to flip the display if necessary.
Connect Raspberry Pi to Screen and Download Icons
Once your Raspberry Pi is set up, hook it up to your screen, a mouse, and a keyboard. Once your Pi is booted up, download these files here. These are your weather icons, which were taken from OpenWeatherMap's API Documentation.
Download Python File
Now that you have your Raspberry Pi and icons all setup, now is time to download and setup the attached python file. If you're familiar with python and pygame, the program might look un-optimized, and I do apologize for that, I'm somewhat limited in my python knowledge.
NOTE: Make sure all the icons and the python file are in the same folder (i.e. Downloads).
Before you run the program, open up the python file. At the top, you'll see a variable called api_key. Delete its string and copy and paste your API Key that we got in Step 1 into the quotation marks. You will also see a variable called city_name. Type the location you want weather from into that variable.
One last thing you might want to do: there's a ticker in the program called "time", which is used to update the weather every 10-15 minutes. My Raspberry Pi 3b is a little slow with the program running, so I have the variable set to reset at 10000, which equates to around 11 minutes for me. However, if you're able to get the full 60 fps, you'll want to change that variable to reset at 54000. You can find and change this number on line 237.
Downloads
Run and Enjoy
Once you setup the python file, you can now run it! If you do need to close the program, click on the program with your mouse and hit the 'X' key on your keyboard.
(Advanced) Things You Can Do
You can find a way to hide the mouse while it's not being used.
You can change the type of weather information being shown in each block.
If you do have a higher resolution display, you'd have to change the positioning of some of the texts and lines.
There's many different things you can do with this program, this is just a good foundation to start on!