Azan Clock

by calisb in Circuits > Raspberry Pi

348 Views, 0 Favorites, 0 Comments

Azan Clock

Screenshot 2023-04-28 at 17.40.47.png
Back.jpeg

This project is supposed to remind Muslims of their prayer times. Muslims are expected to pray five times a day. The "Azan" prayer call plays through the speaker when it is time to pray. The right prayer times are updated daily by using API calls. It can run on its own using a battery pack.

Supplies

  • Rasperry Pi Pico W
  • Breadboard
  • Speaker
  • SD Card
  • 1/8 Baltic Birch
  • Battery pack (optional)

Code

This project requires two API calls. One to get the current time and the second API to the get the prayer times. It is important to note that the community library for scheduling "circuitpython_schedule.mpy" needs to be imported. The two API Urls are the following:

  • http://worldtimeapi.org/api/timezone/etc/gmt+4 (current time)
  • http://api.aladhan.com/v1/timingsByCity?city=Boston&country=US&method=8 (prayer times)


# Internet time, rtc, schedule jobs

import os, time, ssl, wifi, socketpool, adafruit_requests

import board, rtc

import circuitpython_schedule as schedule

from audiopwmio import PWMAudioOut as AudioOut

from audiocore import WaveFile

import busio, sdcardio, storage


# setup SD Card pins for SPI

sck = board.GP10

si = board.GP11

so = board.GP12

cs = board.GP13

spi = busio.SPI(sck, si, so)

sdcard = sdcardio.SDCard(spi, cs)

vfs = storage.VfsFat(sdcard)

storage.mount(vfs, "/sd")


# setup audio

from audiomp3 import MP3Decoder

from audiopwmio import PWMAudioOut as AudioOut

audio = AudioOut(board.GP15)

path = "/sd/robot_sounds/"


filename = "0.mp3"

mp3_file = open(path + filename, "rb")

decoder = MP3Decoder(mp3_file)


# function to play mp3 files

def play_mp3(filename):

  decoder.file = open(path + filename, "rb")

  audio.play(decoder)

  while audio.playing:

    pass


# set up real time clock

clock = rtc.RTC()


# log into the WIFI networl using credentials in settings.toml

wifi.radio.connect(os.getenv("WIFI_SSID"), os.getenv("WIFI_PASSWORD"))

print("Connected to WiFi!")


# sockets set up an endpoint for communication as a resuable 'pool'

pool = socketpool.SocketPool(wifi.radio)

# create an object so that a request for web data can be made

requests = adafruit_requests.Session(pool, ssl.create_default_context())


# to get the time, setup the correct URL for the API call

url = "http://worldtimeapi.org/api/timezone/etc/gmt+4"

url2 = "http://api.aladhan.com/v1/timingsByCity?city=Boston&country=US&method=8"


def get_time():

  print(f"Accessing url: {url}")

  response = requests.get(url)


  # convert response into json

  json = response.json()


  # parse out values that we want

  unixtime = json["unixtime"]

  raw_offset = json["raw_offset"]


  # create the local time in seconds

  location_time = unixtime + raw_offset


  # turn seconds into time components #h #min #secs

  current_time = time.localtime(location_time)


  # format and print time & date

  printable_time = f"{current_time.tm_hour:d}:{current_time.tm_min:02d}:{current_time.tm_sec:02d}"

  printable_date = f"{current_time.tm_mon:d}/{current_time.tm_mday:d}/{current_time.tm_year:02d}"

  print(f"Printable_time: {printable_time}")

  print(f"Printable_date: {printable_date}")


  # set the rtc with the component time in current_time

  clock.datetime = time.struct_time(current_time)


  return printable_time


def get_time2():

  print(f"Accessing url: {url2}")

  response = requests.get(url2)


  # convert response into json

  json = response.json()


  # parse out values that we want

  timings = json["data"]["timings"]


  prayer_times = [timings['Fajr'], timings['Dhuhr'], timings['Asr'], timings['Maghrib'], timings['Isha']]


  print(f"Prayer times: {prayer_times}")


  return prayer_times


def job():

  print("PRAYER TIME !!!!!!!!")

  play_mp3("0.mp3")


# Call get_time() once, first to get the time from the internet

printable_time = get_time()

prayer_times = get_time2()


# Schedule the jobs

schedule.every().day.at("00:00").do(get_time)

schedule.every().day.at("00:00").do(get_time2)


prayer_times.append("11:08") # add extra time to the for example run


for alarm_time in prayer_times:

  schedule.every().day.at(alarm_time).do(job)


while True:

  schedule.run_pending()


Assembly

Inside.jpeg

The front has been designed by using Adobe Illustrator and represents a mosque. The design for the box behind was from boxes.py and uses a living hinge. Additionally, a hole for the speaker has been created. All the electronics are in the box. The different parts have been glued together.