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

      1 /*
      2    RadioLib RF69 Transmit Example
      3 
      4    This example transmits packets using RF69 FSK radio module.
      5    Each packet contains up to 64 bytes of data, in the form of:
      6     - Arduino String
      7     - null-terminated char array (C-string)
      8     - arbitrary binary data (byte array)
      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   // NOTE: some RF69 modules use high power output,
     45   //       those are usually marked RF69H(C/CW).
     46   //       To configure RadioLib for these modules,
     47   //       you must call setOutputPower() with
     48   //       second argument set to true.
     49   /*
     50     Serial.print(F("[RF69] Setting high power module ... "));
     51     state = radio.setOutputPower(20, true);
     52     if (state == RADIOLIB_ERR_NONE) {
     53       Serial.println(F("success!"));
     54     } else {
     55       Serial.print(F("failed, code "));
     56       Serial.println(state);
     57       while (true);
     58     }
     59   */
     60 }
     61 
     62 void loop() {
     63   Serial.print(F("[RF69] Transmitting packet ... "));
     64 
     65   // you can transmit C-string or Arduino string up to 64 characters long
     66   int state = radio.transmit("Hello World!");
     67 
     68   // you can also transmit byte array up to 64 bytes long
     69   /*
     70     byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
     71     int state = radio.transmit(byteArr, 8);
     72   */
     73 
     74   if (state == RADIOLIB_ERR_NONE) {
     75     // the packet was successfully transmitted
     76     Serial.println(F("success!"));
     77 
     78   } else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
     79     // the supplied packet was longer than 64 bytes
     80     Serial.println(F("too long!"));
     81 
     82   } else {
     83     // some other error occurred
     84     Serial.print(F("failed, code "));
     85     Serial.println(state);
     86 
     87   }
     88 
     89   // wait for a second before transmitting again
     90   delay(1000);
     91 }