Skip to content

Instructions on setting up a Raspberry Pi Zero WH with a Waveshare ePaper 7.5 Inch HAT. Date/Time, Weather, Google/Outlook Calendar

Notifications You must be signed in to change notification settings

Maginius/waveshare-epaper-display

 
 

Repository files navigation

Instructions on setting up a Raspberry Pi Zero WH with a Waveshare ePaper 7.5 Inch HAT. The screen will display date, time, weather icon with high and low, and calendar entries.

example

Shopping list

Waveshare 7.5 inch epaper display HAT 640x384
Raspberry Pi Zero WH (presoldered header)
microSDHC card

Setup the PI

Prepare the Pi

I've got a separate post for this, prepare the Raspberry Pi with WiFi and SSH. Once the Pi is set up, and you can access it, come back here.

Connect the display

Turn the Pi off, then put the HAT on top of the Pi's GPIO pins.

Connect the ribbon from the epaper display to the extension. To do this you will need to lift the black latch at the back of the connector, insert the ribbon slowly, then push the latch down. Now turn the Pi back on.

Setup dependencies

sudo apt update && sudo apt upgrade  
sudo apt install git gsfonts python3 python3-pip cairosvg pigpio python3-pigpio  
sudo pip3 install python-dateutil astral spidev RPi.GPIO Pillow google-api-python-client google-auth-httplib2 google-auth-oauthlib msal cryptography==36.0.0
sudo sed -i s/#dtparam=spi=on/dtparam=spi=on/ /boot/config.txt  #This enables SPI
sudo reboot

Using this application

Clone it

git clone this repository in the /home/pi directory.

cd ~
git clone --recursive https://github.com/mendhak/waveshare-epaper-display.git

This should create a /home/pi/waveshare-epaper-display directory.

Waveshare version

Copy env.sh.sample (example environment variables) to env.sh

Modify the env.sh file and set the version of your Waveshare 7.5" e-Paper Module (newer ones are version 2)

export WAVESHARE_EPD75_VERSION=2

Pick a Weather provider

You can pick between OpenWeatherMap, Met Office, AccuWeather, Met.no and Climacell to provide temperature and weather forecasts.
You can switch between them too, by providing the keys and commenting out other ones, but remember to delete the weather-cache.json if you switch weather providers.

OpenWeatherMap

Register on the OpenWeathermap website, and go to the API Keys page, that's the key you'll need. Add it to the env.sh file.

export OPENWEATHERMAP_APIKEY=xxxxxx

Met Office (UK)

Create an account on the Met Office Weather DataHub site.
Next, register an application - just call it Raspberry Pi or Home Project.
You'll be shown a Client Secret, and a Client ID. Copy both of these somewhere, you'll need it later.

After registering an application, you then "subscribe" to an API by going to the API Usage Plans.
Pick "Global spot data bundle" which includes the "Global daily spot data" API. Choose the Basic (free) plan and when prompted, pick that application you previously registered.

Finally, add the Met Office Client ID and Secret to the env.sh file.

export METOFFICEDATAHUB_CLIENT_ID=xxxxxx-xxxxxx-....
export METOFFICEDATAHUB_CLIENT_SECRET=xxxxxx

AccuWeather

Register on the AccuWeather site.
Next, register a new application.
I just named it Personal, marked it as Limited Trial, Internal App, Business to Consumer. Once you do this you'll get an API Key, save it.

You'll also need an AccuWeather Location Key.
Do a normal AccuWeather search for your location.
The last number in the URL is the Location Key. In the example of London, it's 328328.

Add the API Key and Location Key to the env.sh.

export ACCUWEATHER_APIKEY=xxxxxx
export ACCUWEATHER_LOCATIONKEY=328328

Met.no

Met.no's Terms of Service requires you to identify yourself. The purpose is to ensure they can contact you in case you overload or abuse their servers. For this reason, you just need to set your email address in env.sh like so:

Note that the Met.no API provides 6 hours of forecast, rather than a full day.

Climacell (tomorrow.io)

Register on the Climacell site, and when you do you should be given an API Key.
Modify the env.sh file and put your Climacell API key in there.

export CLIMACELL_APIKEY=xxxxxx

Location information for Weather

Whichever weather provider you've picked, you'll need to provide the location and units to display in.

