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 |
SX127x_Settings.ino (4902B)
1 /* 2 RadioLib SX127x 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, digital IO 0, digital IO 1) 7 - carrier frequency 8 - bandwidth 9 - spreading factor 10 - coding rate 11 - sync word 12 - output power during transmission 13 14 Other modules from SX127x/RFM9x family can also be used. 15 16 For default module settings, see the wiki page 17 https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem 18 19 For full API reference, see the GitHub Pages 20 https://jgromes.github.io/RadioLib/ 21 */ 22 23 // include the library 24 #include <RadioLib.h> 25 26 // SX1278 has the following connections: 27 // NSS pin: 10 28 // DIO0 pin: 2 29 // RESET pin: 9 30 // DIO1 pin: 3 31 SX1278 radio1 = new Module(10, 2, 9, 3); 32 33 // SX1272 has different connections: 34 // NSS pin: 9 35 // DIO0 pin: 4 36 // RESET pin: 5 37 // DIO1 pin: 6 38 SX1272 radio2 = new Module(9, 4, 5, 6); 39 40 // or using RadioShield 41 // https://github.com/jgromes/RadioShield 42 //SX1276 radio3 = RadioShield.ModuleB; 43 44 void setup() { 45 Serial.begin(9600); 46 47 // initialize SX1278 with default settings 48 Serial.print(F("[SX1278] Initializing ... ")); 49 int state = radio1.begin(); 50 if (state == RADIOLIB_ERR_NONE) { 51 Serial.println(F("success!")); 52 } else { 53 Serial.print(F("failed, code ")); 54 Serial.println(state); 55 while (true); 56 } 57 58 // initialize the second LoRa instance with 59 // non-default settings 60 // this LoRa link will have high data rate, 61 // but lower range 62 // NOTE: when using spreading factor 6, the total packet 63 // length has to be known in advance! 64 // you have to pass the number of expected bytes 65 // to the receive() method 66 Serial.print(F("[SX1272] Initializing ... ")); 67 // carrier frequency: 915.0 MHz 68 // bandwidth: 500.0 kHz 69 // spreading factor: 6 70 // coding rate: 5 71 // sync word: 0x14 72 // output power: 2 dBm 73 // preamble length: 20 symbols 74 // amplifier gain: 1 (maximum gain) 75 state = radio2.begin(915.0, 500.0, 6, 5, 0x14, 2, 20, 1); 76 if (state == RADIOLIB_ERR_NONE) { 77 Serial.println(F("success!")); 78 } else { 79 Serial.print(F("failed, code ")); 80 Serial.println(state); 81 while (true); 82 } 83 84 // you can also change the settings at runtime 85 // and check if the configuration was changed successfully 86 87 // set carrier frequency to 433.5 MHz 88 if (radio1.setFrequency(433.5) == RADIOLIB_ERR_INVALID_FREQUENCY) { 89 Serial.println(F("Selected frequency is invalid for this module!")); 90 while (true); 91 } 92 93 // set bandwidth to 250 kHz 94 if (radio1.setBandwidth(250.0) == RADIOLIB_ERR_INVALID_BANDWIDTH) { 95 Serial.println(F("Selected bandwidth is invalid for this module!")); 96 while (true); 97 } 98 99 // set spreading factor to 10 100 if (radio1.setSpreadingFactor(10) == RADIOLIB_ERR_INVALID_SPREADING_FACTOR) { 101 Serial.println(F("Selected spreading factor is invalid for this module!")); 102 while (true); 103 } 104 105 // set coding rate to 6 106 if (radio1.setCodingRate(6) == RADIOLIB_ERR_INVALID_CODING_RATE) { 107 Serial.println(F("Selected coding rate is invalid for this module!")); 108 while (true); 109 } 110 111 // set LoRa sync word to 0x14 112 // NOTE: value 0x34 is reserved for LoRaWAN networks and should not be used 113 if (radio1.setSyncWord(0x14) != RADIOLIB_ERR_NONE) { 114 Serial.println(F("Unable to set sync word!")); 115 while (true); 116 } 117 118 // set output power to 10 dBm (accepted range is -3 - 17 dBm) 119 // NOTE: 20 dBm value allows high power operation, but transmission 120 // duty cycle MUST NOT exceed 1% 121 if (radio1.setOutputPower(10) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) { 122 Serial.println(F("Selected output power is invalid for this module!")); 123 while (true); 124 } 125 126 // set over current protection limit to 80 mA (accepted range is 45 - 240 mA) 127 // NOTE: set value to 0 to disable overcurrent protection 128 if (radio1.setCurrentLimit(80) == RADIOLIB_ERR_INVALID_CURRENT_LIMIT) { 129 Serial.println(F("Selected current limit is invalid for this module!")); 130 while (true); 131 } 132 133 // set LoRa preamble length to 15 symbols (accepted range is 6 - 65535) 134 if (radio1.setPreambleLength(15) == RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH) { 135 Serial.println(F("Selected preamble length is invalid for this module!")); 136 while (true); 137 } 138 139 // set amplifier gain to 1 (accepted range is 1 - 6, where 1 is maximum gain) 140 // NOTE: set value to 0 to enable automatic gain control 141 // leave at 0 unless you know what you're doing 142 if (radio1.setGain(1) == RADIOLIB_ERR_INVALID_GAIN) { 143 Serial.println(F("Selected gain is invalid for this module!")); 144 while (true); 145 } 146 147 Serial.println(F("All settings successfully changed!")); 148 } 149 150 void loop() { 151 // nothing here 152 }