-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
5,344 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Contributing to LoRaLib | ||
|
||
First of all, thank you very much for taking the time to contribute! All feedback and ideas are greatly appreciated. | ||
To keep this library organized, please follow these rules. | ||
|
||
1. **Questions are welcome, spam is not.** | ||
Any issues without description will be considered spam and as such will be **CLOSED** and **LOCKED** immediately! | ||
2. **This repository has issue templates.** | ||
To report bugs or suggest new features, use the provided issue templates. Use the default issue only if the templates do not fit your issue type. | ||
3. **LoRaLib is a driver.** | ||
This means that only features available in the SX127x chips will be implemented. LoRaLib will not implement protocols such as LoRaWAN. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# LoRaLib [![Build Status](https://travis-ci.org/jgromes/LoRaLib.svg?branch=master)](https://travis-ci.org/jgromes/LoRaLib) | ||
|
||
## Arduino library for LoRa modules based on SX1278 and SX1272 chips | ||
|
||
## See the [Wiki](https://github.com/jgromes/LoRaLib/wiki) for detailed API reference and further information. | ||
|
||
### This is not the shield you are looking for! | ||
If you're looking for an open-source shield to use with this library, it has its own repository: [https://github.com/jgromes/LoRenz](https://github.com/jgromes/LoRenz) | ||
|
||
--- | ||
|
||
DISCLAIMER: This library is provided 'AS IS'. See `license.txt` for details. | ||
|
||
This library enables easy long range communaction with SX127x family of LoRa modules. It was designed to be used with LoRenz Rev.B shields. However, they are not required and this library can be used with any LoRa module, as long as it is based on of the Semtech LoRa chips. | ||
|
||
Currently supported chips: | ||
* SX1272 and SX1273 | ||
* SX1278, SX1276, SX1277 and SX1279 | ||
|
||
Currently supported platforms: | ||
* All Arduino AVR boards (tested on Uno and Mega) | ||
* ESP32 | ||
* ESP8266 NodeMCU |
67 changes: 67 additions & 0 deletions
67
arduino/lib/LoRaLibMod/examples/ChannelActivityDetection/ChannelActivityDetection.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
LoRaLib Channel Activity Detection Example | ||
This example scans the current LoRa channel and detects | ||
valid LoRa preambles. Preamble is the first part of | ||
LoRa transmission, so this can be used to check | ||
if the LoRa channel is free, or if you should start | ||
receiving a message. | ||
For more detailed information, see the LoRaLib Wiki | ||
https://github.com/jgromes/LoRaLib/wiki | ||
*/ | ||
|
||
// include the library | ||
#include <LoRaLib.h> | ||
|
||
// create instance of LoRa class using SX1278 module | ||
// this pinout corresponds to LoRenz shield: | ||
// https://github.com/jgromes/LoRenz | ||
// NSS pin: 7 (18 on ESP32 boards) | ||
// DIO0 pin: 2 | ||
// DIO1 pin: 3 | ||
SX1278 lora = new LoRa; | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
|
||
// initialize SX1278 with default settings | ||
Serial.print(F("Initializing ... ")); | ||
// carrier frequency: 434.0 MHz | ||
// bandwidth: 125.0 kHz | ||
// spreading factor: 9 | ||
// coding rate: 7 | ||
// sync word: 0x12 | ||
// output power: 17 dBm | ||
// current limit: 100 mA | ||
// preamble length: 8 symbols | ||
// amplifier gain: 0 (automatic gain control) | ||
int state = lora.begin(); | ||
if(state == ERR_NONE) { | ||
Serial.println(F("success!")); | ||
} else { | ||
Serial.print(F("failed, code ")); | ||
Serial.println(state); | ||
while(true); | ||
} | ||
} | ||
|
||
void loop() { | ||
Serial.print("Scanning channel for LoRa preamble ... "); | ||
|
||
// start scanning current channel | ||
int state = lora.scanChannel(); | ||
|
||
if(state == PREAMBLE_DETECTED) { | ||
// LoRa preamble was detected | ||
Serial.println(" detected preamble!"); | ||
|
||
} else if(state == CHANNEL_FREE) { | ||
// no preamble was detected, channel is free | ||
Serial.println(" channel is free!"); | ||
|
||
} | ||
|
||
// wait 100 ms before new scan | ||
delay(100); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
/* | ||
LoRaLib FSK Modem Example | ||
This example shows how to use FSK modem in SX127x chips. | ||
NOTE: The sketch below is just a guide on how to use | ||
FSK modem, so this code should not be run directly! | ||
Instead, modify the other examples to use FSK | ||
modem and use the appropriate configuration | ||
methods. | ||
For more detailed information, see the LoRaLib Wiki | ||
https://github.com/jgromes/LoRaLib/wiki | ||
For more information on FSK modem, see | ||
https://github.com/jgromes/LoRaLib/wiki/FSK-Modem | ||
*/ | ||
|
||
// include the library | ||
#include <LoRaLib.h> | ||
|
||
// create instance of LoRa class using SX1278 module | ||
// this pinout corresponds to LoRenz shield: | ||
// https://github.com/jgromes/LoRenz | ||
// NSS pin: 7 (18 on ESP32 boards) | ||
// DIO0 pin: 2 | ||
// DIO1 pin: 3 | ||
SX1278 fsk = new LoRa; | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
|
||
// initialize SX1278 FSK modem with default settings | ||
Serial.print(F("Initializing ... ")); | ||
// carrier frequency: 434.0 MHz | ||
// bit rate: 48.0 kbps | ||
// frequency deviation: 50.0 kHz | ||
// Rx bandwidth: 125.0 kHz | ||
// output power: 13 dBm | ||
// current limit: 100 mA | ||
// sync word: 0x2D 0x01 | ||
int state = fsk.beginFSK(); | ||
if (state == ERR_NONE) { | ||
Serial.println(F("success!")); | ||
} else { | ||
Serial.print(F("failed, code ")); | ||
Serial.println(state); | ||
while (true); | ||
} | ||
|
||
// if needed, you can switch between LoRa and FSK modes | ||
// | ||
// lora.begin() start LoRa mode (and disable FSK) | ||
// lora.beginFSK() start FSK mode (and disable LoRa) | ||
|
||
// the following settings can also | ||
// be modified at run-time | ||
state = fsk.setFrequency(433.5); | ||
state = fsk.setBitRate(100.0); | ||
state = fsk.setFrequencyDeviation(10.0); | ||
state = fsk.setRxBandwidth(250.0); | ||
state = fsk.setOutputPower(10.0); | ||
state = fsk.setCurrentLimit(100); | ||
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, | ||
0x89, 0xAB, 0xCD, 0xEF}; | ||
state = fsk.setSyncWord(syncWord, 8); | ||
if (state != ERR_NONE) { | ||
Serial.print(F("Unable to set configuration, code ")); | ||
Serial.println(state); | ||
while (true); | ||
} | ||
|
||
#warning "This sketch is just an API guide! Read the note at line 6." | ||
} | ||
|
||
void loop() { | ||
// FSK modem can use the same transmit/receive methods | ||
// as the LoRa modem, even their interrupt-driven versions | ||
// NOTE: FSK modem maximum packet length is 63 bytes! | ||
|
||
// transmit FSK packet | ||
int state = fsk.transmit("Hello World!"); | ||
/* | ||
byte byteArr[] = {0x01, 0x23, 0x45, 0x56, | ||
0x78, 0xAB, 0xCD, 0xEF}; | ||
int state = lora.transmit(byteArr, 8); | ||
*/ | ||
if (state == ERR_NONE) { | ||
Serial.println(F("Packet transmitted successfully!")); | ||
} else if (state == ERR_PACKET_TOO_LONG) { | ||
Serial.println(F("Packet too long!")); | ||
} else if (state == ERR_TX_TIMEOUT) { | ||
Serial.println(F("Timed out while transmitting!")); | ||
} else { | ||
Serial.println(F("Failed to transmit packet, code ")); | ||
} | ||
|
||
// receive FSK packet | ||
String str; | ||
state = fsk.receive(str); | ||
/* | ||
byte byteArr[8]; | ||
int state = lora.receive(byteArr, 8); | ||
*/ | ||
if (state == ERR_NONE) { | ||
Serial.println(F("Received packet!")); | ||
Serial.print(F("Data:\t")); | ||
Serial.println(str); | ||
} else if (state == ERR_RX_TIMEOUT) { | ||
Serial.println(F("Timed out while waiting for packet!")); | ||
} else { | ||
Serial.println(F("Failed to receive packet, code ")); | ||
} | ||
|
||
// FSK modem has built-in address filtering system | ||
// it can be enabled by setting node address, broadcast | ||
// address, or both | ||
// | ||
// to transmit packet to a particular address, | ||
// use the following methods: | ||
// | ||
// fsk.transmit("Hello World!", address); | ||
// fsk.startTransmit("Hello World!", address); | ||
|
||
// set node address to 0x02 | ||
state = fsk.setNodeAddress(0x02); | ||
// set broadcast address to 0xFF | ||
state = fsk.setBroadcastAddress(0xFF); | ||
if (state != ERR_NONE) { | ||
Serial.println(F("Unable to set address filter, code ")); | ||
} | ||
|
||
// address filtering can also be disabled | ||
// NOTE: calling this method will also erase previously set | ||
// node and broadcast address | ||
/* | ||
state = fsk.disableAddressFiltering(); | ||
if (state != ERR_NONE) { | ||
Serial.println(F("Unable to remove address filter, code ")); | ||
} | ||
*/ | ||
|
||
// FSK modem supports direct data transmission | ||
// in this mode, SX127x directly transmits any data | ||
// sent to DIO1 (data) and DIO2 (clock) | ||
|
||
// activate direct mode transmitter | ||
state = fsk.transmitDirect(); | ||
if (state != ERR_NONE) { | ||
Serial.println(F("Unable to start direct transmission mode, code ")); | ||
} | ||
|
||
// using the direct mode, it is possible to transmit | ||
// FM notes with Arduino tone() function | ||
|
||
// tone() function is not available on ESP32 and Arduino Due | ||
#if !defined(ESP32) && !defined(_VARIANT_ARDUINO_DUE_X_) | ||
// transmit FM tone at 1000 Hz for 1 second | ||
// (DIO2 is connected to Arduino pin 4) | ||
tone(4, 1000); | ||
delay(1000); | ||
// transmit FM note at 500 Hz for 1 second | ||
tone(4, 500); | ||
delay(1000); | ||
#endif | ||
|
||
// NOTE: after calling transmitDirect(), SX127x will start | ||
// transmitting immediately! This signal can jam other | ||
// devices at the same frequency, it is up to the user | ||
// to disable it with standby() method! | ||
|
||
// direct mode transmissions can also be received | ||
// as bit stream on DIO1 (data) and DIO2 (clock) | ||
state = fsk.receiveDirect(); | ||
if (state != ERR_NONE) { | ||
Serial.println(F("Unable to start direct reception mode, code ")); | ||
} | ||
|
||
// NOTE: you will not be able to send or receive packets | ||
// while direct mode is active! to deactivate it, call method | ||
// fsk.packetMode() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
LoRaLib Receive Example | ||
This example listens for LoRa transmissions and tries to | ||
receive them. To successfully receive data, the following | ||
settings have to be the same on both transmitter | ||
and receiver: | ||
- carrier frequency | ||
- bandwidth | ||
- spreading factor | ||
- coding rate | ||
- sync word | ||
- preamble length | ||
For more detailed information, see the LoRaLib Wiki | ||
https://github.com/jgromes/LoRaLib/wiki | ||
*/ | ||
|
||
// include the library | ||
#include <LoRaLib.h> | ||
|
||
// create instance of LoRa class using SX1278 module | ||
// this pinout corresponds to LoRenz shield: | ||
// https://github.com/jgromes/LoRenz | ||
// NSS pin: 7 (18 on ESP32 boards) | ||
// DIO0 pin: 2 | ||
// DIO1 pin: 3 | ||
SX1278 lora = new LoRa; | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
|
||
// initialize SX1278 with default settings | ||
Serial.print(F("Initializing ... ")); | ||
// carrier frequency: 434.0 MHz | ||
// bandwidth: 125.0 kHz | ||
// spreading factor: 9 | ||
// coding rate: 7 | ||
// sync word: 0x12 | ||
// output power: 17 dBm | ||
// current limit: 100 mA | ||
// preamble length: 8 symbols | ||
// amplifier gain: 0 (automatic gain control) | ||
int state = lora.begin(); | ||
if (state == ERR_NONE) { | ||
Serial.println(F("success!")); | ||
} else { | ||
Serial.print(F("failed, code ")); | ||
Serial.println(state); | ||
while (true); | ||
} | ||
} | ||
|
||
void loop() { | ||
Serial.print("Waiting for incoming transmission ... "); | ||
|
||
// you can receive data as an Arduino String | ||
String str; | ||
int state = lora.receive(str); | ||
|
||
// you can also receive data as byte array | ||
/* | ||
byte byteArr[8]; | ||
int state = lora.receive(byteArr, 8); | ||
*/ | ||
|
||
if (state == ERR_NONE) { | ||
// packet was successfully received | ||
Serial.println("success!"); | ||
|
||
// print data of the packet | ||
Serial.print("Data:\t\t\t"); | ||
Serial.println(str); | ||
|
||
// print RSSI (Received Signal Strength Indicator) | ||
// of the last received packet | ||
Serial.print("RSSI:\t\t\t"); | ||
Serial.print(lora.lastPacketRSSI); | ||
Serial.println(" dBm"); | ||
|
||
// print SNR (Signal-to-Noise Ratio) | ||
// of the last received packet | ||
Serial.print("SNR:\t\t\t"); | ||
Serial.print(lora.lastPacketSNR); | ||
Serial.println(" dBm"); | ||
|
||
// print frequency error | ||
// of the last received packet | ||
Serial.print("Frequency error:\t"); | ||
Serial.print(lora.getFrequencyError()); | ||
Serial.println(" Hz"); | ||
|
||
} else if (state == ERR_RX_TIMEOUT) { | ||
// timeout occurred while waiting for a packet | ||
Serial.println("timeout!"); | ||
|
||
} else if (state == ERR_CRC_MISMATCH) { | ||
// packet was received, but is malformed | ||
Serial.println("CRC error!"); | ||
|
||
} | ||
|
||
} | ||
|
Oops, something went wrong.