a weather display for a raspberry pi and a adafruit (featherwing) TFT ili9341 display
first of all, i'm a beginner in python... so don't be to hard to me... i'm still learning
written with love in python3
i wrote this app on a mac with PyCharm and tested it quite a while. since it uses only standard python3 modules and libraries it should work on nearly everything that can run python3 and pygame.
this tutorial is basically for running it on a raspberry pi (zero, 1, 2, 3) and a TFT display which matches up with chips like the ones from adafruit. as long as it uses standard spi it should work with the new
dtoverlay
module in the latest jessie versions of raspbian... i think there is no need for a custom kernel. it's just a little bit configuration.
i tested it with following TFT's:
- TFT FeatherWing - 2.4" 320x240 Touchscreen For All Feathers
- Adafruit 2.4" TFT LCD with Touchscreen Breakout w/MicroSD Socket - ILI9341
- adafruit TFT's with ili9341 driver
no configuration needed for:
- official raspberry pi 7" display
- any HDMI display
- skip all the TFT setup parts
- this should explain how to wire up your display
SDO (MISO) TFT Data Out SPI_MISO = GPIO09
SDI (MOSI) TFT Data In SPI_MOSI = GPIO10
SCK TFT Clock SPI_CLK = GPIO11
CS TFT Chip Select SPI_CE0_N = GPIO08
D/C TFT Data / Command = GPIO24
RESET Reset = GPIO23
GND Ground = GND
VCC 3V3 supply = +3V3 or 5V
- optional if you like to use the included PiButtons script
BUTTON 1 used for restart app = GPIO19
BUTTON 2 used for shutdown pi = GPIO26
- give you the option to put some function on a hardware button (like restart the WeatherPiTFT service, shutdown/reboot your Pi, change display brightness, etc.)
- feel free to add your own functions in
PiButtons.py
- get the latest NOOBS installer
https://www.raspberrypi.org/downloads/noobs/
i used NOOBS v2.1.0 which was the latest version for now
TODO: write a tutorial for setting up the SD card
TODO: write a tutorial for first boot
TODO: write a tutorial for setting up SPI
TODO: write a tutorial for connecting to WiFi via terminal
- when your connected to your wifi open up a terminal and type:
sudo apt-get update -y && sudo apt-get upgrade -y
git clone https://github.com/LoveBootCaptain/WeatherPi_TFT.git
cd WeatherPi_TFT
rm -rf docs/
TODO: write a requirements.txt
- go to darksky.net
- and register to get an API key
- create a new config-file
cd
cd WeatherPi_TFT
cp example.config.json config.json
- edit the config.json file
nano config.json
- replace
xxxxxxxxxxxxxxxxxxxxxxxxx
in"FORECAST_IO_KEY": "xxxxxxxxxxxxxxxxxxxxxxxxx"
with your own API key - replace
en
in"FORECAST_LANGUAGE": "en"
with your preferred language - replace
si
in"FORECAST_UNITS": "si"
with your preferred unit format - replace
40.705565
and-74.1180865
in"FORECAST_LAT": 40.705565
and"FORECAST_LON": -74.1180865
with the coordinates of your preferred forecast-location (this example-location data is from new york city) - replace
flags
in"FORECAST_EXCLUDES": "flags"
with whatever you want to exclude in the API-respond - for language-support, units, lat , lon and excludes please refer to -> DarkSky API Docs
- in /boot/config.txt, add in the following at the bottom
# TFT display and touch panel
dtoverlay=rpi-display
dtparam=rotate=0
- change /boot/cmdline.txt to add the following to the end of the existing line
fbcon=map:10 fbcon=font:VGA8x8 logo.nologo
cd
cd WeatherPi_TFT
sudo cp WeatherPi_TFT_Service.sh /etc/init.d/WeatherPiTFT
sudo cp PiButtons_Service.sh /etc/init.d/PiButtons
sudo chmod +x /etc/init.d/WeatherPiTFT
sudo chmod +x /etc/init.d/PiButtons
sudo chmod +x Weatherpi_TFT.py
sudo chmod +x PiButtons.py
- this is useful if you like to run your python scripts on boot and with sudo support in python
sudo chown -v root:root /usr/bin/python3
sudo chmod -v u+s /usr/bin/python3
- this should start your wanted python version just by typing
python
in the terminal - helps if you have projects in python2 and python3 and don't want to hassle with the python version in your service scripts
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2
you can always swap back to python2 with:
update-alternatives --config python
and choose your preferred version of python
- check if python3.x is now default with:
python --version
- it should say something like:
Python 3.4.x
- open up a python console
python
- than run this line by line
import pip
from subprocess import call
for dist in pip.get_installed_distributions():
call("pip install --upgrade " + dist.project_name, shell=True)
- if everything is set up and updated correctly:
sudo reboot
- for the WeatherPiTFT Service
sudo service WeatherPiTFT start
sudo service WeatherPiTFT stop
sudo service WeatherPiTFT restart
sudo service WeatherPiTFT status
- for the PiButtons Service
sudo service PiButtons start
sudo service PiButtons stop
sudo service PiButtons restart
sudo service PiButtons status
- if this is doing what it should you can run the service every time you boot your pi
sudo update-rc.d WeatherPiTFT defaults
sudo update-rc.d PiButtons defaults
- if you have any issues with setting up your
locale
please read the issue #1 - if some special characters of your language is not supported (e.g. like chinese characters) please read the issue #1
- a good way to setup for chinese was given from @yifanshu02 here
- squix78 for his esp8266 weather station color which inspired me to make it in python for a raspberry and another weather api
- adafruit for hardware and tutorials
- darksky / forecast.io weather api and documentation
- icons: fa2png, making them colorful was my work
- fonts: google