How it Works

WIth the AirLift coprocessor board, this Metro M4 Express is going places! Well, at least for this sketch, it is going to get your local weather and display it on the ePaper shield.  There are a number of sites with weather APIs that can get your local area's current conditions and upcoming forecast. A smaller number of these sites offer this data for free for non-commercial purposes. We went with the OpenWeatherMap.com API, which offers free weather data for current conditions and forecasts.

For weather and moon icons, we are taking advantage of the Adafruit GFX Library's support for custom fonts. A font is ideal for this type of display, as we need simple, line drawn icons in different point sizes that look nice on a monochrome ePaper display. For weather icons, we chose the Meteocon font set, a free font containing over 40 weather icons. For the moon phase font, we went with the Moon Phases font by Curtis Clark, which is free for non-commercial use. The font files need to be converted for use with the GFX Library, but don't worry, we have done that already in various point sizes so you can use these fonts for this and other projects.

Speaking of moon phases, the OpenWeatherMap does not include moon phases in their API. That is not a problem, however, as we used math to calculate the current moon phase. We know there is, on average, a new moon every 29.5305882 days. Grabbing the current date and time from OpenWeatherMap, and if we have a known point in time when a new moon occurred, we can calculate the moon phase for the current date.

The weather data from OpenWeatherMap includes the current time and times of future forecasts, like the weather forecast 3 hours from now. This time is in UTC format. We need to convert it to local time so the times will display accurately. Fortunately, OpenWeatherMap recently added the local timezone offset to the data (actually, as we were writing this guide!) so the local time can now be easily determined by taking the current time in UTC and adding the local timezone offset.

adafruit_metro_meteoicons.png
The Meteoicon Font contains over 40 weather related fonts.

The next step is to put it all together: getting the weather data and formatting the display. We modified a portion of the code from the excellent Weather Station Project by Daniel Eichhorn so it was not exclusive for any particular microcontroller. This allows other processors, including the Airlift coprocessor, to retrieve the weather data from the Internet.

This guide was first published on Jun 12, 2019. It was last updated on Jun 12, 2019. This page (How it Works) was last updated on Jul 16, 2019.