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

CC1101_Settings.ino (3802B)

      1 /*
      2    RadioLib CC1101 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#cc1101
     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 // CC1101 has the following connections:
     25 // CS pin:    10
     26 // GDO0 pin:  2
     27 // RST pin:   unused
     28 // GDO2 pin:  3 (optional)
     29 CC1101 radio1 = new Module(10, 2, RADIOLIB_NC, 3);
     30 
     31 // second CC1101 has different connections:
     32 // CS pin:    9
     33 // GDO0 pin:  4
     34 // RST pin:   unused
     35 // GDO2 pin:  5 (optional)
     36 CC1101 radio2 = new Module(9, 4, RADIOLIB_NC, 53);
     37 
     38 // or using RadioShield
     39 // https://github.com/jgromes/RadioShield
     40 //CC1101 radio3 = RadioShield.ModuleB;
     41 
     42 void setup() {
     43   Serial.begin(9600);
     44 
     45   // initialize CC1101 with default settings
     46   Serial.print(F("[CC1101] Initializing ... "));
     47   int state = radio1.begin();
     48   if (state == RADIOLIB_ERR_NONE) {
     49     Serial.println(F("success!"));
     50   } else {
     51     Serial.print(F("failed, code "));
     52     Serial.println(state);
     53     while (true);
     54   }
     55 
     56   // initialize CC1101 with non-default settings
     57   Serial.print(F("[CC1101] Initializing ... "));
     58   // carrier frequency:                   434.0 MHz
     59   // bit rate:                            32.0 kbps
     60   // frequency deviation:                 60.0 kHz
     61   // Rx bandwidth:                        250.0 kHz
     62   // output power:                        7 dBm
     63   // preamble length:                     32 bits
     64   state = radio2.begin(434.0, 32.0, 60.0, 250.0, 7, 32);
     65   if (state == RADIOLIB_ERR_NONE) {
     66     Serial.println(F("success!"));
     67   } else {
     68     Serial.print(F("failed, code "));
     69     Serial.println(state);
     70     while (true);
     71   }
     72 
     73   // you can also change the settings at runtime
     74   // and check if the configuration was changed successfully
     75 
     76   // set carrier frequency to 433.5 MHz
     77   if (radio1.setFrequency(433.5) == RADIOLIB_ERR_INVALID_FREQUENCY) {
     78     Serial.println(F("[CC1101] Selected frequency is invalid for this module!"));
     79     while (true);
     80   }
     81 
     82   // set bit rate to 100.0 kbps
     83   state = radio1.setBitRate(100.0);
     84   if (state == RADIOLIB_ERR_INVALID_BIT_RATE) {
     85     Serial.println(F("[CC1101] Selected bit rate is invalid for this module!"));
     86     while (true);
     87   } else if (state == RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO) {
     88     Serial.println(F("[CC1101] Selected bit rate to bandwidth ratio is invalid!"));
     89     Serial.println(F("[CC1101] Increase receiver bandwidth to set this bit rate."));
     90     while (true);
     91   }
     92 
     93   // set receiver bandwidth to 250.0 kHz
     94   if (radio1.setRxBandwidth(250.0) == RADIOLIB_ERR_INVALID_RX_BANDWIDTH) {
     95     Serial.println(F("[CC1101] Selected receiver bandwidth is invalid for this module!"));
     96     while (true);
     97   }
     98 
     99   // set allowed frequency deviation to 10.0 kHz
    100   if (radio1.setFrequencyDeviation(10.0) == RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION) {
    101     Serial.println(F("[CC1101] Selected frequency deviation is invalid for this module!"));
    102     while (true);
    103   }
    104 
    105   // set output power to 5 dBm
    106   if (radio1.setOutputPower(5) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) {
    107     Serial.println(F("[CC1101] Selected output power is invalid for this module!"));
    108     while (true);
    109   }
    110 
    111   // 2 bytes can be set as sync word
    112   if (radio1.setSyncWord(0x01, 0x23) == RADIOLIB_ERR_INVALID_SYNC_WORD) {
    113     Serial.println(F("[CC1101] Selected sync word is invalid for this module!"));
    114     while (true);
    115   }
    116 
    117 }
    118 
    119 void loop() {
    120   // nothing here
    121 }