سلام عليكم،
هل سمعتم عن Raspberry Pi Pico ؟ هو لوحة تحكم صغيرة وقوية تدعم برمجتها بواسطة لغة ميكروبايثون. تتميز ب:- المعالج: ثنائي النواة Arm Cortex-M0+ بتردد 133 ميجاهرتز
- الذاكرة: 264 كيلوبايت SRAM و 2 ميجابايت QSPI Flash
- مصدر الطاقة: 1.8 – 5.5 فولت عبر منفذ micro USB
- لمنافذ: 26 منفذ GPIO
- لغات البرمجة المدعومة: C/C++ و MicroPython
- الأبعاد: 21 × 51 مم
هناك نسخة حديثة تدعم شبكة LAN لاسلكية مدمجة 2.4 جيجا هرتز 802.11n
و تعرف ب Raspberry Pi Pico W
أولا عليك تحميل برنامج Thonny الذي يدعم تحديث الفريموير الداعم للغة الميكروبيثون
ويمكنك معرفة تفاصيل في الموقع الرسمي له
لنتحدث الآن عن قطعة RYLR998 LORA Module ذات خمسة أقطاب :- Vcc: لتغذية 5 فولت
- RST: لا يستخدم
- RXD: منفذ المستقبل في نظام UART
- TXD: منفذ المرسل في نظام UART
- GND: الأرضي المرتبط بالميكروكنترولر
لقد نقلت هذا الموضوع من LoRa and Raspberry Pi Pico W: Building a Sender-Receiver Communication System
طبعا سوف ارفق صورة المخطط لربط Raspberry Pi Pico و module LoRa
و أيضا كود الميكروبايثون في المرة القادمة
|
أعتذر لأنني لم أكمل شرح هذا المشروع لتواصل بين اثنين من الميكروكنترولر عبر تكنولوجية LoRa
المخطط و الكود البرمجي
بالنسبة للمرسل

sender.py
كود:
from machine import UART, Pin
from utime import sleep
# initialize UART
uart0 = UART(id=0, baudrate=115200, tx=Pin(16), rx=Pin(17))
# Function to send a command to the LoRa module
def send_command(command):
if isinstance(command, str):
command = command.encode('ascii') # Convert string to bytes
uart0.write(command + b"\r\n") # Send command with termination
utime.sleep(0.5) # Wait 0.5 seconds to process
while uart0.any(): # Chack if there is a response
response = uart0.read() # Read the response
if response:
print("Response: ", response.decode('utf-8', 'ignore')) # Print response
# Initialize the LoRa module
def initialize_lora():
print("Initializing LoRa...")
send_command(b"AT")
send_command(b"AT+ADDRESS=1")
send_command(b"AT+BAND=91500000")
print("LoRa initialized.")
def send_message():
message = "Hello Receiver"
length = len(message)
command = f"AT+SEND=2,{length},{message}"
send_command(command)
def main():
initialize_lora()
while True:
print("Sending message to Receiver (Address 2)...")
send_message()
utime.sleep(5)
main()
بالنسبة للمستقبل
reciever.py
كود:
from machine import UART, Pin
from utime import sleep
# initialize UART
uart0 = UART(id=0, baudrate=115200, tx=Pin(16), rx=Pin(17))
def recive_command(command):
if isinstance(command, str):
command = command.encode('ascii')
uart0.write(command + b"\r\n")
utime.sleep(0.5)
response_accum = b""
while uart0.any():
response_accum += uart0.read()
if response_accum:
print("Response:", response_accum.decode('utf-8', 'ignore'))
def initialize_lora():
print("Initializing LoRa...")
recive_command("AT")
recive_command("AT+ADDRESS=2")
recive_command("AT+NETWORID=5")
recive_command("AT+BAND=915000000")
print("Receiver LoRa Initialized. Waiting for messages...")
def listen_for_messages():
buffer = b""
while True:
if uart0.any():
data = uart.read()
print(data)
if data:
buffer += data
if b"\r\n" in buffer:
lines = buffer.split(b"\r\n")
buffer = lines.pop()
for line in lines:
line_str = line.decode('utf-8', 'ignore').strip()
if line_str.startswith("+RCV="):
ports = line_str.split(",")
if len(parts) >= 3:
address = parts[0].split('=')[1] if '=' in parts[0] else None
length = parts[1]
message = parts[2]
rssi = parts[3] if len(parts) > 3 else None
snr = parts[4] if len(parts) > 4 else None
#RSSI (Received Signal Strength Indicator) and SNR (Signal-to-Noise Ratio) are key metrics for wireless communication:
# - RSSI measures the strenght of the received signal in decibels-milliwatts (dBm).
# It ranges from -120 dBm (weak signal) to -30 dBm (strong signal). Ahigher (less negative) RSSI is better.
# - SNR measures the clarity of the signal comared to background noise in decibels (db).
# It range from -20 dB (very noisy) to +10 dB (clear signal). A higher SNR indicatedes better signal qualitiy.
# Together, RSSI and SNR help evaluate the reliability and quality of the received signal.
print(f"Received message from address (address): {message}")
print(f"RSSI: {rssi}, SNR: {snr}")
else:
if line_str:
print("Received line: ", Line_str)
def main():
"""
Main program that initializes the LoRa module and listens for messages indefinitely.
- Calls the 'initialize_lora' function to set up the module.
- Enters a loop to continuausly listen for messages using 'listen_for_messages'.
"""
initialize_lora()
listen_for_messages()
main()
انا لم أجرب الكود لكن يمكن ان تشاهد الفيديو لمعرفة كيفية عمله
https://www.youtube.com/watch?v=XV_J2V2Bvx4