Init fork from Stuart Robinson's repo

This commit is contained in:
2024-10-03 14:30:13 +03:00
commit 9395706524
201 changed files with 45709 additions and 0 deletions

View File

@ -0,0 +1,153 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 08/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 - The program transmits a packet without using a processor buffer, the LoRa device
internal buffer is filled direct with variables. The program is a simulation of the type of packet
that might be sent from a GPS tracker. Note that in this example a buffer of text is part of the
transmitted packet, this does need a processor buffer which is used to fill the LoRa device internal
buffer, if you don't need to transmit text then the uint8_t trackerID[] = "Tracker1"; definition
can be ommited.
The matching receiving program '9_LoRa_LowMemory_RX' can be used to receive and display the packet,
though the program '15_LoRa_RX_Structure' should receive it as well, since the packet contents are
the same.
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 <SX128XLT.h>
#include "Settings.h"
SX128XLT LT;
uint32_t TXpacketCount = 0;
uint8_t TXPacketL;
uint32_t startmS, endmS;
void loop()
{
TXpacketCount++;
if (Send_Test_Packet())
{
Serial.print(TXpacketCount);
Serial.print(F(" "));
Serial.print(TXPacketL);
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);
}
Serial.println();
delay(packet_delay);
}
uint8_t Send_Test_Packet()
{
//The SX12XX buffer is filled with variables of a known type and order. Make sure the receiver
//uses the same variable type and order to read variables out of the receive buffer.
float latitude, longitude;
uint16_t altitude, voltage;
uint8_t satellites;
int16_t temperature;
uint8_t len;
//test data
uint8_t trackerID[] = "tracker1";
latitude = 51.23456;
longitude = -3.12345;
altitude = 199;
satellites = 9;
voltage = 3999;
temperature = -9;
LT.startWriteSXBuffer(0); //start the write at location 0
LT.writeBuffer(trackerID, sizeof(trackerID)); //= 13 bytes (12 characters plus null (0) at end)
LT.writeUint32(TXpacketCount); //+4 = 17 bytes
LT.writeFloat(latitude); //+4 = 21 bytes
LT.writeFloat(longitude); //+4 = 25 bytes
LT.writeUint16(altitude); //+2 = 27 bytes
LT.writeUint8(satellites); //+1 = 28 bytes
LT.writeUint16(voltage); //+2 = 30 bytes
LT.writeInt8(temperature); //+1 = 31 bytes total to send
len = LT.endWriteSXBuffer();
digitalWrite(LED1, HIGH);
startmS = millis();
TXPacketL = LT.transmitSXBuffer(0, len, 5000, TXpower, WAIT_TX); //set a TX timeout of 5000mS
endmS = millis();
digitalWrite(LED1, LOW);
return TXPacketL;
}
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);
led_Flash(2, 125);
Serial.begin(9600);
SPI.begin();
if (LT.begin(NSS, NRESET, RFBUSY, DIO1, 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);
Serial.println(F("Transmitter ready"));
Serial.println();
}

View File

