LoveBootCaptain / WeatherPi_TFT

a weather display for a raspberry pi and a TFT display written in python3 and pygame
Other
78 stars 24 forks source link
adafruit adafruit-tft darcula hyperpixel4 ili9341 pimoroni pimoroni-hyperpixel pimoroni-hyperpixel4 pygame pygame-application python python3 raspberry raspberry-pi tft tft-display theme weather-display weather-icons weatherpi-tft

WeatherPi_TFT

Working on @pimoroni HyperPixel4 Display and a Raspberry Pi 3 B+ Hardware

Working on @HWHardsoft AZ-Touch-Pi0-Weather with ili9341 Display and a Raspberry Pi Zero W Hardware

so it all began

Hardware

a weather display for a raspberry pi and a adafruit (featherwing) TFT ili9341 display

UPDATE

WeatherPiTFT now runs on every display size... from the smallest 128x128, 128x160, 240x320, 320x480, 480x640, 480x720, 480x800 (pimoroni hyperpixel4 or official Raspberry Pi 7" Touchscreen Display), 720x720 (pimoroni hyperpixel4 square) and above. WeatherPiTFT will always be shown in portrait mode but it also works on a landscape configured display (but still in 3x4 centred on your display). The images have a size of 1000x1000px so it should work even on HD monitors without lost of weather image quality.

written with love in python3.7

WeatherPi_TFT WeatherPi_TFT

comes with 2 themes (default and darcula styled)

OLD Pics before AA

WeatherPi_TFT

all available weather icons in 2 sizes

thx @erikflowers for his awesome weather-icons

I colored them and put a little glitter on it :)

Weather Icons

icons for moonphases

moon phase rendering: credits to @miyaichi for his awesome fork

Hardware and wiring

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.

PyCharm IDE by intelliJ jetbrains

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 dtoverlaymodule 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:

no configuration needed for:

  • official raspberry pi 7" display
  • any HDMI display
  • skip all the TFT setup parts

wiring

wiring

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

buy complete hardware kit

You can also buy a complete set and build it yourself from my friend Hartmut over at his shop AZ Touch PI0 Kit

BUY HERE

Setup your Pi

install jessie to a sd card and update

setup the SD card

follow the instructions from raspberrypi.org to setup your sd card and operating system

the first boot

finish your setup by following this guide

enable SPI

enable SPI in raspi-config - Interfacing Options

connect to your WiFi

to connect to a wifi network follow this guide

update all tools

set up the TFT

for ili9341 displays from adafruit

for other displays like this you may have to build your own kernel module or find it from your seller.

for Pimoroni Hyperpixel4

just change "FRAMEBUFFER": "/dev/fb1" to "FRAMEBUFFER": "/dev/fb0" later in your config file

you can also change "FPS" to 60 and "AA" to true for mx quality and frames per second. but 30 is more than enough.

it's just needed for the particle simulation for precipitation types like rain and snow.

Everything from 15-30 fps should give you decent animations.

install and configure WeatherPi_TFT

git clone https://github.com/LoveBootCaptain/WeatherPi_TFT.git
cd WeatherPi_TFT

install the dependencies in python3

since the script has to be run by a root user you have to install the dependencies with sudo

sudo pip3 install -r requirements.txt

create a ram disk to protect your sd card

NEW PLEASE UPDATE

WeatherPiTFT will write a json file to your Pi after updating the weather data from the api provider.

this process will reduce writing to your sd card, cause we're writing it only to RAM.

ramdisk will only be used in production mode. means you have set your "ENV" to "Pi" which is default when you followed this guide.

you may also consider using great tooling for writing all logs to ram from @azlux: log2ram

sudo mkdir /mnt/ramdisk
sudo nano /etc/fstab

add the following line right at the end of the opened file

size=5M specifies the size of the reserved ram (5M is more than enough)

tmpfs /mnt/ramdisk tmpfs nodev,nosuid,size=5M 0 0

CTRL-O to save and CTRL-X to quit nano

finally mount the ram disk and reboot your Pi

sudo mount -a
sudo reboot

while your Pi reboots grep your API key ...

get an api key from weatherbit.io

add API key and other options to the config file

when your Pi has rebooted

create a new config-file

cd
cd WeatherPi_TFT
cp example.config.json config.json

edit the config.json file

nano config.json

configure your display options

  "DISPLAY": {
    "WIDTH": 240,
    "HEIGHT": 320,
    "FPS": 30,
    "AA": false,
    "ANIMATION": false,
    "FRAMEBUFFER": "/dev/fb1",
    "PWM": false,
    "SHOW_FPS": true,
    "SHOW_API_STATS": true,
    "MOUSE": true
  },

configure weatherbit.io settings

localise hardcoded strings and ISO settings

  "LOCALE": {
    "ISO": "en_GB",
    "RAIN_STR": "Rain",
    "SNOW_STR": "Snow",
    "PRECIP_STR": "Precipitation",
    "METRIC": true
  },

timer options

  "TIMER": {
    "UPDATE": 420,
    "RELOAD": 30
  },

theme file and theme options

set your theme file [darcula.theme, light.theme or example.theme] in config.json

"THEME": "darcula.theme",

setup the services

sadly pygame doesn't like to work well with systemd... so it has to run as init.d service. maybe someone can help to solve this one time.

cd
cd WeatherPi_TFT
sudo cp WeatherPiTFT.sh /etc/init.d/WeatherPiTFT
sudo cp PiButtons.sh /etc/init.d/PiButtons

run python with root privileges

setting up python3 as default interpreter

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

test the services

Troubleshooting

WeatherPi_TFT in Chinese

WeatherPi_TFT in Chinese

credits

screenshots

darcula styled theme with another font

Darcula styled Theme for WeatherPi_TFT

WeatherPi_TFT