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 |
SX126x_Channel_Activity_Detection.ino (1827B)
1 /* 2 RadioLib SX126x Channel Activity Detection Example 3 4 This example uses SX1262 to scan the current LoRa 5 channel and detect ongoing LoRa transmissions. 6 Unlike SX127x CAD, SX126x can detect any part 7 of LoRa transmission, not just the preamble. 8 9 Other modules from SX126x family can also be used. 10 11 For default module settings, see the wiki page 12 https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem 13 14 For full API reference, see the GitHub Pages 15 https://jgromes.github.io/RadioLib/ 16 */ 17 18 // include the library 19 #include <RadioLib.h> 20 21 // SX1262 has the following connections: 22 // NSS pin: 10 23 // DIO1 pin: 2 24 // NRST pin: 3 25 // BUSY pin: 9 26 SX1262 radio = new Module(10, 2, 3, 9); 27 28 // or using RadioShield 29 // https://github.com/jgromes/RadioShield 30 //SX1262 radio = RadioShield.ModuleA; 31 32 // or using CubeCell 33 //SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE); 34 35 void setup() { 36 Serial.begin(9600); 37 38 // initialize SX1262 with default settings 39 Serial.print(F("[SX1262] Initializing ... ")); 40 int state = radio.begin(); 41 if (state == RADIOLIB_ERR_NONE) { 42 Serial.println(F("success!")); 43 } else { 44 Serial.print(F("failed, code ")); 45 Serial.println(state); 46 while (true); 47 } 48 } 49 50 void loop() { 51 Serial.print(F("[SX1262] Scanning channel for LoRa transmission ... ")); 52 53 // start scanning current channel 54 int state = radio.scanChannel(); 55 56 if (state == RADIOLIB_LORA_DETECTED) { 57 // LoRa preamble was detected 58 Serial.println(F("detected!")); 59 60 } else if (state == RADIOLIB_CHANNEL_FREE) { 61 // no preamble was detected, channel is free 62 Serial.println(F("channel is free!")); 63 64 } else { 65 // some other error occurred 66 Serial.print(F("failed, code ")); 67 Serial.println(state); 68 69 } 70 71 // wait 100 ms before new scan 72 delay(100); 73 }