At the 2013 Open Hardware Summit that I attended a few months ago, all attendees were given a “BADGEr,” a unique ePaper badge that displayed our credentials, showed the conference schedule, etc. Of course, since this was the OPEN Hardware Summit, the BADGEr (designed by the awesome folks at Wyolum) was completely open source. Not only is the BADGEr hackable, it was designed to be hacked. So, of course, I immediately started hacking on it as soon as I returned home from the summit at MIT. It didn’t take me long to write new firmware for the device, connect it to a web-connected Rapsberry Pi computer, and hang it on my wall with some custom 3D-printed brackets. I’ve been using it for the last several months as a handy weather station that I can glance at before I leave my apartment each morning. A supplementary LED beacon warns me of extreme conditions (hot, cold, or rainy). On the weekends, it shows the weather report for San Francisco (where I live), and on the weekdays, it shows the weather report for Mountain View (where I work). The display checks for new weather data and updates once every 10 minutes.
What to see it in action? Want to learn how to make it yourself? Read on!
Weather Station in Action:
Here’s a quick Instagram video (Don’t you follow me on Instagram!?) that shows the data updating, the warning light coming on, and the ePaper display refreshing. In this example, I’ve chosen to display data for New York City. Since there is a 90% chance of rain, the warning light glows a pleasant blue. Ordinarily, you wouldn’t actually see the terminal program spitting out debug data, since it runs automatically on the headless Raspberry Pi (I’m SSH‘ed into the Pi to show you what the updating process looks like).
Are animated GIF’s more your speed? Here’s a looping GIF showing the display switching back and forth between New York and San Francisco weather reports (my previous and current places of residence):
Here’s how the Weather Station works:
- Once every 10 minutes, a cronjob triggers on the Raspberry Pi. This cronjob launches a python script that uses weather.com and yahoo.com APIs to fetch the following data:
- Yahoo weather code: This corresponds to an image ID that will load on the ePaper display. Different codes represent different conditions like, “sunny”, “cloudy”, etc.
- City name: You provide the script with your zip code, and it will automatically get the name of the city.
- Current Date
- Sunrise Time
- Sunset Time
- Forecast (Sunny, cloudy, etc)
- Chance of Precipitation
- Temperature (high)
- Temperature (low)
- Once the script has grabbed all this info, it parses out the relevant data, and formats it to be sent over USB-serial to the attached BADGEr device. An identifying character is appended to the start of each serial string, which allows the BADGEr to determine which piece of data it is receiving.
- Once the Pi has finished sending data (it sends a termination character to tell the BADGEr it is done), the BADGEr parses through the data.
- The BADGEr identifies and loads the appropriate weather condition image from the loaded SD card (it contains a specially converted and formatted image for each possible weather condition).
- The BADGEr loads the remainder of the data into a buffer and sends it all to the ePaper display.
- Steps 1-5 repeat once every 10 minutes.
Want to Make This? Here are the Steps:
- Visit the GitHub Repository that I link to at the bottom of this post. Either clone it to your computer with git command line tools, or download the entire ZIP by clicking “Download ZIP” on the right side of the GitHub repo page.
- Remove the MicroSD card from your BADGEr and insert it into a card reader on your computer. You may need a microSD to SD adapter. Format the card.
- Copy the contents of the “BADGEr SD Card” folder in my GitHub repo to the SD card. Once you’ve done this, the root of the SD card should contain three files and an IMAGES folder. The Wyolum ePaper library utilizes a special image format (.WIF). I’ve taken the liberty of already converting the weather glyphs to this format, and have included the original .gif files as well. If you’d like to experiment with making your own .WIF files, you can do so by using the Wyolum python-based .WIF image conversion tool.
- Next, you’ll need to flash the BADGEr with my custom firmware. The BADGEr uses a standard FTDI 5-pin connector for this purpose, but NOT all FTDI cables will work. I was only able to flash the device by using the sparkfun FTDI breakout. Connect BADGEr to your computer using one of these cables.
- Follow the instructions from Wyolum to download and install the EReader Arduino Library. Make sure you do this with the Arduino IDE closed.
- Open up the “BADGEr_Display.ino” Arduino sketch contained in the GitHub repo linked from the end of this post. One you have it open in the Arduino IDE, select your USB-Serial port in Tools>Serial Port, and select “Arduino Pro Mini 3v3 8MHz” in Tools>Board.
- Press the upload button to upload my firmware to your BADGEr.
- You can now unplug the BADGEr from your computer, and plug it into the one of the USB ports on your Raspberry Pi. The BADGEr is now ready to accept serial commands that can control its screen. This tutorial assumes you already have Raspberry Pi up and running with internet connectivity. If you don’t, follow the introductory Raspberry Pi tutorials from Adafruit first. I am also assuming that you are connected to your Raspberry Pi over SSH, and that are you comfortable transferring files to it via FTP. The remainder of the steps should be performed on your Raspberry Pi (either directly, or via SSH) unless otherwise noted.
- By default, Arduinos (including the BADGEr) will restart whenever a serial connection is initiated with them. We don’t want the BADGEr to do that while it is plugged into the Pi. Figure out what device your BADGEr is listed as on the Raspberry Pi:
pi@raspberrypi ~ $ cd /devpi@raspberrypi ~ $ ls -l
That will print out an exhaustive list of all hardware devices connected to your Pi. Your USB-Serial converter (the BADGEr) will likely be called something like ttyUSB* where * is some number. Scroll through the list and find those entries. If there is just one, that is your BADGEr. If there are multiple, unplug the BADGEr, re-run ls-l, and see which one disappears – that is your BADGEr. Note down the device name. With the directory appended, it will look something like “/dev/ttyUSB1″. Use your favorite editor to modify your Pi boot file so that it disables Serial resets for that device on boot:pi@raspberrypi ~ $ sudo nano /etc/rc.local
Append “stty -F /dev/ttyUSB* -hupcl” (without the quotes) to the end of that file. Be sure to replace the “*” with the number for your device! Save the file.
- Now, you’ll need to install the Weather and Serial python libraries. Navigate to your home directory:
pi@raspberrypi ~ $ cd /home/pi
Download, unzip, and install the Python Weather API Library:pi@raspberrypi ~ $ wget https://launchpad.net/python-weather-api/trunk/0.3.8/+download/pywapi-0.3.8.tar.gzpi@raspberrypi ~ $ tar -zxvf pywapi-0.3.8.tar.gzpi@raspberrypi ~ $ rm pywapi-0.3.8.tar.gzpi@raspberrypi ~ $ cd pywapi-0.3.8pi@raspberrypi ~ $ python setup.py buildpi@raspberrypi ~ $ sudo python setup.py installpi@raspberrypi ~ $ sudo apt-get install python-dev python-pippi@raspberrypi ~ $ sudo pip install pyserial
- Now, on your main computer, edit my weather.py script to match your needs (you can use any text editor). When you open the file, you’ll see that there is a configuration section at the top. Right off the bat, you’ll probably want to set the “use_SUNN” variable to “False”. SUNN is a custom piece of LED lighting hardware that I’m using to act as the warning light (it’s not open source yet, but may be in the future). Make sure you set “BADGEr_dev” to match the device name that you determined earlier! Save the python script when you are done.
- Next up, you need to copy my weather.py script to your Pi home directory. Since you already have my entire GitHub repo for this project downloaded on your main computer, I recommend sending the file over to your Pi via FTP. The python file is located in the “Weather Checker” directory of the GitHub repo, and should placed in your Pi’s home directory (/home/pi/weather.py). Once you’ve copied it over, make sure you make it executable:
pi@raspberrypi ~ $ cd /home/pipi@raspberrypi ~ $ chmod 755 weather.py
- At this point, you should now be able to manually run this file, and see the BADGEr display update accordingly. Assuming you are still in the home directory, manually run the script like this:
pi@raspberrypi ~ $ ./weather.py 10001
The program accepts a zipcode as its one argument. 10001 is a zip code for New York City. When you run it, replace it with the zipcode for wherever you want to see the weather report. When you run the script, you should see an output on the terminal that looks like this animated GIF:
When you run it, you will see different text because you will presumably have the SUNN functionality disabled, and you will be using a different zipcode.
- As the final step, you’ll setup a cronjob to handle automatically running this script once every 10 minutes. Open up the crontab editor:
pi@raspberrypi ~ $ crontab -e
At the end of this file, add two lines:
*/10 * * * 1-5 /home/pi/weather.py 94043
*/10 * * * 0,6 /home/pi/weather.py 94117
The first line triggers the script once every 10 minutes on weekdays. Replace “94043″ with the zipcode of where you work. The second line triggers the script one every 10 minutes on weekends. Replace “94117″ with the zipcode of where you live. Save and close the crontab.
- You’re done! You can now log out of your SSH session to the Pi. It will continue to run, and will update the display every 10 minutes with the latest weather report. Hooray!