first commit
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
/*******************************************************************************************************
|
||||
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 <SX126XLT.h> //include the appropriate library
|
||||
#include "Settings.h" //include the setiings file, frequencies, LoRa settings etc
|
||||
|
||||
SX126XLT 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 receiver
|
||||
|
||||
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, RFBUSY, DIO1, DIO2, DIO3, RX_EN, TX_EN, SW, 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);
|
||||
LT.setRegulatorMode(USE_DCDC);
|
||||
LT.setPaConfig(0x04, PAAUTO, LORA_DEVICE);
|
||||
LT.setDIO3AsTCXOCtrl(TCXO_CTRL_3_3V);
|
||||
LT.calibrateDevice(ALLDevices); //is required after setting TCXO
|
||||
LT.calibrateImage(Frequency);
|
||||
LT.setDIO2AsRfSwitchCtrl();
|
||||
LT.setPacketType(PACKET_TYPE_LORA);
|
||||
LT.setRfFrequency(Frequency, Offset);
|
||||
LT.setModulationParams(SpreadingFactor, Bandwidth, CodeRate, Optimisation);
|
||||
LT.setBufferBaseAddress(0, 0);
|
||||
LT.setPacketParams(8, LORA_PACKET_VARIABLE_LENGTH, 255, LORA_CRC_ON, LORA_IQ_NORMAL);
|
||||
LT.setDioIrqParams(IRQ_RADIO_ALL, (IRQ_TX_DONE + IRQ_RX_TX_TIMEOUT), 0, 0); //set for IRQ on TX done and timeout on DIO1
|
||||
LT.setHighSensitivity(); //set for maximum gain
|
||||
LT.setSyncWord(LORA_MAC_PRIVATE_SYNCWORD);
|
||||
//***************************************************************************************************
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*******************************************************************************************************
|
||||
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 DIO2,
|
||||
//DIO3, 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 RFBUSY 7 //busy pin on LoRa device
|
||||
#define DIO1 3 //DIO1 pin on LoRa device, used for RX and TX done
|
||||
#define DIO2 -1 //DIO2 pin on LoRa device, normally not used so set to -1
|
||||
#define DIO3 -1 //DIO3 pin on LoRa device, normally not used so set to -1
|
||||
#define RX_EN -1 //pin for RX enable, used on some SX126X devices, set to -1 if not used
|
||||
#define TX_EN -1 //pin for TX enable, used on some SX126X devices, set to -1 if not used
|
||||
#define SW -1 //SW pin on some Dorji LoRa devices, used to power antenna switch, set to -1 if not used
|
||||
#define LED1 8 //on board LED, high for on
|
||||
|
||||
#define LORA_DEVICE DEVICE_SX1262 //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
|
||||
|
||||
//for SX1262, SX1268 power range is +22dBm to -9dBm
|
||||
//for SX1261, power range is +15dBm t0 -9dBm
|
||||
|
||||
const int8_t TXpower = 10; //LoRa transmit power in dBm
|
||||
|
||||
const uint16_t packet_delay = 1000; //mS delay between packets
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
/*******************************************************************************************************
|
||||
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 <SX126XLT.h> //include the appropriate library
|
||||
#include "Settings.h" //include the setiings file, frequencies, LoRa settings etc
|
||||
|
||||
SX126XLT 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
|
||||
int8_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
|
||||
}
|
||||
|
||||
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, RFBUSY, DIO1, DIO2, DIO3, RX_EN, TX_EN, SW, 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);
|
||||
LT.setRegulatorMode(USE_DCDC);
|
||||
LT.setPaConfig(0x04, PAAUTO, LORA_DEVICE);
|
||||
LT.setDIO3AsTCXOCtrl(TCXO_CTRL_3_3V);
|
||||
LT.calibrateDevice(ALLDevices); //is required after setting TCXO
|
||||
LT.calibrateImage(Frequency);
|
||||
LT.setDIO2AsRfSwitchCtrl();
|
||||
LT.setPacketType(PACKET_TYPE_LORA);
|
||||
LT.setRfFrequency(Frequency, Offset);
|
||||
LT.setModulationParams(SpreadingFactor, Bandwidth, CodeRate, Optimisation);
|
||||
LT.setBufferBaseAddress(0, 0);
|
||||
LT.setPacketParams(8, LORA_PACKET_VARIABLE_LENGTH, 255, LORA_CRC_ON, LORA_IQ_NORMAL);
|
||||
LT.setDioIrqParams(IRQ_RADIO_ALL, (IRQ_RX_DONE + IRQ_RX_TX_TIMEOUT), 0, 0); //set for IRQ on TX done and timeout on DIO1
|
||||
LT.setHighSensitivity(); //set for maximum gain
|
||||
LT.setSyncWord(LORA_MAC_PRIVATE_SYNCWORD);
|
||||
//***************************************************************************************************
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*******************************************************************************************************
|
||||
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 DIO2,
|
||||
//DIO3, 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 RFBUSY 7 //busy pin on LoRa device
|
||||
#define DIO1 3 //DIO1 pin on LoRa device, used for RX and TX done
|
||||
#define DIO2 -1 //DIO2 pin on LoRa device, normally not used so set to -1
|
||||
#define DIO3 -1 //DIO3 pin on LoRa device, normally not used so set to -1
|
||||
#define RX_EN -1 //pin for RX enable, used on some SX126X devices, set to -1 if not used
|
||||
#define TX_EN -1 //pin for TX enable, used on some SX126X devices, set to -1 if not used
|
||||
#define SW -1 //SW pin on some Dorji LoRa devices, used to power antenna switch, set to -1 if not used
|
||||
#define LED1 8 //on board LED, high for on
|
||||
#define BUZZER 4 //pin for buzzer, set to -1 if not used
|
||||
|
||||
#define LORA_DEVICE DEVICE_SX1262 //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
|
||||
|
||||
#define RXBUFFER_SIZE 32 //RX buffer size
|
||||
|
||||
|
||||
|
||||
@@ -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 <SX126XLT.h>
|
||||
#include "Settings.h"
|
||||
|
||||
SX126XLT 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, RFBUSY, DIO1, SW, 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();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 06/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 DIO2,
|
||||
//DIO3, BUZZER may not be in used by this sketch so they do not need to be
|
||||
//connected and should be included and 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 RFBUSY 7 //SX126X busy pin
|
||||
#define DIO1 3 //DIO1 pin on LoRa device, used for RX and TX done
|
||||
#define DIO2 -1 //DIO2 pin on LoRa device, normally not used so set to -1
|
||||
#define DIO3 -1 //DIO3 pin on LoRa device, normally not used so set to -1
|
||||
#define SW -1 //SW pin on Dorji devices is used to turn RF switch on\off, set to -1 if not used
|
||||
|
||||
#define LORA_DEVICE DEVICE_SX1262 //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
|
||||
|
||||
@@ -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 <SX126XLT.h>
|
||||
#include "Settings.h"
|
||||
|
||||
SX126XLT LT;
|
||||
|
||||
uint8_t RXPacketL; //stores length of packet received
|
||||
uint32_t RXpacketCount; //count of received packets
|
||||
int8_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, RFBUSY, DIO1, SW, 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();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 06/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 DIO2,
|
||||
//DIO2, BUZZER may not be in used by this sketch so they do not need to be
|
||||
//connected and should be included and 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 RFBUSY 7 //SX126X busy pin
|
||||
#define DIO1 3 //DIO1 pin on LoRa device, used for RX and TX done
|
||||
#define DIO2 -1 //DIO2 pin on LoRa device, normally not used so set to -1
|
||||
#define DIO3 -1 //DIO3 pin on LoRa device, normally not used so set to -1
|
||||
#define SW -1 //SW pin on Dorji devices is used to turn RF switch on\off, set to -1 if not used
|
||||
#define BUZZER 4 //pin for buzzer, on when logic high
|
||||
|
||||
#define LORA_DEVICE DEVICE_SX1262 //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
|
||||
|
||||
#define RXBUFFER_SIZE 32 //RX buffer size
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 06/02/20
|
||||
|
||||
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
|
||||
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"));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,402 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 06/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 - This program is stand alone, it is not necessary to install the SX12XX-LoRa library
|
||||
to use it. This test program is for the SX126X LoRa devices.
|
||||
|
||||
The program checks that a SX126X 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, there is a copy of a 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.
|
||||
|
||||
The Arduino pin numbers that the NSS and NRESET pins on the LoRa device are connected to must be
|
||||
specified in the hardware definitions section below. The LoRa device type in use, SX1261, SX1262,
|
||||
or SX1268 must be specified also.
|
||||
|
||||
Typical printout;
|
||||
|
||||
2_Register_Test Starting
|
||||
Reset device
|
||||
LoRa Device found
|
||||
Reset device
|
||||
Registers at reset
|
||||
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
0x800 00 00 00 00 01 07 20 1E 00 10 19 04 0F FF 0F FF
|
||||
0x810 10 00 10 00 10 00 10 00 00 00 00 00 00 00 00 00
|
||||
0x820 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x830 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x840 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x850 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x860 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x870 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x880 03 00 00 5F 10 08 00 00 08 05 00 39 30 00 00 0C
|
||||
0x890 00 00 00 00 00 0F 0A 07 10 00 26 01 01 53 06 07
|
||||
0x8A0 10 00 AA 20 5A 04 F0 00 56 56 54 43 94 20 40 00
|
||||
0x8B0 00 83 11 00 01 04 0A 4C 14 0A 2F 01 6B FF FF 00
|
||||
0x8C0 00 A0 20 00 00 00 AC 00 1C 00 00 AB 05 30 00 00
|
||||
0x8D0 0C 14 14 40 06 00 00 10 C8 00 00 00 00 00 31 39
|
||||
0x8E0 90 39 0C 04 40 20 1C 18 03 00 05 04 03 02 01 01
|
||||
0x8F0 00 00 00 00 30 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x900 30 00 00 00 00 00 00 00 00 00 00 00 24 04 47 04
|
||||
0x910 14 12 12 04 00 03 0A 00 15 35 09 00 02 1F 5F 08
|
||||
0x920 01 04 05 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x930 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x940 00 07 00 03 02 00 10 0E 0D 0C 03 04 03 70 0C 00
|
||||
0x950 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x960 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x970 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x980 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x990 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x9A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x9B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x9C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x9D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x9E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
0x9F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
||||
|
||||
|
||||
Frequency at reset 915000000
|
||||
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
0x880 03 00 00 5F 10 08 00 00 08 05 00 39 30 00 00 0C
|
||||
Change Frequency 434100000
|
||||
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
0x880 03 00 00 5F 10 08 00 00 08 05 00 1B 21 99 A0 0C
|
||||
Changed Frequency 434100000
|
||||
|
||||
Serial monitor baud rate is set at 9600.
|
||||
*******************************************************************************************************/
|
||||
|
||||
const uint16_t REG_RFFrequency31_24 = 0x088B;
|
||||
const uint16_t REG_RFFrequency23_16 = 0x088C;
|
||||
const uint16_t REG_RFFrequency15_8 = 0x088D;
|
||||
const uint16_t REG_RFFrequency7_0 = 0x088E;
|
||||
const uint8_t RADIO_WRITE_REGISTER = 0x0D;
|
||||
const uint8_t RADIO_READ_REGISTER = 0x1D;
|
||||
const uint8_t RADIO_SET_RFFREQUENCY = 0x86;
|
||||
|
||||
const uint8_t DEVICE_SX1261 = 0x01;
|
||||
const uint8_t DEVICE_SX1262 = 0x00;
|
||||
const uint8_t DEVICE_SX1268 = 0x02;
|
||||
|
||||
//********* Setup hardware definitions here ! *****************
|
||||
|
||||
//These are the pin definitions for one of the Tracker boards, be sure to change them to match your
|
||||
//own setup. You will also need to connect up the pins for the SPI bus, which on an Arduino Pro Mini are
|
||||
//SCK pin 13, MISO pin 12, and MOSI pin 11.
|
||||
|
||||
#define NSS 10 //SX126X device select
|
||||
#define NRESET 9 //SX126X reset pin
|
||||
#define RFBUSY 7 //SX126X busy pin
|
||||
#define LED1 8 //for on board LED, put high for on
|
||||
#define SW -1 //SW pin on Dorji devices is used to turn RF switch on\off, set to -1 if not used
|
||||
#define LORA_DEVICE DEVICE_SX1262 //define the device, DEVICE_SX1261, DEVICE_SX1262 or DEVICE_SX1268
|
||||
|
||||
//**************************************************************/
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
|
||||
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
|
||||
//the DIO1, DIO2 and DIO3 are not used in this example so are set to -1
|
||||
|
||||
if (begin(NSS, NRESET, RFBUSY, -1, -1, -1, SW, LORA_DEVICE))
|
||||
{
|
||||
Serial.println(F("LoRa Device found"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println(F("No device responding"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
uint32_t frequency;
|
||||
resetDevice(LORA_DEVICE); //reset the device
|
||||
Serial.println(F("Registers at reset")); //show the all registers following a reset
|
||||
printRegisters(0x800, 0x9FF);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
frequency = getFreqInt(); //read the set frequency following a reset
|
||||
Serial.print(F("Frequency at reset "));
|
||||
Serial.println(frequency);
|
||||
printRegisters(0x0880, 0x088F); //show the registers before the frequency change
|
||||
setRfFrequency(434100000, 0); //change the frequency at reset, in hertz
|
||||
frequency = getFreqInt(); //read back the changed frequency
|
||||
Serial.print(F("Change Frequency "));
|
||||
Serial.println(frequency); //print the changed frequency, did the write work (allow for rounding errors) ?
|
||||
printRegisters(0x0880, 0x088F); //show the registers after frequency change
|
||||
frequency = getFreqInt(); //read the set frequency following a reset
|
||||
Serial.print(F("Changed Frequency "));
|
||||
Serial.println(frequency);
|
||||
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
|
||||
void readRegisters(uint16_t address, uint8_t *buffer, uint16_t size)
|
||||
{
|
||||
|
||||
uint16_t index;
|
||||
uint8_t addr_l, addr_h;
|
||||
|
||||
addr_h = address >> 8;
|
||||
addr_l = address & 0x00FF;
|
||||
checkBusy();
|
||||
|
||||
digitalWrite(NSS, LOW);
|
||||
SPI.transfer(RADIO_READ_REGISTER);
|
||||
SPI.transfer(addr_h); //MSB
|
||||
SPI.transfer(addr_l); //LSB
|
||||
SPI.transfer(0xFF);
|
||||
for (index = 0; index < size; index++)
|
||||
{
|
||||
*(buffer + index) = SPI.transfer(0xFF);
|
||||
}
|
||||
|
||||
digitalWrite(NSS, HIGH);
|
||||
|
||||
checkBusy();
|
||||
}
|
||||
|
||||
|
||||
uint8_t readRegister(uint16_t address)
|
||||
{
|
||||
uint8_t data;
|
||||
|
||||
readRegisters(address, &data, 1);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
void writeRegisters(uint16_t address, uint8_t *buffer, uint16_t size)
|
||||
{
|
||||
uint8_t addr_l, addr_h;
|
||||
uint8_t i;
|
||||
|
||||
addr_l = address & 0xff;
|
||||
addr_h = address >> 8;
|
||||
checkBusy();
|
||||
|
||||
digitalWrite(NSS, LOW);
|
||||
SPI.transfer(RADIO_WRITE_REGISTER);
|
||||
SPI.transfer(addr_h); //MSB
|
||||
SPI.transfer(addr_l); //LSB
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
SPI.transfer(buffer[i]);
|
||||
}
|
||||
|
||||
digitalWrite(NSS, HIGH);
|
||||
|
||||
checkBusy();
|
||||
}
|
||||
|
||||
|
||||
void writeRegister(uint16_t address, uint8_t value)
|
||||
{
|
||||
writeRegisters( address, &value, 1 );
|
||||
}
|
||||
|
||||
|
||||
uint32_t getFreqInt()
|
||||
{
|
||||
//get the current set device frequency from registers, return as long integer
|
||||
uint8_t MsbH, MsbL, Mid, Lsb;
|
||||
uint32_t uinttemp;
|
||||
float floattemp;
|
||||
MsbH = readRegister(REG_RFFrequency31_24);
|
||||
MsbL = readRegister(REG_RFFrequency23_16);
|
||||
Mid = readRegister(REG_RFFrequency15_8);
|
||||
Lsb = readRegister(REG_RFFrequency7_0);
|
||||
floattemp = ( (MsbH * 0x1000000ul) + (MsbL * 0x10000ul) + (Mid * 0x100ul) + Lsb);
|
||||
floattemp = ((floattemp * 0.95367431640625) / 1000000ul);
|
||||
uinttemp = (uint32_t)(floattemp * 1000000);
|
||||
return uinttemp;
|
||||
}
|
||||
|
||||
|
||||
void printRegisters(uint16_t Start, uint16_t End)
|
||||
{
|
||||
//prints the contents of SX126x 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;) //32 lines
|
||||
{
|
||||
Serial.print(F("0x"));
|
||||
Serial.print((Loopv1), HEX); //print the register number
|
||||
Serial.print(F(" "));
|
||||
for (Loopv2 = 0; Loopv2 <= 15; Loopv2++)
|
||||
{
|
||||
RegData = readRegister(Loopv1);
|
||||
if (RegData < 0x10)
|
||||
{
|
||||
Serial.print(F("0"));
|
||||
}
|
||||
Serial.print(RegData, HEX); //print the register number
|
||||
Serial.print(F(" "));
|
||||
Loopv1++;
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setRfFrequency( uint32_t frequency, int32_t offset )
|
||||
{
|
||||
//Note RF_Freq = freq_reg*32M/(2^25)-----> freq_reg = (RF_Freq * (2^25))/32
|
||||
|
||||
uint8_t Rf_Freq[4];
|
||||
|
||||
frequency = frequency + offset;
|
||||
|
||||
frequency = ( uint32_t )( ( double )frequency / ( double )0.95367431640625 );
|
||||
|
||||
checkBusy();
|
||||
|
||||
Rf_Freq[0] = (frequency >> 24) & 0xFF; //MSB
|
||||
Rf_Freq[1] = (frequency >> 16) & 0xFF;
|
||||
Rf_Freq[2] = (frequency >> 8) & 0xFF;
|
||||
Rf_Freq[3] = frequency & 0xFF;//LSB
|
||||
|
||||
writeCommand(RADIO_SET_RFFREQUENCY, Rf_Freq, 4);
|
||||
}
|
||||
|
||||
|
||||
void checkBusy()
|
||||
{
|
||||
uint8_t busy_timeout_cnt;
|
||||
busy_timeout_cnt = 0;
|
||||
|
||||
while (digitalRead(RFBUSY))
|
||||
{
|
||||
delay(1);
|
||||
busy_timeout_cnt++;
|
||||
|
||||
if (busy_timeout_cnt > 10) //wait 10mS for busy to complete
|
||||
{
|
||||
busy_timeout_cnt = 0;
|
||||
Serial.println(F("ERROR - Busy Timeout!"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void resetDevice(uint8_t device)
|
||||
{
|
||||
if ( (device == DEVICE_SX1261) | (device == DEVICE_SX1262) | (device == DEVICE_SX1268) )
|
||||
{
|
||||
Serial.println(F("Reset device"));
|
||||
delay(10);
|
||||
digitalWrite(NRESET, LOW);
|
||||
delay(2);
|
||||
digitalWrite(NRESET, HIGH);
|
||||
delay(25);
|
||||
checkBusy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool begin(int8_t pinNSS, int8_t pinNRESET, int8_t pinRFBUSY, int8_t pinDIO1, int8_t pinDIO2, int8_t pinDIO3, int8_t pinSW, uint8_t device)
|
||||
{
|
||||
pinMode(pinNSS, OUTPUT);
|
||||
digitalWrite(pinNSS, HIGH);
|
||||
pinMode(pinNRESET, OUTPUT);
|
||||
digitalWrite(pinNRESET, LOW);
|
||||
pinMode(pinRFBUSY, INPUT);
|
||||
|
||||
if (pinDIO1 >= 0)
|
||||
{
|
||||
pinMode( pinDIO1, INPUT);
|
||||
}
|
||||
|
||||
if (pinDIO2 >= 0)
|
||||
{
|
||||
pinMode(pinDIO2, INPUT);
|
||||
}
|
||||
|
||||
if (pinDIO3 >= 0)
|
||||
{
|
||||
pinMode(pinDIO3, INPUT);
|
||||
}
|
||||
|
||||
if (pinSW >= 0)
|
||||
{
|
||||
pinMode(pinSW, OUTPUT); //Dorji devices have an SW pin that needs to be set high to power antenna switch
|
||||
digitalWrite(pinSW, HIGH);
|
||||
}
|
||||
|
||||
resetDevice(device);
|
||||
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(0x88e); //low byte of frequency setting
|
||||
writeRegister(0x88e, (Regdata1 + 1));
|
||||
Regdata2 = readRegister(0x88e); //read changed value back
|
||||
writeRegister(0x88e, Regdata1); //restore register to original value
|
||||
|
||||
if (Regdata2 == (Regdata1 + 1))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void writeCommand(uint8_t Opcode, uint8_t *buffer, uint16_t size)
|
||||
{
|
||||
uint8_t index;
|
||||
checkBusy();
|
||||
|
||||
digitalWrite(NSS, LOW);
|
||||
SPI.transfer(Opcode);
|
||||
|
||||
for (index = 0; index < size; index++)
|
||||
{
|
||||
SPI.transfer(buffer[index]);
|
||||
}
|
||||
digitalWrite(NSS, HIGH);
|
||||
|
||||
checkBusy();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/*******************************************************************************************************
|
||||
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 <SX126XLT.h> //include the appropriate library
|
||||
|
||||
SX126XLT 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 RFBUSY 7 //SX126X busy pin
|
||||
#define DIO1 3 //DIO1 pin on LoRa device, used for sensing RX and TX done
|
||||
#define SW 5 //SW pin on LoRa device, used to power antenna switch
|
||||
#define LORA_DEVICE DEVICE_SX1262 //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, RFBUSY, DIO1, SW, 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
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
/*******************************************************************************************************
|
||||
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 <SX126XLT.h> //include the appropriate library
|
||||
|
||||
SX126XLT 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 RFBUSY 7 //SX126X busy pin
|
||||
#define DIO1 3 //DIO1 pin on LoRa device, used for RX and TX done
|
||||
#define SW 5 //SW pin on LoRa device, used to power antenna switch
|
||||
#define LORA_DEVICE DEVICE_SX1262 //we need to define the device we are using
|
||||
#define RXBUFFER_SIZE 32 //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
|
||||
int8_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, RFBUSY, DIO1, SW, 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"));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*******************************************************************************************************
|
||||
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 <SX126XLT.h> //include the appropriate library
|
||||
#include "Settings.h" //include the setiings file, frequencies, LoRa settings etc
|
||||
|
||||
SX126XLT 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
|
||||
pinMode(4, OUTPUT);
|
||||
|
||||
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, RFBUSY, DIO1, SW, 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();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*******************************************************************************************************
|
||||
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, BUZZER may not be in used by this sketch so they do not need to be
|
||||
//connected and should be included and 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 RFBUSY 7 //SX126X busy pin
|
||||
#define DIO1 3 //DIO1 pin on LoRa device, used for RX and TX done
|
||||
#define DIO2 -1 //DIO2 pin on LoRa device, normally not used so set to -1
|
||||
#define DIO3 -1 //DIO3 pin on LoRa device, normally not used so set to -1
|
||||
#define SW -1 //SW pin on Dorji devices is used to turn RF switch on\off, set to -1 if not used
|
||||
|
||||
#define LORA_DEVICE DEVICE_SX1262 //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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user