In the previous post, I showed how to make a Raspberry Pi powered Prayer times display using PiTFT. In this post I will show how to make a Raspberry Pi powered Prayer times display using a TV or a monitor as not everyone has PiTFT display.
This project is based on article by Jamie Jackson “Raspberry Pi PiTFT Weather Station” and “Turn your Raspberry Pi into an Azaan/Prayer clock”. You can refer to those for more information. I am just an integrator who puts works of other people together according to my requirement.
Disclaimer: Since the Islamic date and prayer times are based upon calculations, it is very well possible that it may differ from the actual date based on moon sighting. Also, the prayer time can vary from the actual prayer time of the location.
Prerequisites
- Raspberry Pi with Raspbian image
- TV or monitor
- Working Internet connection (for Internet Weather)
Procedure
We will begin by creating a folder in the Raspberry Pi Home directory.
mkdir prayerwall
cd prayerwall
We will go to this directory and download all necessary files.
Prior to that we must install the necessary packages. The first package is the pywapi. This package allows us to fetch weather information from sites like Yahoo weather, weather.com, etc and in an easily parse able form such that we can extract daily weather, weekly weather, temperature, pressure, humidity, etc.
wget https://launchpad.net/python-weather-api/trunk/0.3.8/+download/pywapi-0.3.8.tar.gz
we will extract and install this package.
tar -xzvf pywapi-0.3.8.tar.gz
cd pywapi-0.3.8/
python setup.py build
sudo python setup.py install
Now we need to install the module which converts Gregorian to Islamic date. The installer for the converter module “umalqurra” requires pip, so we will have to install it first.
sudo apt-get install python-pip
Now install the converter module
sudo pip install umalqurra
Files
There are several files required for the display to work.
- praytimes.py : This is the file which will calculate the prayer times for us depending upon the location we live in.
- prayerwalltv.py : This is the python code which combines the prayer times code, the weather code and Islamic date code.
- Weather Logos: Every weather condition has an icon code at weather.com. According to these codes, the display will show an image of the weather condition.
Settings
There are several settings we need to do as weather and prayer times are location specific. Also, people at different locations follow different prayer time calculation method.
The only file that will need to be edited is prayerwalltv.py
sudo nano prayerwalltv.py
In here we have to set the Latitude and Longitude of our location. You should be able to get this if you open http://www.wikimapia.org and take your location at the cross-hair and the Latitude and Longitude will be seen at the lower left corner.
lat = 9.327531
long = 8.086139
You need to get your location code from weather.com so that you can get customized weather for your location. Go to weather.com which should show your location. Click on the location and you should see your code in the webpage URL. It should be 2 characters of country code followed by XX and another 4 numbers.
weatherDotComLocationCode = ‘KUXX1087’
We need to set the Prayer times calculation method. To know more about the calculation methods, go to http://praytimes.org/calculation
My location calculation method is Makkah so I have set it as
PT = PrayTimes(‘Makkah’)
The other options are MWL, ISNA, Egypt, Karachi, Tehran and Jafari.
You can set the display to update at defined intervals. At these intervals, the Pi will fetch weather data and refresh the screen.
updateRate = 600 will give you update interval of 10 minutes
If you would like to alter the position of any text in the display, you can use the following parameters
textAnchorX =
textAnchorY =
textYoffset =
The Origin (0,0) for the display is top left, so give the X Y coordinates accordingly.
Do CTRL-X to save the file with a yes
You can check weather it is displaying properly by executing
sudo python prayerwalltv.py
Once you confirm that it is displaying properly, you can start the script at boot time
Edit the rc.local file and add the below line before exit 0
sudo nano /etc/rc.local
sudo python /home/pi/prayerwall/prayerwalltv.py &
After this, your TV will display the Prayer Times on boot.
Salam aleyka,
thank you for this tuto
Unfortunatly the files are not available anymore, could you update all of them, unless prayerwalltv.py
barakallahoufik
Wa Alaikum Assalam
I have updated the links. Please check.
Hello.
Thank you for this tuto
I tried it thoroughly but it didnt work,
After sudo python prayerwalltv.py nothing happens.
Does it throw any errors?
Hello Samir,
i have an error :
File “prayerwalltv.py”, line 255
currPress = weather_com_result[‘current_conditions’][‘barometer’][‘reading’][:-3] + “mb”
^
IndentationError: unexpected indent
Hi,
The entire statement (till mb) should be in one line.
Hi,
i have error
File “prayerwalltv.py”, line 34
print “I’m running under X” display = {0}.format(disp_no)
^
SyntaxError: invalid syntax
It seems you have changed the location of the double quotes. Refer to the python file
ive this error too by the way.
and then
i’ve error with prayerwalltv.py, it’s show :
+ weather_com_result[‘forecasts’][0][‘date’][:3]
KeyError: ‘forecasts’
Can you paste the snippet of code?
which code?
actually im not change anything.
prayerwalltv.py?
You are supposed to change few things as per the post to customize it according to your location.
yes. prayerwalltv.py
File “/home/pi/prayerwall/pywapi-0.3.8/prayerwalltv.py”, line 34
print “I’m running under X display = {0}”.format(disp_no)
^
SyntaxError: invalid syntax
i’ve error with prayerwalltv.py, it’s show :
+ weather_com_result[‘forecasts’][0][‘date’][:3]
KeyError: ‘forecasts’
Python is very specific about spaces and lines. Compare what I have in my file with yours and don’t make major changes. Whatever I have in one line, you also use one line rather than going to second line.
which code?
it works,but when i restart my raspberry it show : “Driver : Fbcon failed”
Assalamualaikum Sir,
i got the same error sir.
File “/home/pi/prayerwall/pywapi-0.3.8/prayerwalltv.py”, line 34
print “I’m running under X display = {0}”.format(disp_no)
^
SyntaxError: invalid syntax
i not change anything…
can u help me sir.
Generally this error comes due to indentation mismatch in python as python is very specific about alignment, tabs and spaces. Can you re download the file as I have changed indentation.
yes sir. i have download the file prayerwall.py…. after i run,the error appear.
Did you download the file again and then it gave error?
Go into Python IDLE, open up the file and press Ctrl+A to select all the text. Then go to Format > Untabify Region and click ‘OK’ to the dialogue box.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pywapi
import pprint
import pygame
import string
import os
import time
import datetime
from praytimes import PrayTimes
# -*- coding: utf-8 -*-
installPath = “/home/pi/prayerwall/”
# convert mph = kpd / kphToMph
kphToMph = 1.60934400061
from umalqurra.hijri_date import HijriDate
#Get Prayer Times
#——————–
lat = 3.1390
long = 101.6869
class pitft :
screen = None;
colourBlack = (0, 0, 0)
def __init__(self):
“Ininitializes a new pygame screen using the framebuffer”
# Based on “Python GUI in Linux frame buffer” http://www.karoltomala.com/blog/?p=679
disp_no = os.getenv(“DISPLAY”)
if disp_no:
print “I’m running under X display = {0}”.format(disp_no)
os.putenv(‘SDL_FBDEV’, ‘/dev/fb0’)
# Select frame buffer driver Make sure that SDL_VIDEODRIVER is set
driver = ‘fbcon’
if not os.getenv(‘SDL_VIDEODRIVER’):
os.putenv(‘SDL_VIDEODRIVER’, driver)
try:
pygame.display.init()
except pygame.error:
print ‘Driver: {0} failed.’.format(driver)
exit(0)
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
# Clear the screen to start
self.screen.fill((0, 0, 0))
# Initialise font support
pygame.font.init()
# Render the screen
pygame.display.update()
def __del__(self):
“Destructor to make sure pygame shuts down, etc.”
# Create an instance of the PyScope class
mytft = pitft()
pygame.mouse.set_visible(False)
# set up the fonts choose the font
fontpath = pygame.font.match_font(‘arial’)
# set up 2 sizes
font = pygame.font.Font(fontpath, 20)
fontSm = pygame.font.Font(fontpath, 18)
fontLg = pygame.font.Font(fontpath, 60)
fontCn = pygame.font.Font(fontpath, 100)
fontMd = pygame.font.Font(fontpath, 42)
#fontLg.set_bold(True)
colourWhite = (255, 255, 255)
colourBlack = (0, 0, 0)
colourYellow = (255, 255, 0)
colourRed = (255, 0, 0)
colourBlue = (0, 0, 255)
colourGreen = (0, 255, 0)
# update interval
updateRate = 600 # seconds
weatherDotComLocationCode = ‘KUXX1118’
# -*- coding: utf-8 -*-
while True:
weather_com_result = pywapi.get_weather_from_weather_com(weatherDotComLocationCode)
today = weather_com_result[‘forecasts’][0][‘day_of_week’][0:3] + ” ” \
+ weather_com_result[‘forecasts’][0][‘date’][4:] + ” ” \
+ weather_com_result[‘forecasts’][0][‘date’][:3]
windSpeed = int(weather_com_result[‘current_conditions’][‘wind’][‘speed’]) / kphToMph
currWind = “{:.0f}mph “.format(windSpeed) + weather_com_result[‘current_conditions’][‘wind’][‘text’]
currTemp = weather_com_result[‘current_conditions’][‘temperature’] + u’\N{DEGREE SIGN}’ + “C”
currPress = weather_com_result[‘current_conditions’][‘barometer’][‘reading’][:-3] + “mb”
uv = “UV {}”.format(weather_com_result[‘current_conditions’][‘uv’][‘text’])
humid = “Hum {}%”.format(weather_com_result[‘current_conditions’][‘humidity’])
# extract forecast data
forecastDays = {}
forecaseHighs = {}
forecaseLows = {}
forecastPrecips = {}
forecastWinds = {}
start = 0
try:
test = float(weather_com_result[‘forecasts’][0][‘day’][‘wind’][‘speed’])
except ValueError:
start = 1
for i in range(start, 5):
if not(weather_com_result[‘forecasts’][i]):
break
forecastDays[i] = weather_com_result[‘forecasts’][i][‘day_of_week’][0:3]
forecaseHighs[i] = weather_com_result[‘forecasts’][i][‘high’] + u’\N{DEGREE SIGN}’ + “C”
forecaseLows[i] = weather_com_result[‘forecasts’][i][‘low’] + u’\N{DEGREE SIGN}’ + “C”
forecastPrecips[i] = weather_com_result[‘forecasts’][i][‘day’][‘chance_precip’] + “%”
forecastWinds[i] = “{:.0f}”.format(int(weather_com_result[‘forecasts’][i][‘day’][‘wind’][‘speed’]) / kphToMph) + \
weather_com_result[‘forecasts’][i][‘day’][‘wind’][‘text’]
now = datetime.datetime.now()
um = HijriDate(now.year,now.month,now.day,gr=True)
Islamicdate=str(int(um.day))
Islamicmonth=str(int(um.month))
Islamicyear=str(int(um.year))
PT = PrayTimes(‘Makkah’)
times = PT.getTimes((now.year,now.month,now.day), (lat, long), 3,0)
try:
currTemp = weather_com_result[‘current_conditions’][‘temperature’] + u’\N{DEGREE SIGN}’ + “C”
except KeyError:
print(“Maybe net down”)
try:
humid = “{}%”.format(weather_com_result[‘current_conditions’][‘humidity’])
except KeyError:
print(“Maybe net down”)
# blank the screen
mytft.screen.fill(colourBlack)
# Render the weather logo at 0,0
icon = installPath+ (weather_com_result[‘current_conditions’][‘icon’]) + “.png”
logo = pygame.image.load(icon).convert()
mytft.screen.blit(logo, (0, 0))
# set the anchor for the current weather data text
textAnchorX = 156
textAnchorY = 5
textYoffset = 64
# add current weather data text artifacts to the screen
text_surface = fontLg.render(today, True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontLg.render(currTemp, True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontLg.render(currWind, True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontLg.render(currPress, True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontLg.render(uv, True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontLg.render(humid, True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
# set X axis text anchor for the forecast text
textAnchorX = 10
textXoffset = 150
# add each days forecast text
for i in forecastDays:
textAnchorY = 450
text_surface = fontMd.render(forecastDays[int(i)], True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontMd.render(forecaseHighs[int(i)], True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontMd.render(forecaseLows[int(i)], True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontMd.render(forecastPrecips[int(i)], True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontMd.render(forecastWinds[int(i)], True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorX+=textXoffset
# set the anchor for the current Islamic date text
textAnchorX = 612
textAnchorY = 5
# add current Islamicdate text artifacts to the screen
text_surface = fontLg.render(Islamicdate+”.”+Islamicmonth+”.”+Islamicyear+”H”, True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
# set the anchor for the current Prayer time text
textAnchorX = 868
textAnchorY = 128
textYoffset = 128
# add current Prayer data text artifacts to the screen
text_surface = fontLg.render(times[‘fajr’], True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontLg.render(times[‘dhuhr’], True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontLg.render(times[‘asr’], True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontLg.render(times[‘maghrib’], True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontLg.render(times[‘isha’], True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
# set the anchor for the current Prayer time text
textAnchorX = 612
textAnchorY = 128
textYoffset = 128
# add current Prayer data text artifacts to the screen
text_surface = fontLg.render(“Fajr”, True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontLg.render(“Dhuhr”, True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontLg.render(“Asr”, True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontLg.render(“Maghrib”, True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
textAnchorY+=textYoffset
text_surface = fontLg.render(“Isha”, True, colourWhite)
mytft.screen.blit(text_surface, (textAnchorX, textAnchorY))
pygame.display.update()
# Wait
time.sleep(updateRate)
————————————————————————————–
Sir, this is the code that has an error… i just change the location…
Can you just remove the line which is giving the error (the line which has print command) and see if it makes a difference.
do i need to input time zone, its seen the time is off
There is no need for time zone. The time has to be correct in Raspberry Pi system time.
Salam Alyakom Bro,
Can I get a pray reminder for kodi xbmc software ?
Sorry, I don’t have that expertise.
Assalamualaikum, I can’t find the prayerwalltv.py file in the pywapi-0.3.8 folder. Do you have this file in the package? These are the only files I can see: build CHANGELOG examples LICENSE MANIFEST pywapi.py pywapi.pyc README setup.py
Wa Alaikum Assalam. These files are not part of pywapi which is the weather api. If you scroll through the post, necessary files are linked. Also, since the weather API has stopped working, you may have to remove the references for weather in the code.
Assalamualaikum brother.
What do you think would change if i want to use a led matrix like this 1 instead? https://www.adafruit.com/product/2345
Wassalamualaikum…
Wa Alaikum Assalam,
My code displays text on secondary display via mytft.screen.blit. You can replace this with whatever code is relevant with displaying text on RGB Matrix.