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 |
SX128x_Settings.ino (3756B)
1 /* 2 RadioLib SX128x Settings Example 3 4 This example shows how to change all the properties of LoRa transmission. 5 RadioLib currently supports the following settings: 6 - pins (SPI slave select, DIO1, DIO2, BUSY pin) 7 - carrier frequency 8 - bandwidth 9 - spreading factor 10 - coding rate 11 - output power during transmission 12 - CRC 13 - preamble length 14 15 Other modules from SX128x family can also be used. 16 17 For default module settings, see the wiki page 18 https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem 19 20 For full API reference, see the GitHub Pages 21 https://jgromes.github.io/RadioLib/ 22 */ 23 24 // include the library 25 #include <RadioLib.h> 26 27 // SX1280 has the following connections: 28 // NSS pin: 10 29 // DIO1 pin: 2 30 // NRST pin: 3 31 // BUSY pin: 9 32 SX1280 radio1 = new Module(10, 2, 3, 9); 33 34 // SX1280 has the following connections: 35 // NSS pin: 8 36 // DIO1 pin: 4 37 // NRST pin: 5 38 // BUSY pin: 6 39 SX1281 radio2 = new Module(8, 4, 5, 6); 40 41 // or using RadioShield 42 // https://github.com/jgromes/RadioShield 43 //SX1282 radio3 = RadioShield.ModuleB; 44 45 void setup() { 46 Serial.begin(9600); 47 48 // initialize SX1280 with default settings 49 Serial.print(F("[SX1280] Initializing ... ")); 50 int state = radio1.begin(); 51 if (state == RADIOLIB_ERR_NONE) { 52 Serial.println(F("success!")); 53 } else { 54 Serial.print(F("failed, code ")); 55 Serial.println(state); 56 while (true); 57 } 58 59 // initialize the second LoRa instance with 60 // non-default settings 61 // this LoRa link will have high data rate, 62 // but lower range 63 Serial.print(F("[SX1281] Initializing ... ")); 64 // carrier frequency: 2450.0 MHz 65 // bandwidth: 1625.0 kHz 66 // spreading factor: 7 67 // coding rate: 5 68 // output power: 2 dBm 69 // preamble length: 20 symbols 70 state = radio2.begin(2450.0, 1625.0, 7, 5, 2, 20); 71 if (state == RADIOLIB_ERR_NONE) { 72 Serial.println(F("success!")); 73 } else { 74 Serial.print(F("failed, code ")); 75 Serial.println(state); 76 while (true); 77 } 78 79 // you can also change the settings at runtime 80 // and check if the configuration was changed successfully 81 82 // set carrier frequency to 2410.5 MHz 83 if (radio1.setFrequency(2410.5) == RADIOLIB_ERR_INVALID_FREQUENCY) { 84 Serial.println(F("Selected frequency is invalid for this module!")); 85 while (true); 86 } 87 88 // set bandwidth to 203.125 kHz 89 if (radio1.setBandwidth(203.125) == RADIOLIB_ERR_INVALID_BANDWIDTH) { 90 Serial.println(F("Selected bandwidth is invalid for this module!")); 91 while (true); 92 } 93 94 // set spreading factor to 10 95 if (radio1.setSpreadingFactor(10) == RADIOLIB_ERR_INVALID_SPREADING_FACTOR) { 96 Serial.println(F("Selected spreading factor is invalid for this module!")); 97 while (true); 98 } 99 100 // set coding rate to 6 101 if (radio1.setCodingRate(6) == RADIOLIB_ERR_INVALID_CODING_RATE) { 102 Serial.println(F("Selected coding rate is invalid for this module!")); 103 while (true); 104 } 105 106 // set output power to -2 dBm 107 if (radio1.setOutputPower(-2) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) { 108 Serial.println(F("Selected output power is invalid for this module!")); 109 while (true); 110 } 111 112 // set LoRa preamble length to 16 symbols (accepted range is 2 - 65535) 113 if (radio1.setPreambleLength(16) == RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH) { 114 Serial.println(F("Selected preamble length is invalid for this module!")); 115 while (true); 116 } 117 118 // disable CRC 119 if (radio1.setCRC(false) == RADIOLIB_ERR_INVALID_CRC_CONFIGURATION) { 120 Serial.println(F("Selected CRC is invalid for this module!")); 121 while (true); 122 } 123 124 Serial.println(F("All settings succesfully changed!")); 125 } 126 127 void loop() { 128 // nothing here 129 }