From d690d7947f185fd7b23aa7b05425f1ed64b712ca Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Sat, 20 Aug 2016 10:00:35 -0400 Subject: [PATCH] Add initial documentation --- API.md | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 56 ++++++++++++++++++++++- 2 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 API.md diff --git a/API.md b/API.md new file mode 100644 index 0000000..3c52e38 --- /dev/null +++ b/API.md @@ -0,0 +1,131 @@ +# LoRa API + +## Include Library + +```arduino +#include +``` + +## Setup + +### Begin + +Initialize the library with the specified frequency. + +```arduino +LoRa.begin(frequency); +``` + * `frequency` - frequency in Hz (`433E6`, `866E6`, `915E6`) + +Returns `1` on success, `0` on failure. + +## Set pins + +Override the default `NSS` and `NRESET` pins used by the library. **Must** be called before `LoRa.begin()`. + +```arduino +LoRa.setPins(ss, reset); +``` + * `ss` new slave select pin to use, defaults to `10` + * `reset` new reset pin to use, defaults to `9` + +### End + +Stop the library + +```arduino +LoRa.end() +``` + +## Sending data + +### Begin packet + +Start the sequence of sending a packet. + +```arduino +LoRa.beginPacket(); +``` + +Returns `1` on success, `0` on failure. + +### Writing + +Write data to the packet. Each packet can contain up to 255 bytes. + +```arduino +LoRa.write(byte); + +LoRa.write(buffer, length); +``` +* `byte` single byte to write to packet + +or + +* `buffer` data to write to packet +* `length` size of data to write + +Returns the number of bytes written. + +**Note:** Other Arduino `Print` API's can also be used to write data into the packet + +### End packet + +End the sequence of sending a packet. + +```arduino +LoRa.endPacket() +``` + +Returns `1` on success, `0` on failure. + +## Receiving data + +### Parsing packet + +Check if a packet has been received. + +```arduino +int packetSize = LoRa.parsePacket(); +``` + +Returns the packet size or `0` if no packet was received. + +### Packet RSSI + +```arduino +int rssi = LoRa.packetRSSI(); +``` + +Returns the RSSI of the received packet. + +### Available + +```arduino +int availableBytes = LoRa.available() +``` + +Returns number of bytes available for reading. + +### Peeking + +Peek at the next byte in the packet. + +```arduino +byte b = LoRa.peek(); +``` + +Returns the next byte in the packet or `-1` if no bytes available. + +### Reading + +Read the next byte from the packet. + +```arduino +byte b = LoRa.read(); +``` + +Returns the next byte in the packet or `-1` if no bytes available. + +**Note:** Other Arduino [`Stream` API's](https://www.arduino.cc/en/Reference/Stream) can also be used to read data from the packet + diff --git a/README.md b/README.md index 0b53e55..a3c98c3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,54 @@ -# arduino-LoRa -An Arduino library for sending and receiving data using LoRa radios. +# Arduino LoRa + +An [Arduino](http://arduino.cc/) library for sending and receiving data using [LoRa](https://www.lora-alliance.org/) radios. + +## Compatible Hardware + + * [Semtech SX1276/77/78/79](http://www.semtech.com/apps/product.php?pn=SX1276) based boards including: + * [Dragino Lora Shield](http://www.dragino.com/products/module/item/102-lora-shield.html) + * [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) + * [NiceRF LoRa1276](http://www.nicerf.com/product_view.aspx?id=99) + +### Semtech SX1276/77/78/79 wiring + +| Semtech SX1276/77/78/79 | Arduino | +| :---------------------: | :------:| +| VCC | 3.3V | +| GND | GND | +| SCK | SCK | +| MISO | MISO | +| MOSI | MOSI | +| NSS | 10 | +| NRESET | 9 | + + +`NSS` and `NRESET` pins can be changed by using `LoRa.setPins(ss, reset)`. + +## Installation + +### Using the Arduino IDE Library Manager + +1. Choose `Sketch` -> `Include Library` -> `Manage Libraries...` +2. Type `LoRa` into the search box. +3. Click the row to select the library. +4. Click the `Install` button to install the library. + +### Using Git + +```sh +cd ~/Documents/Arduino/libraries/ +git clone https://github.com/sandeepmistry/arduino-LoRa LoRa +``` + +## API + +See [API.md](API.md). + +## Examples + +See [examples](examples) folder. + +## License + +This libary is [licensed](LICENSE) under the [MIT Licence](http://en.wikipedia.org/wiki/MIT_License).