MagTag Page


Home                               Craigs Pages                               Heathers Pages

Mar 2023

I bought a MagTag device from Adafruit.com awhile back and never did anything with it. As I was looking through my parts bin the other day I came across it and decided it was time for a new project. I saw that Adafruit had a weather station project for this device and I thought that was pretty cool except it was written in Python. I have nothing against Python except that there are so many libraries available for doing just about anything you would ever want to do, I never learn new things if I always use Python libraries and code that other people wrote. And of course my language of choice is Forth and more specifically my version of ESP32Forth.

So I decided to write my own weather station in ESP32Forth and learn about ePaper displays along the way. I have written many device drivers for LCD type displays (in ESP32Forth) but a driver for an ePaper was a whole new ball game. After studying the data sheet for the display controller used in the MagTag and Googling device drivers for ePaper displays, I wrote a basic monochrome driver. I then decided I needed at least 4 shades of gray to be able to display weather icons accurately. It took me an additional 2 weeks to come up with a working, reliable gray scale device driver. I call this driver IL0373_GRAY.fth because the IL0373 is the display controller chip used in the MagTag. The monochrome or black and white driver is called IL0373_BW.fth. I should note that neither of these device drivers supports partial display updates as I didn't need that functionality for this project.

Of course there is more to a weather station than the display. I also had to write some networking code to get the time using NTP and to access weather data available from Open Weather Map. To complicate things further I had to use a Json parser I had previously
written to extract pertinent data from the returned streams of weather data. In fact, I had to retrieve both the current conditions weather data (displayed on the left side of the screen in the image below) and the 5 day forecast data for presentation on the right side of the screen.

I should also note that the Future data shown on the right side of the ePaper display shows the conditions at noon on the specified day. Also, if the future temperature gets above 99 degrees, the display indicates HOT instead of the actual temperature. Similarly, if the temperature is less than 0 degrees, the display indicates BRR.
 
Because I wanted to run this weather station on a battery I had to design the code to save as much power as possible. To this end, I structured the code such that the weather station wakes up from a deep sleep every one half hour and:

1. Accesses an NTP server for the current time
2. Connects to Open Weather Map and gets the current conditions data
3. Connects again to Open Weather Map and gets the 5 day forecast data
4. Parses the returned Json data and formats it for display
5. Writes the formatted data to the display
6. Goes back into a deep sleep

It will be interesting to see how long a battery lasts between charges using this approach.

Picture
Description

Here is the MagTag weather station in action. In this image the MagTag device is mounted on a 3D printed base which I downloaded from Adafruit. Eventually I plan to buy the magnetic feet so I can attach this device to my refrigerator.

None of the NeoPixels or switches on the MagTag are used in this application.

Click here to view my ESP32Forth development tree/workspace which contains code for this project along with a bunch of other ESP32Forth projects.

 
Questions and comments to me Craig at: calhjh@gmail.com


Home                               Craigs Pages                               Heathers Pages