[CC1101] Updated examples

This commit is contained in:
jgromes 2019-06-02 14:09:10 +02:00
parent b3f228e207
commit 554f894adf
7 changed files with 140 additions and 30 deletions
examples/CC1101
CC1101_Receive
CC1101_Receive_Address
CC1101_Receive_Interrupt
CC1101_Settings
CC1101_Transmit
CC1101_Transmit_Address
CC1101_Transmit_Interrupt

View file

@ -1,15 +1,30 @@
/* /*
RadioLib CC1101 Receive Example RadioLib CC1101 Receive Example
This example receives packets using CC1101 FSK radio This example receives packets using CC1101 FSK radio module.
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 the library
#include <RadioLib.h> #include <RadioLib.h>
// CC1101 is in slot A on the shield // CC1101 has the following connections:
CC1101 cc = RadioShield.ModuleA; // NSS pin: 10
// GDO0 pin: 2
// GDO2 pin: 3
CC1101 cc = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//CC1101 cc = RadioShield.ModuleA;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
@ -67,5 +82,10 @@ void loop() {
// packet was received, but is malformed // packet was received, but is malformed
Serial.println(F("CRC error!")); Serial.println(F("CRC error!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
} }
} }

View file

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

View file

@ -4,13 +4,30 @@
This example listens for FSK transmissions and tries to This example listens for FSK transmissions and tries to
receive them. Once a packet is received, an interrupt is receive them. Once a packet is received, an interrupt is
triggered. triggered.
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 the library
#include <RadioLib.h> #include <RadioLib.h>
// CC1101 module is in slot A on the shield // CC1101 has the following connections:
CC1101 cc = RadioShield.ModuleA; // NSS pin: 10
// GDO0 pin: 2
// GDO2 pin: 3
CC1101 cc = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//CC1101 cc = RadioShield.ModuleA;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
@ -113,6 +130,16 @@ void loop() {
// of the last received packet, lower is better // of the last received packet, lower is better
Serial.print(F("[CC1101] LQI:\t\t")); Serial.print(F("[CC1101] LQI:\t\t"));
Serial.println(cc.getLQI()); Serial.println(cc.getLQI());
} 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, // we're ready to receive more packets,

View file

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

View file

@ -2,13 +2,27 @@
RadioLib CC1101 Transmit Example RadioLib CC1101 Transmit Example
This example transmits packets using CC1101 FSK radio module. This example transmits packets using CC1101 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 the library
#include <RadioLib.h> #include <RadioLib.h>
// CC1101 is in slot A on the shield // CC1101 has the following connections:
CC1101 cc = RadioShield.ModuleA; // NSS pin: 10
// GDO0 pin: 2
// GDO2 pin: 3
CC1101 cc = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//CC1101 cc = RadioShield.ModuleA;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
@ -50,6 +64,11 @@ void loop() {
// the supplied packet was longer than 255 bytes // the supplied packet was longer than 255 bytes
Serial.println(F(" too long!")); 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 // wait for a second before transmitting again

View file

@ -6,13 +6,23 @@
destination node. After setting node address, this node destination node. After setting node address, this node
will automatically filter out any packets that do not will automatically filter out any packets that do not
contain either node address or broadcast addresses. contain either node address or broadcast addresses.
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/ */
// include the library // include the library
#include <RadioLib.h> #include <RadioLib.h>
// CC1101 is in slot A on the shield // CC1101 has the following connections:
CC1101 cc = RadioShield.ModuleA; // NSS pin: 10
// GDO0 pin: 2
// GDO2 pin: 3
CC1101 cc = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//CC1101 cc = RadioShield.ModuleA;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
@ -86,6 +96,11 @@ void loop() {
// the supplied packet was longer than 255 bytes // the supplied packet was longer than 255 bytes
Serial.println(F(" too long!")); 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 // wait for a second before transmitting again

View file

@ -1,19 +1,29 @@
/* /*
RadioLib CC1101 Transmit with Interrupts Example RadioLib CC1101 Transmit with Interrupts Example
This example transmits FSK packets with one second delays This example transmits packets using CC1101 FSK radio module.
between them. Each packet contains up to 64 bytes Once a packet is transmitted, an interrupt is triggered.
of data, in the form of: Each packet contains up to 64 bytes of data, in the form of:
- Arduino String - Arduino String
- null-terminated char array (C-string) - null-terminated char array (C-string)
- arbitrary binary data (byte array) - arbitrary binary data (byte array)
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/ */
// include the library // include the library
#include <RadioLib.h> #include <RadioLib.h>
// CC1101 module is in slot A on the shield // CC1101 has the following connections:
CC1101 cc = RadioShield.ModuleA; // NSS pin: 10
// GDO0 pin: 2
// GDO2 pin: 3
CC1101 cc = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//CC1101 cc = RadioShield.ModuleA;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
@ -34,7 +44,7 @@ void setup() {
while (true); while (true);
} }
// set the function that will be called // set the function that will be called
// when packet transmission is finished // when packet transmission is finished
cc.setGdo0Action(setFlag); cc.setGdo0Action(setFlag);
@ -51,10 +61,11 @@ void setup() {
0x78, 0xAB, 0xCD, 0xEF}; 0x78, 0xAB, 0xCD, 0xEF};
state = cc.transmit(byteArr, 8); state = cc.transmit(byteArr, 8);
*/ */
if (state != ERR_NONE) { if (state != ERR_NONE) {
Serial.print(F("failed, code ")); Serial.print(F("failed, code "));
Serial.println(state); Serial.println(state);
while (true);
} }
} }
@ -69,7 +80,7 @@ void setFlag(void) {
void loop() { void loop() {
// check if the previous transmission finished // check if the previous transmission finished
if(transmittedFlag) { if(transmittedFlag) {
Serial.println(F("[CC1101] Packet transmission finished!")); Serial.println(F("packet transmission finished!"));
// wait one second before next transmission // wait one second before next transmission
delay(1000); delay(1000);
@ -80,14 +91,14 @@ void loop() {
// you can transmit C-string or Arduino string up to // you can transmit C-string or Arduino string up to
// 64 characters long // 64 characters long
int state = cc.startTransmit("Hello World!"); int state = cc.startTransmit("Hello World!");
// you can also transmit byte array up to 256 bytes long // you can also transmit byte array up to 256 bytes long
/* /*
byte byteArr[] = {0x01, 0x23, 0x45, 0x56, byte byteArr[] = {0x01, 0x23, 0x45, 0x56,
0x78, 0xAB, 0xCD, 0xEF}; 0x78, 0xAB, 0xCD, 0xEF};
int state = cc.transmit(byteArr, 8); int state = cc.transmit(byteArr, 8);
*/ */
if (state != ERR_NONE) { if (state != ERR_NONE) {
Serial.print(F("failed, code ")); Serial.print(F("failed, code "));
Serial.println(state); Serial.println(state);