first commit

This commit is contained in:
2021-05-11 20:43:42 +03:00
commit 9f3ffaba30
381 changed files with 69596 additions and 0 deletions

View File

@@ -0,0 +1,183 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 02/03/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - This is a program that demonstrates the detailed setup of a LoRa test transmitter.
A packet containing ASCII text is sent according to the frequency and LoRa settings specified in the
'Settings.h' file. The pins to access the lora device need to be defined in the 'Settings.h' file also.
The details of the packet sent and any errors are shown on the Arduino IDE Serial Monitor, together with
the transmit power used, the packet length and the CRC of the packet. The matching receive program,
'104_LoRa_Receiver' can be used to check the packets are being sent correctly, the frequency and LoRa
settings (in Settings.h) must be the same for the transmitter and receiver programs. Sample Serial
Monitor output;
10dBm Packet> Hello World 1234567890* BytesSent,23 CRC,DAAB TransmitTime,64mS PacketsSent,2
Serial monitor baud rate is set at 9600
*******************************************************************************************************/
#define Program_Version "V1.1"
#include <SPI.h> //the lora device is SPI based so load the SPI library
#include <SX127XLT.h> //include the appropriate library
#include "Settings.h" //include the setiings file, frequencies, LoRa settings etc
SX127XLT LT; //create a library class instance called LT
uint8_t TXPacketL;
uint32_t TXPacketCount, startmS, endmS;
uint8_t buff[] = "Hello World 1234567890";
void loop()
{
Serial.print(TXpower); //print the transmit power defined
Serial.print(F("dBm "));
Serial.print(F("Packet> "));
Serial.flush();
TXPacketL = sizeof(buff); //set TXPacketL to length of array
buff[TXPacketL - 1] = '*'; //replace null character at buffer end so its visible on reciver
LT.printASCIIPacket(buff, TXPacketL); //print the buffer (the sent packet) as ASCII
digitalWrite(LED1, HIGH);
startmS = millis(); //start transmit timer
if (LT.transmit(buff, TXPacketL, 10000, TXpower, WAIT_TX)) //will return packet length sent if OK, otherwise 0 if transmit error
{
endmS = millis(); //packet sent, note end time
TXPacketCount++;
packet_is_OK();
}
else
{
packet_is_Error(); //transmit packet returned 0, there was an error
}
digitalWrite(LED1, LOW);
Serial.println();
delay(packet_delay); //have a delay between packets
}
void packet_is_OK()
{
//if here packet has been sent OK
uint16_t localCRC;
Serial.print(F(" BytesSent,"));
Serial.print(TXPacketL); //print transmitted packet length
localCRC = LT.CRCCCITT(buff, TXPacketL, 0xFFFF);
Serial.print(F(" CRC,"));
Serial.print(localCRC, HEX); //print CRC of transmitted packet
Serial.print(F(" TransmitTime,"));
Serial.print(endmS - startmS); //print transmit time of packet
Serial.print(F("mS"));
Serial.print(F(" PacketsSent,"));
Serial.print(TXPacketCount); //print total of packets sent OK
}
void packet_is_Error()
{
//if here there was an error transmitting packet
uint16_t IRQStatus;
IRQStatus = LT.readIrqStatus(); //read the the interrupt register
Serial.print(F(" SendError,"));
Serial.print(F("Length,"));
Serial.print(TXPacketL); //print transmitted packet length
Serial.print(F(",IRQreg,"));
Serial.print(IRQStatus, HEX); //print IRQ status
LT.printIrqStatus(); //prints the text of which IRQs set
}
void led_Flash(uint16_t flashes, uint16_t delaymS)
{
uint16_t index;
for (index = 1; index <= flashes; index++)
{
digitalWrite(LED1, HIGH);
delay(delaymS);
digitalWrite(LED1, LOW);
delay(delaymS);
}
}
void setup()
{
pinMode(LED1, OUTPUT); //setup pin as output for indicator LED
led_Flash(2, 125); //two quick LED flashes to indicate program start
Serial.begin(9600);
Serial.println();
Serial.print(F(__TIME__));
Serial.print(F(" "));
Serial.println(F(__DATE__));
Serial.println(F(Program_Version));
Serial.println();
Serial.println(F("103_LoRa_Transmitter_Detailed_Setup Starting"));
SPI.begin();
//SPI beginTranscation is normally part of library routines, but if it is disabled in library
//a single instance is needed here, so uncomment the program line below
//SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
//setup hardware pins used by device, then check if device is found
if (LT.begin(NSS, NRESET, DIO0, DIO1, DIO2, LORA_DEVICE))
{
Serial.println(F("LoRa Device found"));
led_Flash(2, 125); //two further quick LED flashes to indicate device found
delay(1000);
}
else
{
Serial.println(F("No device responding"));
while (1)
{
led_Flash(50, 50); //long fast speed LED flash indicates device error
}
}
//The function call list below shows the complete setup for the LoRa device using the information defined in the
//Settings.h file.
//The 'Setup LoRa device' list below can be replaced with a single function call;
//LT.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate, Optimisation);
//***************************************************************************************************
//Setup LoRa device
//***************************************************************************************************
LT.setMode(MODE_STDBY_RC); //got to standby mode to configure device
LT.setPacketType(PACKET_TYPE_LORA); //set for LoRa transmissions
LT.setRfFrequency(Frequency, Offset); //set the operating frequency
LT.calibrateImage(0); //run calibration after setting frequency
LT.setModulationParams(SpreadingFactor, Bandwidth, CodeRate, LDRO_AUTO); //set LoRa modem parameters
LT.setBufferBaseAddress(0x00, 0x00); //where in the SX buffer packets start, TX and RX
LT.setPacketParams(8, LORA_PACKET_VARIABLE_LENGTH, 255, LORA_CRC_ON, LORA_IQ_NORMAL); //set packet parameters
LT.setSyncWord(LORA_MAC_PRIVATE_SYNCWORD); //syncword, LORA_MAC_PRIVATE_SYNCWORD = 0x12, or LORA_MAC_PUBLIC_SYNCWORD = 0x34
LT.setHighSensitivity(); //set for highest sensitivity at expense of slightly higher LNA current
LT.setDioIrqParams(IRQ_RADIO_ALL, IRQ_TX_DONE, 0, 0); //set for IRQ on RX done
//***************************************************************************************************
Serial.println();
LT.printModemSettings(); //reads and prints the configured LoRa settings, useful check
Serial.println();
LT.printOperatingSettings(); //reads and prints the configured operating settings, useful check
Serial.println();
Serial.println();
LT.printRegisters(0x00, 0x4F); //print contents of device registers, normally 0x00 to 0x4F
Serial.println();
Serial.println();
Serial.print(F("Transmitter ready"));
Serial.println();
}

View File

@@ -0,0 +1,39 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 02/03/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
//******* Setup hardware pin definitions here ! ***************
//These are the pin definitions for one of my own boards, the Easy Pro Mini,
//be sure to change the definitions to match your own setup. Some pins such as DIO1,
//DIO2, BUZZER are not used by this sketch so they do not need to be connected and
//should be set to -1.
#define NSS 10 //select pin on LoRa device
#define NRESET 9 //reset pin on LoRa device
#define LED1 8 //on board LED, high for on
#define DIO0 3 //DIO0 pin on LoRa device, used for RX and TX done
#define DIO1 -1 //DIO1 pin on LoRa device, normally not used so set to -1
#define DIO2 -1 //DIO2 pin on LoRa device, normally not used so set to -1
#define LORA_DEVICE DEVICE_SX1278 //we need to define the device we are using
//******* Setup LoRa Parameters Here ! ***************
//LoRa Modem Parameters
const uint32_t Frequency = 434000000; //frequency of transmissions in hertz
const uint32_t Offset = 0; //offset frequency for calibration purposes
const uint8_t Bandwidth = LORA_BW_125; //LoRa bandwidth
const uint8_t SpreadingFactor = LORA_SF7; //LoRa spreading factor
const uint8_t CodeRate = LORA_CR_4_5; //LoRa coding rate
const uint8_t Optimisation = LDRO_AUTO; //low data rate optimisation setting, normally set to auto
const int8_t TXpower = 10; //LoRa transmit power in dBm
const uint16_t packet_delay = 1000; //mS delay between packets

