From a49f1da0937e4728d75a69314676053fa3edcf73 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 2 Jun 2019 15:02:56 +0200 Subject: [PATCH] [RF69] Updated examples --- examples/RF69/RF69_Receive/RF69_Receive.ino | 25 +++++++++++++++++-- .../RF69_Receive_AES/RF69_Receive_AES.ino | 22 +++++++++++++--- .../RF69_Receive_Address.ino | 19 ++++++++++++-- .../RF69_Receive_Interrupt.ino | 24 ++++++++++++++++-- examples/RF69/RF69_Settings/RF69_Settings.ino | 19 ++++++++------ examples/RF69/RF69_Transmit/RF69_Transmit.ino | 23 +++++++++++++++-- .../RF69_Transmit_AES/RF69_Transmit_AES.ino | 24 ++++++++++++++---- .../RF69_Transmit_Address.ino | 23 ++++++++++++++--- .../RF69_Transmit_Interrupt.ino | 24 ++++++++++++------ 9 files changed, 167 insertions(+), 36 deletions(-) diff --git a/examples/RF69/RF69_Receive/RF69_Receive.ino b/examples/RF69/RF69_Receive/RF69_Receive.ino index 15bbef16..fb8b69bd 100644 --- a/examples/RF69/RF69_Receive/RF69_Receive.ino +++ b/examples/RF69/RF69_Receive/RF69_Receive.ino @@ -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 -// 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); + } } diff --git a/examples/RF69/RF69_Receive_AES/RF69_Receive_AES.ino b/examples/RF69/RF69_Receive_AES/RF69_Receive_AES.ino index 1664304d..cc5e074a 100644 --- a/examples/RF69/RF69_Receive_AES/RF69_Receive_AES.ino +++ b/examples/RF69/RF69_Receive_AES/RF69_Receive_AES.ino @@ -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 -// 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); + } } diff --git a/examples/RF69/RF69_Receive_Address/RF69_Receive_Address.ino b/examples/RF69/RF69_Receive_Address/RF69_Receive_Address.ino index 61530cc0..c0444357 100644 --- a/examples/RF69/RF69_Receive_Address/RF69_Receive_Address.ino +++ b/examples/RF69/RF69_Receive_Address/RF69_Receive_Address.ino @@ -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 -// 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); + } } diff --git a/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino b/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino index 8d38952d..336f41a1 100644 --- a/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino +++ b/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino @@ -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 -// 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, diff --git a/examples/RF69/RF69_Settings/RF69_Settings.ino b/examples/RF69/RF69_Settings/RF69_Settings.ino index ed86e505..1f223745 100644 --- a/examples/RF69/RF69_Settings/RF69_Settings.ino +++ b/examples/RF69/RF69_Settings/RF69_Settings.ino @@ -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 -// 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); diff --git a/examples/RF69/RF69_Transmit/RF69_Transmit.ino b/examples/RF69/RF69_Transmit/RF69_Transmit.ino index e8b92c40..dca4f975 100644 --- a/examples/RF69/RF69_Transmit/RF69_Transmit.ino +++ b/examples/RF69/RF69_Transmit/RF69_Transmit.ino @@ -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 -// 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 diff --git a/examples/RF69/RF69_Transmit_AES/RF69_Transmit_AES.ino b/examples/RF69/RF69_Transmit_AES/RF69_Transmit_AES.ino index a8b93576..b0b127ff 100644 --- a/examples/RF69/RF69_Transmit_AES/RF69_Transmit_AES.ino +++ b/examples/RF69/RF69_Transmit_AES/RF69_Transmit_AES.ino @@ -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 -// 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 diff --git a/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino b/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino index 77e2a38c..03b61a70 100644 --- a/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino +++ b/examples/RF69/RF69_Transmit_Address/RF69_Transmit_Address.ino @@ -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 -// 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 diff --git a/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino b/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino index 294164bf..1f4481ec 100644 --- a/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino +++ b/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino @@ -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 -// 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);