- the code has been updated ( 15 jan 2022) due to some bugs in the previous version (epd library was containing somes problems). It's now working fine.
- GITHUB ADDED
This project :
- Call a weather and news API to get information
- Parse the incoming JSON to use it later
- Create a GUI thanks to PILLOW (suggest method by screen manufacturer)
- Print it on a 7.5" e paper display
2021-01-21 : few bugs correction, added debug mode, added file saving and restoring for past pressure and temperature values
Goal of the projetThe idea behind was to discover and use API but also getting a nice weather station with the info I wanted plus the top news to stay update.
Nota : as a french guy, you will find some french in the code (labels, specified language for api)
HardwareAs the main idea was to have a nice display which consumed few power so I chose to get a e-paper from waveshare which is not expensive and seems to be some good quality. Also you easily find examples of use on the internet which ease the use. To enhance a bit the display the screen is a three color one.
So the display is a 7.5inch e paper :
- Resolution : 800x480px
- 3 colors : white, black, red
- Screen size : 163.2 × 97.92mm x ~2mm (It's soooo thin!)
- Total size : 170.2 × 111.2mm
To run the code I chose a Raspberry pi zero W. I think an arduino would be sufficient but I might use the raspberry for something else (as a wifi relay). The raspberry is very economic solution, easy to set.
To make the final project pretty I enclosed it in a wooden photo frame. The result is satisfying in my opinion. The Rpi and Waveshare hat taped (double side) on the frame.
The code is written with PYTHON 3.8.
It uses the following libraries:
- requests
- json
- PIL
- textwrap
Sure that the code can be enhanced but it works this way.
Future enhancement : make the display more parametric
IMPORTANT NOTE : YOU WILL NEED .PY FILES PROVIDED BY WAVESHARE TO MAKE IT WORK WITH ePAPER SCREEN (epd7in5b_V2.py & epdconfig.py), YOU WILL FIND THEM HERE
<WAVESHARE GIT>
The code is launch at boot thanks to crontab :
crontab -e
@reboot bash /path/launcher.sh
launcher.sh :
#!/usr/bin/bash
cd /path_to_main.py
python3 main.py
WeatherThe weather informations are download from OPEN WEATHER MAP. It is quite easy to make it work and free up to 60calls/minute (I make 1 a hour).
To reduce the number of call, I chose the "One call" API. You get current weather, rain forecast for the next hour, hourly forecast for 48h and daily forecast up to 7 days.
The following are the selected value for the station :
- Current temperature
- Current humidity
- Current Wind speed and orientation (convert degrees to "compass")
- Current Weather icon
- Rain forecast for the next hour (per 10min intervals)
- Hourly forecast for +3h, +6h, +12h printing temperature, probability of precipitation and icon
- Daily forecast up to 4 days, printing, icon, min and max temperature and probability of rain
- Historical values of pressure and temperature for the 6 passed days (graph) (updated once a day)
I chose to use NEWS API to get the last top news. It is simple to use and free up to 100 calls/day (I make 24).
To get a "global" view I chose googlenews as a source (in french). I select the last 5 top news and just print the 120 first characters (sufficient most of the time).
UNDER DEVELOPPEMENT : POLLUTION & ALERTSOpenWeatherMaps also provides weather alert (snow, wind,...) and pollution data. I currently download and parse these data but not use them. As a future improvement I will replace part of the news by a pollution or weather alert if there is one.
DisplayThe ePaper used is the "7.5inch e-Paper HAT (B)" from Waveshare.
It 800x480px.
It is quite easy to use : create your interface thanks to pillow librairy and load it to the screen. The documentation provided by the manufacturer makes it easily understandable.
I'm sure Pillow can be replaced by another way to create a 800x480 array
You will find all you need here : WAVESHARE WIKI LINK
Conclusion (absolutely not objective)I'm pretty happy with the result. It's prettier than many commercial weather station. As I'm running a Pi Zero for that I think I will find it another utility at the same time.
Feel free to reproduce it and share the result :) It's not totally straight forward but I must have provided all the information you need to make it work.
Comments