View File

@@ -0,0 +1,250 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 02/03/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - This is a program that demonstrates the detailed setup of a LoRa test receiver.
The program listens for incoming packets using the LoRa settings in the 'Settings.h' file. The pins
to access the lora device need to be defined in the 'Settings.h' file also.
There is a printout on the Arduino IDE Serial Monitor of the valid packets received, the packet is
assumed to be in ASCII printable text, if it's not ASCII text characters from 0x20 to 0x7F, expect
weird things to happen on the Serial Monitor. The LED will flash for each packet received and the
buzzer will sound, if fitted.
Sample serial monitor output;
7s Hello World 1234567890*,CRC,DAAB,RSSI,-52dBm,SNR,9dB,Length,23,Packets,5,Errors,0,IRQreg,50
If there is a packet error it might look like this, which is showing a CRC error,
968s PacketError,RSSI,-87dBm,SNR,-11dB,Length,23,Packets,613,Errors,2,IRQreg,70,IRQ_HEADER_VALID,IRQ_CRC_ERROR,IRQ_RX_DONE
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
#define Program_Version "V1.1"
#include <SPI.h> //the lora device is SPI based so load the SPI library
#include <SX127XLT.h> //include the appropriate library
#include "Settings.h" //include the setiings file, frequencies, LoRa settings etc
SX127XLT LT; //create a library class instance called LT
uint32_t RXpacketCount;
uint32_t errors;
uint8_t RXBUFFER[RXBUFFER_SIZE]; //create the buffer that received packets are copied into
uint8_t RXPacketL; //stores length of packet received
int16_t PacketRSSI; //stores RSSI of received packet
int8_t PacketSNR; //stores signal to noise ratio (SNR) of received packet
void loop()
{
RXPacketL = LT.receive(RXBUFFER, RXBUFFER_SIZE, 60000, WAIT_RX); //wait for a packet to arrive with 60seconds (60000mS) timeout
digitalWrite(LED1, HIGH); //something has happened
if (BUZZER > 0) //turn buzzer on
{
digitalWrite(BUZZER, HIGH);
}
PacketRSSI = LT.readPacketRSSI(); //read the recived RSSI value
PacketSNR = LT.readPacketSNR(); //read the received SNR value
if (RXPacketL == 0) //if the LT.receive() function detects an error, RXpacketL is 0
{
packet_is_Error();
}
else
{
packet_is_OK();
}
if (BUZZER > 0)
{
digitalWrite(BUZZER, LOW); //buzzer off
}
delay(10); //so we can see LED flash more easily on fast processors
digitalWrite(LED1, LOW); //LED off
Serial.println();
}
void packet_is_OK()
{
uint16_t IRQStatus, localCRC;
IRQStatus = LT.readIrqStatus(); //read the LoRa device IRQ status register
RXpacketCount++;
printElapsedTime(); //print elapsed time to Serial Monitor
Serial.print(F(" "));
LT.printASCIIPacket(RXBUFFER, RXPacketL); //print the packet as ASCII characters
localCRC = LT.CRCCCITT(RXBUFFER, RXPacketL, 0xFFFF); //calculate the CRC, this is the external CRC calculation of the RXBUFFER
Serial.print(F(",CRC,")); //contents, not the LoRa device internal CRC
Serial.print(localCRC, HEX);
Serial.print(F(",RSSI,"));
Serial.print(PacketRSSI);
Serial.print(F("dBm,SNR,"));
Serial.print(PacketSNR);
Serial.print(F("dB,Length,"));
Serial.print(RXPacketL);
Serial.print(F(",Packets,"));
Serial.print(RXpacketCount);
Serial.print(F(",Errors,"));
Serial.print(errors);
Serial.print(F(",IRQreg,"));
Serial.print(IRQStatus, HEX);
}
void packet_is_Error()
{
uint16_t IRQStatus;
IRQStatus = LT.readIrqStatus(); //read the LoRa device IRQ status register
printElapsedTime(); //print elapsed time to Serial Monitor
if (IRQStatus & IRQ_RX_TIMEOUT) //check for an RX timeout
{
Serial.print(F(" RXTimeout"));
}
else
{
errors++;
Serial.print(F(" PacketError"));
Serial.print(F(",RSSI,"));
Serial.print(PacketRSSI);
Serial.print(F("dBm,SNR,"));
Serial.print(PacketSNR);
Serial.print(F("dB,Length,"));
Serial.print(LT.readRXPacketL()); //get the device packet length
Serial.print(F(",Packets,"));
Serial.print(RXpacketCount);
Serial.print(F(",Errors,"));
Serial.print(errors);
Serial.print(F(",IRQreg,"));
Serial.print(IRQStatus, HEX);
LT.printIrqStatus(); //print the names of the IRQ registers set
}
delay(250); //gives a longer buzzer and LED flash for error
}
void printElapsedTime()
{
float seconds;
seconds = millis() / 1000;
Serial.print(seconds, 0);
Serial.print(F("s"));
}
void led_Flash(uint16_t flashes, uint16_t delaymS)
{
uint16_t index;
for (index = 1; index <= flashes; index++)
{
digitalWrite(LED1, HIGH);
delay(delaymS);
digitalWrite(LED1, LOW);
delay(delaymS);
}
}
void setup()
{
pinMode(LED1, OUTPUT); //setup pin as output for indicator LED
led_Flash(2, 125); //two quick LED flashes to indicate program start
Serial.begin(9600);
Serial.println();
Serial.print(F(__TIME__));
Serial.print(F(" "));
Serial.println(F(__DATE__));
Serial.println(F(Program_Version));
Serial.println();
Serial.println(F("104_Lora_Receiver_Detailed_Setup Starting"));
Serial.println();
if (BUZZER > 0)
{
pinMode(BUZZER, OUTPUT);
digitalWrite(BUZZER, HIGH);
delay(50);
digitalWrite(BUZZER, LOW);
}
SPI.begin();
//SPI beginTranscation is normally part of library routines, but if it is disabled in the library
//a single instance is needed here, so uncomment the program line below
//SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
//setup hardware pins used by device, then check if device is found
if (LT.begin(NSS, NRESET, DIO0, DIO1, DIO2, LORA_DEVICE))
{
Serial.println(F("Lora Device found"));
led_Flash(2, 125);
delay(1000);
}
else
{
Serial.println(F("No device responding"));
while (1)
{
led_Flash(50, 50); //long fast speed LED flash indicates device error
}
}
//The function call list below shows the complete setup for the LoRa device using the information defined in the
//Settings.h file.
//The 'Setup Lora device' list below can be replaced with a single function call;
//LT.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate, Optimisation);
//***************************************************************************************************
//Setup Lora device
//***************************************************************************************************
LT.setMode(MODE_STDBY_RC); //got to standby mode to configure device
LT.setPacketType(PACKET_TYPE_LORA); //set for LoRa transmissions
LT.setRfFrequency(Frequency, Offset); //set the operating frequency
LT.calibrateImage(0); //run calibration after setting frequency
LT.setModulationParams(SpreadingFactor, Bandwidth, CodeRate, LDRO_AUTO); //set LoRa modem parameters
LT.setBufferBaseAddress(0x00, 0x00); //where in the SX buffer packets start, TX and RX
LT.setPacketParams(8, LORA_PACKET_VARIABLE_LENGTH, 255, LORA_CRC_ON, LORA_IQ_NORMAL); //set packet parameters
LT.setSyncWord(LORA_MAC_PRIVATE_SYNCWORD); //syncword, LORA_MAC_PRIVATE_SYNCWORD = 0x12, or LORA_MAC_PUBLIC_SYNCWORD = 0x34
LT.setHighSensitivity(); //set for highest sensitivity at expense of slightly higher LNA current
LT.setDioIrqParams(IRQ_RADIO_ALL, IRQ_RX_DONE, 0, 0); //set for IRQ on RX done
//***************************************************************************************************
Serial.println();
LT.printModemSettings(); //reads and prints the configured LoRa settings, useful check
Serial.println();
LT.printOperatingSettings(); //reads and prints the configured operting settings, useful check
Serial.println();
Serial.println();
LT.printRegisters(0x00, 0x4F); //print contents of device registers, normally 0x00 to 0x4F
Serial.println();
Serial.println();
Serial.print(F("Receiver ready - RXBUFFER_SIZE "));
Serial.println(RXBUFFER_SIZE);
Serial.println();
}