Modify the env.sh file and update with the latitude and longitude of your location.
As needed, change the temperature format (CELSIUS or FAHRENHEIT).

export WEATHER_LATITUDE=51.3656
export WEATHER_LONGITUDE=0.1963
export WEATHER_FORMAT=CELSIUS

Pick a Calendar provider

You can use Google Calendar or Outlook Calendar to display events.

Google Calendar setup

The script will by default get its info from your primary Google Calendar. If you need to pick a specific calendar you will need its ID. To get its ID, open up Google Calendar and go to the settings for your preferred calendar. Under the 'Integrate Calendar' section you will see a Calendar ID which looks like [email protected]. Set that value in env.sh

Google Calendar token

The Oauth process needs to complete once manually in order to allow the Python code to then continuously query Google Calendar for information.

Go to the Google Cloud Platform library page, search for and enable the Calendar API.

Next, head over to the API Dashboard Credentials page, and create new credentials of type "OAuth Client ID". For application type, choose "Desktop app" and give it a name such as "Epaper Display". When presented, download or copy the credentials.json file and add it to this directory.

You can now kick off the authentication process. On the Raspberry Pi, run:

python3 screen-calendar-get.py

The script will prompt you to visit a URL in your browser and then wait. Copy the URL, open it in a browser and you will go through the login process. When the OAuth workflow tries to redirect back (and fails), copy the URL it was trying to go to (eg: http://localhost:8080/...) and in another SSH session with the Raspberry Pi,

curl "http://localhost:8080/..." 

On the first screen you should see the auth flow complete, and a new token.pickle file appears. The Python script should now be able to run in the future without prompting required.

I also have a post here with screenshots walking through the process.

Outlook Calendar

The setup is much simpler, just run this script which will give instructions on how to login:

python3 outlook_util.py

Login with the Microsoft account you want to get the calendar from, and accept the consent screen.
After a moment, the script will then display a set of Calendar IDs and some sample events from those Calendars.
Copy the ID of the calendar you want, and add it to env.sh like so:

export OUTLOOK_CALENDAR_ID=AQMkAxyz...

Note that if you set an Outlook Calendar ID, the Google Calendar will be ignored.

Run it

Run ./run.sh which should query the weather provider and Google/Outlook Calendar. It will then create a png, convert to a 1-bit black and white bmp, then display the bmp on screen.

Using a 1-bit, low grade BMP is what allows the screen to refresh relatively quickly. Calling the BCM code to do it takes about 6 seconds. Rendering a high quality PNG or JPG and rendering to screen with Python takes about 35 seconds.

Automate it

Once you've proven that the run works, and an image is sent to your epaper display, you can automate it by setting up a cronjob.

crontab -e

Add this entry so it runs every minute:

* * * * * cd /home/pi/waveshare-epaper-display && bash run.sh > run.log 2>&1

This will cause the script to run every minute, and write the output as well as errors to the run.log file.

Troubleshooting

If the scripts don't work at all, try going through the Waveshare sample code linked below - if you can get those working, this script should work for you too.

You may want to further troubleshoot if you're seeing or not seeing something expected.
If you've set up the cron job as shown above, a run.log file will appear which contains some info and errors.
If there isn't enough information in there, you can set export LOG_LEVEL=DEBUG in the env.sh and the run.log will contain even more information.

The scripts cache the calendar and weather information, to avoid hitting weather API rate limits.
If you want to force a weather update, you can delete the weather-cache.json.
If you want to force a calendar update, you can delete the calendar.pickle or outlookcalendar.pickle.
If you want to force a re-login to Google or Outlook, delete the token.pickle or outlooktoken.bin.

Waveshare documentation and sample code

Waveshare have a user manual which you can get to from their Wiki

The Waveshare demo repo is here. Assuming all dependencies are installed, these demos should work.

git clone https://github.com/waveshare/e-Paper
cd e-Paper

This is the best place to start for troubleshooting - try to make sure the examples given in their repo works for you.

Readme for the C demo

Readme for the Python demo

About

Instructions on setting up a Raspberry Pi Zero WH with a Waveshare ePaper 7.5 Inch HAT. Date/Time, Weather, Google/Outlook Calendar

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.0%
  • Shell 1.0%