Prayer Times Display using Raspberry Pi and PiTFT

For so long I have wanted a mini display to go with my many Raspberry Pis and recently I got the PiTFT 3.5inch to go with the older Raspberry Pis I have and was searching for projects. I landed upon a project “Raspberry Pi PiTFT Weather Station” by Jamie Jackson and started implementing it. After using the weather display for few days, I did not find it much useful as maybe I am not that much into weather. At the same time when I was searching for projects for the PiTFT, I was also searching for ways to sound alarm at the 5 daily prayer times. This is when it clicked me to use the PiTFT to display prayer times. Since the timing for the 5 daily prayer changes every day and changes from location to location, I referred to “Turn your Raspberry Pi into an Azaan/Prayer clock” for the code. In this article, I will show you the procedure how I completed this project. There is lots of room for improvement in this project but I am limited to the knowledge I have of programming. For more information, you can refer to the links above.

PiTFT

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.

This display is not limited to just the prayer times, it also has Islamic Date as well as current weather.

Prerequisites

  1. Raspberry Pi with Raspbian Wheezy image prefererably from Adafruit supporting PiTFT
  2. PiTFT (any size)
  3. 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.

  1. praytimes.py : This is the file which will calculate the prayer times for us depending upon the location we live in.
  2. prayerwall.py : This is the python code which combines the prayer times code, the weather code and Islamic date code.
  3. background.jpg : There will be many static portion on the display, so rather than setting those at their coordinates on the display, I chose to make a static background.

You need to copy the above files to the prayerwall folder

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 prayerwall.py

sudo nano prayerwall.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 prayerwall.py

You might have to change the rotation of the screen in config.txt.

sudo nano /boot/config.txt

Change the “rotate” parameter depending on which side you want to be up. You can keep 0 or 180

dtoverlay=pitft35r,rotate=0,speed=42000000,fps=20

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/prayerwall.py &

After this, your PiTFT will display the Prayer Times on boot.

Mode 2

PiTFT

Recently I got inspired by Fajr Clock which does the same job as this project but the display content is different. So below are the files and procedure if you want such a display.

Files

There are several files required for the display to work.

  1. praytimes.py : This is the file which will calculate the prayer times for us depending upon the location we live in.
  2. horiprayerwall.py : This is the python code which combines the prayer times code, the weather code and Islamic date code.
  3. background.jpg : There will be many static portion on the display, so rather than setting those at their coordinates on the display, I chose to make a static background.

You need to copy the above files to the prayerwall folder

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 horiprayerwall.py

sudo nano horiprayerwall.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 horiprayerwall.py

You might have to change the rotation of the screen in config.txt.

sudo nano /boot/config.txt

Change the “rotate” parameter depending on which side you want to be up. You can keep 90 or 270

dtoverlay=pitft35r,rotate=0,speed=42000000,fps=20

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/horiprayerwall.py &

After this, your PiTFT will display the Prayer Times on boot.

 

8 thoughts on “Prayer Times Display using Raspberry Pi and PiTFT

      • My question was how to insert this line of code, I always get an error, I have some notion in programming but the python escapes me (sorry for my english)

      • Try adding the following line in the prayerwall.py file just below
        times = PT.getTimes((now.year,now.month,now.day), (lat, long), 3,0)
        prayTimes.tune({fajr: -12,sunrise: -1, sunset: 3.5})
        The indentation of the 2 lines should be same
        Even I am not into Python

      • didn’t work ! I still have the same problem :

        Traceback (most recent call last):
        File “/home/pi/prayerwall/prayerwall.py”, line 92, in
        prayTimes.tune({fajr: -12,sunrise: -1, sunset: 3.5})
        NameError: name ‘prayTimes’ is not defined

        Even trying : PT.getTimes((now.year,now.month,now.day), (lat, long), 1,1)
        I changed praytimes.tune whith this — > PT.tune({fajr: -12,sunrise: -1, sunset: 3.5})

        Error:
        Traceback (most recent call last):
        File “/home/pi/prayerwall/prayerwall.py”, line 92, in
        PT.tune({fajr: -12,sunrise: -1, sunset: 3.5})
        NameError: name ‘fajr’ is not defined

  1. Sorry the script crashed

    Traceback (most recent call last):
    File “/home/pi/prayerwall/prayerwall.py”, line 94, in
    PrayTimes.tune( {sunrise: -1, sunset: 3.5} );
    NameError: name ‘sunrise’ is not defined

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s