Initial commit

This commit is contained in:
tom
2025-01-28 21:44:32 +01:00
commit a410b03909
15 changed files with 687 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
/*
Code Base from RadioLib: https://github.com/jgromes/RadioLib/tree/master/examples/SX126x
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <RadioLib.h>
#define LoRa_MOSI 10
#define LoRa_MISO 11
#define LoRa_SCK 9
#define LoRa_nss 8
#define LoRa_dio1 14
#define LoRa_nrst 12
#define LoRa_busy 13
SX1262 radio = new Module(LoRa_nss, LoRa_dio1, LoRa_nrst, LoRa_busy);
void setup()
{
Serial.begin(9600);
SPI.begin(LoRa_SCK, LoRa_MISO, LoRa_MOSI, LoRa_nss);
// initialize SX1262 with default settings
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == RADIOLIB_ERR_NONE)
{
Serial.println(F("success!"));
}
else
{
Serial.print(F("failed, code "));
Serial.println(state);
while (true)
;
}
}
void loop()
{
Serial.print(F("[SX1262] Waiting for incoming transmission ... "));
// you can receive data as an Arduino String
// NOTE: receive() is a blocking method!
// See example ReceiveInterrupt for details
// on non-blocking reception method.
String str;
int state = radio.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE)
{
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[SX1262] Data:\t\t"));
Serial.println(str);
// print the RSSI (Received Signal Strength Indicator)
// of the last received packet
Serial.print(F("[SX1262] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
// print the SNR (Signal-to-Noise Ratio)
// of the last received packet
Serial.print(F("[SX1262] SNR:\t\t"));
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
}
else if (state == RADIOLIB_ERR_RX_TIMEOUT)
{
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
}
else if (state == RADIOLIB_ERR_CRC_MISMATCH)
{
// packet was received, but is malformed
Serial.println(F("CRC error!"));
}
else
{
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}