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

      1 /*
      2    RadioLib SX127x Direct Receive Example
      3 
      4    This example shows how to receive FSK packets without using
      5    SX127x packet engine.
      6 
      7    For default module settings, see the wiki page
      8    https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
      9 
     10    For full API reference, see the GitHub Pages
     11    https://jgromes.github.io/RadioLib/
     12 */
     13 
     14 // include the library
     15 #include <RadioLib.h>
     16 
     17 // SX1278 has the following connections:
     18 // NSS pin:   10
     19 // DIO0 pin:  2
     20 // RESET pin: 9
     21 // DIO1 pin:  3
     22 SX1278 radio = new Module(10, 2, 9, 3);
     23 
     24 // DIO2 pin:  5
     25 const int pin = 5;
     26 
     27 // or using RadioShield
     28 // https://github.com/jgromes/RadioShield
     29 //SX1278 radio = RadioShield.ModuleA;
     30 
     31 void setup() {
     32   Serial.begin(9600);
     33 
     34   // initialize SX1278 with FSK modem at 9600 bps
     35   Serial.print(F("[SX1278] Initializing ... "));
     36   int state = radio.beginFSK(434.0, 9.6, 20.0);
     37   if (state == RADIOLIB_ERR_NONE) {
     38     Serial.println(F("success!"));
     39   } else {
     40     Serial.print(F("failed, code "));
     41     Serial.println(state);
     42     while (true);
     43   }
     44 
     45   // set the direct mode sync word
     46   // the default RadioLib FSK sync word is 0x12AD
     47   // we can add in some preamble bits, to lower the chance
     48   // of false detection
     49   radio.setDirectSyncWord(0x555512AD, 32);
     50 
     51   // set function that will be called each time a bit is received
     52   radio.setDirectAction(readBit);
     53 
     54   // start direct mode reception
     55   radio.receiveDirect();
     56 }
     57 
     58 // this function is called when a new bit is received
     59 void readBit(void) {
     60   // read the data bit
     61   radio.readBit(pin);
     62 }
     63 
     64 void loop() {
     65   // we expect the packet to contain the string "Hello World!",
     66   // a length byte and 2 CRC bytes, that's 15 bytes in total
     67   if(radio.available() >= 15) {
     68     Serial.println("[SX1278] Received packet in direct mode!");
     69     while(radio.available()) {
     70       // read a byte
     71       byte b = radio.read();
     72   
     73       // print it
     74       Serial.print(b, HEX);
     75       Serial.print('\t');
     76       Serial.write(b);
     77       Serial.println();
     78     }
     79   }
     80 }