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

Si443x_Receive.ino (2095B)

      1 /*
      2    RadioLib Si443x Receive Example
      3 
      4    This example receives packets using Si443x FSK radio module.
      5    To successfully receive data, the following settings have to be the same
      6    on both transmitter and receiver:
      7     - carrier frequency
      8     - bit rate
      9     - frequency deviation
     10     - sync word
     11 
     12    Other modules from Si443x/RFM2x family can also be used.
     13 
     14    For default module settings, see the wiki page
     15    https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x
     16 
     17    For full API reference, see the GitHub Pages
     18    https://jgromes.github.io/RadioLib/
     19 */
     20 
     21 // include the library
     22 #include <RadioLib.h>
     23 
     24 // Si4432 has the following connections:
     25 // nSEL pin:  10
     26 // nIRQ pin:  2
     27 // SDN pin:   9
     28 Si4432 radio = new Module(10, 2, 9);
     29 
     30 // or using RadioShield
     31 // https://github.com/jgromes/RadioShield
     32 //Si4432 radio = RadioShield.ModuleA;
     33 
     34 void setup() {
     35   Serial.begin(9600);
     36 
     37   // initialize Si4432 with default settings
     38   Serial.print(F("[Si4432] Initializing ... "));
     39   int state = radio.begin();
     40   if (state == RADIOLIB_ERR_NONE) {
     41     Serial.println(F("success!"));
     42   } else {
     43     Serial.print(F("failed, code "));
     44     Serial.println(state);
     45     while (true);
     46   }
     47 }
     48 
     49 void loop() {
     50   Serial.print(F("[Si4432] Waiting for incoming transmission ... "));
     51 
     52   // you can receive data as an Arduino String
     53   String str;
     54   int state = radio.receive(str);
     55 
     56   // you can also receive data as byte array
     57   /*
     58     byte byteArr[8];
     59     int state = radio.receive(byteArr, 8);
     60   */
     61 
     62   if (state == RADIOLIB_ERR_NONE) {
     63     // packet was successfully received
     64     Serial.println(F("success!"));
     65 
     66     // print the data of the packet
     67     Serial.print(F("[Si4432] Data:\t\t"));
     68     Serial.println(str);
     69 
     70   } else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
     71     // timeout occurred while waiting for a packet
     72     Serial.println(F("timeout!"));
     73 
     74   } else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
     75     // packet was received, but is malformed
     76     Serial.println(F("CRC error!"));
     77 
     78   } else {
     79     // some other error occurred
     80     Serial.print(F("failed, code "));
     81     Serial.println(state);
     82 
     83   }
     84 }