View File

@@ -0,0 +1,44 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 02/03/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
//******* Setup hardware pin definitions here ! ***************
//These are the pin definitions for one of my own boards, the Easy Pro Mini,
//be sure to change the definitions to match your own setup. Some pins such as DIO1,
//DIO2, BUZZER may not be in used by this sketch so they do not need to be
//connected and should be set to -1.
#define NSS 10 //select pin on LoRa device
#define NRESET 9 //reset pin on LoRa device
#define LED1 8 //on board LED, high for on
#define DIO0 3 //DIO0 pin on LoRa device, used for RX and TX done
#define DIO1 -1 //DIO1 pin on LoRa device, normally not used so set to -1
#define DIO2 -1 //DIO2 pin on LoRa device, normally not used so set to -1
#define BUZZER 4 //pin for buzzer, on when logic high
#define LORA_DEVICE DEVICE_SX1278 //we need to define the device we are using
//******* Setup LoRa Parameters Here ! ***************
//LoRa Modem Parameters
const uint32_t Frequency = 434000000; //frequency of transmissions in hertz
const uint32_t Offset = 0; //offset frequency for calibration purposes
const uint8_t Bandwidth = LORA_BW_125; //LoRa bandwidth
const uint8_t SpreadingFactor = LORA_SF7; //LoRa spreading factor
const uint8_t CodeRate = LORA_CR_4_5; //LoRa coding rate
const uint8_t Optimisation = LDRO_AUTO; //low data rate optimisation setting, normally set to auto
const int8_t TXpower = 2; //LoRa transmit power in dBm
const uint16_t packet_delay = 1000; //mS delay between packets
#define RXBUFFER_SIZE 32 //RX buffer size

View File

@@ -0,0 +1,145 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 16/12/19
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - This program demonstrates the transmitting of a structure as a LoRa packet. The
contents of the structure are the same as in the '8_LoRa_LowMemory_TX' program. The packet sent is
typical of what might be sent from a GPS tracker.
The structure type is defined as trackerPacket and an instance called location1 is created. The struture
which includes a character array (text) is filled with values and transmitted.
The matching receiving program '15_LoRa_RX_Structure' can be used to receive and display the packet,
though the program '9_LoRa_LowMemory_RX' should receive it as well, since the contents are the same.
Note that the structure definition and variable order (including the buffer size) used in the transmitter
need to match those used in the receiver.
The contents of the packet transmitted should be;
"tracker1" (buffer) - trackerID
1+ (uint32_t) - packet count
51.23456 (float) - latitude
-3.12345 (float) - longitude
199 (uint16_t) - altitude
8 (uint8_t) - number of satellites
3999 (uint16_t) - battery voltage
-9 (int8_t) - temperature
Good luck.
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
#include <SPI.h>
#include <SX127XLT.h>
#include "Settings.h"
SX127XLT LT;
uint32_t TXpacketCount = 1;
uint32_t startmS, endmS;
struct trackerPacket
{
uint8_t trackerID[13];
uint32_t txcount;
float latitude;
float longitude;
uint16_t altitude;
uint8_t satellites;
uint16_t voltage;
int8_t temperature;
};
struct trackerPacket location1; //define an instance called location1 of the structure trackerPacket
void loop()
{
//fill the defined structure with values
uint8_t buff[] = "tracker1"; //create the contents to be of location1.trackerID
memcpy (&location1.trackerID, &buff, sizeof(buff)); //copy the contents of buff[] into the structure
location1.txcount = TXpacketCount;
location1.latitude = 51.23456;
location1.longitude = -3.12345;
location1.altitude = 199;
location1.satellites = 8;
location1.voltage = 3999;
location1.temperature = -9;
digitalWrite(LED1, HIGH);
startmS = millis();
if (LT.transmit((uint8_t *) &location1, sizeof(location1), 0, TXpower, WAIT_TX)) //will return packet length sent if OK, otherwise 0
{
endmS = millis();
digitalWrite(LED1, LOW);
TXpacketCount++;
Serial.print(TXpacketCount);
Serial.print(F(" "));
Serial.print(sizeof(location1));
Serial.print(F(" Bytes Sent"));
Serial.print(F(" "));
Serial.print(endmS - startmS);
Serial.print(F("mS"));
}
else
{
Serial.print(F("Send Error - IRQreg,"));
Serial.print(LT.readIrqStatus(), HEX);
}
digitalWrite(LED1, LOW);
Serial.println();
delay(packet_delay);
}
void led_Flash(uint16_t flashes, uint16_t delaymS)
{
uint16_t index;
for (index = 1; index <= flashes; index++)
{
digitalWrite(LED1, HIGH);
delay(delaymS);
digitalWrite(LED1, LOW);
delay(delaymS);
}
}
void setup()
{
pinMode(LED1, OUTPUT); //setup pin as output for indicator LED
led_Flash(2, 125); //two quick LED flashes to indicate program start
Serial.begin(9600);
SPI.begin();
if (LT.begin(NSS, NRESET, DIO0, DIO1, DIO2, LORA_DEVICE))
{
led_Flash(2, 125);
}
else
{
Serial.println(F("Device error"));
while (1)
{
led_Flash(50, 50); //long fast speed flash indicates device error
}
}
LT.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate, Optimisation);
Serial.println(F("Transmitter ready"));
Serial.println();
}

View File

@@ -0,0 +1,39 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 16/12/19
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
//******* Setup hardware pin definitions here ! ***************
//These are the pin definitions for one of my own boards, the Easy Pro Mini,
//be sure to change the definitiosn to match your own setup. Some pins such as DIO1,
//DIO2, may not be in used by this sketch so they do not need to be connected and
//should be set to -1.
#define NSS 10 //select on LoRa device
#define NRESET 9 //reset on LoRa device
#define DIO0 3 //DIO0 on LoRa device, used for RX and TX done
#define DIO1 -1 //DIO1 on LoRa device, normally not used so set to -1
#define DIO2 -1 //DIO2 on LoRa device, normally not used so set to -1
#define LED1 8 //On board LED, high for on
#define LORA_DEVICE DEVICE_SX1278 //this is the device we are using
//******* Setup LoRa Test Parameters Here ! ***************
//LoRa Modem Parameters
const uint32_t Frequency = 434000000; //frequency of transmissions
const uint32_t Offset = 0; //offset frequency for calibration purposes
const uint8_t Bandwidth = LORA_BW_125; //LoRa bandwidth
const uint8_t SpreadingFactor = LORA_SF7; //LoRa spreading factor
const uint8_t CodeRate = LORA_CR_4_5; //LoRa coding rate
const uint8_t Optimisation = LDRO_AUTO; //low data rate optimisation setting
const int8_t TXpower = 10; //LoRa TX power
#define packet_delay 1000 //mS delay between packets

View File

