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

SX127x_Transmit.ino (2727B)

      1 /*
      2    RadioLib SX127x Transmit Example
      3 
      4    This example transmits packets using SX1278 LoRa radio module.
      5    Each packet contains up to 256 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    Other modules from SX127x/RFM9x family can also be used.
     11 
     12    For default module settings, see the wiki page
     13    https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
     14 
     15    For full API reference, see the GitHub Pages
     16    https://jgromes.github.io/RadioLib/
     17 */
     18 
     19 // include the library
     20 #include <RadioLib.h>
     21 
     22 // SX1278 has the following connections:
     23 // NSS pin:   10
     24 // DIO0 pin:  2
     25 // RESET pin: 9
     26 // DIO1 pin:  3
     27 SX1278 radio = new Module(10, 2, 9, 3);
     28 
     29 // or using RadioShield
     30 // https://github.com/jgromes/RadioShield
     31 //SX1278 radio = RadioShield.ModuleA;
     32 
     33 void setup() {
     34   Serial.begin(9600);
     35 
     36   // initialize SX1278 with default settings
     37   Serial.print(F("[SX1278] Initializing ... "));
     38   int state = radio.begin();
     39   if (state == RADIOLIB_ERR_NONE) {
     40     Serial.println(F("success!"));
     41   } else {
     42     Serial.print(F("failed, code "));
     43     Serial.println(state);
     44     while (true);
     45   }
     46 
     47   // some modules have an external RF switch
     48   // controlled via two pins (RX enable, TX enable)
     49   // to enable automatic control of the switch,
     50   // call the following method
     51   // RX enable:   4
     52   // TX enable:   5
     53   /*
     54     radio.setRfSwitchPins(4, 5);
     55   */
     56 }
     57 
     58 void loop() {
     59   Serial.print(F("[SX1278] Transmitting packet ... "));
     60 
     61   // you can transmit C-string or Arduino string up to
     62   // 256 characters long
     63   // NOTE: transmit() is a blocking method!
     64   //       See example SX127x_Transmit_Interrupt for details
     65   //       on non-blocking transmission method.
     66   int state = radio.transmit("Hello World!");
     67 
     68   // you can also transmit byte array up to 256 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     // print measured data rate
     79     Serial.print(F("[SX1278] Datarate:\t"));
     80     Serial.print(radio.getDataRate());
     81     Serial.println(F(" bps"));
     82 
     83   } else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
     84     // the supplied packet was longer than 256 bytes
     85     Serial.println(F("too long!"));
     86 
     87   } else if (state == RADIOLIB_ERR_TX_TIMEOUT) {
     88     // timeout occurred while transmitting packet
     89     Serial.println(F("timeout!"));
     90 
     91   } else {
     92     // some other error occurred
     93     Serial.print(F("failed, code "));
     94     Serial.println(state);
     95 
     96   }
     97 
     98   // wait for a second before transmitting again
     99   delay(1000);
    100 }