LoRaLib
Arduino library for LoRa modules based on LoRa chips by Semtech (SX1272, SX1276, SX1278) and HopeRF (RFM95, RFM96, RFM98)
SX1278 Class Reference

Derived class for SX1278 modules. Also used as base class for SX1276, SX1277, SX1279, RFM95 and RFM96. All of these modules use the same basic hardware and only differ in parameter ranges (and names). More...

#include <SX1278.h>

Inheritance diagram for SX1278:
SX127x PhysicalLayer RFM95 RFM96 SX1276 SX1277 SX1279 RFM97

Public Member Functions

 SX1278 (Module *mod)
 Default constructor. Called from Arduino sketch when creating new LoRa instance. More...
 
int16_t begin (float freq=434.0, float bw=125.0, uint8_t sf=9, uint8_t cr=7, uint8_t syncWord=SX127X_SYNC_WORD, int8_t power=17, uint8_t currentLimit=100, uint16_t preambleLength=8, uint8_t gain=0)
 LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module. More...
 
int16_t beginFSK (float freq=434.0, float br=48.0, float freqDev=50.0, float rxBw=125.0, int8_t power=13, uint8_t currentLimit=100, uint16_t preambleLength=16, bool enableOOK=false)
 FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module. More...
 
int16_t setFrequency (float freq)
 Sets carrier frequency. Allowed values range from 137.0 MHz to 525.0 MHz. More...
 
int16_t setBandwidth (float bw)
 Sets LoRa link bandwidth. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. Only available in LoRa mode. More...
 
int16_t setSpreadingFactor (uint8_t sf)
 Sets LoRa link spreading factor. Allowed values range from 6 to 12. Only available in LoRa mode. More...
 
int16_t setCodingRate (uint8_t cr)
 Sets LoRa link coding rate denominator. Allowed values range from 5 to 8. Only available in LoRa mode. More...
 
int16_t setOutputPower (int8_t power)
 Sets transmission output power. Allowed values range from 2 to 17 dBm. More...
 
int16_t setGain (uint8_t gain)
 Sets gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain. Set to 0 to enable automatic gain control (recommended). Only available in LoRa mode. More...
 
int16_t setDataShaping (float sh)
 Sets Gaussian filter bandwidth-time product that will be used for data shaping. Allowed values are 0.3, 0.5 or 1.0. Set to 0 to disable data shaping. Only available in FSK mode with FSK modulation. More...
 
int16_t setDataShapingOOK (uint8_t sh)
 Sets filter cutoff frequency that will be used for data shaping. Allowed values are 1 for frequency equal to bit rate and 2 for frequency equal to 2x bit rate. Set to 0 to disable data shaping. Only available in FSK mode with OOK modulation. More...
 
float getRSSI ()
 Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem. More...
 
int16_t setCRC (bool enableCRC)
 Enables/disables CRC check of received packets. More...
 
- Public Member Functions inherited from SX127x
 SX127x (Module *mod)
 Default constructor. Called internally when creating new LoRa instance. More...
 
int16_t begin (uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimit, uint16_t preambleLength)
 Initialization method. Will be called with appropriate parameters when calling initialization method from derived class. More...
 
int16_t beginFSK (uint8_t chipVersion, float br, float freqDev, float rxBw, uint8_t currentLimit, uint16_t preambleLength, bool enableOOK)
 Initialization method for FSK modem. Will be called with appropriate parameters when calling FSK initialization method from derived class. More...
 
int16_t transmit (uint8_t *data, size_t len, uint8_t addr=0)
 Binary transmit method. Will transmit arbitrary binary data up to 255 bytes long using LoRa or up to 63 bytes using FSK modem. For overloads to transmit Arduino String or C-string, see PhysicalLayer::transmit. More...
 
int16_t receive (uint8_t *data, size_t len)
 Binary receive method. Will attempt to receive arbitrary binary data up to 255 bytes long using LoRa or up to 63 bytes using FSK modem. For overloads to receive Arduino String, see PhysicalLayer::receive. More...
 
int16_t scanChannel ()
 Performs scan for valid LoRa preamble in the current channel. More...
 
int16_t sleep ()
 Sets the LoRa module to sleep to save power. Module will not be able to transmit or receive any data while in sleep mode. Module will wake up automatically when methods like transmit or receive are called. More...
 
int16_t standby ()
 Sets the LoRa module to standby. More...
 
int16_t transmitDirect (uint32_t FRF=0)
 Enables direct transmission mode on pins DIO1 (clock) and DIO2 (data). While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode. More...
 
int16_t receiveDirect ()
 Enables direct reception mode on pins DIO1 (clock) and DIO2 (data). While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode. More...
 
