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 |
SX1231_Receive.ino (2025B)
1 /* 2 RadioLib SX1231 Receive Example 3 4 This example receives packets using SX1231 FSK radio module. 5 6 NOTE: SX1231 offers the same features as RF69 and has the same 7 interface. Please see RF69 examples for examples on AES, 8 address filtering, interrupts and settings. 9 10 For default module settings, see the wiki page 11 https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 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 // SX1231 has the following connections: 21 // CS pin: 10 22 // DIO0 pin: 2 23 // RESET pin: 3 24 SX1231 radio = new Module(10, 2, 3); 25 26 // or using RadioShield 27 // https://github.com/jgromes/RadioShield 28 //SX1231 radio = RadioShield.ModuleA; 29 30 void setup() { 31 Serial.begin(9600); 32 33 // initialize SX1231 with default settings 34 Serial.print(F("[SX1231] Initializing ... ")); 35 int state = radio.begin(); 36 if (state == RADIOLIB_ERR_NONE) { 37 Serial.println(F("success!")); 38 } else { 39 Serial.print(F("failed, code ")); 40 Serial.println(state); 41 while (true); 42 } 43 } 44 45 void loop() { 46 Serial.print(F("[SX1231] Waiting for incoming transmission ... ")); 47 48 // you can receive data as an Arduino String 49 String str; 50 int state = radio.receive(str); 51 52 // you can also receive data as byte array 53 /* 54 byte byteArr[8]; 55 int state = radio.receive(byteArr, 8); 56 */ 57 58 if (state == RADIOLIB_ERR_NONE) { 59 // packet was successfully received 60 Serial.println(F("success!")); 61 62 // print the data of the packet 63 Serial.print(F("[SX1231] Data:\t\t")); 64 Serial.println(str); 65 66 } else if (state == RADIOLIB_ERR_RX_TIMEOUT) { 67 // timeout occurred while waiting for a packet 68 Serial.println(F("timeout!")); 69 70 } else if (state == RADIOLIB_ERR_CRC_MISMATCH) { 71 // packet was received, but is malformed 72 Serial.println(F("CRC error!")); 73 74 } else { 75 // some other error occurred 76 Serial.print(F("failed, code ")); 77 Serial.println(state); 78 79 } 80 }