acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
CC1101_Receive_Address.ino (3374B)
1 /* 2 RadioLib CC1101 Receive with Address Example 3 4 This example receives packets using CC1101 FSK radio 5 module. Packets can have 1-byte address of the 6 destination node. After setting node address, this node 7 will automatically filter out any packets that do not 8 contain either node address or broadcast addresses. 9 10 For default module settings, see the wiki page 11 https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101 12 13 For full API reference, see the GitHub Pages 14 https://jgromes.github.io/RadioLib/ 15 */ 16 17 // include the library 18 #include <RadioLib.h> 19 20 // CC1101 has the following connections: 21 // CS pin: 10 22 // GDO0 pin: 2 23 // RST pin: unused 24 // GDO2 pin: 3 (optional) 25 CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3); 26 27 // or using RadioShield 28 // https://github.com/jgromes/RadioShield 29 //CC1101 radio = RadioShield.ModuleA; 30 31 void setup() { 32 Serial.begin(9600); 33 34 // initialize CC1101 with default settings 35 Serial.print(F("[CC1101] Initializing ... ")); 36 int state = radio.begin(); 37 if (state == RADIOLIB_ERR_NONE) { 38 Serial.println(F("success!")); 39 } else { 40 Serial.print(F("failed, code ")); 41 Serial.println(state); 42 while (true); 43 } 44 45 // set node address 46 // NOTE: Calling this method will automatically enable 47 // address filtering. CC1101 also allows to set 48 // number of broadcast address (0/1/2). 49 // The following sets one broadcast address 0x00. 50 // When setting two broadcast addresses, 0x00 and 51 // 0xFF will be used. 52 Serial.print(F("[CC1101] Setting node address ... ")); 53 state = radio.setNodeAddress(0x01, 1); 54 if (state == RADIOLIB_ERR_NONE) { 55 Serial.println(F("success!")); 56 } else { 57 Serial.print(F("failed, code ")); 58 Serial.println(state); 59 while (true); 60 } 61 62 // address filtering can also be disabled 63 // NOTE: Calling this method will also erase previously 64 // set node address 65 /* 66 Serial.print(F("[CC1101] Disabling address filtering ... ")); 67 state == radio.disableAddressFiltering(); 68 if(state == RADIOLIB_ERR_NONE) { 69 Serial.println(F("success!")); 70 } else { 71 Serial.print(F("failed, code ")); 72 Serial.println(state); 73 while(true); 74 } 75 */ 76 } 77 78 void loop() { 79 Serial.print(F("[CC1101] Waiting for incoming transmission ... ")); 80 81 // you can receive data as an Arduino String 82 String str; 83 int state = radio.receive(str); 84 85 // you can also receive data as byte array 86 /* 87 byte byteArr[8]; 88 int state = radio.receive(byteArr, 8); 89 */ 90 91 if (state == RADIOLIB_ERR_NONE) { 92 // packet was successfully received 93 Serial.println(F("success!")); 94 95 // print the data of the packet 96 Serial.print(F("[CC1101] Data:\t\t")); 97 Serial.println(str); 98 99 // print RSSI (Received Signal Strength Indicator) 100 // of the last received packet 101 Serial.print(F("[CC1101] RSSI:\t\t")); 102 Serial.print(radio.getRSSI()); 103 Serial.println(F(" dBm")); 104 105 // print LQI (Link Quality Indicator) 106 // of the last received packet, lower is better 107 Serial.print(F("[CC1101] LQI:\t\t")); 108 Serial.println(radio.getLQI()); 109 110 } else if (state == RADIOLIB_ERR_CRC_MISMATCH) { 111 // packet was received, but is malformed 112 Serial.println(F("CRC error!")); 113 114 } else { 115 // some other error occurred 116 Serial.print(F("failed, code ")); 117 Serial.println(state); 118 119 } 120 }