int16_t packetMode ()
 Disables direct mode and enables packet mode, allowing the module to receive packets. Can only be activated in FSK mode. More...
 
void setDio0Action (void(*func)(void))
 Set interrupt service routine function to call when DIO0 activates. More...
 
void setDio1Action (void(*func)(void))
 Set interrupt service routine function to call when DIO1 activates. More...
 
int16_t startTransmit (uint8_t *data, size_t len, uint8_t addr=0)
 Interrupt-driven binary transmit method. Will start transmitting arbitrary binary data up to 255 bytes long using LoRa or up to 63 bytes using FSK modem. More...
 
int16_t startReceive (uint8_t len=0, uint8_t mode=SX127X_RXCONTINUOUS)
 Interrupt-driven receive method. DIO0 will be activated when full valid packet is received. More...
 
int16_t readData (uint8_t *data, size_t len)
 Reads data that was received after calling startReceive method. This method reads len characters. More...
 
int16_t setSyncWord (uint8_t syncWord)
 Sets LoRa sync word. Only available in LoRa mode. More...
 
int16_t setCurrentLimit (uint8_t currentLimit)
 Sets current limit for over current protection at transmitter amplifier. Allowed values range from 45 to 120 mA in 5 mA steps and 120 to 240 mA in 10 mA steps. More...
 
int16_t setPreambleLength (uint16_t preambleLength)
 Sets LoRa preamble length. Allowed values range from 6 to 65535. Only available in LoRa mode. More...
 
float getFrequencyError (bool autoCorrect=false)
 Gets frequency error of the latest received packet. More...
 
float getSNR ()
 Gets signal-to-noise ratio of the latest received packet. More...
 
float getDataRate ()
 Get data rate of the latest transmitted packet. More...
 
int16_t setBitRate (float br)
 Sets FSK bit rate. Allowed values range from 1.2 to 300 kbps. Only available in FSK mode. More...
 
int16_t setFrequencyDeviation (float freqDev)
 Sets FSK frequency deviation from carrier frequency. Allowed values depend on bit rate setting and must be lower than 200 kHz. Only available in FSK mode. More...
 
int16_t setRxBandwidth (float rxBw)
 Sets FSK receiver bandwidth. Allowed values range from 2.6 to 250 kHz. Only available in FSK mode. More...
 
int16_t setSyncWord (uint8_t *syncWord, size_t len)
 Sets FSK sync word. Allowed sync words are up to 8 bytes long and can not contain null bytes. Only available in FSK mode. More...
 
int16_t setNodeAddress (uint8_t nodeAddr)
 Sets FSK node address. Calling this method will enable address filtering. Only available in FSK mode. More...
 
int16_t setBroadcastAddress (uint8_t broadAddr)
 Sets FSK broadcast address. Calling this method will enable address filtering. Only available in FSK mode. More...
 
int16_t disableAddressFiltering ()
 Disables FSK address filtering. More...
 
int16_t setOOK (bool enableOOK)
 Enables/disables OOK modulation instead of FSK. More...
 
size_t getPacketLength (bool update=true)
 Query modem for the packet length of received payload. More...
 
int16_t fixedPacketLengthMode (uint8_t len=SX127X_MAX_PACKET_LENGTH_FSK)
 Set modem in fixed packet length mode. Available in FSK mode only. More...
 
int16_t variablePacketLengthMode (uint8_t maxLen=SX127X_MAX_PACKET_LENGTH_FSK)
 Set modem in variable packet length mode. Available in FSK mode only. More...
 
int16_t setRSSIConfig (uint8_t smoothingSamples, int8_t offset=0)
 Sets RSSI measurement configuration in FSK mode. More...
 
int16_t setEncoding (uint8_t encoding)
 Sets transmission encoding. Only available in FSK mode. More...
 
- Public Member Functions inherited from PhysicalLayer
 PhysicalLayer (float crysFreq, uint8_t divExp, size_t maxPacketLength)
 Default constructor. More...
 
int16_t transmit (__FlashStringHelper *fstr, uint8_t addr=0)
 Arduino Flash String transmit method. More...
 
int16_t transmit (String &str, uint8_t addr=0)
 Arduino String transmit method. More...
 
int16_t transmit (const char *str, uint8_t addr=0)
 C-string transmit method. More...
 
int16_t receive (String &str, size_t len=0)
 Arduino String receive method. More...
 
int16_t startTransmit (String &str, uint8_t addr=0)
 Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes. More...
 
int16_t startTransmit (const char *str, uint8_t addr=0)
 Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes. More...
 
int16_t readData (String &str, size_t len=0)
 Reads data that was received after calling startReceive method. More...
 
float getCrystalFreq ()
 Gets the module crystal oscillator frequency that was set in constructor. More...
 
