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

      1 /*
      2    RadioLib SX127x Receive Example
      3 
      4    This example listens for LoRa transmissions using SX127x Lora modules.
      5    To successfully receive data, the following settings have to be the same
      6    on both transmitter and receiver:
      7     - carrier frequency
      8     - bandwidth
      9     - spreading factor
     10     - coding rate
     11     - sync word
     12     - preamble length
     13 
     14    Other modules from SX127x/RFM9x family can also be used.
     15 
     16    For default module settings, see the wiki page
     17    https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
     18 
     19    For full API reference, see the GitHub Pages
     20    https://jgromes.github.io/RadioLib/
     21 */
     22 
     23 // include the library
     24 #include <RadioLib.h>
     25 
     26 // SX1278 has the following connections:
     27 // NSS pin:   10
     28 // DIO0 pin:  2
     29 // RESET pin: 9
     30 // DIO1 pin:  3
     31 SX1278 radio = new Module(10, 2, 9, 3);
     32 
     33 // or using RadioShield
     34 // https://github.com/jgromes/RadioShield
     35 //SX1278 radio = RadioShield.ModuleA;
     36 
     37 void setup() {
     38   Serial.begin(9600);
     39 
     40   // initialize SX1278 with default settings
     41   Serial.print(F("[SX1278] Initializing ... "));
     42   int state = radio.begin();
     43   if (state == RADIOLIB_ERR_NONE) {
     44     Serial.println(F("success!"));
     45   } else {
     46     Serial.print(F("failed, code "));
     47     Serial.println(state);
     48     while (true);
     49   }
     50 }
     51 
     52 void loop() {
     53   Serial.print(F("[SX1278] Waiting for incoming transmission ... "));
     54 
     55   // you can receive data as an Arduino String
     56   // NOTE: receive() is a blocking method!
     57   //       See example ReceiveInterrupt for details
     58   //       on non-blocking reception method.
     59   String str;
     60   int state = radio.receive(str);
     61 
     62   // you can also receive data as byte array
     63   /*
     64     byte byteArr[8];
     65     int state = radio.receive(byteArr, 8);
     66   */
     67 
     68   if (state == RADIOLIB_ERR_NONE) {
     69     // packet was successfully received
     70     Serial.println(F("success!"));
     71 
     72     // print the data of the packet
     73     Serial.print(F("[SX1278] Data:\t\t\t"));
     74     Serial.println(str);
     75 
     76     // print the RSSI (Received Signal Strength Indicator)
     77     // of the last received packet
     78     Serial.print(F("[SX1278] RSSI:\t\t\t"));
     79     Serial.print(radio.getRSSI());
     80     Serial.println(F(" dBm"));
     81 
     82     // print the SNR (Signal-to-Noise Ratio)
     83     // of the last received packet
     84     Serial.print(F("[SX1278] SNR:\t\t\t"));
     85     Serial.print(radio.getSNR());
     86     Serial.println(F(" dB"));
     87 
     88     // print frequency error
     89     // of the last received packet
     90     Serial.print(F("[SX1278] Frequency error:\t"));
     91     Serial.print(radio.getFrequencyError());
     92     Serial.println(F(" Hz"));
     93 
     94   } else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
     95     // timeout occurred while waiting for a packet
     96     Serial.println(F("timeout!"));
     97 
     98   } else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
     99     // packet was received, but is malformed
    100     Serial.println(F("CRC error!"));
    101 
    102   } else {
    103     // some other error occurred
    104     Serial.print(F("failed, code "));
    105     Serial.println(state);
    106 
    107   }
    108 }