@ -0,0 +1,30 @@
/*******************************************************************************************************
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.
#define NSS 10
#define RFBUSY 7
#define NRESET 9
#define LED1 8
#define DIO1 3
#define LORA_DEVICE DEVICE_SX1280 //we need to define the device we are using
//LoRa Modem Parameters
#define Frequency 2445000000 //frequency of transmissions
#define Offset 0 //offset frequency for calibration purposes
#define Bandwidth LORA_BW_0400 //LoRa bandwidth
#define SpreadingFactor LORA_SF7 //LoRa spreading factor
#define CodeRate LORA_CR_4_5 //LoRa coding rate
#define TXpower 10 //power for transmissions in dBm
#define packet_delay 1000 //mS delay between packets

View File

@ -0,0 +1,106 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 05/11/21
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 - The program transmits a packet without using a processor buffer, the LoRa device
internal buffer is filled direct with variables. The program is a simulation of the type of packet
that might be sent from a GPS tracker. Note that in this example a buffer of text is part of the
transmitted packet.
The matching receiving program '9_LoRa_LowMemory_RXIRQ' can be used to receive and display the packet
The contents of the packet received, and printed to serial monitor, should be;
TR1 (buffer) - trackerID
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
Memory use on an Arduino Pro Mini;
Sketch uses 4958 bytes (15%) of program storage space.
Global variables use 224 bytes (10%) of dynamic memory, leaving 1824 bytes for local variables.
This is a version of example 8_LoRa_LowMemory_TX.ino that does not require the use of the DIO1 pin to
check for transmit done. In addition no NRESET pin is needed either, so its a program for use with a
minimum pin count Arduino. Leave the DIO1 and NRESET pins on the LoRa device not connected.
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
#include <Arduino.h>
#include <SPI.h>
#include <SX128XLT.h>
#include "Settings.h"
SX128XLT LoRa;
void loop()
{
//The SX12XX buffer is filled with variables of a known type and order. Make sure the receiver
//uses the same variable type and order to read variables out of the receive buffer.
char trackerID[] = "TR1";
float latitude = 51.23456;
float longitude = -3.12345;
uint16_t altitude = 199;
uint8_t satellites = 8;
uint16_t voltage = 3999;
int16_t temperature = 9;
uint8_t TXPacketL = 0;
uint8_t BytesSent = 0;
LoRa.startWriteSXBuffer(0); //start the write at SX12XX internal buffer location 0
LoRa.writeBufferChar(trackerID, sizeof(trackerID)); //+4 bytes (3 characters plus null (0) at end)
LoRa.writeFloat(latitude); //+4 = 8 bytes
LoRa.writeFloat(longitude); //+4 = 12 bytes
LoRa.writeUint16(altitude); //+2 = 14 bytes
LoRa.writeUint8(satellites); //+1 = 15 bytes
LoRa.writeUint16(voltage); //+2 = 17 bytes
LoRa.writeInt8(temperature); //+1 = 18 bytes total to send
TXPacketL = LoRa.endWriteSXBuffer(); //closes packet write and returns the length of the packet to send
BytesSent = LoRa.transmitSXBufferIRQ(0, TXPacketL, 5000, TXpower, WAIT_TX); //set a TX timeout of 5000mS
if (BytesSent == 0) //if bytessent is 0, there has been a error
{
Serial.print(F("Send Error"));
}
else
{
Serial.print(BytesSent);
Serial.print(F(" Bytes Sent"));
}
Serial.println();
delay(packet_delay);
}
void setup()
{
Serial.begin(9600);
SPI.begin();
if (LoRa.begin(NSS, NRESET, RFBUSY, LORA_DEVICE))
{
Serial.println(F("LoRa Device found"));
delay(1000);
}
else
{
Serial.println(F("No LoRa device responding"));
while (1);
}
LoRa.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate);
Serial.flush();
}

View File

@ -0,0 +1,28 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 18/09/21
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.
#define NSS 10 //select on LoRa device
#define NRESET 9 //reset pin on LoRa device
#define RFBUSY 7 //busy pin on LoRa device
#define LORA_DEVICE DEVICE_SX1280 //we need to define the device we are using
//LoRa Modem Parameters
const uint32_t Frequency = 2445000000; //frequency of transmissions
const uint32_t Offset = 0; //offset frequency for calibration purposes
const uint8_t Bandwidth = LORA_BW_0400; //LoRa bandwidth
const uint8_t SpreadingFactor = LORA_SF7; //LoRa spreading factor
const uint8_t CodeRate = LORA_CR_4_5; //LoRa coding rate
const int8_t TXpower = 10; //LoRa TX power in dBm
const uint16_t packet_delay = 1000; //mS delay between packets

View File

@ -0,0 +1,192 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 08/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 - The program receives a packet without using a processor buffer, the LoRa device
internal buffer is read direct and copied to variables. The program is a simulation of the type of packet
that might be received from a GPS tracker. Note that in this example a buffer of text is part of the
received packet, this does need a processor buffer which is filled with data from the LoRa device internal
buffer, if you don't need to send and receive text then the uint8_t receivebuffer[32]; definition can be
ommited.
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 <SX128XLT.h>
#include "Settings.h"
SX128XLT LT;
uint32_t RXpacketCount;
uint16_t errors;
uint8_t RXPacketL; //length of received packet
int16_t PacketRSSI; //RSSI of received packet
int8_t PacketSNR; //signal to noise ratio of received packet
void loop()
{
RXPacketL = LT.receiveSXBuffer(0, 0, WAIT_RX); //returns 0 if packet error of some sort, no timeout
digitalWrite(LED1, HIGH); //something has happened
PacketRSSI = LT.readPacketRSSI();
PacketSNR = LT.readPacketSNR();
if (RXPacketL == 0)
{
packet_is_Error();
}
else
{
packet_is_OK();
}
digitalWrite(LED1, LOW);
Serial.println();
}
uint8_t packet_is_OK()
{
float latitude, longitude;
uint16_t altitude, voltage;
uint8_t satellites;
int8_t temperature;
uint32_t txcount;
char receivebuffer[16]; //create receive buffer, make sure this is big enough for buffer sent !!!
//packet has been received, now read from the SX12xx Buffer using the same variable type and
//order as the transmit side used.
RXpacketCount++;
Serial.print(RXpacketCount);
Serial.print(F(" "));
LT.startReadSXBuffer(0); //start buffer read at location 0
LT.readBufferChar(receivebuffer); //read in the character buffer
txcount = LT.readUint32(); //read in the TXCount
latitude = LT.readFloat(); //read in the latitude
longitude = LT.readFloat(); //read in the longitude
altitude = LT.readUint16(); //read in the altitude
satellites = LT.readUint8(); //read in the number of satellites
voltage = LT.readUint16(); //read in the voltage
temperature = LT.readInt8(); //read in the temperature
RXPacketL = LT.endReadSXBuffer();
Serial.print((char*)receivebuffer); //print the received buffer, cast to char needed
Serial.print(F(","));
Serial.print(txcount);
Serial.print(F(","));
Serial.print(latitude, 5);
Serial.print(F(","));
Serial.print(longitude, 5);
Serial.print(F(","));
Serial.print(altitude);
Serial.print(F("m,"));
Serial.print(satellites);
Serial.print(F("sats,"));
Serial.print(voltage);
Serial.print(F("mV,"));
Serial.print(temperature);
Serial.print(F("c "));
Serial.print(F(" RSSI"));
Serial.print(PacketRSSI);
Serial.print(F("dBm,SNR,"));
Serial.print(PacketSNR);
Serial.print(F("dB"));
return RXPacketL;
}
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()
{
pinMode(LED1, OUTPUT);
led_Flash(2, 125);
Serial.begin(9600);
SPI.begin();
if (LT.begin(NSS, NRESET, RFBUSY, DIO1, 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);
Serial.println(F("Receiver ready"));
Serial.println();
}

View File

@ -0,0 +1,32 @@
/*******************************************************************************************************
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.
#define NSS 10
#define RFBUSY 7
#define NRESET 9
#define LED1 8
#define DIO1 3
#define LORA_DEVICE DEVICE_SX1280 //we need to define the device we are using
//LoRa Modem Parameters
#define Frequency 2445000000 //frequency of transmissions
#define Offset 0 //offset frequency for calibration purposes
#define Bandwidth LORA_BW_0400 //LoRa bandwidth
#define SpreadingFactor LORA_SF7 //LoRa spreading factor
#define CodeRate LORA_CR_4_5 //LoRa coding rate
#define TXpower 10 //power for transmissions in dBm
#define packet_delay 1000 //mS delay between packets
#define RXBUFFER_SIZE 255 //RX buffer size, not used in this program

View File

@ -0,0 +1,169 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 18/09/21
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 - The program receives a packet without using a memory buffer, the LoRa device
internal buffer is read direct for variables. The program is a simulation of the type of packet
that might be received from a GPS tracker. Note that in this example a buffer of text is part of the
received packet.
The matching transmitter program '8_LoRa_LowMemory_TXIRQ' is used to transmit the packet.
The contents of the packet received, and printed to serial monitor, should be;
TR1 (buffer) - trackerID
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
Memory use on an Arduino Pro Mini;
Sketch uses 6290 bytes (19%) of program storage space.
Global variables use 237 bytes (11%) of dynamic memory, leaving 1811 bytes for local variables.
This is a version of example 9_LoRa_LowMemory_RX.ino that does not require the use of the DIO1 pin to
check for receive done. In addition no NRESET pin is needed either, so its a program for use with a
minimum pin count Arduino. Leave the DIO1 and NRESET pins on the LoRa device not connected.
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
#include <SPI.h>
#include <SX128XLT.h>
#include "Settings.h"
SX128XLT LoRa;
void loop()
{
uint8_t RXPacketL;
RXPacketL = LoRa.receiveSXBufferIRQ(0, 0, WAIT_RX); //returns 0 if packet error of some sort, no timeout
if (RXPacketL == 0)
{
packet_is_Error();
}
else
{
packet_is_OK();
}
Serial.println();
}
uint8_t packet_is_OK()
{
char receivebuffer[4]; //create receive buffer, make sure this is big enough for buffer sent !!!
float latitude;
float longitude;
uint16_t altitude;
uint8_t satellites;
uint16_t voltage;
int8_t temperature;
uint8_t RXPacketL;
static uint8_t RXpacketCount;
//packet has been received, now read from the SX12xx Buffer using the same variable type and
//order as the transmit side used.
RXpacketCount++;
Serial.print(RXpacketCount);
Serial.print(F(" "));
LoRa.startReadSXBuffer(0); //start buffer read at location 0
LoRa.readBufferChar(receivebuffer); //read in the character buffer
latitude = LoRa.readFloat(); //read in the latitude
longitude = LoRa.readFloat(); //read in the longitude
altitude = LoRa.readUint16(); //read in the altitude
satellites = LoRa.readUint8(); //read in the number of satellites
voltage = LoRa.readUint16(); //read in the voltage
temperature = LoRa.readInt8(); //read in the temperature
RXPacketL = LoRa.endReadSXBuffer(); //finish packet read, get received packet length
Serial.print(receivebuffer); //print the received character buffer
Serial.print(F(","));
Serial.print(latitude, 5);
Serial.print(F(","));
Serial.print(longitude, 5);
Serial.print(F(","));
Serial.print(altitude);
Serial.print(F("m,"));
Serial.print(satellites);
Serial.print(F("sats,"));
Serial.print(voltage);
Serial.print(F("mV,"));
Serial.print(temperature);
Serial.print(F("c "));
printpacketDetails();
return RXPacketL;
}
void packet_is_Error()
{
uint16_t IRQStatus;
IRQStatus = LoRa.readIrqStatus();
if (IRQStatus & IRQ_RX_TIMEOUT)
{
Serial.print(F("RXTimeout"));
}
else
{
Serial.print(F("PacketError"));
printpacketDetails();
Serial.print(F("IRQreg,"));
Serial.print(IRQStatus, HEX);
}
}
void printpacketDetails()
{
int16_t PacketRSSI; //RSSI of received packet
int8_t PacketSNR; //signal to noise ratio of received packet
PacketRSSI = LoRa.readPacketRSSI();
PacketSNR = LoRa.readPacketSNR();
Serial.print(F(" RSSI,"));
Serial.print(PacketRSSI);
Serial.print(F("dBm,SNR,"));
Serial.print(PacketSNR);
Serial.print(F("dB"));
}
void setup()
{
Serial.begin(9600);
SPI.begin();
if (LoRa.begin(NSS, NRESET, RFBUSY, LORA_DEVICE))
{
Serial.println(F("Device OK"));
}
else
{
Serial.println(F("Device error"));
while (1);
}
Serial.flush();
LoRa.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate);
}

View File

@ -0,0 +1,27 @@
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 05/11/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.
#define NSS 10 //select on LoRa device
#define NRESET 9 //reset pin on LoRa device
#define RFBUSY 7 //busy pin on LoRa device
#define LORA_DEVICE DEVICE_SX1280 //we need to define the device we are using
//LoRa Modem Parameters
const uint32_t Frequency = 2445000000; //frequency of transmissions
const uint32_t Offset = 0; //offset frequency for calibration purposes
const uint8_t Bandwidth = LORA_BW_0400; //LoRa bandwidth
const uint8_t SpreadingFactor = LORA_SF7; //LoRa spreading factor
const uint8_t CodeRate = LORA_CR_4_5; //LoRa coding rate
const int8_t TXpower = 10; //LoRa TX power in dBm
const uint16_t packet_delay = 1000; //mS delay between packets