# Raspberry Pi and LoRa-E5: P2P Connectivity
## Overview
:::info
:bulb: This template is for onboarding new recruits.
:::
:::success
Hi:smile: Welcome join `company name`!!
:::
[TOC]
### **Raspberry Pi**
Raspberry Pi, renowned for its versatility across various models like the Raspberry Pi 4, 3B+, 3B, and others, is a series of small, powerful single-board computers. These devices are widely used in educational, hobbyist, and professional projects. Each model offers unique features suitable for different applications, but all are characterized by their GPIO interface, support for diverse operating systems, and robust community support.
### **LoRa-E5**
LoRa-E5 is a wireless module based on LoRa technology, designed for long-range, low-power communication in Internet of Things (IoT) applications. It's an embedded module featuring the STM32WLE5JC, integrating both an MCU and LoRa transceiver. LoRa-E5 supports the LoRaWAN protocol and operates on EU868 & US915 frequency bands. It's ideal for applications like smart agriculture, environmental monitoring, and smart city solutions due to its long transmitting range and low power consumption.
## **Peer-to-Peer (P2P) Communication with LoRa**
In P2P communication, two or more devices connect directly with each other without a central network or server. LoRa technology is often used for P2P setups due to its wide coverage area, as illustrated. This range is beneficial in remote or challenging environments where traditional Wi-Fi or cellular connections are impractical or unavailable.
### **Why LoRa for P2P Communication**
- Long Range: LoRa stands out for its ability to cover vast distances, often several kilometers, making it ideal for remote sensor networks or devices spread across large areas.
- Low Power: Devices using LoRa consume minimal power, which is critical for battery-powered sensors or devices in field applications.
- Robustness: LoRa signals can penetrate through obstacles and provide stable connections in various environments, from urban landscapes to rural areas.
- Cost-Effective: Deploying a LoRa-based P2P network can be more affordable compared to cellular or satellite communication, especially in large-scale or geographically dispersed applications.
LoRa's unique characteristics make it an excellent choice for P2P applications, especially where long-range and low-power communication are crucial.
## Demo Overview
This wiki section demonstrates how to pair Raspberry Pi with the Grove Wio-E5 LoRa module for efficient Peer-to-Peer (P2P) communication using LoRa technology.

