generated from cepdnaclk/eYY-3yp-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0865922
commit bcf7657
Showing
24 changed files
with
3,284 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
03. Hardware Implementation/LoRa Communication/Reciever/Reciever_V1.0.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
|
||
# Simple demo of sending and recieving data with the RFM95 LoRa radio. | ||
# Author: Tony DiCola | ||
import board | ||
import busio | ||
import digitalio | ||
|
||
import adafruit_rfm9x | ||
|
||
|
||
# Define radio parameters. | ||
RADIO_FREQ_MHZ = 433.0 # Frequency of the radio in Mhz. Must match your | ||
# module! Can be a value like 915.0, 433.0, etc. | ||
|
||
# Define pins connected to the chip, use these if wiring up the breakout according to the guide: | ||
CS = digitalio.DigitalInOut(board.CE1) | ||
RESET = digitalio.DigitalInOut(board.D22) | ||
|
||
# Initialize SPI bus. | ||
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) | ||
|
||
# Initialze RFM radio | ||
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ, baudrate=100000) | ||
|
||
# Note that the radio is configured in LoRa mode so you can't control sync | ||
# word, encryption, frequency deviation, or other settings! | ||
|
||
# You can however adjust the transmit power (in dB). The default is 13 dB but | ||
# high power radios like the RFM95 can go up to 23 dB: | ||
rfm9x.tx_power = 23 | ||
|
||
# Apply new modem config settings to the radio to improve its effective range | ||
rfm9x.signal_bandwidth = 125000 | ||
rfm9x.coding_rate = 8 | ||
rfm9x.spreading_factor = 12 | ||
rfm9x.enable_crc = True | ||
|
||
# Send a packet. Note you can only send a packet up to 252 bytes in length. | ||
# This is a limitation of the radio packet size, so if you need to send larger | ||
# amounts of data you will need to break it into smaller send calls. Each send | ||
# call will wait for the previous one to finish before continuing. | ||
rfm9x.send(bytes("Hello world!\r\n", "utf-8")) | ||
print("Sent Hello World message!") | ||
|
||
# Wait to receive packets. Note that this library can't receive data at a fast | ||
# rate, in fact it can only receive and process one 252 byte packet at a time. | ||
# This means you should only use this for low bandwidth scenarios, like sending | ||
# and receiving a single message at a time. | ||
print("Waiting for packets...") | ||
|
||
while True: | ||
#packet = rfm9x.receive() | ||
# Optionally change the receive timeout from its default of 0.5 seconds: | ||
packet = rfm9x.receive(timeout=5.0,with_header=True) | ||
# If no packet was received during the timeout then None is returned. | ||
if packet is None: | ||
# Packet has not been received | ||
print("Received nothing! Listening again...") | ||
else: | ||
# Received a packet! | ||
# Print out the raw bytes of the packet: | ||
print("Received (raw bytes): {0}".format(packet)) | ||
# And decode to ASCII text and print it too. Note that you always | ||
# receive raw bytes and need to convert to a text format like ASCII | ||
# if you intend to do string processing on your data. Make sure the | ||
# sending side is sending ASCII data before you try to decode! | ||
packet_text = str(packet, "ascii") | ||
print("Received (ASCII): {0}".format(packet_text)) | ||
# Also read the RSSI (signal strength) of the last received message and | ||
# print it. | ||
rssi = rfm9x.last_rssi | ||
print("Received signal strength: {0} dB".format(rssi)) |
131 changes: 131 additions & 0 deletions
131
03. Hardware Implementation/LoRa Communication/Sender/Imager/Imager_V1.0.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
""" | ||
Created by Bimsara Gawesh | ||
Last update on 02 March 2025 | ||
Imager for LoRa communication | ||
This module requires a server for the communication | ||
This is currenty support for load image from the current directory and produce numpy array for communication | ||
Version 1.0 | ||
Key Parameters: | ||
Compatible OS: Raspberry Pi Bustter 2020 | ||
Compatible Python Version: Python 3 | ||
Prerequisites: numpy, pillow | ||
Note: Please reffer github repository for more information | ||
https://github.com/cepdnaclk/e20-3yp-SkyT | ||
""" | ||
|
||
# Import Python System Libraries | ||
import numpy as np | ||
from PIL import Image | ||
|
||
# Function to print details of the image | ||
def printDetails(image): | ||
""" | ||
Prints detailed information about the image. | ||
Parameters: | ||
image (PIL.Image): A Pillow Image object. | ||
Returns: | ||
None | ||
""" | ||
try: | ||
print("Image Details:") | ||
print(f"Format: {image.format}") # Image format (e.g., JPEG, PNG) | ||
print(f"Size: {image.size}") # Tuple (width, height) in pixels | ||
print(f"Mode: {image.mode}") # Color mode (e.g., 'RGB', 'L', 'RGBA') | ||
print(f"Width: {image.width} pixels") | ||
print(f"Height: {image.height} pixels") | ||
print(f"Channels: {len(image.getbands())}") # Number of channels (e.g., 3 for RGB, 1 for grayscale) | ||
|
||
# Additional details | ||
if image.mode == 'P': | ||
print("Note: Image uses a palette (indexed colors).") | ||
if image.info: | ||
print("\nAdditional Metadata:") | ||
for key, value in image.info.items(): | ||
print(f"{key}: {value}") | ||
else: | ||
print("\nNo additional metadata found.") | ||
except AttributeError: | ||
print("Error: Input is not a valid Pillow Image object.") | ||
except Exception as e: | ||
print(f"Error processing image: {e}") | ||
|
||
# Function to print numpy array | ||
def printArrayDetails(array, sample_size=5): | ||
""" | ||
Prints details of a NumPy array, including shape, data type, and a sample of the array. | ||
Parameters: | ||
array (numpy.ndarray): The NumPy array to analyze. | ||
sample_size (int): Number of elements to display from the beginning and end of the array. | ||
Returns: | ||
None | ||
""" | ||
try: | ||
if not isinstance(array, np.ndarray): | ||
raise ValueError("Input is not a NumPy array.") | ||
|
||
print("NumPy Array Details:") | ||
print(f"Shape: {array.shape}") # Dimensions of the array | ||
print(f"Data Type: {array.dtype}") # Data type of the array elements | ||
print(f"Number of Elements: {array.size}") # Total number of elements | ||
print(f"Number of Dimensions: {array.ndim}") # Number of dimensions | ||
|
||
# Print a sample of the array | ||
if array.size <= 2 * sample_size: | ||
print("\nArray Data:") | ||
print(array) | ||
else: | ||
print("\nArray Data (Sample):") | ||
print("First few elements:") | ||
print(array.flatten()[:sample_size]) | ||
print("Last few elements:") | ||
print(array.flatten()[-sample_size:]) | ||
|
||
except Exception as e: | ||
print(f"Error processing NumPy array: {e}") | ||
|
||
# Function to load image and convert it into a numpy array | ||
def loadImage(image_path): | ||
""" | ||
Loads an image from the specified path and converts it into a NumPy array. | ||
Parameters: | ||
image_path (str): Path to the image file. | ||
Returns: | ||
numpy.ndarray: A NumPy array representing the image. | ||
The shape of the array will be (height, width, channels) for RGB images | ||
or (height, width) for grayscale images. | ||
""" | ||
try: | ||
# Open the image using Pillow | ||
img = Image.open(image_path) | ||
|
||
# Print details of the loaded image | ||
printDetails(img) | ||
|
||
# Convert the image to a NumPy array | ||
img_array = np.array(img) | ||
|
||
# Print array details | ||
printArrayDetails(img_array) | ||
|
||
return img_array | ||
|
||
except Exception as e: | ||
print(f"Error loading image: {e}") | ||
return None | ||
|
||
try: | ||
print("LoRa Server Started...") | ||
imageArr = loadImage("image.webp") | ||
except KeyboardInterrupt: | ||
print("\nProgram interrupted") | ||
finally: | ||
# Clean up | ||
print("GPIO cleaned up and program terminated.") |
114 changes: 114 additions & 0 deletions
114
03. Hardware Implementation/LoRa Communication/Sender/Imager/Imager_V1.1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
""" | ||
Created by Bimsara Gawesh | ||
Last update on 02 March 2025 | ||
Imager for LoRa communication | ||
This module requires a server for the communication | ||
This is currenty support for load image from the current directory and produce numpy array for communication | ||
Version 1.0 | ||
Key Parameters: | ||
Compatible OS: Raspberry Pi Bustter 2020 | ||
Compatible Python Version: Python 3 | ||
Prerequisites: numpy, pillow | ||
Note: Please reffer github repository for more information | ||
https://github.com/cepdnaclk/e20-3yp-SkyT | ||
""" | ||
|
||
# Import Python System Libraries | ||
import numpy as np | ||
from PIL import Image | ||
|
||
# Function to print details of the image | ||
def printDetails(image): | ||
""" | ||
Prints detailed information about the image. | ||
Parameters: | ||
image (PIL.Image): A Pillow Image object. | ||
Returns: | ||
None | ||
""" | ||
try: | ||
print("Image Details:") | ||
print(f"Format: {image.format}") # Image format (e.g., JPEG, PNG) | ||
print(f"Size: {image.size}") # Tuple (width, height) in pixels | ||
print(f"Mode: {image.mode}") # Color mode (e.g., 'RGB', 'L', 'RGBA') | ||
print(f"Width: {image.width} pixels") | ||
print(f"Height: {image.height} pixels") | ||
print(f"Channels: {len(image.getbands())}") # Number of channels (e.g., 3 for RGB, 1 for grayscale) | ||
|
||
except AttributeError: | ||
print("Error: Input is not a valid Pillow Image object.") | ||
except Exception as e: | ||
print(f"Error processing image: {e}") | ||
|
||
# Function to print numpy array | ||
def printArrayDetails(array, sample_size=5): | ||
""" | ||
Prints details of a NumPy array, including shape, data type, and a sample of the array. | ||
Parameters: | ||
array (numpy.ndarray): The NumPy array to analyze. | ||
sample_size (int): Number of elements to display from the beginning and end of the array. | ||
Returns: | ||
None | ||
""" | ||
try: | ||
if not isinstance(array, np.ndarray): | ||
raise ValueError("Input is not a NumPy array.") | ||
|
||
print("NumPy Array Details:") | ||
print(f"Shape: {array.shape}") # Dimensions of the array | ||
print(f"Data Type: {array.dtype}") # Data type of the array elements | ||
print(f"Number of Elements: {array.size}") # Total number of elements | ||
print(f"Number of Dimensions: {array.ndim}") # Number of dimensions | ||
|
||
# Print a sample of the array | ||
if array.size <= 2 * sample_size: | ||
print("\nArray Data:") | ||
print(array) | ||
else: | ||
|
||
print("\nArray Data (Sample):") | ||
print("First few elements:") | ||
print(array.flatten()[:sample_size]) | ||
print("Last few elements:") | ||
print(array.flatten()[-sample_size:]) | ||
|
||
except Exception as e: | ||
print(f"Error processing NumPy array: {e}") | ||
|
||
# Function to load image and convert it into a numpy array | ||
def loadImage(image_path): | ||
""" | ||
Loads an image from the specified path and converts it into a NumPy array. | ||
Parameters: | ||
image_path (str): Path to the image file. | ||
Returns: | ||
numpy.ndarray: A NumPy array representing the image. | ||
The shape of the array will be (height, width, channels) for RGB images | ||
or (height, width) for grayscale images. | ||
""" | ||
try: | ||
# Open the image using Pillow | ||
img = Image.open(image_path) | ||
|
||
# Print details of the loaded image | ||
printDetails(img) | ||
|
||
# Convert the image to a NumPy array | ||
img_array = np.array(img, dtype=np.uint8) | ||
|
||
# Print array details | ||
printArrayDetails(img_array) | ||
|
||
return img_array | ||
|
||
except Exception as e: | ||
print(f"Error loading image: {e}") | ||
return None |
45 changes: 45 additions & 0 deletions
45
03. Hardware Implementation/LoRa Communication/Sender/Sender/Sender_V1.0.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Import Python System Libraries | ||
import time | ||
|
||
# Import RFM9x | ||
import adafruit_rfm9x | ||
|
||
# Configure LoRa Radio | ||
# Import Blinka Libraries | ||
import busio | ||
from digitalio import DigitalInOut, Direction, Pull | ||
import board | ||
|
||
RADIO_FREQ_MHZ = 433.0 | ||
|
||
print("Board:", end=": ") | ||
print(board.CE0) | ||
|
||
CS = DigitalInOut(board.CE1) | ||
RESET = DigitalInOut(board.D22) | ||
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) | ||
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)# | ||
|
||
# You can however adjust the transmit power (in dB). The default is 13 dB but | ||
# high power radios like the RFM95 can go up to 23 dB: | ||
rfm9x.tx_power = 23 | ||
|
||
# Apply new modem config settings to the radio to improve its effective range | ||
rfm9x.signal_bandwidth = 125000 | ||
rfm9x.coding_rate = 14 | ||
#rfm9x.spreading_factor = 12 | ||
rfm9x.enable_crc = True | ||
|
||
count = 0 | ||
|
||
while True: | ||
data=bytes(str(count),"utf-8") | ||
rfm9x.send(data) | ||
print(f"data sent: {data.decode()}") | ||
|
||
if(count >= 99): | ||
count = 0 | ||
else: | ||
count += 1 | ||
|
||
time.sleep(1) |
Oops, something went wrong.