From cf4cab06c7ddc22560f6bf466839f5edae2cb7e3 Mon Sep 17 00:00:00 2001 From: Kent Wiliams Date: Tue, 7 Apr 2020 15:13:26 -0700 Subject: [PATCH] adding sparkfun pro rf example --- sparkfun-pro-rf/README.md | 24 ++++++ sparkfun-pro-rf/longfi-us915.ino | 140 +++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 sparkfun-pro-rf/README.md create mode 100644 sparkfun-pro-rf/longfi-us915.ino diff --git a/sparkfun-pro-rf/README.md b/sparkfun-pro-rf/README.md new file mode 100644 index 0000000..72e486d --- /dev/null +++ b/sparkfun-pro-rf/README.md @@ -0,0 +1,24 @@ +# Sparkfun Pro RF - Basic LongFi Example + +This example demonstrates sending a simple data packet using a Sparkfun Pro RF development board. Visit our quickstart guide [here](https://developer.helium.com/devices/arduino-quickstart/sparkfun-pro-rf). + +## Required Arduino Libraries + +From the Arduino IDE, open the Library Manager (Sketch->Include Library->Manage Libraries). In the search box, type the library name below and install the latest version. + +[IBM LMIC framework](https://github.com/matthijskooijman/arduino-lmic) + +## Required Arduino Board Support + +### Arduino SAMD Boards (32-bits ARM Cortex-M0+) + SparkFun SAMD Boards +Install board support packages, find instructions [here](https://learn.sparkfun.com/tutorials/sparkfun-samd21-pro-rf-hookup-guide?_ga=2.148378999.1172134851.1586114454-289367592.1582349414&_gac=1.242421430.1585837307.EAIaIQobChMI86GEgfjJ6AIVBQF9Ch0mpwyeEAEYASAAEgLFn_D_BwE#setting-up-arduino). + +Arduino IDE: +1. Select Tools -> Board: -> Discovery +2. Select Tools -> Board part number: -> Discovery L072Z-LRWAN1 + +## Required Hardware + +### Sparkfun Pro RF +* [Sparkfun Pro RF Product Page](https://www.sparkfun.com/products/14916?_ga=2.151319289.1172134851.1586114454-289367592.1582349414&_gac=1.175849750.1585837307.EAIaIQobChMI86GEgfjJ6AIVBQF9Ch0mpwyeEAEYASAAEgLFn_D_BwE#) +* [Sparkfun Pro RF ](https://learn.sparkfun.com/tutorials/sparkfun-samd21-pro-rf-hookup-guide?_ga=2.5036659.1172134851.1586114454-289367592.1582349414&_gac=1.244975921.1585837307.EAIaIQobChMI86GEgfjJ6AIVBQF9Ch0mpwyeEAEYASAAEgLFn_D_BwE) \ No newline at end of file diff --git a/sparkfun-pro-rf/longfi-us915.ino b/sparkfun-pro-rf/longfi-us915.ino new file mode 100644 index 0000000..0cf5c16 --- /dev/null +++ b/sparkfun-pro-rf/longfi-us915.ino @@ -0,0 +1,140 @@ +#include +#include +#include + +// This EUI must be in little-endian format, so least-significant-byte +// first. When copying an EUI from ttnctl output, this means to reverse +// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, +// 0x70. +static const u1_t PROGMEM APPEUI[8]={FILL_ME_IN}; +void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);} + +// This should also be in little endian format, see above. +static const u1_t PROGMEM DEVEUI[8]={FILL_ME_IN}; +void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);} + +// This key should be in big endian format (or, since it is not really a +// number but a block of memory, endianness does not really apply). In +// practice, a key taken from ttnctl can be copied as-is. +// The key shown here is the semtech default key. +static const u1_t PROGMEM APPKEY[16] = {FILL_ME_IN}; +void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);} + +static uint8_t mydata[] = "Hello, world!"; +static osjob_t sendjob; + +// Schedule TX every this many seconds (might become longer due to duty +// cycle limitations). +const unsigned TX_INTERVAL = 5; + +//Sparkfun Pro RF +const lmic_pinmap lmic_pins = { + .nss = 12,//RFM Chip Select + .rxtx = LMIC_UNUSED_PIN, + .rst = 7,//RFM Reset + .dio = {6, 10, 11}, //RFM Interrupt, RFM LoRa pin, RFM LoRa pin +}; + +void onEvent (ev_t ev) { + SerialUSB.print(os_getTime()); + SerialUSB.print(": "); + switch(ev) { + case EV_SCAN_TIMEOUT: + SerialUSB.println(F("EV_SCAN_TIMEOUT")); + break; + case EV_BEACON_FOUND: + SerialUSB.println(F("EV_BEACON_FOUND")); + break; + case EV_BEACON_MISSED: + SerialUSB.println(F("EV_BEACON_MISSED")); + break; + case EV_BEACON_TRACKED: + SerialUSB.println(F("EV_BEACON_TRACKED")); + break; + case EV_JOINING: + SerialUSB.println(F("EV_JOINING")); + break; + case EV_JOINED: + SerialUSB.println(F("EV_JOINED")); + + // Disable link check validation (automatically enabled + // during join, but not supported by TTN at this time). + LMIC_setLinkCheckMode(0); + break; + case EV_RFU1: + SerialUSB.println(F("EV_RFU1")); + break; + case EV_JOIN_FAILED: + SerialUSB.println(F("EV_JOIN_FAILED")); + break; + case EV_REJOIN_FAILED: + SerialUSB.println(F("EV_REJOIN_FAILED")); + break; + break; + case EV_TXCOMPLETE: + SerialUSB.println(F("EV_TXCOMPLETE (includes waiting for RX windows)")); + if (LMIC.txrxFlags & TXRX_ACK) + SerialUSB.println(F("Received ack")); + if (LMIC.dataLen) { + SerialUSB.println(F("Received ")); + SerialUSB.println(LMIC.dataLen); + SerialUSB.println(F(" bytes of payload")); + } + // Schedule next transmission + os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send); + break; + case EV_LOST_TSYNC: + SerialUSB.println(F("EV_LOST_TSYNC")); + break; + case EV_RESET: + SerialUSB.println(F("EV_RESET")); + break; + case EV_RXCOMPLETE: + // data received in ping slot + SerialUSB.println(F("EV_RXCOMPLETE")); + break; + case EV_LINK_DEAD: + SerialUSB.println(F("EV_LINK_DEAD")); + break; + case EV_LINK_ALIVE: + SerialUSB.println(F("EV_LINK_ALIVE")); + break; + default: + SerialUSB.println(F("Unknown event")); + break; + } +} + +void do_send(osjob_t* j){ + // Check if there is not a current TX/RX job running + if (LMIC.opmode & OP_TXRXPEND) { + SerialUSB.println(F("OP_TXRXPEND, not sending")); + } else { + // Prepare upstream data transmission at the next possible time. + LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0); + SerialUSB.println(F("Packet queued")); + } + // Next TX is scheduled after TX_COMPLETE event. +} + +void setup() { + SerialUSB.begin(9600); + while(!SerialUSB); + SerialUSB.println(F("Starting")); + + // LMIC init + os_init(); + // Reset the MAC state. Session and pending data transfers will be discarded. + LMIC_reset(); + + LMIC_selectSubBand(6); + LMIC_setLinkCheckMode(0); + LMIC_setDrTxpow(DR_SF7, 14); + + // Start job (sending automatically starts OTAA too) + do_send(&sendjob); +} + +void loop() { + os_runloop_once(); +} \ No newline at end of file