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.ino (2447B)
1 /* 2 RadioLib CC1101 Receive Example 3 4 This example receives packets using CC1101 FSK radio module. 5 To successfully receive data, the following settings have to be the same 6 on both transmitter and receiver: 7 - carrier frequency 8 - bit rate 9 - frequency deviation 10 - sync word 11 12 For default module settings, see the wiki page 13 https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101 14 15 For full API reference, see the GitHub Pages 16 https://jgromes.github.io/RadioLib/ 17 */ 18 19 // include the library 20 #include <RadioLib.h> 21 22 // CC1101 has the following connections: 23 // CS pin: 10 24 // GDO0 pin: 2 25 // RST pin: unused 26 // GDO2 pin: 3 (optional) 27 CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3); 28 29 // or using RadioShield 30 // https://github.com/jgromes/RadioShield 31 //CC1101 radio = RadioShield.ModuleA; 32 33 void setup() { 34 Serial.begin(9600); 35 36 // initialize CC1101 with default settings 37 Serial.print(F("[CC1101] Initializing ... ")); 38 int state = radio.begin(); 39 if (state == RADIOLIB_ERR_NONE) { 40 Serial.println(F("success!")); 41 } else { 42 Serial.print(F("failed, code ")); 43 Serial.println(state); 44 while (true); 45 } 46 } 47 48 void loop() { 49 Serial.print(F("[CC1101] Waiting for incoming transmission ... ")); 50 51 // you can receive data as an Arduino String 52 String str; 53 int state = radio.receive(str); 54 55 // you can also receive data as byte array 56 /* 57 byte byteArr[8]; 58 int state = radio.receive(byteArr, 8); 59 */ 60 61 if (state == RADIOLIB_ERR_NONE) { 62 // packet was successfully received 63 Serial.println(F("success!")); 64 65 // print the data of the packet 66 Serial.print(F("[CC1101] Data:\t\t")); 67 Serial.println(str); 68 69 // print RSSI (Received Signal Strength Indicator) 70 // of the last received packet 71 Serial.print(F("[CC1101] RSSI:\t\t")); 72 Serial.print(radio.getRSSI()); 73 Serial.println(F(" dBm")); 74 75 // print LQI (Link Quality Indicator) 76 // of the last received packet, lower is better 77 Serial.print(F("[CC1101] LQI:\t\t")); 78 Serial.println(radio.getLQI()); 79 80 } else if (state == RADIOLIB_ERR_RX_TIMEOUT) { 81 // timeout occurred while waiting for a packet 82 Serial.println(F("timeout!")); 83 84 } else if (state == RADIOLIB_ERR_CRC_MISMATCH) { 85 // packet was received, but is malformed 86 Serial.println(F("CRC error!")); 87 88 } else { 89 // some other error occurred 90 Serial.print(F("failed, code ")); 91 Serial.println(state); 92 93 } 94 }