Simple Weather Display Using Raspberry PI and Cyntech WeatherHAT

Introduction: Simple Weather Display Using Raspberry PI and Cyntech WeatherHAT

About: I am a Ham Radio operator, computer geek, currently a service tech, robotic hobbyist. I've been "playing" with microcontrolers for the last several years, basic stamps, arduinos, and arduino like co…

* In 2019 Yahoo changed it's API, and this stopped working. I was unaware of the change. In September of 2020 this project has been updated to use the OPENWEATHERMAP API See the updated section below, the rest of this information is still good however. Thanks for looking, and thanks for letting me know about the Yahoo change. *

Recently I acquired a Cyntech WeatherHAT, but I was a little disappointed with the lack of software for it.

The HAT it's self appears to be well constructed, with 6 blue LEDs in the form of rain drops, 6 orange LEDs in the form of a thunder-bolt, 6 white LEDs in the form of a cloud. 1 (What I believe is a RGB LED) for the SUN - it displays orange (so I might be wrong about it being a RGB). And 6 WS2812 LEDs (These are RGB :-))

Cyntech does have a getting-started guide, and even that is good - it's easy to install and use the HAT.

So I was just surprised to not really see any software (other then the demo provided by Cyntech). I was equally surprise to not find anyone really using this - Maybe people want a "fancy" display with temperatures, and all that kind of information. For me it's nice to just look up at a few LEDs and know - it's Raining, or Thunderstorm, or Cloudy - At that point if I need more information I can look at my tablet or phone. :-)

A little more - this is really my first time using python, I'm by no means good at it. And I'm sure that people who really know python will tell me better way to do this.

Let's get started:

We need a SD card (at least 8gb)

