[RF69] Updated examples

This commit is contained in:
jgromes 2019-06-02 15:02:56 +02:00
parent 8fbfb68749
commit a49f1da093
9 changed files with 167 additions and 36 deletions

View file

@ -2,13 +2,29 @@
RadioLib RF69 Receive Example
This example receives packets using RF69 FSK radio module.
To successfully receive data, the following settings have to be the same
on both transmitter and receiver:
- carrier frequency
- bit rate
- frequency deviation
- sync word
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 module is in slot A on the shield
RF69 rf = RadioShield.ModuleA;
// RF69 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// DIO1 pin: 3
RF69 rf = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 rf = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
@ -60,5 +76,10 @@ void loop() {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}

View file

@ -4,13 +4,23 @@
This example receives packets using RF69 FSK radio module.
Packets are decrypted using hardware AES.
NOTE: When using address filtering, the address byte is NOT encrypted!
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 module is in slot A on the shield
RF69 rf = RadioShield.ModuleA;
// RF69 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// DIO1 pin: 3
RF69 rf = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 rf = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
@ -35,8 +45,7 @@ void setup() {
// set AES key that will be used to decrypt the packet
// NOTE: the key must be exactly 16 bytes long!
uint8_t key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
};
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
rf.setAESKey(key);
// enable AES encryption
@ -77,5 +86,10 @@ void loop() {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}

View file

@ -6,13 +6,23 @@
After setting node (or broadcast) address, this node will
automatically filter out any packets that do not contain
either node address or broadcast address.
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 module is in slot A on the shield
RF69 rf = RadioShield.ModuleA;
// RF69 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// DIO1 pin: 3
RF69 rf = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 rf = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
@ -105,5 +115,10 @@ void loop() {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}

View file

@ -4,13 +4,23 @@
This example listens for FSK transmissions and tries to
receive them. Once a packet is received, an interrupt is
triggered.
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 module is in slot A on the shield
RF69 rf = RadioShield.ModuleA;
// RF69 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// DIO1 pin: 3
RF69 rf = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 rf = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
@ -103,6 +113,16 @@ void loop() {
// print data of the packet
Serial.print(F("[RF69] Data:\t\t\t"));
Serial.println(str);
} else if (state == ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// we're ready to receive more packets,

View file

@ -10,20 +10,23 @@
- allowed frequency deviation
- output power during transmission
- sync word
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 module is in slot A on the shield
RF69 rf1 = RadioShield.ModuleA;
// RF69 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// DIO1 pin: 3
RF69 rf1 = new Module(10, 2, 3);
// if you're not using RadioShield, you can specify
// the connection yourself
// NSS pin: 6
// DIO0 pin: 4
// DIO1 pin: 5
RF69 rf2 = new Module(6, 4, 5);
// or using RadioShield
// https://github.com/jgromes/RadioShield
RF69 rf2 = RadioShield.ModuleB;
void setup() {
Serial.begin(9600);

View file

@ -2,13 +2,27 @@
RadioLib RF69 Transmit Example
This example transmits packets using RF69 FSK radio module.
Each packet contains up to 64 bytes of data, in the form of:
- Arduino String
- null-terminated char array (C-string)
- arbitrary binary data (byte array)
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 module is in slot A on the shield
RF69 rf = RadioShield.ModuleA;
// RF69 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// DIO1 pin: 3
RF69 rf = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 rf = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
@ -51,6 +65,11 @@ void loop() {
// the supplied packet was longer than 64 bytes
Serial.println(F(" too long!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before transmitting again

View file

@ -4,13 +4,23 @@
This example transmits packets using RF69 FSK radio module.
Packets are encrypted using hardware AES.
NOTE: When using address filtering, the address byte is NOT encrypted!
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 module is in slot A on the shield
RF69 rf = RadioShield.ModuleA;
// RF69 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// DIO1 pin: 3
RF69 rf = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 rf = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
@ -35,8 +45,7 @@ void setup() {
// set AES key to encrypt the packet
// NOTE: the key must be exactly 16 bytes long!
uint8_t key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
};
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
rf.setAESKey(key);
// enable AES encryption
@ -65,9 +74,14 @@ void loop() {
Serial.println(F(" success!"));
} else if (state == ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
// the supplied packet was longer than 64 bytes
Serial.println(F(" too long!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before transmitting again

View file

@ -6,13 +6,23 @@
After setting node (or broadcast) address, this node will
automatically filter out any packets that do not contain
either node address or broadcast address.
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 module is in slot A on the shield
RF69 rf = RadioShield.ModuleA;
// RF69 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// DIO1 pin: 3
RF69 rf = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 rf = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
@ -35,7 +45,7 @@ void setup() {
}
// set node address
// NOTE: calling this method will autmatically enable
// NOTE: calling this method will automatically enable
// address filtering (node address only)
Serial.print(F("[RF69] Setting node address ... "));
state = rf.setNodeAddress(0x01);
@ -104,9 +114,14 @@ void loop() {
Serial.println(F(" success!"));
} else if (state == ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
// the supplied packet was longer than 64 bytes
Serial.println(F(" too long!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before transmitting again

View file

@ -7,13 +7,23 @@
- Arduino String
- null-terminated char array (C-string)
- arbitrary binary data (byte array)
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 module is in slot A on the shield
RF69 rf = RadioShield.ModuleA;
// RF69 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// DIO1 pin: 3
RF69 rf = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 rf = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
@ -35,7 +45,7 @@ void setup() {
while (true);
}
// set the function that will be called
// set the function that will be called
// when packet transmission is finished
rf.setDio0Action(setFlag);
@ -52,7 +62,7 @@ void setup() {
0x78, 0xAB, 0xCD, 0xEF};
state = rf.transmit(byteArr, 8);
*/
if (state != ERR_NONE) {
Serial.print(F("failed, code "));
Serial.println(state);
@ -70,7 +80,7 @@ void setFlag(void) {
void loop() {
// check if the previous transmission finished
if(transmittedFlag) {
Serial.println(F("[RF69] Packet transmission finished!"));
Serial.println(F("packet transmission finished!"));
// wait one second before next transmission
delay(1000);
@ -81,14 +91,14 @@ void loop() {
// you can transmit C-string or Arduino string up to
// 64 characters long
int state = rf.startTransmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x56,
0x78, 0xAB, 0xCD, 0xEF};
int state = rf.transmit(byteArr, 8);
*/
if (state != ERR_NONE) {
Serial.print(F("failed, code "));
Serial.println(state);