### :dart:Goal
The goal is to wirelessly connect two Raspberry Pis with the Grove Wio-E5 LoRa module.
- The first Pi, connected to a light sensor, will detect light levels and wirelessly send this information to the second Pi.
- The second Pi, upon receiving the light data, will control an LED to turn it on or off depending on the light intensity.
### :trophy:Achievements
:small_orange_diamond: Sensor Integration: Using Raspberry Pi's GPIO for sensor interfacing and device control.
:small_orange_diamond: LoRa-Based Communication: Implementing long-distance, stable data transmission with LoRa technology.
## Prerequisites
### Background Knowledge
Before proceeding with the demo, it is assumed that you possess the following skills:
- **Raspberry Pi Setup**: Familiar with setting up a Raspberry Pi, including the installation and configuration of the operating system.
- **Basic Command Line Usage**: Comfort and familiarity with using the command line interface for tasks such as navigating directories, software installation, and file editing.
If you require additional guidance on these topics, you can refer to the resources provided at the end of this article.
### Hardware Requirements
- Raspberry Pi Components
- Two Raspberry Pi boards (such as [Raspberry Pi 4](https://www.seeedstudio.com/Raspberry-Pi-4-Computer-Model-B-8GB-p-4595.html)/[3B+](https://www.seeedstudio.com/Raspberry-Pi-3-Model-B--p-3037.html)/[3B](https://www.seeedstudio.com/Raspberry-Pi-3-Model-B-p-2625.html)/[3](https://www.seeedstudio.com/Raspberry-Pi-Compute-Module-3-p-2848.html)/[3A+](https://www.seeedstudio.com/Raspberry-Pi-3-Model-p-3216.html)/[2B](https://www.seeedstudio.com/Raspberry-Pi-2-Model-B-w-ARMv7-Quad-Core-1GB-RAM-p-2289.html)/[B](https://www.seeedstudio.com/Raspberry-Pi-Model-B-p-1634.html)/[Zero](https://www.seeedstudio.com/Raspberry-Pi-Zero-p-4254.html))
- Wi-Fi network or mobile hotspot
- 4GB (or larger) SD card with an SD card reader
- Computer for connecting (PC or Mac)
- 5V 3A USB adapter for power supply (optional)
- One USB-C data cable (used as an example with Pi 4)
- Jumper, Sensors and Actuators
- [Grove - 4 pin Female Jumper to Grove 4 pin Conversion Cable](https://www.seeedstudio.com/Grove-4-pin-Female-Jumper-to-Grove-4-pin-Conversion-Cable-5-PCs-per-PAck.html)
- Light Sensor
- LED
- Network Module
- Grove Wio-E5 LoRa module

> It's worth *noting* that you can replace the Raspberry Pi and LoRa-E5 with any device that supports LoRa functionality.
## Setting Up Raspberry Pi
Before we dive into the demo, it's essential to have your Raspberry Pi devices set up and ready for action. Here are the steps to get your Raspberry Pi boards prepared:
### Install Raspberry Pi OS
To simplify the setup process, we recommend following the official instructions provided on the [Raspberry Pi Official website](https://www.raspberrypi.com/documentation/computers/getting-started.html) or [Setting up your Raspberry Pi](https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up/0). Here's a summarized guide:
1. **Prepare Your SD Card**: Begin by preparing your SD card. You can find detailed steps on how to do this on the official website.
2. **Use Raspberry Pi Imager**: Download and use the [Raspberry Pi Imager](https://www.raspberrypi.com/software/) to install the Raspberry Pi OS on your SD card. This tool simplifies the installation process and ensures you have the latest version of the operating system.

:::info
For more detailed instructions on how to flash the Raspberry Pi OS onto an SD card, refer to the [official Raspberry Pi documentation](https://www.raspberrypi.org/documentation/installation/installing-images/).
:::
In this case, we have preconfigured these parameters to enable the Raspberry Pi OS to quickly establish a Wi-Fi connection and become discoverable on the local network, allowing to be connected via SSH:

By following these steps, you will have the Raspberry Pi OS installed and ready on your SD card.
### Accessing the Terminal
Once the installation is complete, you should be able to access the terminal on both Raspberry Pi boards upon powering them up. You have two options for access:
- **Direct Access**: If you have a keyboard and display connected to your Raspberry Pi, you can access the terminal directly.
- **Remote Access via SSH**: Alternatively, you can access the terminal remotely using SSH, which is particularly useful for headless setups. This enables you to control your Raspberry Pi from another computer. Ensure that SSH is enabled in your Raspberry Pi configuration.
### Setting up your Raspberry Pi
instead of using default GPIO processing, here we use `grove.py` for base.
:::info
For more details about GPIO, navigate to [GPIO and the 40-pin Header](https://www.raspberrypi.com/documentation/computers/os.html#gpio-and-the-40-pin-header).
:::
for example:
```cmd!
python -m venv ~/p2p-e5 // make a
source ~/p2p-e5/bin/activate
pip3 install RPi.GPIO
git clone https://github.com/Seeed-Studio/grove.py ~/grove.py
# All of this are under the p2p-e5 virtual environment
pip3 install ~/grove.py
pip3 install seeed-python-dht
```
How to activate your ...
```
source ~/p2p-e5/bin/activate
```
## Hardware Setup
## Software Setup
If you need to use any with grove, navigate to https://wiki.seeedstudio.com/Grove_Base_Hat_for_Raspberry_Pi to find more for RPI which has given lots library for Python.
Befor you install, I recommand using a vurtual development for it:https://raspberrypi-guide.github.io/programming/create-python-virtual-environment.
对,使用这个,我们会直接采用 Seeed 的grove 库进行。
### Sensor and Actuator Setup

If you have the grove expander, you don't need to have jumper wires.
#### LoRa-E5
....
#### LED For RPI1
1. Connect the LED to the Grove Wio-E5 module using the Grove connector.
With the hardware connections in place, you're ready to start coding and configuring the Raspberry Pis for P2P communication using LoRa technology. In the next section, we'll provide you with the necessary code and steps to make this communication possible.
##### Test Activator
```python
import RPi.GPIO as GPIO
import time
# Set up GPIO using BCM numbering
GPIO.setmode(GPIO.BCM)
led_pin = 3 # GPIO3
# Set up BCM pin 18 (GPIO18) as an output
GPIO.setup(led_pin, GPIO.OUT)
# Example: Blink an LED connected to BCM pin 18 (GPIO18)
try:
while True:
GPIO.output(led_pin, GPIO.HIGH) # Turn LED on
print("LED On")
time.sleep(1) # Wait for 1 second
GPIO.output(led_pin, GPIO.LOW) # Turn LED off
print("LED Off")
time.sleep(1) # Wait for 1 second
except KeyboardInterrupt:
GPIO.cleanup() # Clean up GPIO on CTRL+C exit
```
https://gpiozero.readthedocs.io/en/stable/api_pins.html
change the default pin factory
```python!
import time
from grove.grove_led import GroveLed
led = GroveLed(3) # GPIO3
while True:
led.on() # Turn LED on
print("LED On")
time.sleep(1) # Wait for 1 second
led.off() # Turn LED off
print("LED Off")
time.sleep(1) # Wait for 1 second
```
【Gif 图片】
#### Light Sensor For RPI2
1. Connect the light sensor to the Grove Wio-E5 module using the Grove connector.
##### Test Sensing
```shell
git clone https://github.com/Seeed-Studio/Seeed_Python_DHT.git ~/Seeed_Python_DHT
pip3 install ~/Seeed_Python_DHT
```
```python
import RPi.GPIO as GPIO
import time
# Set up GPIO using BCM numbering
GPIO.setmode(GPIO.BCM)
light_sensor = 3 # GPIO3
# Set up BCM pin 18 (GPIO18) as an output
GPIO.setup(light_sensor, GPIO.read)
# Example: Blink an LED connected to BCM pin 18 (GPIO18)
try:
while True:
GPIO.output(led_pin, GPIO.HIGH) # Turn LED on
time.sleep(1) # Wait for 1 second
GPIO.output(led_pin, GPIO.LOW) # Turn LED off
time.sleep(1) # Wait for 1 second
except KeyboardInterrupt:
GPIO.cleanup() # Clean up GPIO on CTRL+C exit
```
## Software Setup
**GPIO Pin Setup**: As this demo involves using GPIO pins, make sure you are familiar with the GPIO layout of your Raspberry Pi model. You can use the `pinout` command to get a visual representation of the GPIO pins and their functions.
```bash
pinout
```

Ensure you connect the light sensor and LED to the appropriate GPIO pins based on your setup.
With your Raspberry Pi devices prepared and connected, you're ready to move on to the hardware setup and configuring the Grove Wio-E5 LoRa module for P2P communication.-
### LoRaE5 Python Code for P2P Communication
This Python code is designed to facilitate P2P communication using a LoRaE5 module on a Raspberry Pi OS (Linux), leveraging the UART functionality for serial communication. The code provides a framework for sending and receiving data over LoRa, including setup, message formatting, and handling.
```python!
from serial import Serial
import threading
import time
import re
```
According to AT Command Dataset to
## Coding for P2P Communication
Python on Raspberry Pi: https://www.raspberrypi.com/documentation/computers/os.html#python-on-raspberry-pi
Stay tuned for the coding section, where we'll guide you through setting up the code on both Raspberry Pis to enable P2P communication via LoRa technology. We'll cover the GPIO setup, sensor data transmission, and LED control.
This hands-on demonstration will help you understand the practical implementation of P2P communication using Raspberry Pi and LoRa-E5. Get ready to explore the world of IoT communication!
Once you've completed the hardware setup, proceed to the coding section to bring your P2P communication project to life.
I've added the content for the "Setting Up Raspberry Pi" and "Hardware Setup" sections, including the steps to prepare Raspberry Pi boards and connect the Grove Wio-E5 module. Additionally, I've mentioned that the coding section will follow in the next part of the Wiki, where you'll find instructions on setting up the code for P2P communication.
If you have any specific code or details you'd like to include in the coding section, please let me know, and I'll include them in the next part of the Wiki.
https://pinout.xyz/ 引脚定义
## Conclusion and Further Applications
<!-- ### Summarizing the Project
- Recap of what was achieved in the demo and why it’s significant.
### Expanding the Project
- Ideas on how this setup can be modified or expanded for other applications.
-->
## References and Additional Resources
- **Code Samples**: Links to code repositories or Gists containing the scripts used.
- **Further Reading**: Suggested resources for more advanced LoRa and Raspberry Pi applications.
## Tech Support & Product Discussion
Thank you for choosing our products! We are here to provide you with different support to ensure that your experience with our products is as smooth as possible. We offer several communication channels to cater to different preferences and needs.