uint8_t getDivExponent ()
 Gets the module frequency divider exponent that was set in constructor. More...
 

Detailed Description

Derived class for SX1278 modules. Also used as base class for SX1276, SX1277, SX1279, RFM95 and RFM96. All of these modules use the same basic hardware and only differ in parameter ranges (and names).

Constructor & Destructor Documentation

SX1278::SX1278 ( Module mod)

Default constructor. Called from Arduino sketch when creating new LoRa instance.

Parameters
modInstance of Module that will be used to communicate with the LoRa chip.

Member Function Documentation

int16_t SX1278::begin ( float  freq = 434.0,
float  bw = 125.0,
uint8_t  sf = 9,
uint8_t  cr = 7,
uint8_t  syncWord = SX127X_SYNC_WORD,
int8_t  power = 17,
uint8_t  currentLimit = 100,
uint16_t  preambleLength = 8,
uint8_t  gain = 0 
)

LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.

Parameters
freqCarrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
bwLoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
sfLoRa link spreading factor. Allowed values range from 6 to 12.
crLoRa link coding rate denominator. Allowed values range from 5 to 8.
syncWordLoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
powerTransmission output power in dBm. Allowed values range from 2 to 17 dBm.
currentLimitTrim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. Set to 0 to disable OCP (not recommended).
preambleLengthLength of LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. Allowed values range from 6 to 65535.
gainGain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain. Set to 0 to enable automatic gain control (recommended).
Returns
Status Codes
int16_t SX1278::beginFSK ( float  freq = 434.0,
float  br = 48.0,
float  freqDev = 50.0,
float  rxBw = 125.0,
int8_t  power = 13,
uint8_t  currentLimit = 100,
uint16_t  preambleLength = 16,
bool  enableOOK = false 
)

FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.

Parameters
freqCarrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
brBit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
freqDevFrequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz. Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
rxBwReceiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
powerTransmission output power in dBm. Allowed values range from 2 to 17 dBm.
currentLimitTrim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA. Set to 0 to disable OCP (not recommended).
preambleLengthLength of FSK preamble in bits.
enableOOKUse OOK modulation instead of FSK.
Returns
Status Codes
float SX1278::getRSSI ( )

Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem.

Returns
Last packet RSSI for LoRa modem, or current RSSI level for FSK modem.
int16_t SX1278::setBandwidth ( float  bw)

Sets LoRa link bandwidth. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. Only available in LoRa mode.

Parameters
bwLoRa link bandwidth to be set in kHz.
Returns
Status Codes
int16_t SX1278::setCodingRate ( uint8_t  cr)

Sets LoRa link coding rate denominator. Allowed values range from 5 to 8. Only available in LoRa mode.

Parameters
crLoRa link coding rate denominator to be set.
Returns
Status Codes
int16_t SX1278::setCRC ( bool  enableCRC)

Enables/disables CRC check of received packets.

Parameters
enableCRCEnable (true) or disable (false) CRC.
Returns
Status Codes
int16_t SX1278::setDataShaping ( float  sh)

Sets Gaussian filter bandwidth-time product that will be used for data shaping. Allowed values are 0.3, 0.5 or 1.0. Set to 0 to disable data shaping. Only available in FSK mode with FSK modulation.

Parameters
shGaussian shaping bandwidth-time product that will be used for data shaping
Returns
Status Codes
int16_t SX1278::setDataShapingOOK ( uint8_t  sh)

Sets filter cutoff frequency that will be used for data shaping. Allowed values are 1 for frequency equal to bit rate and 2 for frequency equal to 2x bit rate. Set to 0 to disable data shaping. Only available in FSK mode with OOK modulation.

Parameters
shCutoff frequency that will be used for data shaping
Returns
Status Codes
int16_t SX1278::setFrequency ( float  freq)

Sets carrier frequency. Allowed values range from 137.0 MHz to 525.0 MHz.

Parameters
freqCarrier frequency to be set in MHz.
Returns
Status Codes
int16_t SX1278::setGain ( uint8_t  gain)

Sets gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain. Set to 0 to enable automatic gain control (recommended). Only available in LoRa mode.

Parameters
gainGain of receiver LNA (low-noise amplifier) to be set.
Returns
Status Codes
int16_t SX1278::setOutputPower ( int8_t  power)

Sets transmission output power. Allowed values range from 2 to 17 dBm.

Parameters
powerTransmission output power in dBm.
Returns
Status Codes
int16_t SX1278::setSpreadingFactor ( uint8_t  sf)

Sets LoRa link spreading factor. Allowed values range from 6 to 12. Only available in LoRa mode.

Parameters
sfLoRa link spreading factor to be set.
Returns
Status Codes

The documentation for this class was generated from the following files: