# Part 2 - Hands On

## 4. Practicum: LoRa Implementation on ESP32

### A. Hardware Setup (Wiring)

Connect the SX1276/RFM95 module to the ESP32 using the standard SPI configuration:

<table id="bkmrk-lora-pin-esp32-gpio-"><thead><tr><th>LoRa Pin</th><th>ESP32 GPIO</th><th>Function</th></tr></thead><tbody><tr><td>**GND**</td><td>GND</td><td>Ground</td></tr><tr><td>**3.3V**</td><td>3.3V</td><td>Power (Do not use 5V)</td></tr><tr><td>**MISO**</td><td>GPIO 19</td><td>SPI Master In Slave Out</td></tr><tr><td>**MOSI**</td><td>GPIO 23</td><td>SPI Master Out Slave In</td></tr><tr><td>**SCK**</td><td>GPIO 18</td><td>SPI Clock</td></tr><tr><td>**NSS/CS**</td><td>GPIO 5</td><td>Chip Select</td></tr><tr><td>**RST**</td><td>GPIO 14</td><td>Reset</td></tr><tr><td>**DIO0**</td><td>GPIO 26</td><td>Interrupt (IRQ)</td></tr></tbody></table>

### B. Software Preparation

1. Install the **"**LoRa by Sandeep Mistry**"** library via the Arduino Library Manager.
2. Ensure the frequency (`433E6`, `868E6`, or `915E6`) matches your hardware module.

### C. Experiment 1: Basic Sender &amp; Receiver

#### Sender Code:

```c++
#include <SPI.h>
#include <LoRa.h>

// Pin Definitions
#define SS_PIN    5
#define RST_PIN   14
#define DIO0_PIN  26
#define BAND      923E6 

int counter = 0;

void setup() {
  Serial.begin(115200);
  while (!Serial);
  Serial.println("LoRa Sender");
  LoRa.setPins(SS_PIN, RST_PIN, DIO0_PIN);
  
  if (!LoRa.begin(BAND)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
  Serial.print("Sending packet: ");
  Serial.println(counter);

  LoRa.beginPacket();
  LoRa.print("hello ");
  LoRa.print(counter);
  LoRa.endPacket();

  counter++;
  delay(5000);
}
```