Introduction: LED Weather Forecast
This project utilizes a 6 x 16 matrix of RGB LEDs to visualize a weather forecast pulled from the Weather Underground API. A Raspberry Pi runs a python program designed to fetch weather forecast data from the API at regular intervals, parse the data into temperature, pressure, humidity, wind speed, chance of precipitation, and weather condition arrays, and then colorize and display that data across the LED matrix.
Mounted in its own enclosure, the project can set on a shelf, desk, or hang on a wall as a compact visual display for upcoming weather conditions over the next 32 hours.
Step 1: Materials
Hardware
- Raspberry Pi with Raspbian installed and configured to connect to the internet (for this project, I prototyped with the 2 B and later installed the Zero*)
- 5 Volt Power Supply, 2 Amps or greater
- 2.1mm Female Barrel Jack Adapter or MicroB USB Connector (depending on your power supply jack)
- Micro USB Connector Shell
- Capacitor - 1000 µF, 6.3V or higher (I used a 1000µF, 16V that I had on hand)
- Resistor (300 to 500 Ohm)
- 74AHCT125 Level Converter
- Twelve (12) NeoPixel Sticks - 8 x 5050 RGB LEDs
- Breadboard, Connecting Wires, and Headers
* Note that if you choose to use the Zero, you will need a USB hub, a Micro USB Male to USB Female Adapter, and a Mini HDMI to Standard HDMI Jack Adapter to interface with the Pi for software setup and troubleshooting.
Software
- NeoPixel Library for Raspberry Pi - rpi_ws281x library (available here)
- Program Files - apiboot.txt and weather_color.py (available here)
- API key from WeatherUnderground (available here)
Other Materials
- 8" x 10" Shadow Box Frame (or other enclosure to suit)
- Cardboard
- Vellum
- Construction Paper or Mat Board
- Double Sided Tape
Special Tools
- You will need to be able to solder for this project. The NeoPixel Sticks will need to be soldered together and will need headers soldered for their inputs and outputs. The Raspberry Pi Zero will need to have at least two headers soldered for GPIO connections.
Step 2: Connect the Hardware
The LED matrix consists of six rows of two NeoPixel Sticks soldered together using trimmed header terminals to connect GND-to-GND, DIN-to-DOUT, VDC-to-VDC and (for flexibility) GND-to-GND. Header terminals were also soldered to GND, DIN, VDC, and GND again (for flexibility) on one end of the pixel row and DOUT on the other end.
The Raspberry Pi Zero does not have headers assembled to the GPIO pads. You will need to solder at least two headers to the Pin 6 location (GND) and another to the Pin 12 location (GPIO18).
The basic hardware installation is an almost one-for-one implementation of the Level-converter Chip Wiring setup found on Adafruit's Learning System tutorial NeoPixels on Raspberry Pi. The breadboard setup is summarized as follows:
- Connect power supply ground to 74AHCT125 ground & 1OE pins, Raspberry Pi ground, and each row of NeoPixel GND (all six rows connected in parallel).
- Connect power supply 5V to 74AHCT125 VCC and each row of NeoPixel DIN (all six rows connected in parallel).
- Connect Raspberry Pi pin 12 (GPIO18) to 74AHCT125 pin 1A.
- Connect 74AHCT125 pin 1Y to the first NeoPixel row DIN.
- Connect the first NeoPixel row DOUT to the second NeoPixel row DIN (continuing this series until all six rows are connected).
In addition to the above, I chose to add a capacitor(1000 µF, 6.3V or higher) across the + and – terminals and a data line resistor (300 to 500 Ohm) between the 74AHCT125 pin 1Y and the input to the first NeoPixel. The project was tested without the added hardware with no observable ill effect but were added as a precaution based on the Best Practices found in the "Adafruit NeoPixel Überguide".
Power is brought into the enclosure via a MicroB USB Connector Breakout and split to power both the Pi and the breadboard in parallel. Solder header terminals to VCC and GND. Solder the capacitor and two pair of wire to each header terminal (be sure that the capacitor leads are correctly matched to the positive/VCC terminal and the negative/GND terminal). Connect one pair of VCC and GND wire ends to the breadboard. Solder the Micro USB Connector Shell to the other pair of wire ends and connect it to the Raspberry Pi.
You should now be able to power up the Pi from the micro USB connections. However, the LED's won't do anything yet until the NeoPixel Library is installed in the next step.
For this tutorial, I'm not going to go into a step-by-step of how the project is mounted and displayed. From the pictures, you can see that the LED's are mounted in evenly spaced rows approximately 1 cm apart. I found that cardboard and double-sided adhesive tape worked well for the mounting of the LED's, breadboard, and Raspberry Pi. Also, a single sheet of white vellum worked well to subtly diffuse the LED's. The entire project is mounted inside of a shadow box frame. You will want to choose a frame that is at least 2.5 inches deep to provide enough room for the connecting wires and terminal headers.
Step 3: Install the NeoPixel Library and Test the LED's
Download and install the NeoPixel Library for Raspberry Pi (rpi_ws281x library), following the Software instructions from the Adafruit Learning System tutorial with one exception. In addition to the tutorial instruction to install the library to Python by executing:
cd python sudo python setup.py install
You will also need to install the library to Python 3 by executing:
sudo python3 setup.py install
This is because the weather_color.py program that you will install in a later step was written in Python 3.
Continue the Software instructions with the Strandtest Example. Be sure to change the LED_COUNT constant to the reflect the number of pixels in your project (in this case 96) or else only the first row of your matrix will be controlled when you execute the example code.
If all of your connections are good, you will get a nice bright* demonstration across the entire matrix!
* Note that for the Strandtest example and using a brightness setting of 255 and a pixel count of 96, a 2 Amp power supply will suffice (I measured about 1.2 Amps for the LED's while running the rainbow chase sequence). However, use caution when playing with the code. An all white (255, 255, 255) setting could pull more than 5 Amps (reference the Powering NeoPixels section of the "Adafruit NeoPixel Überguide" for estimating NeoPixel power requirements).
Step 4: Install the "Weather Color" Programming
The Weather Color program is designed to fetch weather forecast data from an API in 15 minute intervals, parse the data into temperature, pressure, humidity, wind speed, chance of precipitation, and weather condition arrays, and then colorize and display that data across the LED matrix.
In order for the API to work, you will need to obtain an API key from the WeatherUnderground website (available here). This key will be entered into the apiboot.txt file at a later step.
From the Raspberry Pi terminal, execute the following command to download and install the needed apiboot.txt and weather_color.py program files.
git clone https://github.com/aughtnaughtzero/weather_color.git
You will now need to edit the apiboot.txt file to add your API key and to choose (uncomment) one of the API query options. Executing the following command will open the apiboot.txt file in the nano text editor.
sudo nano /home/pi/weather_color/apiboot.txt
By default, the city/state query is uncommented (Miami/FL). Choose and modify any query of your liking, just be sure to comment (#) any unused query. Reference the Weather Underground documentation for more examples about the query types and how to tailor the queries to work with your specific need. When you are done editing the nano file, Ctrl-X to exit and Y to save the file. Note that you can edit the apiboot.txt and log.txt files with any text editor of your choice. If you boot into the Raspbian desktop environment, you can use Leafpad to modify and save the files by browsing to the /home/pi/weather_color directory.
Now, to test the installation, execute the following:
sudo python3 /home/pi/weather_color/weather_color.py
Upon execution, the program will write its first log.txt file. Though, if you open the log file now, the log file will only indicate that the program is initializing with the rainbow color sequence.
The rainbow color sequence will chase across the LED matrix for 60 seconds. The weather_color program is intended to be launched upon Raspberry Pi startup. The 60 second delay is meant to give the Pi plenty of time to boot and connect to wifi before it makes the first API call.
After approximately 60 seconds have passed, the program will make its first API call. If all goes well, a nice mix of LED colors will be displayed which represent 32 hours of forecasted weather. Opening the log.txt file will reveal the data set from the API call. The program will continue to make API calls and update the LED matrix and log.txt file every 15 minutes until the Pi is shutdown or the program is terminated (Ctrl-C from the terminal).
If the API call fails to connect or returns an error, the program will wipe the LED matrix with a red display, write the error encountered to the log.txt file, and terminate.
If the API call times out during the boot sequence, the program will wipe the LED matrix with a yellow display, write a message to the log.txt file, and attempt to connect again in 3 minutes.
For more details about the color representations used in the forecast display, see the file color_key.txt located in the /home/pi/weather_color directory. In general, blue represents low-range values, green represents mid-range values and red represents high-range values.
The final step in the software installation is to have the Pi launch the program at startup. This is accomplished by using the following terminal command to modify the crontab.
sudo crontab -e
Scroll to the bottom of the file and add the line:
@reboot sudo python3 /home/pi/weather_color/weather_color.py
When you are done editing the file, Ctrl-X to exit and Y to save the file.
Now when you shutdown and reboot your Pi, the weather_color program will launch as intended. Be patient during launch as there will be no display for the first 15 seconds or so until the crontab is executed.
You can now untether the project from your keyboard, mouse, and display and place it anywhere that you would want to see the current weather and forecast at a glance!