kopia lustrzana https://github.com/helium/longfi-arduino
Merge pull request #14 from helium/kent-williams/add-sparkfun-pro-rf-example
Add Sparkfun Pro RF Examplepull/15/head
commit
3ddf664241
|
@ -0,0 +1,23 @@
|
|||
# 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: -> SparkFun SAMD21 Pro RF
|
||||
|
||||
## 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)
|
|
@ -0,0 +1,148 @@
|
|||
#include <lmic.h>
|
||||
#include <hal/hal.h>
|
||||
#include <SPI.h>
|
||||
|
||||
// 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();
|
||||
|
||||
// allow much more clock error than the X/1000 default. See:
|
||||
// https://github.com/mcci-catena/arduino-lorawan/issues/74#issuecomment-462171974
|
||||
// https://github.com/mcci-catena/arduino-lmic/commit/42da75b56#diff-16d75524a9920f5d043fe731a27cf85aL633
|
||||
// the X/1000 means an error rate of 0.1%; the above issue discusses using
|
||||
// values up to 10%. so, values from 10 (10% error, the most lax) to 1000
|
||||
// (0.1% error, the most strict) can be used.
|
||||
LMIC_setClockError(1 * MAX_CLOCK_ERROR / 40);
|
||||
|
||||
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();
|
||||
}
|
Ładowanie…
Reference in New Issue