Init fork from Stuart Robinson's repo
This commit is contained in:
@ -0,0 +1,233 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 29/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 tests the sleep mode and register retention of the lora device in sleep
|
||||
mode, it assumes an Atmel ATMega328P processor is in use. The LoRa settings to use are specified in the
|
||||
'Settings.h' file.
|
||||
|
||||
A packet is sent, containing the text 'Before Device Sleep' and the LoRa device and Atmel processor are put
|
||||
to sleep. The processor watchdog timer should wakeup the processor in 15 seconds (approx) and register
|
||||
values should be retained. The device then attempts to transmit another packet 'After Device Sleep'
|
||||
without re-loading all the LoRa settings. The receiver should see 'After Device Sleep' for the first
|
||||
packet and 'After Device Sleep' for the second.
|
||||
|
||||
Tested on a 'bare bones' ATmega328P board, the current in sleep mode was 12.2uA.
|
||||
|
||||
Serial monitor baud rate is set at 9600.
|
||||
*******************************************************************************************************/
|
||||
|
||||
#include <avr/wdt.h> //watchdog timer library, integral to Arduino IDE
|
||||
#include <SPI.h>
|
||||
#include <LowPower.h> //get the library here; https://github.com/rocketscream/Low-Power
|
||||
|
||||
#include <SX128XLT.h>
|
||||
#include "Settings.h"
|
||||
|
||||
SX128XLT LT;
|
||||
|
||||
bool SendOK;
|
||||
int8_t TestPower;
|
||||
uint8_t TXPacketL;
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(LED1, HIGH);
|
||||
Serial.print(TXpower);
|
||||
Serial.print(F("dBm "));
|
||||
Serial.print(F("TestPacket1> "));
|
||||
Serial.flush();
|
||||
|
||||
if (Send_Test_Packet1())
|
||||
{
|
||||
packet_is_OK();
|
||||
}
|
||||
else
|
||||
{
|
||||
packet_is_Error();
|
||||
}
|
||||
Serial.println();
|
||||
delay(packet_delay);
|
||||
|
||||
LT.setSleep(CONFIGURATION_RETENTION); //preserve register settings in sleep.
|
||||
Serial.println(F("Sleeping zzzzz...."));
|
||||
Serial.println();
|
||||
Serial.flush();
|
||||
digitalWrite(LED1, LOW);
|
||||
|
||||
sleep1second(15); //goto sleep for 15 seconds
|
||||
|
||||
Serial.println(F("Awake !"));
|
||||
Serial.flush();
|
||||
digitalWrite(LED1, HIGH);
|
||||
LT.wake();
|
||||
|
||||
Serial.print(TXpower);
|
||||
Serial.print(F("dBm "));
|
||||
Serial.print(F("TestPacket2> "));
|
||||
Serial.flush();
|
||||
|
||||
if (Send_Test_Packet2())
|
||||
{
|
||||
packet_is_OK();
|
||||
}
|
||||
else
|
||||
{
|
||||
packet_is_Error();
|
||||
}
|
||||
Serial.println();
|
||||
delay(packet_delay);
|
||||
}
|
||||
|
||||
|
||||
void sleep1second(uint32_t sleeps)
|
||||
{
|
||||
//uses the lowpower library
|
||||
uint32_t index;
|
||||
|
||||
for (index = 1; index <= sleeps; index++)
|
||||
{
|
||||
LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF); //sleep in 1 second steps
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void packet_is_OK()
|
||||
{
|
||||
Serial.print(F(" "));
|
||||
Serial.print(TXPacketL);
|
||||
Serial.print(F(" Bytes SentOK"));
|
||||
}
|
||||
|
||||
|
||||
void packet_is_Error()
|
||||
{
|
||||
uint16_t IRQStatus;
|
||||
IRQStatus = LT.readIrqStatus(); //get the IRQ status
|
||||
Serial.print(F("SendError,"));
|
||||
Serial.print(F("Length,"));
|
||||
Serial.print(TXPacketL);
|
||||
Serial.print(F(",IRQreg,"));
|
||||
Serial.print(IRQStatus, HEX);
|
||||
LT.printIrqStatus();
|
||||
digitalWrite(LED1, LOW); //this leaves the LED on slightly longer for a packet error
|
||||
}
|
||||
|
||||
|
||||
bool Send_Test_Packet1()
|
||||
{
|
||||
uint8_t bufffersize;
|
||||
|
||||
uint8_t buff[] = "Before Device Sleep";
|
||||
TXPacketL = sizeof(buff);
|
||||
buff[TXPacketL - 1] = '*';
|
||||
|
||||
if (sizeof(buff) > TXBUFFER_SIZE) //check that defined buffer is not larger than TX_BUFFER
|
||||
{
|
||||
bufffersize = TXBUFFER_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
bufffersize = sizeof(buff);
|
||||
}
|
||||
|
||||
TXPacketL = bufffersize;
|
||||
|
||||
LT.printASCIIPacket( (uint8_t*) buff, bufffersize);
|
||||
digitalWrite(LED1, HIGH);
|
||||
|
||||
if (LT.transmit( (uint8_t*) buff, TXPacketL, 10000, TXpower, WAIT_TX))
|
||||
{
|
||||
digitalWrite(LED1, LOW);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Send_Test_Packet2()
|
||||
{
|
||||
uint8_t bufffersize;
|
||||
|
||||
uint8_t buff[] = "After Device Sleep";
|
||||
TXPacketL = sizeof(buff);
|
||||
buff[TXPacketL - 1] = '*';
|
||||
|
||||
if (sizeof(buff) > TXBUFFER_SIZE) //check that defined buffer is not larger than TX_BUFFER
|
||||
{
|
||||
bufffersize = TXBUFFER_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
bufffersize = sizeof(buff);
|
||||
}
|
||||
|
||||
TXPacketL = bufffersize;
|
||||
|
||||
LT.printASCIIPacket( (uint8_t*) buff, bufffersize);
|
||||
digitalWrite(LED1, HIGH);
|
||||
|
||||
if (LT.transmit( (uint8_t*) buff, TXPacketL, 10000, TXpower, WAIT_TX))
|
||||
{
|
||||
digitalWrite(LED1, LOW);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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(F("5_LoRa_TX_Sleep_Timed_Wakeup_Atmel Starting"));
|
||||
|
||||
SPI.begin();
|
||||
|
||||
if (LT.begin(NSS, NRESET, RFBUSY, DIO1, 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 flash indicates device error
|
||||
}
|
||||
}
|
||||
|
||||
LT.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate);
|
||||
|
||||
Serial.print(F("Transmitter ready - TXBUFFER_SIZE "));
|
||||
Serial.println(TXBUFFER_SIZE);
|
||||
Serial.println();
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 29/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
|
||||
const uint32_t Frequency = 2445000000; //frequency of transmissions
|
||||
const int32_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; //Power for transmissions in dBm
|
||||
const uint16_t packet_delay = 1000; //mS delay between packets
|
||||
|
||||
#define TXBUFFER_SIZE 32 //RX buffer size
|
||||
@ -0,0 +1,215 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 19/06/20
|
||||
|
||||
This program is supplied as is, it is up to the user of the program to decide if the program is
|
||||
suitable for the intended purpose and free from errors.
|
||||
*******************************************************************************************************/
|
||||
|
||||
/*******************************************************************************************************
|
||||
Program Operation - 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.
|
||||
|
||||
When the program starts the LoRa device is setup to recieve packets with pin DIO1 set to go high when a
|
||||
packet arrives. The receiver remains powered (it cannot receive otherwise) and the processor
|
||||
(Atmel ATMega328P or 1284P) is put to sleep. When pin DIO1 does go high, indicating a packet is received,
|
||||
the processor wakes up and prints the packet. It then goes back to sleep.
|
||||
|
||||
There is a printout of the valid packets received, these are assumed to be in ASCII printable text.
|
||||
The LED will flash for each packet received and the buzzer will sound,if fitted.
|
||||
|
||||
Tested on a 'bare bones' ATmega328P board, the current in sleep mode was 11.32mA.
|
||||
|
||||
Serial monitor baud rate is set at 9600.
|
||||
*******************************************************************************************************/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <SX128XLT.h>
|
||||
#include "Settings.h"
|
||||
|
||||
#include <avr/sleep.h>
|
||||
#include <avr/wdt.h>
|
||||
#include "PinChangeInterrupt.h" //get the library here; https://github.com/NicoHood/PinChangeInterrupt
|
||||
|
||||
#include <AtmelSleep.h>
|
||||
|
||||
SX128XLT LT;
|
||||
|
||||
uint32_t RXpacketCount;
|
||||
uint32_t errors;
|
||||
|
||||
uint8_t RXBUFFER[RXBUFFER_SIZE]; //create a buffer for the received packet
|
||||
|
||||
uint8_t RXPacketL; //stores length of packet received
|
||||
int16_t PacketRSSI; //stores RSSI of received packet
|
||||
int8_t PacketSNR; //stores signal to noise ratio of received packet
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
RXPacketL = LT.receive(RXBUFFER, RXBUFFER_SIZE, 0, NO_WAIT); //setup LoRa device for receive with no timeout
|
||||
|
||||
Serial.println(F("Waiting for RX - Sleeping"));
|
||||
Serial.flush();
|
||||
|
||||
attachInterrupt(digitalPinToInterrupt(DIO1), wakeUp, HIGH);
|
||||
|
||||
atmelSleepPermanent(); //sleep the processor
|
||||
|
||||
detachInterrupt(digitalPinToInterrupt(DIO1));
|
||||
|
||||
//something has happened ?
|
||||
Serial.println(F("Awake"));
|
||||
digitalWrite(LED1, HIGH);
|
||||
|
||||
if (BUZZER > 0)
|
||||
{
|
||||
digitalWrite(BUZZER, HIGH);
|
||||
}
|
||||
|
||||
RXPacketL = LT.readPacket(RXBUFFER, RXBUFFER_SIZE); //now read in the received packet to the RX buffer
|
||||
|
||||
PacketRSSI = LT.readPacketRSSI();
|
||||
PacketSNR = LT.readPacketSNR();
|
||||
|
||||
if (RXPacketL == 0)
|
||||
{
|
||||
packet_is_Error();
|
||||
}
|
||||
else
|
||||
{
|
||||
packet_is_OK();
|
||||
}
|
||||
|
||||
digitalWrite(LED1, LOW);
|
||||
|
||||
if (BUZZER > 0)
|
||||
{
|
||||
|
||||
digitalWrite(BUZZER, LOW);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
void wakeUp()
|
||||
{
|
||||
//handler for the interrupt
|
||||
}
|
||||
|
||||
|
||||
void packet_is_OK()
|
||||
{
|
||||
uint16_t IRQStatus, localCRC;
|
||||
|
||||
IRQStatus = LT.readIrqStatus();
|
||||
RXpacketCount++;
|
||||
|
||||
RXPacketL = LT.readPacket(RXBUFFER, RXBUFFER_SIZE); //now read in the received packet to the RX buffer
|
||||
|
||||
Serial.print(F("Packet> "));
|
||||
LT.printASCIIPacket(RXBUFFER, RXPacketL);
|
||||
|
||||
localCRC = LT.CRCCCITT(RXBUFFER, RXPacketL, 0xFFFF);
|
||||
Serial.print(F(" 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);
|
||||
Serial.println();
|
||||
led_Flash(2, 125); //LED flash for approx 10 seconds
|
||||
}
|
||||
|
||||
|
||||
void packet_is_Error()
|
||||
{
|
||||
uint16_t IRQStatus;
|
||||
IRQStatus = LT.readIrqStatus(); //get the IRQ status
|
||||
|
||||
if (IRQStatus & IRQ_RX_TIMEOUT)
|
||||
{
|
||||
Serial.println(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();
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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(F("62_LoRa_Wake_on_RX_Atmel Starting"));
|
||||
|
||||
if (BUZZER > 0)
|
||||
{
|
||||
pinMode(BUZZER, OUTPUT);
|
||||
digitalWrite(BUZZER, HIGH);
|
||||
delay(50);
|
||||
digitalWrite(BUZZER, LOW);
|
||||
}
|
||||
|
||||
SPI.begin();
|
||||
|
||||
if (LT.begin(NSS, NRESET, RFBUSY, DIO1, 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);
|
||||
}
|
||||
}
|
||||
|
||||
LT.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate);
|
||||
|
||||
Serial.print(F("Receiver ready - RXBUFFER_SIZE "));
|
||||
Serial.println(RXBUFFER_SIZE);
|
||||
Serial.println();
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/*******************************************************************************************************
|
||||
Programs for Arduino - Copyright of the author Stuart Robinson - 19/06/20
|
||||
|
||||
This program is supplied as is, it is up to the user of the program to decide if the program is
|
||||
suitable for the intended purpose and free from errors.
|
||||
*******************************************************************************************************/
|
||||
|
||||
//******* Setup hardware pin definitions here ! ***************
|
||||
|
||||
//These are the pin definitions for one of my own boards, the Easy Pro Mini,
|
||||
//be sure to change the definitions to match your own setup. BUZZER may not be 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 LED1 8 //on board LED, high for on
|
||||
#define BUZZER -1 //pin for buzzer, on when logic high
|
||||
|
||||
#define LORA_DEVICE DEVICE_SX1280 //we need to define the device we are using
|
||||
|
||||
|
||||
//******* Setup LoRa Parameters Here ! ***************
|
||||
|
||||
//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
|
||||
|
||||
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
|
||||
const uint16_t packetCRCcheck = 0x3F83; //CRC to check RX packet for
|
||||
const uint8_t packetCRClengthcheck = 23; //packet length to check for
|
||||
Reference in New Issue
Block a user