Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Raspberry pi pico 2w
120 min
Share

بناء مشروع لعد عدد ركعات الصلاة باستخدام لوحة راسبيرى باى بيكو

في هذا الدرس سنتعلم كيفية بناء دائرة لعد عدد ركعات الصلاة التى يؤديها المصلى باستخدام لوحة راسبيرى باى بيكو 2W، وباستخدام حساس موجات فوق صوتية يستشعر وجود المصلى ويقوم بعد عدد السجدات التى يؤديها المصلى ويزيد عدد الركعات بمقدار ركعة واحدة كل سجدتين لان الركعة الواحدة تحتوى على سجدتين.

Project Video

Overview

Getting the Items

Raspberry Pi Pico 2 wireless
Get Item
Ultrasonic Sensor (HC-SR04)
Get Item
2×16 LCD with I2C Module
Get Item
Push button Switch (5 Pack) - 12mm
Get Item
Full-size Breadboard
Get Item
Jumper Wires - Male to Male (40 Pack)
Get Item
Jumper Wires – Male to Female (40 Pack)
Get Item

Steps

Wiring it Up

قم بتوصيل الأسلاك بين لوحة راسبيرى باى بيكو 2W والشاشة الكريستالية وحساس الموجات فوق الصوتية والزر ضغاط كما فى الصورة التالية:

التوصيلات من لوحة راسبيرى باى بيكو 2W :

•نقوم بتوصيل منفذ ال VBUS بلوحة راسبيرى باى بيكو2W   ← المنافذ الموجبة بلوحة التجارب

•منفذ ال GND بلوحة راسبيرى باى بيكو2W  ←المنافذ السالبة بلوحة التجارب

التوصيلات من حساس الموجات فوق الصوتية :

• منفذ ال VCC للحساس ← المنافذ الموجبة بلوحة التجارب

• منفذ ال GNDللحساس ← المنافذ السالبة بلوحة التجارب

• منفذ الـ TRIG للحساس ← منفذ رقم 13 في لوحة راسبيرى باى بيكو 2W

• منفذ الـ Echo للحساس ← منفذ رقم 14 في بلوحة راسبيرى باى بيكو2W

ثالثا : التوصيلات من الشاشة الكريستالية:

• منفذ ال VCC  للشاشة الكريستالية ← المنافذ الموجبة بلوحة التجارب

• منفذ ال GND  للشاشة الكريستالية ← المنافذ السالبة بلوحة التجارب

• منفذ SDA للشاشة الكريستالية ← منفذ رقم 16 بلوحة راسبيرى باى بيكو 2W

• منفذ SCL للشاشة الكريستالية ← منفذ رقم 17 بلوحة راسبيرى باى بيكو 2W

رابعا: التوصيلات من المفتاح:

• الطرف الأول للمفتاح ← منفذ رقم 15 في بلوحة راسبيرى باى بيكو 2W

• الطرف الثانى للمفتاح ← المنافذ السالبة بلوحة التجارب

Coding

وظيفة هذا النص البرمجى هو عد عدد ركعات الصلاة التى يؤديها المصلى باستخدام حساس موجات فوق صوتية حيث يزيد عدد الركعات بمقدار ركعة واحدة كل سجدتين لان الركعة الواحدة تحتوى على سجدتين.

'''

Voltaat Learn (http://learn.voltaat.com)

Link to the full tutorial:

Tutorial: Building a project to count the number of prayer cycles using a Raspberry Pi Pico board

The function of this code is to count the number of prayer cycles

Note: You can use this sketch with any Raspberry Pi Pico.

'''

import machine

import utime

from machine import Pin, I2C

from lcd_api import LcdApi

from pico_i2c_lcd import I2cLcd

# -----------------------------

# LCD Configuration

# -----------------------------

I2C_ADDR = 0x27

I2C_ROWS = 2

I2C_COLS = 16

i2c = I2C(0, sda=Pin(16), scl=Pin(17), freq=400000)

lcd = I2cLcd(i2c, I2C_ADDR, I2C_ROWS, I2C_COLS)

# -----------------------------

# Pins

# -----------------------------

trig = Pin(13, Pin.OUT)