@@ -0,0 +1,194 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 17/12/19
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - This program demonstrates the receiving of a structure as a LoRa packet. The packet
sent is typical of what might be sent from a GPS tracker.
The structure type is defined as trackerPacket and an instance called location1 is created. The structure
includes a character array (text).
The matching receiving program is '15_LoRa_RX_Structure' can be used to receive and display the packet,
though the program '9_LoRa_LowMemory_RX' should receive it as well, since the packet contents are the same.
Not that the structure definition and variable order (including the buffer size) used in the transmitter
need to match those used in the receiver. Good luck.
The contents of the packet received, and printed to serial monitor, should be;
"tracker1" (buffer) - trackerID
1+ (uint32_t) - packet count
51.23456 (float) - latitude
-3.12345 (float) - longitude
199 (uint16_t) - altitude
8 (uint8_t) - number of satellites
3999 (uint16_t) - battery voltage
-9 (int8_t) - temperature
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
#include <SPI.h>
#include <SX127XLT.h>
#include "Settings.h"
SX127XLT LT;
uint8_t RXPacketL; //stores length of packet received
uint32_t RXpacketCount; //count of received packets
int16_t PacketRSSI; //RSSI of received packet
int8_t PacketSNR; //signal to noise ratio of received packet
uint32_t errors; //count of packet errors
struct trackerPacket
{
uint8_t trackerID[13];
uint32_t txcount;
float latitude;
float longitude;
uint16_t altitude;
uint8_t satellites;
uint16_t voltage;
int8_t temperature;
};
struct trackerPacket location1; //define an instance called location1 of the structure trackerPacket
void loop()
{
RXPacketL = LT.receive( (uint8_t *) &location1, sizeof(location1), 0, WAIT_RX); //wait for a packet to arrive with no timeout
digitalWrite(LED1, HIGH); //something has happened, what I wonder ?
PacketRSSI = LT.readPacketRSSI();
PacketSNR = LT.readPacketSNR();
if (RXPacketL == 0)
{
packet_is_Error();
}
else
{
packet_is_OK();
}
digitalWrite(LED1, LOW);
Serial.println();
}
void printlocation1()
{
uint8_t buff[13]; //define a buffer to receive a copy from the structure
memcpy (&buff, &location1.trackerID, sizeof(buff)); //copy the contents of buffer in struture to buff[]
//now print the contents of the structure
Serial.print((char*) buff); //cast to a char type for printing
Serial.print(F(","));
Serial.print(location1.txcount);
Serial.print(F(","));
Serial.print(location1.latitude, 5);
Serial.print(F(","));
Serial.print(location1.longitude, 5);
Serial.print(F(","));
Serial.print(location1.altitude);
Serial.print(F("m,"));
Serial.print(location1.satellites);
Serial.print(F("sats,"));
Serial.print(location1.voltage);
Serial.print(F("mV,"));
Serial.print(location1.temperature);
Serial.print(F("c "));
}
void packet_is_OK()
{
RXpacketCount++;
Serial.print(RXpacketCount);
Serial.print(F(" "));
printlocation1();
printpacketDetails();
}
void packet_is_Error()
{
uint16_t IRQStatus;
IRQStatus = LT.readIrqStatus();
if (IRQStatus & IRQ_RX_TIMEOUT)
{
Serial.print(F("RXTimeout"));
}
else
{
errors++;
Serial.print(F("PacketError"));
printpacketDetails();
Serial.print(F("IRQreg,"));
Serial.print(IRQStatus, HEX);
}
}
void printpacketDetails()
{
Serial.print(F(" RSSI,"));
Serial.print(PacketRSSI);
Serial.print(F("dBm,SNR,"));
Serial.print(PacketSNR);
Serial.print(F("dB"));
}
void led_Flash(uint16_t flashes, uint16_t delaymS)
{
uint16_t index;
for (index = 1; index <= flashes; index++)
{
digitalWrite(LED1, HIGH);
delay(delaymS);
digitalWrite(LED1, LOW);
delay(delaymS);
}
}
void setup(void)
{
pinMode(LED1, OUTPUT); //setup pin as output for indicator LED
led_Flash(2, 125); //two quick LED flashes to indicate program start
Serial.begin(9600);
SPI.begin();
if (LT.begin(NSS, NRESET, DIO0, DIO1, DIO2, LORA_DEVICE))
{
led_Flash(2, 125);
delay(1000);
}
else
{
Serial.println(F("Device error"));
while (1)
{
led_Flash(50, 50);
}
}
LT.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate, Optimisation);
Serial.print(F("Receiver ready"));
Serial.println();
Serial.println();
}

View File

@@ -0,0 +1,39 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 17/12/19
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
//******* Setup hardware pin definitions here ! ***************
//These are the pin definitions for one of my own boards, the Easy Pro Mini,
//be sure to change the definitiosn to match your own setup. Some pins such as DIO1,
//DIO2, may not be in used by this sketch so they do not need to be connected and
//should be set to -1.
#define NSS 10 //select on LoRa device
#define NRESET 9 //reset on LoRa device
#define DIO0 3 //DIO0 on LoRa device, used for RX and TX done
#define DIO1 -1 //DIO1 on LoRa device, normally not used so set to -1
#define DIO2 -1 //DIO2 on LoRa device, normally not used so set to -1
#define LED1 8 //On board LED, high for on
#define LORA_DEVICE DEVICE_SX1278 //this is the device we are using
//******* Setup LoRa Test Parameters Here ! ***************
//LoRa Modem Parameters
const uint32_t Frequency = 434000000; //frequency of transmissions
const uint32_t Offset = 0; //offset frequency for calibration purposes
const uint8_t Bandwidth = LORA_BW_125; //LoRa bandwidth
const uint8_t SpreadingFactor = LORA_SF7; //LoRa spreading factor
const uint8_t CodeRate = LORA_CR_4_5; //LoRa coding rate
const uint8_t Optimisation = LDRO_AUTO; //low data rate optimisation setting
const int8_t TXpower = 10; //LoRa TX power in dBm
#define packet_delay 1000 //mS delay between packets

View File

@@ -0,0 +1,72 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 16/12/19
This programs is supplied as is, it is up to the user of the program to decide if the programs are
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - This program blinks an LED connected the pin number defined below. The pin 13 LED,
fitted to some Arduinos is blinked as well. The blinks should be close to one per second. messages are
sent to the Serial Monitor also.
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
#define LED1 8 //pin number for LED, set logic level high for on
#define Program_Version "V1.0"
uint16_t seconds; //used to display time elapsed on Serial Monitor
void loop()
{
Serial.print(seconds);
Serial.println(F(" Seconds")); //this message should print on console at close to once per second
seconds++;
digitalWrite(LED1, HIGH);
digitalWrite(13, HIGH);
delay(100);
digitalWrite(LED1, LOW);
digitalWrite(13, LOW);
delay(890); //should give approx 1 second flash
}
void led_Flash(uint16_t flashes, uint16_t delaymS)
{
//general purpose routine for flashing LED as indicator
uint16_t index;
for (index = 1; index <= flashes; index++)
{
digitalWrite(LED1, HIGH); //LED on
digitalWrite(13, HIGH); //Arduino board LED on
delay(delaymS);
digitalWrite(LED1, LOW); //LED off
digitalWrite(13, LOW); //Arduino board LED off
delay(delaymS);
}
}
void setup()
{
pinMode(LED1, OUTPUT); //setup pin as output for indicator LED
pinMode(13, OUTPUT); //setup pin as output for some Arduino boards that include an LED on pin 13
digitalWrite(LED1, HIGH);
digitalWrite(13, HIGH);
led_Flash(2, 125); //two quick LED flashes to indicate program start
Serial.begin(9600);
Serial.println();
Serial.print(__TIME__);
Serial.print(F(" "));
Serial.println(__DATE__);
Serial.println(F(Program_Version));
Serial.println();
Serial.println(F("1_LED_Blink Starting"));
}

View File

