Skip to content

Update #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ script:
buildExampleSketch LoRaReceiverCallback;
fi
- buildExampleSketch LoRaSender
- buildExampleSketch LoRaSenderNonBlocking
- buildExampleSketch LoRaSetSpread
- buildExampleSketch LoRaSetSyncWord
17 changes: 15 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ LoRa.beginPacket(implicitHeader);

* `implicitHeader` - (optional) `true` enables implicit header mode, `false` enables explicit header mode (default)

Returns `1` on success, `0` on failure.
Returns `1` if radio is ready to transmit, `0` if busy or on failure.

### Writing

Expand All @@ -109,8 +109,11 @@ Returns the number of bytes written.
End the sequence of sending a packet.

```arduino
LoRa.endPacket()
LoRa.endPacket();

LoRa.endPacket(async);
```
* `async` - (optional) `true` enables non-blocking mode, `false` waits for transmission to be completed (default)

Returns `1` on success, `0` on failure.

Expand Down Expand Up @@ -329,6 +332,16 @@ LoRa.enableCrc();
LoRa.disableCrc();
```

### Invert IQ Signals

Enable or disable Invert the LoRa I and Q signals, by default a invertIQ is not used.

```arduino
LoRa.enableInvertIQ();

LoRa.disableInvertIQ();
```

## Other functions

### Random
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ An [Arduino](https://arduino.cc/) library for sending and receiving data using [
* [HopeRF](http://www.hoperf.com/rf_transceiver/lora/) [RFM95W](http://www.hoperf.com/rf_transceiver/lora/RFM95W.html), [RFM96W](http://www.hoperf.com/rf_transceiver/lora/RFM96W.html), and [RFM98W](http://www.hoperf.com/rf_transceiver/lora/RFM98W.html)
* [Modtronix](http://modtronix.com/) [inAir4](http://modtronix.com/inair4.html), [inAir9](http://modtronix.com/inair9.html), and [inAir9B](http://modtronix.com/inair9b.html)
* [Arduino MKR WAN 1300](https://store.arduino.cc/usa/mkr-wan-1300)
* **NOTE:** Requires firmware v1.1.6 or later on the on-board Murata module
* **NOTE:** Requires firmware v1.1.6 or later on the on-board Murata module. Please use the [MKRWANFWUpdate_standalone example](https://github.com/arduino-libraries/MKRWAN/blob/master/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino) from latest [MKRWAN library](https://github.com/arduino-libraries/MKRWAN) release to update the firmware.
* **WARNING**: [LoRa.onReceive(...)](https://github.com/sandeepmistry/arduino-LoRa/blob/master/API.md#register-callback) and [LoRa.recieve()](https://github.com/sandeepmistry/arduino-LoRa/blob/master/API.md#receive-mode) is not compatible with this board!

### Semtech SX1276/77/78/79 wiring
Expand Down
35 changes: 35 additions & 0 deletions examples/LoRaSenderNonBlocking/LoRaSenderNonBlocking.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <SPI.h>
#include <LoRa.h>

int counter = 0;

void setup() {
Serial.begin(9600);
while (!Serial);

Serial.println("LoRa Sender non-blocking");

if (!LoRa.begin(915E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}

void loop() {
// wait until the radio is ready to send a packet
while (LoRa.beginPacket() == 0) {
Serial.print("waiting for radio ... ");
delay(100);
}

Serial.print("Sending packet non-blocking: ");
Serial.println(counter);

// send in async / non-blocking mode
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket(true); // true = async / non-blocking mode

counter++;
}
113 changes: 113 additions & 0 deletions examples/LoRaSimpleGateway/LoRaSimpleGateway.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
LoRa Simple Gateway/Node Exemple

This code uses InvertIQ function to create a simple Gateway/Node logic.

Gateway - Sends messages with enableInvertIQ()
- Receives messages with disableInvertIQ()

Node - Sends messages with disableInvertIQ()
- Receives messages with enableInvertIQ()

With this arrangement a Gateway never receive messages from another Gateway
and a Node never receive message from another Node.
Only Gateway to Node and vice versa.

This code receives messages and sends a message every second.

InvertIQ function basically invert the LoRa I and Q signals.

See the Semtech datasheet, http://www.semtech.com/images/datasheet/sx1276.pdf
for more on InvertIQ register 0x33.

created 05 August 2018
by Luiz H. Cassettari
*/

#include <SPI.h> // include libraries
#include <LoRa.h>

const long frequency = 915E6; // LoRa Frequency

const int csPin = 10; // LoRa radio chip select
const int resetPin = 9; // LoRa radio reset
const int irqPin = 2; // change for your board; must be a hardware interrupt pin

void setup() {
Serial.begin(9600); // initialize serial
while (!Serial);

LoRa.setPins(csPin, resetPin, irqPin);

if (!LoRa.begin(frequency)) {
Serial.println("LoRa init failed. Check your connections.");
while (true); // if failed, do nothing
}

Serial.println("LoRa init succeeded.");
Serial.println();
Serial.println("LoRa Simple Gateway");
Serial.println("Only receive messages from nodes");
Serial.println("Tx: invertIQ enable");
Serial.println("Rx: invertIQ disable");
Serial.println();

LoRa.onReceive(onReceive);
LoRa_rxMode();
}

void loop() {
if (runEvery(5000)) { // repeat every 5000 millis

String message = "HeLoRa World! ";
message += "I'm a Gateway! ";
message += millis();

LoRa_sendMessage(message); // send a message

Serial.println("Send Message!");
}
}

void LoRa_rxMode(){
LoRa.disableInvertIQ(); // normal mode
LoRa.receive(); // set receive mode
}

void LoRa_txMode(){
LoRa.idle(); // set standby mode
LoRa.enableInvertIQ(); // active invert I and Q signals
}

void LoRa_sendMessage(String message) {
LoRa_txMode(); // set tx mode
LoRa.beginPacket(); // start packet
LoRa.print(message); // add payload
LoRa.endPacket(); // finish packet and send it
LoRa_rxMode(); // set rx mode
}

void onReceive(int packetSize) {
String message = "";

while (LoRa.available()) {
message += (char)LoRa.read();
}

Serial.print("Gateway Receive: ");
Serial.println(message);

}

boolean runEvery(unsigned long interval)
{
static unsigned long previousMillis = 0;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
return true;
}
return false;
}

113 changes: 113 additions & 0 deletions examples/LoRaSimpleNode/LoRaSimpleNode.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
LoRa Simple Gateway/Node Exemple

This code uses InvertIQ function to create a simple Gateway/Node logic.

Gateway - Sends messages with enableInvertIQ()
- Receives messages with disableInvertIQ()

Node - Sends messages with disableInvertIQ()
- Receives messages with enableInvertIQ()

With this arrangement a Gateway never receive messages from another Gateway
and a Node never receive message from another Node.
Only Gateway to Node and vice versa.

This code receives messages and sends a message every second.

InvertIQ function basically invert the LoRa I and Q signals.

See the Semtech datasheet, http://www.semtech.com/images/datasheet/sx1276.pdf
for more on InvertIQ register 0x33.

created 05 August 2018
by Luiz H. Cassettari
*/

#include <SPI.h> // include libraries
#include <LoRa.h>

const long frequency = 915E6; // LoRa Frequency

const int csPin = 10; // LoRa radio chip select
const int resetPin = 9; // LoRa radio reset
const int irqPin = 2; // change for your board; must be a hardware interrupt pin

void setup() {
Serial.begin(9600); // initialize serial
while (!Serial);

LoRa.setPins(csPin, resetPin, irqPin);

if (!LoRa.begin(frequency)) {
Serial.println("LoRa init failed. Check your connections.");
while (true); // if failed, do nothing
}

Serial.println("LoRa init succeeded.");
Serial.println();
Serial.println("LoRa Simple Node");
Serial.println("Only receive messages from gateways");
Serial.println("Tx: invertIQ disable");
Serial.println("Rx: invertIQ enable");
Serial.println();

LoRa.onReceive(onReceive);
LoRa_rxMode();
}

void loop() {
if (runEvery(1000)) { // repeat every 1000 millis

String message = "HeLoRa World! ";
message += "I'm a Node! ";
message += millis();

LoRa_sendMessage(message); // send a message

Serial.println("Send Message!");
}
}

void LoRa_rxMode(){
LoRa.enableInvertIQ(); // active invert I and Q signals
LoRa.receive(); // set receive mode
}

void LoRa_txMode(){
LoRa.idle(); // set standby mode
LoRa.disableInvertIQ(); // normal mode
}

void LoRa_sendMessage(String message) {
LoRa_txMode(); // set tx mode
LoRa.beginPacket(); // start packet
LoRa.print(message); // add payload
LoRa.endPacket(); // finish packet and send it
LoRa_rxMode(); // set rx mode
}

void onReceive(int packetSize) {
String message = "";

while (LoRa.available()) {
message += (char)LoRa.read();
}

Serial.print("Node Receive: ");
Serial.println(message);

}

boolean runEvery(unsigned long interval)
{
static unsigned long previousMillis = 0;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
return true;
}
return false;
}

2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ setPreambleLength KEYWORD2
setSyncWord KEYWORD2
enableCrc KEYWORD2
disableCrc KEYWORD2
enableInvertIQ KEYWORD2
disableInvertIQ KEYWORD2

random KEYWORD2
setPins KEYWORD2
Expand Down
Loading