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

SSTV_Transmit.ino (6805B)

      1 /*
      2    RadioLib SSTV Transmit Example
      3 
      4    The following example sends SSTV picture using
      5    SX1278's FSK modem.
      6 
      7    Other modules that can be used for SSTV:
      8     - SX127x/RFM9x
      9     - RF69
     10     - SX1231
     11     - SX126x
     12 
     13    NOTE: SSTV is an analog modulation, and
     14          requires precise frequency control.
     15          Some of the above modules can only
     16          set their frequency in rough steps,
     17          so the result can be distorted.
     18          Using high-precision radio with TCXO
     19          (like SX126x) is recommended.
     20 
     21    NOTE: Some platforms (such as Arduino Uno)
     22          might not be fast enough to correctly
     23          send pictures via high-speed modes
     24          like Scottie2 or Martin2. For those,
     25          lower speed modes such as Wrasse,
     26          Scottie1 or Martin1 are recommended.
     27 
     28    For default module settings, see the wiki page
     29    https://github.com/jgromes/RadioLib/wiki/Default-configuration
     30 
     31    For full API reference, see the GitHub Pages
     32    https://jgromes.github.io/RadioLib/
     33 */
     34 
     35 // include the library
     36 #include <RadioLib.h>
     37 
     38 // SX1278 has the following connections:
     39 // NSS pin:   10
     40 // DIO0 pin:  2
     41 // RESET pin: 9
     42 // DIO1 pin:  3
     43 SX1278 radio = new Module(10, 2, 9, 3);
     44 
     45 // or using RadioShield
     46 // https://github.com/jgromes/RadioShield
     47 //SX1278 radio = RadioShield.ModuleA;
     48 
     49 // create SSTV client instance using the FSK module
     50 SSTVClient sstv(&radio);
     51 
     52 // test "image" - actually just a single 320px line
     53 // will be sent over and over again, to create vertical color stripes at the receiver
     54 uint32_t line[320] = {
     55   // black
     56   0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
     57   0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
     58 
     59   // blue
     60   0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
     61   0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
     62 
     63   // green
     64   0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00,
     65   0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00,
     66 
     67   // cyan
     68   0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF,
     69   0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF,
     70 
     71   // red
     72   0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000,
     73   0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000,
     74 
     75   // magenta
     76   0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF,
     77   0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF,
     78 
     79   // yellow
     80   0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00,
     81   0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00,
     82 
     83   // white
     84   0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF,
     85   0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF
     86 };
     87 
     88 void setup() {
     89   Serial.begin(9600);
     90 
     91   // initialize SX1278 with default settings
     92   Serial.print(F("[SX1278] Initializing ... "));
     93   int state = radio.beginFSK();
     94   if (state == RADIOLIB_ERR_NONE) {
     95     Serial.println(F("success!"));
     96   } else {
     97     Serial.print(F("failed, code "));
     98     Serial.println(state);
     99     while (true);
    100   }
    101 
    102   // when using one of the non-LoRa modules for SSTV
    103   // (RF69, SX1231 etc.), use the basic begin() method
    104   // int state = radio.begin();
    105 
    106   // initialize SSTV client
    107   Serial.print(F("[SSTV] Initializing ... "));
    108   // 0 Hz tone frequency:         434.0 MHz
    109   // SSTV mode:                   Wrasse (SC2-180)
    110   // correction factor:           0.95
    111   // NOTE: Due to different speeds of various platforms
    112   //       supported by RadioLib (Arduino Uno, ESP32 etc),
    113   //       and because SSTV is analog protocol, incorrect
    114   //       timing of pulses can lead to distortions.
    115   //       To compensate, correction factor can be used
    116   //       to adjust the length of timing pulses
    117   //       (lower number = shorter pulses).
    118   //       The value is usually around 0.95 (95%).
    119   state = sstv.begin(434.0, Wrasse, 0.95);
    120   if(state == RADIOLIB_ERR_NONE) {
    121     Serial.println(F("success!"));
    122   } else {
    123     Serial.print(F("failed, code "));
    124     Serial.println(state);
    125     while(true);
    126   }
    127 
    128   // to help tune the receiver, SSTVClient can send
    129   // continuous beep at the frequency corresponding to
    130   // 1900 Hz in upper sideband (aka USB) modulation
    131   // (SSTV header "leader tone")
    132   /*
    133     sstv.idle();
    134     while(true);
    135   */
    136 }
    137 
    138 void loop() {
    139   // send picture with 8 color stripes
    140   Serial.print(F("[SSTV] Sending test picture ... "));
    141 
    142   // send synchronization header first
    143   sstv.sendHeader();
    144 
    145   // send all picture lines
    146   for(uint16_t i = 0; i < sstv.getPictureHeight(); i++) {
    147     sstv.sendLine(line);
    148   }
    149 
    150   // turn off transmitter
    151   radio.standby();
    152 
    153   Serial.println(F("done!"));
    154 
    155   delay(30000);
    156 }