@@ -0,0 +1,266 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 18/03/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - This program is stand alone, it is not necessary to install the SX12XX-LoRa library
to use it. This test program is for the SX127X LoRa devices.
The program checks that a lora device can be accessed by doing a test register write and read.
If there is no device found a message is printed on the serial monitor. The contents of the registers
from 0x00 to 0x7F are printed and the program then changes the frequency between two values and prints
out the registers. This is to prove that the device registers are being read and written correctly.
There is a copy of the typical printout below. Note that the read back changed frequency may be slightly
different to the programmed frequency, there is a rounding error due to the use of floats to calculate
the frequency. Although the program sets the frequency in the 434Mhz band, it will work on 868Mhz and
915Mhz devices and there is no attempt to confugure the device for transmission or reception.
The Arduino pin number that NSS on the LoRa device is connected to must be specified in #define NSS
line below. Leave the NRESET and DIOx pins not connected.
Typical printout;
2_Register_Test Starting
LoRa Device found
Device version 0x12
Frequency at Start 434000000
Registers at Start
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
0x00 00 09 1A 0B 00 52 6C 80 00 4F 09 2B 20 08 02 0A
0x10 FF 70 15 0B 28 0C 12 47 32 3E 00 00 00 00 00 40
0x20 00 00 00 00 05 00 03 93 55 55 55 55 55 55 55 55
0x30 90 40 40 00 00 0F 00 00 00 F5 20 82 FD 02 80 40
0x40 00 00 12 24 2D 00 03 00 04 23 00 09 05 84 32 2B
0x50 14 00 00 10 00 00 00 0F E0 00 0C FD 06 00 5C 78
0x60 00 19 0C 4B CC 0D FD 20 04 47 AF 3F F6 3F DB 0B
0x70 D0 01 10 00 00 00 00 00 00 00 00 00 00 00 00 00
Change Frequency to 434100000
Changed Frequency 434099968
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
0x00 00 09 1A 0B 00 52 6C 86 66 4F 09 2B 20 08 02 0A
0x10 FF 70 15 0B 28 0C 12 47 32 3E 00 00 00 00 00 40
0x20 00 00 00 00 05 00 03 93 55 55 55 55 55 55 55 55
0x30 90 40 40 00 00 0F 00 00 00 F5 20 82 FD 02 80 40
0x40 00 00 12 24 2D 00 03 00 04 23 00 09 05 84 32 2B
0x50 14 00 00 10 00 00 00 0F E0 00 0C FD 06 00 5C 78
0x60 00 19 0C 4B CC 0D FD 20 04 47 AF 3F F6 3F DB 0B
0x70 D0 01 10 00 00 00 00 00 00 00 00 00 00 00 00 00
Change Frequency to 434200000
Changed Frequency 434199936
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
0x00 00 09 1A 0B 00 52 6C 8C CC 4F 09 2B 20 08 02 0A
0x10 FF 70 15 0B 28 0C 12 47 32 3E 00 00 00 00 00 40
0x20 00 00 00 00 05 00 03 93 55 55 55 55 55 55 55 55
0x30 90 40 40 00 00 0F 00 00 00 F5 20 82 FD 02 80 40
0x40 00 00 12 24 2D 00 03 00 04 23 00 09 05 84 32 2B
0x50 14 00 00 10 00 00 00 0F E0 00 0C FD 06 00 5C 78
0x60 00 19 0C 4B CC 0D FD 20 04 47 AF 3F F6 3F DB 0B
0x70 D0 01 10 00 00 00 00 00 00 00 00 00 00 00 00 00
Note: An SX1272 will report as version 0x22 and the frequency at power up is 915000000hz.
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
const uint8_t REG_FRMSB = 0x06; //register number for setting and reading frequency, high byte
const uint8_t REG_FRMID = 0x07; //register number for setting and reading frequency, mid byte
const uint8_t REG_FRLSB = 0x08; //register number for setting and reading frequency, low byte
const uint8_t REG_VERSION = 0x42; //register containg version number of device
//********* Setup hardware pin definition here ! **************
#define NSS 10 //lora device select
//**************************************************************/
#include <SPI.h>
uint32_t frequency;
void setup()
{
Serial.begin(9600);
Serial.println(F("2_Register_Test Starting"));
SPI.begin();
SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
//The begin function setups the hardware pins used by device and then checks if device is found
if (begin(NSS))
{
Serial.println(F("LoRa Device found"));
}
else
{
Serial.println(F("No device responding"));
}
Serial.print(F("Device version 0x"));
uint8_t deviceversion = readRegister(REG_VERSION);
if (deviceversion < 0x10)
{
Serial.print(F("0"));
}
Serial.println(deviceversion, HEX);
frequency = getFreqInt(); //read the set frequency following a reset
Serial.print(F("Frequency at Start "));
Serial.println(frequency);
Serial.println(F("Registers at Start ")); //show the all registers following a power up
printRegisters(0x00, 0x7F);
}
void loop()
{
Serial.println();
Serial.println();
Serial.println(F("Change Frequency to 434100000"));
setRfFrequency(434100000, 0); //change the frequency at reset, in hertz
frequency = getFreqInt(); //read back the changed frequency
Serial.print(F("Changed Frequency "));
Serial.println(frequency); //print the changed frequency, did the write work (allow for rounding errors) ?
printRegisters(0x00, 0x7F); //show the registers after frequency change
Serial.println();
Serial.println(F("Change Frequency to 434200000"));
setRfFrequency(434200000, 0); //change the frequency at reset, in hertz
frequency = getFreqInt(); //read back the changed frequency
Serial.print(F("Changed Frequency "));
Serial.println(frequency); //print the changed frequency, did the write work (allow for rounding errors) ?
printRegisters(0x00, 0x7F); //show the registers after frequency change
Serial.println();
delay(5000);
}
uint8_t readRegister(uint8_t address)
{
uint8_t regdata;
digitalWrite(NSS, LOW); //set NSS low
SPI.transfer(address & 0x7F); //mask address for read
regdata = SPI.transfer(0); //read the byte
digitalWrite(NSS, HIGH); //set NSS high
return regdata;
}
void writeRegister(uint8_t address, uint8_t value)
{
digitalWrite(NSS, LOW); //set NSS low
SPI.transfer(address | 0x80); //mask address for write
SPI.transfer(value); //write the byte
digitalWrite(NSS, HIGH); //set NSS high
}
uint32_t getFreqInt()
{
//get the current set LoRa device frequency, return as long integer
uint8_t Msb, Mid, Lsb;
uint32_t uinttemp;
float floattemp;
Msb = readRegister(REG_FRMSB);
Mid = readRegister(REG_FRMID);
Lsb = readRegister(REG_FRLSB);
floattemp = ((Msb * 0x10000ul) + (Mid * 0x100ul) + Lsb);
floattemp = ((floattemp * 61.03515625) / 1000000ul);
uinttemp = (uint32_t)(floattemp * 1000000);
return uinttemp;
}
void printRegisters(uint16_t Start, uint16_t End)
{
//prints the contents of lora device registers to serial monitor
uint16_t Loopv1, Loopv2, RegData;
Serial.print(F("Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F"));
Serial.println();
for (Loopv1 = Start; Loopv1 <= End;)
{
Serial.print(F("0x"));
if (Loopv1 < 0x10)
{
Serial.print(F("0"));
}
Serial.print((Loopv1), HEX);
Serial.print(F(" "));
for (Loopv2 = 0; Loopv2 <= 15; Loopv2++)
{
RegData = readRegister(Loopv1);
if (RegData < 0x10)
{
Serial.print(F("0"));
}
Serial.print(RegData, HEX);
Serial.print(F(" "));
Loopv1++;
}
Serial.println();
}
}
void setRfFrequency(uint64_t freq64, int32_t offset)
{
freq64 = freq64 + offset;
freq64 = ((uint64_t)freq64 << 19) / 32000000;
writeRegister(REG_FRMSB, (uint8_t)(freq64 >> 16));
writeRegister(REG_FRMID, (uint8_t)(freq64 >> 8));
writeRegister(REG_FRLSB, (uint8_t)(freq64 >> 0));
}
bool begin(int8_t pinNSS)
{
pinMode(pinNSS, OUTPUT);
digitalWrite(pinNSS, HIGH);
if (checkDevice())
{
return true;
}
return false;
}
bool checkDevice()
{
//check there is a device out there, writes a register and reads back
uint8_t Regdata1, Regdata2;
Regdata1 = readRegister(REG_FRMID); //low byte of frequency setting
writeRegister(REG_FRMID, (Regdata1 + 1));
Regdata2 = readRegister(REG_FRMID); //read changed value back
writeRegister(REG_FRMID, Regdata1); //restore register to original value
if (Regdata2 == (Regdata1 + 1))
{
return true;
}
else
{
return false;
}
}

