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_Transmit_Address.ino (3053B)

      1 /*
      2    RadioLib CC1101 Transmit to Address Example
      3 
      4    This example transmits packets using CC1101 FSK radio
      5    module. Packets can have 1-byte address of the
      6    destination node. After setting node address, this node
      7    will automatically filter out any packets that do not
      8    contain either node address or broadcast addresses.
      9 
     10    For default module settings, see the wiki page
     11    https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101
     12 
     13    For full API reference, see the GitHub Pages
     14    https://jgromes.github.io/RadioLib/
     15 */
     16 
     17 // include the library
     18 #include <RadioLib.h>
     19 
     20 // CC1101 has the following connections:
     21 // CS pin:    10
     22 // GDO0 pin:  2
     23 // RST pin:   unused
     24 // GDO2 pin:  3 (optional)
     25 CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3);
     26 
     27 // or using RadioShield
     28 // https://github.com/jgromes/RadioShield
     29 //CC1101 radio = RadioShield.ModuleA;
     30 
     31 void setup() {
     32   Serial.begin(9600);
     33 
     34   // initialize CC1101 with default settings
     35   Serial.print(F("[CC1101] Initializing ... "));
     36   int state = radio.begin();
     37   if (state == RADIOLIB_ERR_NONE) {
     38     Serial.println(F("success!"));
     39   } else {
     40     Serial.print(F("failed, code "));
     41     Serial.println(state);
     42     while (true);
     43   }
     44 
     45   // set node address
     46   // NOTE: Calling this method will automatically enable
     47   //       address filtering. CC1101 also allows to set
     48   //       number of broadcast address (0/1/2).
     49   //       The following sets one broadcast address 0x00.
     50   //       When setting two broadcast addresses, 0x00 and
     51   //       0xFF will be used.
     52   Serial.print(F("[CC1101] Setting node address ... "));
     53   state = radio.setNodeAddress(0x01, 1);
     54   if (state == RADIOLIB_ERR_NONE) {
     55     Serial.println(F("success!"));
     56   } else {
     57     Serial.print(F("failed, code "));
     58     Serial.println(state);
     59     while (true);
     60   }
     61 
     62   // address filtering can also be disabled
     63   // NOTE: Calling this method will also erase previously
     64   //       set node address
     65   /*
     66     Serial.print(F("[CC1101] Disabling address filtering ... "));
     67     state == radio.disableAddressFiltering();
     68     if(state == RADIOLIB_ERR_NONE) {
     69       Serial.println(F("success!"));
     70     } else {
     71       Serial.print(F("failed, code "));
     72       Serial.println(state);
     73       while(true);
     74     }
     75   */
     76 }
     77 
     78 void loop() {
     79   Serial.print(F("[CC1101] Transmitting packet ... "));
     80 
     81   // you can transmit C-string or Arduino string up to 63 characters long
     82   int state = radio.transmit("Hello World!");
     83 
     84   // you can also transmit byte array up to 63 bytes long
     85   /*
     86     byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
     87     int state = radio.transmit(byteArr, 8);
     88   */
     89 
     90   if (state == RADIOLIB_ERR_NONE) {
     91     // the packet was successfully transmitted
     92     Serial.println(F("success!"));
     93 
     94   } else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
     95     // the supplied packet was longer than 255 bytes
     96     Serial.println(F("too long!"));
     97 
     98   } else {
     99     // some other error occurred
    100     Serial.print(F("failed, code "));
    101     Serial.println(state);
    102 
    103   }
    104 
    105   // wait for a second before transmitting again
    106   delay(1000);
    107 }