Simple Weather Display Using Raspberry PI and Cyntech WeatherHAT

655

3

4

Posted

Introduction: Simple Weather Display Using Raspberry PI and Cyntech WeatherHAT

Microcontroller Contest

This is an entry in the
Microcontroller Contest

Pocket-Sized Contest

This is an entry in the
Pocket-Sized Contest

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  https://github.com/jgarff/rpi_ws281x.git
git clone  https://github.com/CyntechUK/WeatherHAT.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.

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)

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">  https://github.com/kd8bxp/WeatherHAT.git  </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

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.

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.

@reboot python /home/pi/getWeather/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.

Share

    Recommendations

    • Science of Cooking

      Science of Cooking
    • Pocket-Sized Contest

      Pocket-Sized Contest
    • Trash to Treasure

      Trash to Treasure
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    1 Questions

    Any particular reason this doesn't use a $2 ESP8266 over a $10 Pi0W? Seem like it could be turned into a fantastic cheap kit to teach SMD soldering, how to flash micro controllers, and how to use API's! :)

    0

    Hi, I didn't design the HAT - and really have no idea why they decided to make it for the PI. (A PI does seem over kill for this) I also have no idea why they didn't finish out the software - using APIs on the PI would still have a good learning experince.

    Mine is dated 2016, but I think they were made/designed earlier - it looks to me like they may have been designed for use with the PI 2, but that is only a guess on my part. There was or is a timing issue with the PI 3 that can be solved pretty easy.

    I don't think it would be hard to have this work with a Arduino or a ESP8266 and I might try it one day - there are so many other projects that I want to do.

    Comments