Component: LoRa SX1262 wrapper library - Albin-Tenghagen/The-Fellowship-of-the-Code-Flood-checker GitHub Wiki
The SX1262 Module is a module for broadcasting and receiving Long Range
The SX1262 module can be used to send data to other sensors or stations far from where the sensor is.
- Broadcast data
- Receive data
The pins being used in the wrapper library are LORA_NSS, LORA_DIO1, LORA_RST, and LORA_BUSY
It can supply a maximum of 22 dBm.
The wrapper initializes LoRa to use the frequency 434 but the board supports frequencies from 150 MHz to 960 MHz.
#include <Arduino.h>
#include <RTOS.h>
#include "lora/fellowship_lora.h"
uint16_t sensor_value;
uint16_t depth_mm;
uint16_t sensor_value_sum;
uint16_t sensor_average_value;
const uint8_t SENSOR = A4;
const uint8_t MEASURING_POINTS = 50;
void setup()
{
Serial.begin(115200);
int16_t status = fellowshipLoRa::init(); // Initialize LoRa with some predefined values from fellowship_lora_config.h
if (status != RADIOLIB_ERR_NONE)
{
Serial.print("Unable to initialize LoRa! Error ");
Serial.println(status);
while ( true ) { }
}
}
void loop()
{
for (uint8_t i = 0; i < MEASURING_POINTS; i++)
{
sensor_value = analogRead(SENSOR);
depth_mm = (float(map(sensor_value, 600, 3840, 0, 2000)) * 1.20f) / 10;
delay(100);
}
Serial.print("Sensor value: ");
Serial.print(sensor_value);
Serial.print(", Depth in mm: ");
Serial.println(depth_mm);
int16_t status = fellowshipLoRa::write(depth_mm); // Transmit message
if (status != RADIOLIB_ERR_NONE)
{
Serial.print("Unable to write to LoRa! Error ");
Serial.println(status);
while ( true ) { }
}
delay(5000);
}