A Raspberry PI (I'm using a Zero W) it needs to have internet access.

and we need the Cyntech weatherHAT https://shop.cyntech.co.uk/products/weatherhat

If you use a Raspberry PI Zero W you will need to also be able to solder a set of headers to the board.

Otherwise the skills needed are the ability to use software and setup the SD card.

Step 1: Set the SD Card and Raspberry PI

You will need to download the latest Raspbian (at the time of this instructable that is Raspbian Stretch March 2018 (2018-03-13))

https://www.raspberrypi.org/downloads/raspbian/

I used the desktop edition, even thou I am running my setup headless, and doing most things from the CLI (command line interface) over ssh.

Follow the setup guide found here:

https://www.raspberrypi.org/documentation/installa...

After Etcher is done, remove the SD card, and reinsert it into the computer.

* You really only need to do this step below if you plan on doing a headless install

We need to setup SSH and WIFI before we use the SD card in the Raspberry PI. In the BOOT partition of the card, create a file named "ssh" without the quotes. nothing has to be in the that file. When the PI boots it will see that file, and turn on SSH.

We also need to create a file called "wpa_supplicant.conf". We need to edit this file with your wifi settings.

It should looks something like this:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1


network={

	ssid="yourwifiSSID"

	psk="yourwifipassword"

	scan_ssid=1
}

* You really only need to do this if you plan on doing a headless install


Once that is done, safely remove the SD card and put in the Raspberry PI (make sure there is no power on the PI).

Attach the weatherHAT, and power on the Raspberry PI.

Step 2: Setup the WeatherHAT Libraries

For this step we will be following the Getting Started Guide found

http://guides.cyntech.co.uk/weatherhat/getting-sta...

IF you are doing a headless install you'll want to ssh pi@raspberrypi.local

If you don't have a ssh client - PUTTY is a good one. https://www.chiark.greenend.org.uk/~sgtatham/putty...

If you are using a keyboard and monitor - the guide above is a good one to follow, it starts you at a GUI desktop.

The important steps here are to install the WS281x library and the WeatherHAT libraries, along with the dependence for each.

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install build-essential python-dev git scons swig python-smbus
git clone <a href="https://github.com/jgarff/rpi_ws281x.git" rel="nofollow">  https://github.com/jgarff/rpi_ws281x.git
>
git clone <a href="https://github.com/CyntechUK/WeatherHAT.git" rel="nofollow">  https://github.com/jgarff/rpi_ws281x.git
>
cd rpi_ws281x
scons
cd python
sudo python setup.py install

Now we need to make sure I2C is turned on.

sudo raspi-config

The guide is written for a older version of raspi-config and says to goto "Advanced Options" which has been replaced by I believe "Interfaces"

Once you turn on I2C you'll have to reboot.

Now it's time to test the HAT

cd WeatherHAT
sudo python cycle.py

If everything went well you should see all the features and a rainbow.

ctrl-z will stop the program.

*Special Notes: I learned that the timings of the Raspberry PI 3 are different and the rainbow may not work correctly. IF you have this issue here is how to fix it.

https://github.com/CyntechUK/WeatherHAT/issues/3

http://guides.cyntech.co.uk/raspberry-pi/assemblin...

Once everything is working, we can continue to the next step.

Update: (Oct 6, 2020) This repository now contains my getWeather.py script, this is great news, as interest has sparked again, and new things are bound to happen.

Step 3: Installing Weather-api and GetWeather Script

So, I put in a PULL request to CyntechUK for my script - hopefully they will accept the request, and you can skip download my repository. (they may not want to include my code thou)

(Oct 6, 2020) The PULL request was approved, my getWeather script is now included in the Weatherhat repository.

*********You can still use this information if you like, however getWeather.py has been included in the weatherhat repository now ************************************

My respository can be found here:

https://github.com/kd8bxp/WeatherHAT/tree/getWeath...

and my script is called getWeather.py

IF they do accept the pull request you'll already have this script - if not you'll need to clone the repository.

in your home directory (/home/pi) type:

git clone <a href="https://github.com/kd8bxp/WeatherHAT.git"> <a href="https://github.com/kd8bxp/WeatherHAT.git" rel="nofollow"> <a href="https://github.com/kd8bxp/WeatherHAT.git" rel="nofollow">  https://github.com/kd8bxp/WeatherHAT.git  </a> </a> </a> getWeather

this will clone the repository into a directory called getWeather, next we need to checkout the getWeather branch.

cd getWeather
git checkout getWeather

**********************************************************************

You will need to cd into the weatherHAT directory that was cloned earlier and

We need to edit the getWeather.py script for your location.

nano getWeather.py

You should see a line that starts with

location and ends with lookup(45042) - This is my zip code, I've found that it doesn't work as well as you'd think

and the line right above it that is commented out works better with a city name. That is the one that you probably want to use. So Comment the zip code line (#) and uncomment and change your city name.

*********** OLD YAHOO INFORMATION - No Longer required ***********

We need to install one more library for this to work, weather-api which is a wrapper for the Yahoo weather API.

https://pypi.python.org/pypi/weather-api/0.0.5

The install is easy -

pip install weather-api

***********************************************************************************

Now we can run the script:

sudo python getWeather.py &

The & will let the script run in the background. The script sleeps for about 5 minutes, and then checks Yahoo Weather if something has changed - if so it updates the display. The 5 minute time can be changed, it's near the bottom of the script.

sleep(60 * 5)

You could set up a crontab job (remember this needs to be run as root) that will start the script at each boot.

use:

sudo crontab -e

enter:

@reboot python /home/pi/weatherHAT/getWeather.py

I think that should work - I've not setup cron yet on my system.

That's pretty much it -

As I stated this is one of my first python programs, and I'm sure someone who know more will see a better way to do this.

I've only done limited tested on this - I have seen "Snow" "Rain" and "Thunderstorm" work so far,

There are some conditions that I'm not sure how to handle yet - I welcome ideas.

Step 4: Updated Information For: Openweathermap API

In Sept of 2020, I updated the script to use the https://openweathermap.org API.

NOTE: This was a "quick" fix for me, and limited tested - (It's been overcast for the past few days, and all I see is the cloud and rain display) - While I believe I caught all the conditions that are easy to display, it's possable that I missed a couple because of how "quick" this fix was done. That being said, if you think there is a problem please leave a comment and time permitting I'll look into it - or try to point you in the right direction. *

You will need to sign up for an API key using the link above, when you edit the script to place your city, you'll see a place for the key. Just copy and paste it, and you should be good.

Other notes:

This script now uses the "Current weather data API" information about that API can be found here:

https://openweathermap.org/current One thing to note is you can use a city, state, and country.

IE: the city "Dayton" becomes "Dayton, OH, US" notice how the state and the country codes are both uppercase, this is required. The API says it can use just "Dayton, OH" but I got errors from the script when I did this - and since this was a quick fix, I haven't looked into why. SO, I recommend using the "city, state, country"

IF for some reason you don't get good information using a city name, you can also lookup the City ID, or use latitude and longitude or the zip code. In each case the URL will need to be changed, if you click on the link on the right hand side of the API website, it will give an example of what the URL should be.

You need to change the URL in the script as well.

Even more notes: Oct 3, 2020

@Itsmedoofer pointed out that they needed to install the library python-requests with the new update. I'm not sure that I did need this, (it's also possible that I had it installed from years ago, or different versions of python install different libraries by default). So if the script gives an error about python-requests it's simple to fix.

type this command into the CLI: python -m pip install requests

and you should be good.

Hopefully this makes since, this was a quick fix, and maybe one day time permitting I can work on cleaning it up a bit better.

Update (Oct 6, 2020) The github pull request was accepted, the original CyntechUK original repository now includes this script. https://github.com/CyntechUK/WeatherHAT The user Boeerb has some ideas on how to display some of the conditions that are currently not displayed, as well as some other ideas for use. So keep an eye on that repository. And hopefully things will be happening.

Update: (Oct 8, 2020) Open Weather Map has a short tutorial on setting up and using the API, https://openweathermap.org/appid A good place to start.

*Thanks for the users below in the comments that pointed out this wasn't working*

Microcontroller Contest

Participated in the
Microcontroller Contest

Pocket-Sized Contest

Participated in the
Pocket-Sized Contest

Be the First to Share

    Recommendations

    • Make it Fly Challenge

      Make it Fly Challenge
    • Maps Challenge

      Maps Challenge
    • DIY Summer Camp Contest

      DIY Summer Camp Contest

    33 Comments

    0
    Itsmedoofer
    Itsmedoofer

    9 months ago

    Hi,

    This project has really inspired me !

    I've extended the functionality a little by adding a little OLED display, giving some data that wouldn't be possible with just the HAT on it's own, when I've finished I'll do my first Instructable :-)

    20201015_133219.jpg
    0
    kd8bxp
    kd8bxp

    Reply 9 months ago

    This looks great, I think some type of display is what is missing on this HAT - now just need a nice 3D printed case, and your all set. :-)

    I worked on a ISS display using just the HAT - https://github.com/kd8bxp/WeatherHAT/tree/iss
    Of course if you look at the original ESP8266/ESP32 project, there is more information that can be displayed as well, so it should be easy enough to port the entire ESP32 ISS display project over (easy is relative of course) - but I did use that project as the base to start on displaying iss on this HAT :-) every thing has to start from somewhere.
    (If you have the script set to autostart, you need to sudo killall python before you try the iss.py script, otherwise you may run into problems.)

    You may also want to submit a pull request into the original project once you get your instructable done - I'm sure with the renewed interest in this project the original creator would like to see it as well.


    0
    Itsmedoofer
    Itsmedoofer

    Reply 9 months ago

    haha, well I am a mechanical design engineer with 3D CAD and access to a 3D printer so there's not a lot of excuses there other than it's a bit too close to my day job to be interesting ;-) I've just finished playing with the display code to get it to scroll so the project is finished for me with the exception of a case ;-)

    It will be interesting to see if Cyntech do finish off the code improvements for the hat. I was thinking of reworking the weather script again (for my own learning benefit) to use the python openweathermap API, however I kind of like it how it is, I think it's better for learning and easier to adapt for other uses the way it is. I may do a fork that uses forecast data, say for the next 24 hours for that I would probably use the python API...

    I'll have a look at your ISS work later, sounds really interesting, I have an app on my phone that gives pass times, I do occasionally go out and look up :-)

    I did raise a pull request for the modifications I done to your script, the guy declined it though because he was working on other mods to it, I have it in my own repository though so people can find it if it goes stale again...

    1
    ajsorchard
    ajsorchard

    11 months ago on Step 3

    Hi, Just tried making this (August 2020) and found the Weather API from Yahoo has completely changed. Have you any ideas on how to integrate with the new API (which has also reached its end of life) please? Thanks for the Instructable!!

    0
    kd8bxp
    kd8bxp

    Reply 9 months ago

    @Itsmedoofer Just updated the instructable, I am still getting over cast and rain - so let me know if it finally changes, or if you think it isn't displaying something it should.

    0
    Itsmedoofer
    Itsmedoofer

    Reply 9 months ago

    @kd8bxp
    Top stuff, will have a proper read through later.. All we have had here in the south east UK is cloud and rain, works well for that, will keep it running though see what happens.. With regards to the timing issue, happens on my Pi4 as well, I'm thinking it could be something with the rpi_ws281x library, there are a few different sources for that so I was going to have a play with them... I'll report back if I get anywhere. Again thanks for getting us this far !

    Strike that, the rpi_ws281x library is only going to be for the rainbow LEDs, doh!

    0
    kd8bxp
    kd8bxp

    Reply 9 months ago

    @Itsmedoofer I pretty much echoed what we are talking about here, just wanted you guys to know that I did update the instructable.
    Yes, cloudy and rain is all we have - we need the rain, but I'm pretty sick of it now LOL.
    The timing issue I am pretty sure that is in the weatherhat.py script:
    ```
    def cloudrun(self): while self.cloudrunning == 1: for i in range(60,1,-1): if j == 1: if k == 1: self.cloud1(j) self.cloud2(i) sleep(0.005) self.cloud3(i) sleep(0.005) sleep(0.005) self.cloud4(j) self.cloud5(k) sleep(0.005) self.cloud6(k) self.cloud1(0) self.cloud2(0) self.cloud3(0) self.cloud4(0) self.cloud5(0) self.cloud6(0)
    ```
    The above is one of the functions (the one I think is causing the issue). You can see there are two sleep statements back to back, and self.cloud4(j) and self.cloud5(j) are together - what I think is one of the sleep statements should be inbetween the cloud4 and cloud5 statements.
    I'm not sure but I think there are two sets of 3 leds for the cloud.
    I want to dig into that script a little more and see what each command does, but that is going to take a little time to do - and I'm really not sure when I might be able to get to play.
    I really think the problem is in the weatherhat.py script, but without breaking down what it is really doing it is hard to say for sure.
    Maybe one day I'll be able to know more.

    0
    Itsmedoofer
    Itsmedoofer

    Reply 9 months ago

    Hi, I think I found a fix for the timing issue, I was playing about with a stripped down cycle.py script and managed to recreate the problem, from that I found a fix...It seems if the main loop restarts straight away it triggers the timing issue, you need a delay of at least 2 seconds from the loop ending to restarting to prevent it, the actual length of the loop don't appear to matter. It could be something underlying in weather.py causing this but simply adding sleep (2) towards the end of getweather.py seems to fix it.

    wh.sun("stop")
    wh.rainbow("stop")
    sleep (2) <-My addition
    panel.setPixelColor(0,Color(0,0,0))
    panel.se...........

    With this you get 2 seconds with nothing lit between each weather update, but I can live with that.. Maybe this is a pointer for what is going on in weather.py ?

    I've had it running for a couple of hours now and it seems to be OK...

    0
    kd8bxp
    kd8bxp

    Reply 9 months ago

    Pushed a new update a few minutes ago (Oct 6, 2020 3:30ish Eastern time), not critical - but it does have the "clear" condition, which for some reason openweathermaps is using for sunny - not sure if "clear" and "sunny" are the same, but I'll go with it.
    For everyone else I also added the what needs to change for the url if you should decide that the city, state, country isn't working correctly for you.
    And the timing correction by @Itsmedoofer
    I think those are the only changes, as always if you think of a way to display some of the conditions we are not displaying, let me know, if you see a condition that you think should be displayed let me know.

    0
    Itsmedoofer
    Itsmedoofer

    Reply 9 months ago


    @kd8bxp
    I'll say it again you are the man, running great out of the box here. Still no change from clouds and rain to try it out, but thats blighty for you :)

    For those who want to run the script at startup, a really easy way is to edit (sudo nano):
    /etc/rc.local
    and add this directly above 'exit 0'
    python /home/pi/getWeather/getWeather.py ?

    In rc.local you dont need sudo as thats done by default, the & is important, failure to include this could stop your Pi booting. I found it easier than cron, could never get my head around that.

    Also if you install the python3 dependencies this script runs just fine under Python 3.7. To save the load on kd8bxp I would be quite happy to go through this with anyone who needs Python 3, or indeed needs help with rc.local

    0
    kd8bxp
    kd8bxp

    Reply 9 months ago

    LOL, Maybe I'm just old school, when it comes to cron, been using it for years, and I never really got into using rc.local :-) Yes, many different ways now a days to get (They could also make a service for systemd thou I never really got into using that either) To get cron to run as a super user (sudo) you edit the cron job like:
    sudo crontab -e
    And that will run the script each time like it is sudo, like I said many ways to do it now. :-)
    The & tells the system to run the program (app or whatever) in the background, releasing the foreground so you can still use your computer. It's very handy, and it is really important.
    So some good news, this project was finally added to the original project - the git pull request was finally accepted -The really good news is user Boeeerb has some ideas on some changes to the timings, and adding the conditions like fog and haze - apparently they can dim the cloud and that is what they though would work for fog and haze. They are also in your part of the world (not sure where) but they pretty much said the same "cloudy" and "rain"....
    Kind of interesting, the renewed interest in this hat. It's a good sign thou, so I need to update the instructable again.

    0
    Itsmedoofer
    Itsmedoofer

    Reply 9 months ago

    @kd8bxp
    I should learn to make more use of cron it is a very powerful tool, dam my laziness !! :)
    Thats great news on the pull request, just commented on there as well, I've starred the project so will keep an eye out for updates....
    I'm in the UK, a little seaside town called Herne Bay, yet more cloud and rain today, but, wait for it, showers Fri & Sat and sun on Sun ?!
    I do feel kinda bad hijacking your time on this....

    0
    kd8bxp
    kd8bxp

    Reply 9 months ago

    @Itsmedoofer Everyone is in the UK, I'm the odd man out. LOL - it's no problem, and I plan on doing more work to this, renewed interest, some of the ideas on the original github page now, now I'm interesting in using this to display the ISS with the rainbow.
    Still a lot of little projects going on, but I'm getting excited by this again. :-)

    0
    kd8bxp
    kd8bxp

    Reply 9 months ago

    @Itsmedoofer Ok, I made the change over here as well. Of course today we didn't have clouds or rain - so now it's a waiting game again. However I did find a condition that I missed, so I'll get that fixed up and push some new code to get hub very soon - probably tomorrow, just because too many things are going on tonight.
    I'm sure there is a fix to the timing issue (if it is a timing issue), it's just going to take some time to work it out I think.
    Thanks for the help, and we will get it sorted :-) Have a great day.

    0
    Itsmedoofer
    Itsmedoofer

    Reply 9 months ago

    Hi, me again, I think I had to install python-requests for the new API to work, will try again on a fresh install later....

    0
    kd8bxp
    kd8bxp

    Reply 9 months ago

    Quite possible, I didn't, but I'm not sure if I needed to a couple of years ago. (It may depend on which version of python installed as well) I'll make a note of it thou, because like most things in life - everything is different and changes :-)

    0
    kd8bxp
    kd8bxp

    Reply 11 months ago

    Sorry, I don't. Honestly I have used this project in a long time, and missed that the API from Yahoo has changed. Perhaps using Openweathermap.org API I will put this on a list of projects to revisit that list is growing, and see if I can get something going again, but it might be awhile before I can look at it again.

    0
    Itsmedoofer
    Itsmedoofer

    Reply 10 months ago

    Hi, Just to say there is at least one other person out here with this HAT. I had been using your script for about a month before Yahoo pulled the plug on the API, I have been looking for ages for a drop in replacement but to no avail.. I did find this, sopel-modules.weather, that looks like a re-factor of the old API for the Sopel IRC software, not sure if you could use that as a base and save some work, sadly my phyton is nowhere near the level required. I appreciate the work that you put into this originally and understand if it falls off the bottom of the list, be great to have it working again tho. Thanks !

    0
    kd8bxp
    kd8bxp

    Reply 10 months ago

    Yeah, I really don't know when I'll get back to this project - I'll put it higher on the list - It seems people are finding it now, and trying to get some use out of it :-) makes me happy really - I'm just sorry that it's not working any more.
    I'll take a look at the sopel-modules.weather - Using Openweathermap.org would require a complete re-wright I think, that may not be so bad. But if there was a drop in replacement, that would be a quick fix. I'll see if I can get to this this up coming week - still have a few projects that I just have to get done, but should be able to look this week.

    0
    ajsorchard
    ajsorchard

    Reply 10 months ago

    Hi, this is great news. I’d love to be able to get this up and running. We bought this to get our son interested in computing and coding. Any development would be fantastic. Thanks for putting time into this. I tried to contact the guy who built it but haven’t had a response yet. Fingers crossed eh?