View File

@@ -0,0 +1,121 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 02/03/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - This is a minimum setup LoRa test transmitter. A packet containing the ASCII text
"Hello World 1234567890" is sent using the frequency and LoRa settings specified in the LT.setupLoRa()
command. The pins to access the lora device need to be defined at the top of the program also.
The details of the packet sent and any errors are shown on the Arduino IDE Serial Monitor, together with
the transmit power used and the packet length. The matching receiver program, '4_LoRa_Receiver' can be used
to check the packets are being sent correctly, the frequency and LoRa settings (in the LT.setupLoRa()
commands) must be the same for the transmitter and receiver programs. Sample Serial Monitor output;
10dBm Packet> Hello World 1234567890* BytesSent,23 PacketsSent,6
For an example of a more detailed configuration for a transmitter, see program 103_LoRa_Transmitter.
Serial monitor baud rate is set at 9600
*******************************************************************************************************/
#define Program_Version "V1.0"
#include <SPI.h> //the lora device is SPI based so load the SPI library
#include <SX127XLT.h> //include the appropriate library
SX127XLT LT; //create a library class instance called LT
#define NSS 10 //select pin on LoRa device
#define NRESET 9 //reset pin on LoRa device
#define DIO0 3 //DIO0 pin on LoRa device, used for sensing RX and TX done
#define LORA_DEVICE DEVICE_SX1278 //we need to define the device we are using
#define TXpower 10 //LoRa transmit power in dBm
uint8_t TXPacketL;
uint32_t TXPacketCount;
uint8_t buff[] = "Hello World 1234567890"; //the message to send
void setup()
{
Serial.begin(9600);
Serial.println();
Serial.println(F("3_LoRa_Transmitter Starting"));
SPI.begin();
if (LT.begin(NSS, NRESET, DIO0, LORA_DEVICE))
{
Serial.println(F("LoRa Device found"));
delay(1000);
}
else
{
Serial.println(F("No device responding"));
while (1);
}
LT.setupLoRa(434000000, 0, LORA_SF7, LORA_BW_125, LORA_CR_4_5, LDRO_AUTO); //configure frequency and LoRa settings
Serial.print(F("Transmitter ready"));
Serial.println();
}
void loop()
{
Serial.print(TXpower); //print the transmit power defined
Serial.print(F("dBm "));
Serial.print(F("Packet> "));
Serial.flush();
TXPacketL = sizeof(buff); //set TXPacketL to length of array
buff[TXPacketL - 1] = '*'; //replace null character at buffer end so its visible on receiver
LT.printASCIIPacket(buff, TXPacketL); //print the buffer (the sent packet) as ASCII
if (LT.transmit(buff, TXPacketL, 10000, TXpower, WAIT_TX)) //will return packet length sent if OK, otherwise 0 if transmit error
{
TXPacketCount++;
packet_is_OK();
}
else
{
packet_is_Error(); //transmit packet returned 0, there was an error
}
Serial.println();
delay(1000); //have a delay between packets
}
void packet_is_OK()
{
//if here packet has been sent OK
Serial.print(F(" BytesSent,"));
Serial.print(TXPacketL); //print transmitted packet length
Serial.print(F(" PacketsSent,"));
Serial.print(TXPacketCount); //print total of packets sent OK
}
void packet_is_Error()
{
//if here there was an error transmitting packet
uint16_t IRQStatus;
IRQStatus = LT.readIrqStatus(); //read the the interrupt register
Serial.print(F(" SendError,"));
Serial.print(F("Length,"));
Serial.print(TXPacketL); //print transmitted packet length
Serial.print(F(",IRQreg,"));
Serial.print(IRQStatus, HEX); //print IRQ status
LT.printIrqStatus(); //prints the text of which IRQs set
}

View File

@@ -0,0 +1,168 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 02/03/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - This is a minimum setup LoRa test receiver. The program listens for incoming packets
using the frequency and LoRa settings in the LT.setupLoRa() command. The pins to access the lora device
need to be defined at the top of the program also.
There is a printout on the Arduino IDE serial monitor of the valid packets received, the packet is assumed
to be in ASCII printable text, if it's not ASCII text characters from 0x20 to 0x7F, expect weird things to
happen on the Serial Monitor. Sample serial monitor output;
8s Hello World 1234567890*,RSSI,-44dBm,SNR,9dB,Length,23,Packets,7,Errors,0,IRQreg,50
If there is a packet error it might look like this, which is showing a CRC error;
137s PacketError,RSSI,-89dBm,SNR,-8dB,Length,23,Packets,37,Errors,2,IRQreg,70,IRQ_HEADER_VALID,IRQ_CRC_ERROR,IRQ_RX_DONE
If there are no packets received in a 10 second period then you should see a message like this;
112s RXTimeout
For an example of a more detailed configuration for a receiver, see program 104_LoRa_Receiver.
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
#define Program_Version "V1.1"
#include <SPI.h> //the lora device is SPI based so load the SPI library
#include <SX127XLT.h> //include the appropriate library
SX127XLT LT; //create a library class instance called LT
#define NSS 10 //select pin on LoRa device
#define NRESET 9 //reset pin on LoRa device
#define DIO0 3 //DIO0 pin on LoRa device, used for RX and TX done
#define LORA_DEVICE DEVICE_SX1278 //we need to define the device we are using
#define RXBUFFER_SIZE 255 //RX buffer size
uint32_t RXpacketCount;
uint32_t errors;
uint8_t RXBUFFER[RXBUFFER_SIZE]; //create the buffer that received packets are copied into
uint8_t RXPacketL; //stores length of packet received
int16_t PacketRSSI; //stores RSSI of received packet
int8_t PacketSNR; //stores signal to noise ratio (SNR) of received packet
void setup()
{
Serial.begin(9600);
Serial.println();
Serial.println(F("4_LoRa_Receiver Starting"));
Serial.println();
SPI.begin();
if (LT.begin(NSS, NRESET, DIO0, LORA_DEVICE))
{
Serial.println(F("LoRa Device found"));
delay(1000);
}
else
{
Serial.println(F("No device responding"));
while (1);
}
LT.setupLoRa(434000000, 0, LORA_SF7, LORA_BW_125, LORA_CR_4_5, LDRO_AUTO); //configure frequency and LoRa settings
Serial.print(F("Receiver ready - RXBUFFER_SIZE "));
Serial.println(RXBUFFER_SIZE);
Serial.println();
}
void loop()
{
RXPacketL = LT.receive(RXBUFFER, RXBUFFER_SIZE, 60000, WAIT_RX); //wait for a packet to arrive with 60seconds (60000mS) timeout
PacketRSSI = LT.readPacketRSSI(); //read the received packets RSSI value
PacketSNR = LT.readPacketSNR(); //read the received packets SNR value
if (RXPacketL == 0) //if the LT.receive() function detects an error RXpacketL is 0
{
packet_is_Error();
}
else
{
packet_is_OK();
}
Serial.println();
}
void packet_is_OK()
{
uint16_t IRQStatus;
RXpacketCount++;
IRQStatus = LT.readIrqStatus(); //read the LoRa device IRQ status register
printElapsedTime(); //print elapsed time to Serial Monitor
Serial.print(F(" "));
LT.printASCIIPacket(RXBUFFER, RXPacketL); //print the packet as ASCII characters
Serial.print(F(",RSSI,"));
Serial.print(PacketRSSI);
Serial.print(F("dBm,SNR,"));
Serial.print(PacketSNR);
Serial.print(F("dB,Length,"));
Serial.print(RXPacketL);
Serial.print(F(",Packets,"));
Serial.print(RXpacketCount);
Serial.print(F(",Errors,"));
Serial.print(errors);
Serial.print(F(",IRQreg,"));
Serial.print(IRQStatus, HEX);
}
void packet_is_Error()
{
uint16_t IRQStatus;
IRQStatus = LT.readIrqStatus(); //read the LoRa device IRQ status register
printElapsedTime(); //print elapsed time to Serial Monitor
if (IRQStatus & IRQ_RX_TIMEOUT) //check for an RX timeout
{
Serial.print(F(" RXTimeout"));
}
else
{
errors++;
Serial.print(F(" PacketError"));
Serial.print(F(",RSSI,"));
Serial.print(PacketRSSI);
Serial.print(F("dBm,SNR,"));
Serial.print(PacketSNR);
Serial.print(F("dB,Length,"));
Serial.print(LT.readRXPacketL()); //get the real packet length
Serial.print(F(",Packets,"));
Serial.print(RXpacketCount);
Serial.print(F(",Errors,"));
Serial.print(errors);
Serial.print(F(",IRQreg,"));
Serial.print(IRQStatus, HEX);
LT.printIrqStatus(); //print the names of the IRQ registers set
}
}
void printElapsedTime()
{
float seconds;
seconds = millis() / 1000;
Serial.print(seconds, 0);
Serial.print(F("s"));
}

