FILENAME: README.md
This code uses a Raspberry Pi Zero W to query the Open Weather Maps API, retrieve the current weather data for a location specified by the user, formats the response, and then displays it on a PaPiRus eInk display.
This code was based on code taken from a tutorial on the Adafruit website. The original code was written to work with an Adafruit eInk display. This version was modified to work with a 2.0" (200x96) PaPiRus eInk display attached to a Raspberry Pi Zero W.
ID | FILENAME | DESCRIPTION |
---|---|---|
1 | README.md | This README file. |
2 | weather.py | Contains the primary code to be edited and called by the user. |
3 | weather_graphics.py | Contains the primary driver display code. Generally, the user should not need to edit this code. |
4 | DejaVuSans.ttf DejaVuSans.ttf DejaVuSans.ttf DejaVuSans-Bold.ttf |
Display Fonts - All of these will be located in /usr/share/fonts/truetype/dejavu/ |
5 | ./meteocons.ttf |
Weather icons |
Prior to running this code, you will need to install the PaPiRus eInk API. The full documentation for this API is available via https://github.com/PiSupply/PaPiRus. However, if you want to try to do the quick install of the API, try running the following command and make sure that it completes with no errors:
curl -sSL https://pisupp.ly/papiruscode | sudo bash
See https://www.alessioatzeni.com/meteocons/ for icons
curl --remote-name https://www.alessioatzeni.com/meteocons/res/download/meteocons-icons.zip && unzip meteocons-icons.zip
curl --remote-name https://www.alessioatzeni.com/meteocons/res/download/meteocons-font.zip && unzip meteocons-font.zip
cp ./meteocons-font/FONT/Desktop-font/meteocons.ttf ./
ITEM | NOTES |
---|---|
PaPiRus eInk Display |
For this project, I used the 2" display, which has a resolution of 200x96 pixels. Although I used dynamic variables that queried the display width and height, the actual display code will likely need to be modified if a different sized screen is used, especially if it is smaller than 2". |
Raspberry Pi Zero W |
Option 1 - (with header pins installed) This model, which was the one used for this project, has the header pins installed. The base model Pi Zero W could be used, but only after the header pins have been installed. Option 2 - Base model - no pre-installed header pins To use this model, header pins will need to be installed first. |
PaPiRus Github Repo | Contains installation instructions and sample code for the API. |
Call python3 weather.py
at the command line.
Be sure that the Python interpreter can find the font files called in weather_graphics.py
. The best way to ensure the font files are available is to specify the full path name.
For system fonts, specifying a fixed path is not a problem. However, for specialized fonts, such as meteocons.ttf, the easiest way to guarantee they are found is to place the font file in the same folders as weather.py
& weather_graphics.py
, and issue the call to the Python interpreter as follows:
cd /INSERT-CORRECT-PATH-NAME-HERE/ && python3 weather.py
At the command line, run the following command to start the crontab file editor. If you have not run it previously, you will be asked to select your text editor. If you are unsure of which one to use, select the nano
option.
crontab -e
Add the following lines of code. This code will run the weather update code every 15 minutes during the hours of 7 AM - 10 PM. However, during the hours of 11 PM - 6 AM, it will only run the code every hour. You can change these times to suit your own preferences.
# min hr dom mon dow command
00,15,30,45 7-22 * * * cd /home/pi/projects/PaPiRus/WeatherStation/python/ && python3 weather.py
00 0-6 * * * cd /home/pi/projects/PaPiRus/WeatherStation/python/ && python3 weather.py
00 23 * * * cd /home/pi/projects/PaPiRus/WeatherStation/python/ && python3 weather.py
Here are the biggest changes between this code and the original code in the Adafruit tutorial.
- The original code was written for an Adafruit branded eInk bonnet. This code was written for the PaPiRus eInk display.
- The original code contained a
while
loop inweather.py
. For this code, I chose to get rid of thewhile
loop and use acron
job to update the display periodically. I made this decision because- the
cron
daemon is perfectly suited for tasks that run at scheduled intervals, and - the
cron
approach will be easier and more robust. - With the original code, a user would need to explicitly run the code after every reboot. Additionally, after manually running the code, the user would need to either
- stay logged in permanently, which will fail as soon as their terminal connection is broken, or
- the user would need to install a package like
screen
, which can continue to run jobs even if a user's terminal connection is broken.
- By using cron, all of the aforementioned problems are obviated.
- the
- I added a smaller font (tiny_font), which allowed me to add some additional weather elements to the screen, specifically, the day and date, the seconds to the time, and the relative humidity.
- I believe there is enough screen real estate to be able to display the
feels_like
data, which the code does retrieve and stores. - However, I don't display it because the current displayed items would need to be repositioned in an optimal way. That task will be done in a future update.
- I believe there is enough screen real estate to be able to display the
Hi @Gassolo:
So long as
you should be able to start with my code base and then make the necessary modifications without too much trouble.
My recommendation is to contact the vendor and ask them for sample code. In the page that you linked for me, they state they are happy to provide it. Then, once you have the sample code, compare their sample code with the code base for the PaPiRus display that I used, which is available at https://github.com/PiSupply/PaPiRus.
So long as they have corresponding functionality, then I think you'll see that modifying my code to work with their display won't be too difficult. The obvious places where you'll need to make changes to my code are line 36 in weather.py and line 23 in weather_graphics.py. Instead of importing the
Papirus
module, you'd be importing whatever module the vendor for the other screen has specified.You'll also need to modify line 62 in weather.py.
You will almost certainly have to make some other tweaks to the code in weather_graphics.py, but, the required changes should be very obvious once you understand how to use the API for your vendor's eInk screen to write text and graphics to the screen.
Good luck, and let me know if I can help!