echo = Pin(14, Pin.IN)

button = Pin(15, Pin.IN, Pin.PULL_UP)

# -----------------------------

# Variables

# -----------------------------

prostrations = 0

rakats = 0

isProstrating = False

prostrationDistance = 40

# -----------------------------

# Custom characters (bars)

# -----------------------------

bar1 = bytearray([0x1C,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1C])

bar2 = bytearray([0x07,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x07])

bar3 = bytearray([0x1F,0x1F,0x00,0x00,0x00,0x00,0x1F,0x1F])

bar4 = bytearray([0x1E,0x1C,0x00,0x00,0x00,0x00,0x18,0x1C])

bar5 = bytearray([0x0F,0x07,0x00,0x00,0x00,0x00,0x03,0x07])

bar6 = bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F])

bar7 = bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F])

bar8 = bytearray([0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00])

lcd.custom_char(1, bar1)

lcd.custom_char(2, bar2)

lcd.custom_char(3, bar3)

lcd.custom_char(4, bar4)

lcd.custom_char(5, bar5)

lcd.custom_char(6, bar6)

lcd.custom_char(7, bar7)

lcd.custom_char(8, bar8)

# -----------------------------

# Distance measuring

# -----------------------------

def measure_distance():

   trig.low()

   utime.sleep_us(2)

   trig.high()

   utime.sleep_us(10)

   trig.low()

   while echo.value() == 0:

       pass

   start = utime.ticks_us()

   while echo.value() == 1:

       pass

   end = utime.ticks_us()

   duration = utime.ticks_diff(end, start)

   distance = (duration * 0.0343) / 2

   return distance

# -----------------------------

# Printing large numbers

# -----------------------------

def printNumber(value, col):

   lcd.move_to(col, 0)

   patterns = {

       0: [[2, 8, 1], [2, 6, 1]],

       1: [[32,32,1], [32,32,1]],

       2: [[5,3,1], [2,6,6]],

       3: [[5,3,1], [7,6,1]],

       4: [[2,6,1], [32,32,1]],

       5: [[2,3,4], [7,6,1]],

       6: [[2,3,4], [2,6,1]],

       7: [[2,8,1], [32,32,1]],

       8: [[2,3,1], [2,6,1]],

       9: [[2,3,1], [7,6,1]]

   }

   top, bottom = patterns[value]

   # Print top row

   lcd.move_to(col, 0)

   for c in top:

       if c == 32:

           lcd.putchar(' ')

       else:

           lcd.putchar(chr(c))

   # Print bottom row

   lcd.move_to(col, 1)

   for c in bottom:

       if c == 32:

           lcd.putchar(' ')

       else:

           lcd.putchar(chr(c))

# -----------------------------

# Main Program

# -----------------------------

# عرض رسالة البداية

lcd.clear()

lcd.move_to(0, 0)

lcd.putstr("     VOLTAAT")  # السطر الأول

lcd.move_to(0, 1)

lcd.putstr(" RAKAT COUNTER")  # السطر الثاني

utime.sleep(2)  # انتظر ثانيتين

# إعداد الشاشة للعرض الرئيسي

lcd.clear()

lcd.move_to(0, 0)

lcd.putstr("Rakat Count:")

printNumber(0, 13)

# -----------------------------

# Loop

# -----------------------------

while True:

   distance = measure_distance()

   # Check for prostration

   if distance < prostrationDistance:

       if not isProstrating:

           isProstrating = True

           prostrations += 1

           # Every two prostrations = one rakat

           if prostrations % 2 == 0:

               rakats += 1

               lcd.move_to(0, 1)

               lcd.putstr(" " * 16)

               printNumber(rakats, 13)

   else:

       isProstrating = False

   # Reset button

   if button.value() == 0:

       prostrations = 0

       rakats = 0

       isProstrating = False

       lcd.move_to(0, 1)

       lcd.putstr(" " * 16)

       printNumber(0, 13)

   utime.sleep_ms(100)

Testing it Out

بعد تشغيل النص البرمجى سوف تجد انه يتم عد عدد ركعات الصلاة التى يؤديها المصلى امام حساس الموجات فوق صوتية.

Resources

No items found.