View File

@@ -0,0 +1,93 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 23/02/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - Transmits a FM tone using the LoRa device that can be picked up on an FM UHF
handheld receiver. The tones are not true FM but the UHF receiver does not know that.
Serial monitor baud rate is set at 9600
*******************************************************************************************************/
#define Program_Version "V1.0"
#include <SPI.h> //the lora device is SPI based so load the SPI library
#include <SX127XLT.h> //include the appropriate library
#include "Settings.h" //include the setiings file, frequencies, LoRa settings etc
SX127XLT LT; //create a library class instance called LT
void loop()
{
Serial.print(TXpower); //print the transmit power defined
Serial.print(F("dBm "));
Serial.println(F("PlayTone> "));
Serial.println();
digitalWrite(LED1, HIGH);
LT.toneFM(1000, 1000, deviation, adjustfreq, TXpower);
digitalWrite(LED1, LOW);
delay(1000);
}
void led_Flash(uint16_t flashes, uint16_t delaymS)
{
uint16_t index;
for (index = 1; index <= flashes; index++)
{
digitalWrite(LED1, HIGH);
delay(delaymS);
digitalWrite(LED1, LOW);
delay(delaymS);
}
}
void setup()
{
pinMode(LED1, OUTPUT); //setup pin as output for indicator LED
led_Flash(2, 125); //two quick LED flashes to indicate program start
Serial.begin(9600);
Serial.println();
Serial.print(F(__TIME__));
Serial.print(F(" "));
Serial.println(F(__DATE__));
Serial.println(F(Program_Version));
Serial.println();
Serial.println(F("58_FM_Tone Starting"));
SPI.begin();
//SPI beginTranscation is normally part of library routines, but if it is disabled in library
//a single instance is needed here, so uncomment the program line below
//SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
//setup hardware pins used by device, then check if device is found
if (LT.begin(NSS, NRESET, DIO0, DIO1, DIO2, LORA_DEVICE))
{
Serial.println(F("LoRa Device found"));
led_Flash(2, 125); //two further quick LED flashes to indicate device found
delay(1000);
}
else
{
Serial.println(F("No device responding"));
while (1)
{
led_Flash(50, 50); //long fast speed LED flash indicates device error
}
}
LT.setupDirect(Frequency, Offset);
Serial.print(F("Tone Transmitter ready"));
Serial.println();
}

View File

@@ -0,0 +1,32 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 23/02/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
//******* Setup hardware pin definitions here ! ***************
//These are the pin definitions for one of my own boards, the Easy Pro Mini,
//be sure to change the definitions to match your own setup. Some pins such as DIO1,
//DIO2 are not used by this particular sketch so they are set to -1 and not connected.
#define NSS 10 //select pin on LoRa device
#define NRESET 9 //reset pin on LoRa device
#define LED1 8 //on board LED, high for on
#define DIO0 3 //DIO0 pin on LoRa device, used for RX and TX done
#define DIO1 -1 //DIO1 pin on LoRa device, normally not used so set to -1
#define DIO2 -1 //DIO2 pin on LoRa device, normally not used so set to -1
#define LORA_DEVICE DEVICE_SX1278 //we need to define the device we are using
//******* Setup Direct Modem Parameters Here ! ***************
const uint32_t Frequency = 434000000; //frequency of transmissions in hertz
const uint32_t Offset = 0; //offset frequency for calibration purposes
const uint16_t deviation = 10000; //deviation, total frequency shift low to high
const float adjustfreq = 0.9; //adjustment to tone frequency
const int8_t TXpower = 10; //LoRa transmit power in dBm

View File

@@ -0,0 +1,200 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 10/06/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - This is demonstration of using automatic frequency adjustments (AFC) on a receiver
to keep the frequency difference between transmitter and receiver as low as possible. The LoRa settings
used are defined in the Settings.h file.
If a packet is received OK, then all that is needed is a call to the LT.doAFC() function, that reads the
last frequency error, calculates the new offset and changes the set frequency accordingly.
When the receiver starts the frequency error may be as large as 4000hz, when the AFC operates the error
should reduce to 100hz or so. The first AFC correction to run is doAFCPPM(); which based on the frequency
error also adjusts the PPM setting. If doAFC(); were only used then as the frequency error is reduced then
the PPM adjustment would reduce.
Note that the maximum permitted frequency error between transmitter and receiver is 25% of the bandwidth
in use. So at 125000hz bandwidth the maximum frequency error is 31500hz, if the bandwidth is 7800hz the
maximum frequency error is 1950hz. Whilst the AFC functionality can keep transmitter and receiver close
together when reception is working if the transmitter and receiver are to far apart in frequency for
reception to work in the first place then AFC cannot operate to correct for the frequency differences.
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
#define Program_Version "V1.0"
#include <SPI.h> //the lora device is SPI based so load the SPI library
#include <SX127XLT.h> //include the appropriate library
#include "Settings.h"
SX127XLT LT; //create a library class instance called LT
uint32_t RXpacketCount;
uint32_t errors;
uint8_t RXBUFFER[RXBUFFER_SIZE]; //create the buffer that received packets are copied into
uint8_t RXPacketL; //stores length of packet received
int16_t PacketRSSI; //stores RSSI of received packet
int8_t PacketSNR; //stores signal to noise ratio (SNR) of received packet
int32_t frequencyerror; //frequency error of receved packet
bool FirstAFC = true; //used to note that AFC has been called more than once
void loop()
{
Serial.print(F("SetFrequency,"));
Serial.print(Frequency);
Serial.print(F("hz,Offset,"));
Serial.print(LT.getOffset());
Serial.print(F("hz "));
RXPacketL = LT.receive(RXBUFFER, RXBUFFER_SIZE, 60000, WAIT_RX); //wait for a packet to arrive with 60seconds (60000mS) timeout
PacketRSSI = LT.readPacketRSSI(); //read the received packets RSSI value
PacketSNR = LT.readPacketSNR(); //read the received packets SNR value
if (RXPacketL == 0) //if the LT.receive() function detects an error RXpacketL is 0
{
packet_is_Error();
}
else
{
packet_is_OK();
if (FirstAFC)
{
LT.doAFCPPM(); //the first time AFC is called do the PPM adjust also
FirstAFC = false;
}
else
{
LT.doAFC(); //PPM adjust has been done so now just adjust frequency
}
}
Serial.println();
}
void packet_is_OK()
{
uint16_t IRQStatus;
RXpacketCount++;
IRQStatus = LT.readIrqStatus(); //read the LoRa device IRQ status register
frequencyerror = LT.getFrequencyErrorHz();
printElapsedTime(); //print elapsed time to Serial Monitor
Serial.print(F(" "));
LT.printASCIIPacket(RXBUFFER, RXPacketL); //print the packet as ASCII characters
Serial.print(F(","));
Serial.print(LT.readRegister(REG_FEIMSB),HEX);
Serial.print(F(","));
Serial.print(LT.readRegister(REG_FEIMID),HEX);
Serial.print(F(","));
Serial.print(LT.readRegister(REG_FEILSB),HEX);
Serial.print(F(",Regval,"));
Serial.print(LT.getFrequencyErrorRegValue(),HEX);
Serial.print(F(",FreqErrror,"));
Serial.print(frequencyerror);
Serial.print(F("hz,PpmCorrection,"));
Serial.print(LT.readRegister(REG_PPMCORRECTION));
Serial.print(F(",RSSI,"));
Serial.print(PacketRSSI);
Serial.print(F("dBm,SNR,"));
Serial.print(PacketSNR);
Serial.print(F("dB,Length,"));
Serial.print(RXPacketL);
Serial.print(F(",Packets,"));
Serial.print(RXpacketCount);
Serial.print(F(",Errors,"));
Serial.print(errors);
Serial.print(F(",IRQreg,"));
Serial.print(IRQStatus, HEX);
}
void packet_is_Error()
{
uint16_t IRQStatus;
IRQStatus = LT.readIrqStatus(); //read the LoRa device IRQ status register
printElapsedTime(); //print elapsed time to Serial Monitor
if (IRQStatus & IRQ_RX_TIMEOUT) //check for an RX timeout
{
Serial.print(F(" RXTimeout"));
}
else
{
errors++;
Serial.print(F(" PacketError"));
Serial.print(F(",RSSI,"));
Serial.print(PacketRSSI);
Serial.print(F("dBm,SNR,"));
Serial.print(PacketSNR);
Serial.print(F("dB,Length,"));
Serial.print(LT.readRXPacketL()); //get the real packet length
Serial.print(F(",Packets,"));
Serial.print(RXpacketCount);
Serial.print(F(",Errors,"));
Serial.print(errors);
Serial.print(F(",IRQreg,"));
Serial.print(IRQStatus, HEX);
LT.printIrqStatus(); //print the names of the IRQ registers set
}
}
void printElapsedTime()
{
float seconds;
seconds = millis() / 1000;
Serial.print(seconds, 0);
Serial.print(F("s"));
}
void setup()
{
Serial.begin(9600);
Serial.println();
Serial.println(F("73_LoRa_Receiver_AFC starting"));
Serial.println();
SPI.begin();
if (LT.begin(NSS, NRESET, DIO0, LORA_DEVICE))
{
Serial.println(F("LoRa Device found"));
delay(1000);
}
else
{
Serial.println(F("No device responding"));
while (1);
}
LT.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate, Optimisation);
Serial.println();
LT.printModemSettings(); //reads and prints the configured LoRa settings, useful check
Serial.println();
LT.printOperatingSettings(); //reads and prints the configured operating settings, useful check
Serial.println();
Serial.print(F("Receiver ready - RXBUFFER_SIZE "));
Serial.println(RXBUFFER_SIZE);
Serial.println();
}

