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

AFSK_Tone_AM.ino (2499B)

      1 /*
      2    RadioLib AM-modulated AFSK Example
      3 
      4    This example shows hot to send AM-modulated
      5    audio FSK tones using SX1278's OOK modem.
      6 
      7    Other modules that can be used for AFSK:
      8     - SX127x/RFM9x
      9     - RF69
     10     - SX1231
     11     - CC1101
     12 
     13    For default module settings, see the wiki page
     14    https://github.com/jgromes/RadioLib/wiki/Default-configuration
     15 
     16    For full API reference, see the GitHub Pages
     17    https://jgromes.github.io/RadioLib/
     18 */
     19 
     20 // include the library
     21 #include <RadioLib.h>
     22 
     23 // SX1278 has the following connections:
     24 // NSS pin:   10
     25 // DIO0 pin:  2
     26 // RESET pin: 9
     27 SX1278 radio = new Module(10, 2, 9);
     28 
     29 // create AFSK client instance using the FSK module
     30 // this requires connection to the module direct
     31 // input pin, here connected to Arduino pin 5
     32 // SX127x/RFM9x:  DIO2
     33 // RF69:          DIO2
     34 // SX1231:        DIO2
     35 // CC1101:        GDO2
     36 AFSKClient audio(&radio, 5);
     37 
     38 void setup() {
     39   Serial.begin(9600);
     40 
     41   // initialize SX1278 with default settings
     42   Serial.print(F("[SX1278] Initializing ... "));
     43   int state = radio.beginFSK();
     44 
     45   // when using one of the non-LoRa modules for AFSK
     46   // (RF69, CC1101, Si4432 etc.), use the basic begin() method
     47   // int state = radio.begin();
     48 
     49   if(state == RADIOLIB_ERR_NONE) {
     50     Serial.println(F("success!"));
     51   } else {
     52     Serial.print(F("failed, code "));
     53     Serial.println(state);
     54     while(true);
     55   }
     56 
     57   // initialize AFSK client
     58   Serial.print(F("[AFSK] Initializing ... "));
     59   state = audio.begin();
     60   if(state == RADIOLIB_ERR_NONE) {
     61     Serial.println(F("success!"));
     62   } else {
     63     Serial.print(F("failed, code "));
     64     Serial.println(state);
     65     while(true);
     66   }
     67 
     68   // after that, set mode to OOK
     69   Serial.print(F("[SX1278] Switching to OOK ... "));
     70   state = radio.setOOK(true);
     71   if(state == RADIOLIB_ERR_NONE) {
     72     Serial.println(F("success!"));
     73   } else {
     74     Serial.print(F("failed, code "));
     75     Serial.println(state);
     76     while(true);
     77   }
     78 }
     79 
     80 void loop() {
     81   // AFSKClient can be used to transmit tones,
     82   // same as Arduino tone() function
     83 
     84   // 400 Hz tone
     85   Serial.print(F("[AFSK] 400 Hz tone ... "));
     86   audio.tone(400);
     87   delay(1000);
     88 
     89   // silence
     90   Serial.println(F("done!"));
     91   audio.noTone();
     92   delay(1000);
     93 
     94   // AFSKClient can also be used to transmit HAM-friendly
     95   // RTTY, Morse code, Hellschreiber, SSTV and AX.25.
     96   // Details on how to use AFSK are in the example
     97   // folders for each of the above modes.
     98 
     99   // CAUTION: Unlike standard AFSK, the result when using OOK
    100   // must be demodulated as AM!
    101 }