Raspberry Pi RSS
This project uses the Raspberry PI Zero to connect to the internet, read the BBC RSS weather feed and display the readings on an inexpensive 320 x 240 pixel TFT colour screen. I have used the feedparser library to get the content of the feed. The code then pulls out the various pieces of information and displays them on the TFT screen. In addition, the screen also shows an appropriate weather icon. The display regularly auto-updates and so can be left to run.
This project has been extremely frustrating. This is the fourth version I have coded. My first one, using the Adafruit Python TFT driver kept falling over due to a memory leak in the library. So i tried another ILI9341 library I downloaded from the net. After changing all my code to use this one I still had a memory leak. Back to the drawing board again! In desperation, I ported the Adafruit Arduino C library to Raspberry Pi. My method then was to parse the data from the feed to an sqlite database and use the c-based TFT driver to read from the database display the data. This worked, but I was never happy that it was so clunky. My final iteration involved heavily adapting the Adafruit ILI9341 python library. This effort started after reading a blog post about a memory leak in the PIL putdata() function.
This has worked, and I now have a display that is purely Python-based and cycles between the current observations and the three-day forecast for any location.
The hardware I have used is the Raspberry Pi Zero and a cheap TFT screen from ebay.
In the outside columns are the pin numbers for the Raspberry Pi GPIO connector. The numbers inside are for the specific display I am using,
|3V3||1||8 - LED||2||5V|
|0||GPIO17||11||5 - D/C||12||GPIO18 (PWM0)||1|
|3||GPIO22||15||4 - RST||16||GPIO23||4|
|3V3||17||1 - VCC||18||GPIO24||5|
|12||GPIO10(MOSI)||19||6 - MOSI||2 - GND||20||GND|
|13||GPIO9(MISO)||21||9 - MISO||22||GPIO25||6|
|14||GPIO11(SCLK)||23||7 - SCLK||3 - CS||24||GPIO8(CE0)||10|
In order to get the info from the RSS feed I am using feedparser
Install it like this:
sudo apt-get install python3-pip
sudo pip3 install feedparser
To help with the date / time stuff I am using dateutil
Install it like this:
sudo pip3 install python-dateutil
sudo apt-get install python-rpi.gpio python3-rpi.gpio
Make sure the SPI interface is enabled.
sudo apt-get update sudo apt-get upgrade sudo apt-get install git sudo apt-get install python-dev python3-dev cd ~ git clone https://github.com/doceme/py-spidev.git cd py-spidev make sudo make install
sudo apt-get install libjpeg62 sudo apt-get install libjpeg62-dev sudo apt-get install zlib1g-dev sudo apt-get install libfreetype6-dev sudo apt-get install liblcms1-dev sudo apt-get install libopenjp2-7-dev sudo apt-get install libtiff5 sudo pip3 install pillow
The default buffer size is 4KB. The TFT library can update the whole screen in on go. This means the buffer size must be width x height x 2 = 153,600.
sudo nano /boot/cmdline.txt
Now you will need to reboot
In order to get the URL link for the weather feed, go to BBC Weather and search for your required location. On the page find the RSS link - see below:
Click on the 'Observations' link and a new browser page will open showing you the returned XML.
<?xml version="1.0" encoding="UTF-8"?> <rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" version="2.0"> <channel> <atom:link href="http://open.live.bbc.co.uk/weather/feeds/en/2643743/observations.rss" rel="self" type="application/rss+xml" /> <title>BBC Weather - Observations for London, United Kingdom</title> <link>http://www.bbc.co.uk/weather/2643743</link> <description>Latest observations for London from BBC Weather, including weather, temperature and wind information</description> <language>en</language> <copyright>Copyright: (C) British Broadcasting Corporation, see http://www.bbc.co.uk/terms/additional_rss.shtml for more details</copyright> <pubDate>Thu, 10 Mar 2016 16:05:34 +0000</pubDate> <item> <title>Thursday - 15:00 GMT: Light Cloud, 9°C (48°F)</title> <link>http://www.bbc.co.uk/weather/2643743</link> <description>Temperature: 9°C (48°F), Wind Direction: Northerly, Wind Speed: 5mph, Humidity: 73%, Pressure: 1022mb, Rising, Visibility: Good</description> <pubDate>Thu, 10 Mar 2016 16:05:34 +0000</pubDate> <guid isPermaLink="false">http://www.bbc.co.uk/weather/2643743-2016-03-10T16:05:34.000Z</guid> <georss:point>51.50853 -0.12574</georss:point> </item> </channel> </rss>
Copy the link from the address bar of that page and paste it into the code below.
Auto StartupIn order to have the script run automatically at boot time you need to edit
rc.localwhich is in the
/etcfolder. For example:
sudo nano /etc/rc.localAt the end of the file, just above
exit 0, add the line:
python '/home/pi/Documents/Python Projects/feedparserBBC.py' &This assumes you have called your python file
feedparserBBC.pyand it is in the folder
/home/pi/Documents/Python Projects/. The path to the Python script is in quotes as there is a space character in my folder name. Don't miss off the ampersand as this means that the Pi should carry on and boot to the Terminal or GUI.
Now, whenever you boot the Pi, the script will run in the background. This means you can run with just the TFT connected and a WiFi dongle in the USB port, i.e. 'headless'.
These are some links that gave me useful information while I was putting this project together