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 |
RF69_Settings.ino (4610B)
1 /* 2 RadioLib RF69 Settings Example 3 4 This example shows how to change all the properties of RF69 radio. 5 RadioLib currently supports the following settings: 6 - pins (SPI slave select, digital IO 0, digital IO 1) 7 - carrier frequency 8 - bit rate 9 - receiver bandwidth 10 - allowed frequency deviation 11 - output power during transmission 12 - sync word 13 14 For default module settings, see the wiki page 15 https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 16 17 For full API reference, see the GitHub Pages 18 https://jgromes.github.io/RadioLib/ 19 */ 20 21 // include the library 22 #include <RadioLib.h> 23 24 // RF69 has the following connections: 25 // CS pin: 10 26 // DIO0 pin: 2 27 // RESET pin: 3 28 RF69 radio1 = new Module(10, 2, 3); 29 30 // second CC1101 has different connections: 31 // CS pin: 9 32 // DIO0 pin: 4 33 // RESET pin: 5 34 RF69 radio2 = new Module(9, 4, 5); 35 36 // or using RadioShield 37 // https://github.com/jgromes/RadioShield 38 //RF69 radio3 = RadioShield.ModuleB; 39 40 void setup() { 41 Serial.begin(9600); 42 43 // initialize RF69 with default settings 44 Serial.print(F("[RF69] Initializing ... ")); 45 int state = radio1.begin(); 46 if (state == RADIOLIB_ERR_NONE) { 47 Serial.println(F("success!")); 48 } else { 49 Serial.print(F("failed, code ")); 50 Serial.println(state); 51 while (true); 52 } 53 54 // initialize RF69 with non-default settings 55 Serial.print(F("[RF69] Initializing ... ")); 56 // carrier frequency: 868.0 MHz 57 // bit rate: 300.0 kbps 58 // frequency deviation: 60.0 kHz 59 // Rx bandwidth: 250.0 kHz 60 // output power: 17 dBm 61 // preamble length: 32 bits 62 state = radio2.begin(868.0, 300.0, 60.0, 250.0, 17, 32); 63 if (state == RADIOLIB_ERR_NONE) { 64 Serial.println(F("success!")); 65 } else { 66 Serial.print(F("failed, code ")); 67 Serial.println(state); 68 while (true); 69 } 70 71 // you can also change the settings at runtime 72 // and check if the configuration was changed successfully 73 74 // set carrier frequency to 433.5 MHz 75 if (radio1.setFrequency(433.5) == RADIOLIB_ERR_INVALID_FREQUENCY) { 76 Serial.println(F("[RF69] Selected frequency is invalid for this module!")); 77 while (true); 78 } 79 80 // set bit rate to 100.0 kbps 81 state = radio1.setBitRate(100.0); 82 if (state == RADIOLIB_ERR_INVALID_BIT_RATE) { 83 Serial.println(F("[RF69] Selected bit rate is invalid for this module!")); 84 while (true); 85 } else if (state == RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO) { 86 Serial.println(F("[RF69] Selected bit rate to bandwidth ratio is invalid!")); 87 Serial.println(F("[RF69] Increase receiver bandwidth to set this bit rate.")); 88 while (true); 89 } 90 91 // set receiver bandwidth to 250.0 kHz 92 state = radio1.setRxBandwidth(250.0); 93 if (state == RADIOLIB_ERR_INVALID_RX_BANDWIDTH) { 94 Serial.println(F("[RF69] Selected receiver bandwidth is invalid for this module!")); 95 while (true); 96 } else if (state == RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO) { 97 Serial.println(F("[RF69] Selected bit rate to bandwidth ratio is invalid!")); 98 Serial.println(F("[RF69] Decrease bit rate to set this receiver bandwidth.")); 99 while (true); 100 } 101 102 // set allowed frequency deviation to 10.0 kHz 103 if (radio1.setFrequencyDeviation(10.0) == RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION) { 104 Serial.println(F("[RF69] Selected frequency deviation is invalid for this module!")); 105 while (true); 106 } 107 108 // set output power to 2 dBm 109 if (radio1.setOutputPower(2) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) { 110 Serial.println(F("[RF69] Selected output power is invalid for this module!")); 111 while (true); 112 } 113 114 // up to 8 bytes can be set as sync word 115 // NOTE: sync word must not contain any zero bytes 116 // set sync word to 0x0123456789ABCDEF 117 uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; 118 if (radio1.setSyncWord(syncWord, 8) == RADIOLIB_ERR_INVALID_SYNC_WORD) { 119 Serial.println(F("[RF69] Selected sync word is invalid for this module!")); 120 while (true); 121 } 122 123 Serial.println(F("[RF69] All settings changed successfully!")); 124 125 // RF69 can also measure temperature (roughly) 126 // to get correct temperature measurements, the sensor must be calibrated 127 // at ambient temperature 128 radio1.setAmbientTemperature(25); // replace 25 with your ambient temperature 129 } 130 131 void loop() { 132 // measure temperature 133 Serial.print(F("[RF69] Measured temperature: ")); 134 Serial.print(radio1.getTemperature()); 135 Serial.println(F(" deg C")); 136 137 // wait 100 ms before the next measurement 138 delay(100); 139 }