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

      1 /*
      2    RadioLib RF69 Transmit to Address Example
      3 
      4    This example transmits packets using RF69 FSK radio module.
      5    Packets can have 1-byte address of the destination node.
      6    After setting node (or broadcast) address, this node will
      7    automatically filter out any packets that do not contain
      8    either node address or broadcast address.
      9 
     10    For default module settings, see the wiki page
     11    https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
     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 // RF69 has the following connections:
     21 // CS pin:    10
     22 // DIO0 pin:  2
     23 // RESET pin: 3
     24 RF69 radio = new Module(10, 2, 3);
     25 
     26 // or using RadioShield
     27 // https://github.com/jgromes/RadioShield
     28 //RF69 radio = RadioShield.ModuleA;
     29 
     30 void setup() {
     31   Serial.begin(9600);
     32 
     33   // initialize RF69 with default settings
     34   Serial.print(F("[RF69] Initializing ... "));
     35   int state = radio.begin();
     36   if (state == RADIOLIB_ERR_NONE) {
     37     Serial.println(F("success!"));
     38   } else {
     39     Serial.print(F("failed, code "));
     40     Serial.println(state);
     41     while (true);
     42   }
     43 
     44   // set node address
     45   // NOTE: calling this method will automatically enable
     46   // address filtering (node address only)
     47   Serial.print(F("[RF69] Setting node address ... "));
     48   state = radio.setNodeAddress(0x01);
     49   if (state == RADIOLIB_ERR_NONE) {
     50     Serial.println(F("success!"));
     51   } else {
     52     Serial.print(F("failed, code "));
     53     Serial.println(state);
     54     while (true);
     55   }
     56 
     57   // set broadcast address
     58   // NOTE: calling this method will automatically enable
     59   // address filtering (node or broadcast address)
     60   Serial.print(F("[RF69] Setting broadcast address ... "));
     61   state = radio.setBroadcastAddress(0xFF);
     62   if (state == RADIOLIB_ERR_NONE) {
     63     Serial.println(F("success!"));
     64   } else {
     65     Serial.print(F("failed, code "));
     66     Serial.println(state);
     67     while (true);
     68   }
     69 
     70   // address filtering can also be disabled
     71   // NOTE: calling this method will also erase previously set
     72   //       node and broadcast address
     73   /*
     74     Serial.print(F("[RF69] Disabling address filtering ... "));
     75     state = radio.disableAddressFiltering();
     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 }
     85 
     86 void loop() {
     87   Serial.print(F("[RF69] Transmitting packet ... "));
     88 
     89   // transmit C-string or Arduino string to node with address 0x02
     90   int state = radio.transmit("Hello World!", 0x02);
     91 
     92   // transmit byte array to node with address 0x02
     93   /*
     94   byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
     95   int state = radio.transmit(byteArr, 8, 0x02);
     96   */
     97 
     98   // transmit C-string or Arduino string in broadcast mode
     99   /*
    100     int state = radio.transmit("Hello World!", 0xFF);
    101   */
    102 
    103   // transmit byte array in broadcast mode
    104   /*
    105     byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
    106     int state = radio.transmit(byteArr, 8, 0xFF);
    107   */
    108 
    109   if (state == RADIOLIB_ERR_NONE) {
    110     // the packet was successfully transmitted
    111     Serial.println(F("success!"));
    112 
    113   } else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
    114     // the supplied packet was longer than 64 bytes
    115     Serial.println(F("too long!"));
    116 
    117   } else {
    118     // some other error occurred
    119     Serial.print(F("failed, code "));
    120     Serial.println(state);
    121 
    122   }
    123 
    124   // wait for a second before transmitting again
    125   delay(1000);
    126 }