View File

@@ -0,0 +1,41 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 10/06/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
//******* Setup hardware pin definitions here ! ***************
//These are the pin definitions for one of my own boards, the Easy Pro Mini,
//be sure to change the definitions to match your own setup. Some pins such as DIO1,
//DIO2, BUZZER may not be in used by this sketch so they do not need to be
//connected and should be set to -1.
#define NSS 10 //select pin on LoRa device
#define NRESET 9 //reset pin on LoRa device
#define LED1 8 //on board LED, high for on
#define DIO0 3 //DIO0 pin on LoRa device, used for RX and TX done
#define LORA_DEVICE DEVICE_SX1278 //we need to define the device we are using
//******* Setup LoRa Parameters Here ! ***************
//LoRa Modem Parameters
const uint32_t Frequency = 434000000; //frequency of transmissions in hertz
const uint32_t Offset = 0; //offset frequency for calibration purposes
const uint8_t Bandwidth = LORA_BW_125; //LoRa bandwidth
const uint8_t SpreadingFactor = LORA_SF7; //LoRa spreading factor
const uint8_t CodeRate = LORA_CR_4_5; //LoRa coding rate
const uint8_t Optimisation = LDRO_AUTO; //low data rate optimisation setting, normally set to auto
const int8_t TXpower = 2; //LoRa transmit power in dBm
const uint16_t packet_delay = 1000; //mS delay between packets
#define RXBUFFER_SIZE 128 //RX buffer size

View File

@@ -0,0 +1,106 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 23/02/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - Transmits a FM tone using the LoRa device that can be picked up on an FM UHF
handheld receiver. The tones are generated in direct mode by applying a pulse using the Arduino tone()
function (not supported by all Arduinos) to the DIO2 pin.
Serial monitor baud rate is set at 9600
*******************************************************************************************************/
#define Program_Version "V1.0"
#include <SPI.h> //the lora device is SPI based so load the SPI library
#include <SX127XLT.h> //include the appropriate library
#include "Settings.h" //include the setiings file, frequencies, LoRa settings etc
SX127XLT LoRa; //create a library class instance called LoRa
void loop()
{
Serial.print(TXpower); //print the transmit power defined
Serial.print(F("dBm "));
Serial.println(F("PlayTones> "));
Serial.println();
LoRa.setupDirect(Frequency, Offset);
LoRa.setTXDirect(); //turn on transmit
LoRa.setTxParams(TXpower, RADIO_RAMP_DEFAULT); //set TX power
LoRa.writeRegister(REG_FDEVLSB, deviation); //set the deviation
LoRa.writeRegister(REG_PLLHOP, 0xAD); //set fast hop mode, needed for fast changes of frequency
while(1) //repeat forever
{
digitalWrite(LED1, HIGH);
tone(DIO2, 1000); //pin, frequency, durationmS
delay(1000);
digitalWrite(LED1, LOW);
noTone(DIO2);
delay(1000);
};
}
void led_Flash(uint16_t flashes, uint16_t delaymS)
{
uint16_t index;
for (index = 1; index <= flashes; index++)
{
digitalWrite(LED1, HIGH);
delay(delaymS);
digitalWrite(LED1, LOW);
delay(delaymS);
}
}
void setup()
{
pinMode(LED1, OUTPUT); //setup pin as output for indicator LED
pinMode(6, OUTPUT);
led_Flash(2, 125); //two quick LED flashes to indicate program start
Serial.begin(9600);
Serial.println();
Serial.print(F(__TIME__));
Serial.print(F(" "));
Serial.println(F(__DATE__));
Serial.println(F(Program_Version));
Serial.println();
Serial.println(F("80_Direct_DIO2_Tone Starting"));
SPI.begin();
//SPI beginTranscation is normally part of library routines, but if it is disabled in library
//a single instance is needed here, so uncomment the program line below
//SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
//setup hardware pins used by device, then check if device is found
if (LoRa.begin(NSS, NRESET, DIO0, DIO1, DIO2, LORA_DEVICE))
{
Serial.println(F("LoRa Device found"));
led_Flash(2, 125); //two further quick LED flashes to indicate device found
delay(1000);
}
else
{
Serial.println(F("No device responding"));
while (1)
{
led_Flash(50, 50); //long fast speed LED flash indicates device error
}
}
Serial.print(F("Tone Transmitter ready"));
Serial.println();
}

View File

@@ -0,0 +1,31 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 23/02/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
//******* Setup hardware pin definitions here ! ***************
//These are the pin definitions for one of my own boards, the Easy Pro Mini,
//be sure to change the definitions to match your own setup. Some pins such as DIO1,
//DIO2 are not used by this particular sketch so they are set to -1 and not connected.
#define NSS 10 //select pin on LoRa device
#define NRESET 9 //reset pin on LoRa device
#define LED1 8 //on board LED, high for on
#define DIO0 3 //DIO0 pin on LoRa device, used for RX and TX done
#define DIO1 -1 //DIO1 pin on LoRa device, normally not used so set to -1
#define DIO2 6 //DIO2 pin on LoRa device can be used for tone
#define LORA_DEVICE DEVICE_SX1278 //we need to define the device we are using
//******* Setup Direct Modem Parameters Here ! ***************
const uint32_t Frequency = 434000000; //frequency of transmissions in hertz
const uint32_t Offset = 0; //offset frequency for calibration purposes
const uint8_t deviation = 0x52; //set approx 5khz deviation
const int8_t TXpower = 10; //LoRa transmit power in dBm