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

Si443x_Settings.ino (3811B)

      1 /*
      2    RadioLib Si443x 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, nIRQ, shutdown)
      7     - carrier frequency
      8     - bit rate
      9     - receiver bandwidth
     10     - 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#si443xrfm2x
     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 // Si4432 has the following connections:
     25 // nSEL pin:  10
     26 // nIRQ pin:  2
     27 // SDN pin:   9
     28 Si4432 radio1 = new Module(10, 2, 9);
     29 
     30 // Si4432 has the following connections:
     31 // nSEL pin:  8
     32 // nIRQ pin:  3
     33 // SDN pin:   7
     34 Si4432 radio2 = new Module(8, 3, 7);
     35 
     36 // or using RadioShield
     37 // https://github.com/jgromes/RadioShield
     38 //Si4432 radio3 = RadioShield.ModuleB;
     39 
     40 void setup() {
     41   Serial.begin(9600);
     42 
     43   // initialize Si4432 with default settings
     44   Serial.print(F("[Si4432] 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 Si4432 with non-default settings
     55   Serial.print(F("[Si4432] Initializing ... "));
     56   // carrier frequency:           868.0 MHz
     57   // bit rate:                    200.0 kbps
     58   // frequency deviation:         60.0 kHz
     59   // Rx bandwidth:                335.5 kHz
     60   // output power:                17 dBm
     61   // preamble length:             32 bits
     62   state = radio2.begin(868.0, 200.0, 60.0, 335.5, 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("[Si4432] 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("[Si4432] 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("[Si4432] Selected bit rate to bandwidth ratio is invalid!"));
     87     Serial.println(F("[Si4432] Increase receiver bandwidth to set this bit rate."));
     88     while (true);
     89   }
     90 
     91   // set receiver bandwidth to 284.8 kHz
     92   state = radio1.setRxBandwidth(284.8);
     93   if (state == RADIOLIB_ERR_INVALID_RX_BANDWIDTH) {
     94     Serial.println(F("[Si4432] Selected receiver bandwidth is invalid for this module!"));
     95     while (true);
     96   }
     97 
     98   // set frequency deviation to 10.0 kHz
     99   if (radio1.setFrequencyDeviation(10.0) == RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION) {
    100     Serial.println(F("[Si4432] Selected frequency deviation is invalid for this module!"));
    101     while (true);
    102   }
    103 
    104   // set output power to 2 dBm
    105   if (radio1.setOutputPower(2) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) {
    106     Serial.println(F("[Si4432] Selected output power is invalid for this module!"));
    107     while (true);
    108   }
    109 
    110   // up to 4 bytes can be set as sync word
    111   // set sync word to 0x01234567
    112   uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67};
    113   if (radio1.setSyncWord(syncWord, 4) == RADIOLIB_ERR_INVALID_SYNC_WORD) {
    114     Serial.println(F("[Si4432] Selected sync word is invalid for this module!"));
    115     while (true);
    116   }
    117 
    118   Serial.println(F("[Si4432] All settings changed successfully!"));
    119 }
    120 
    121 void loop() {
    122   // nothing here
    123 }