SHARE
TWEET

TTGO_V2_1-1_6_T3_Senderer_Sketch_From_Bob_Rader_Feb_6_2020

a guest Feb 6th, 2020 103 in 127 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  **************.......... TTGO V2.1-1.6 T3 Transmit/ Sender Sketch..........***********
  3.  Original sketch from
  4.  Rui Santos
  5.   Complete original project details at https://RandomNerdTutorials.com/ttgo-lora32-sx1276-arduino-ide/
  6.    
  7.  
  8.                        Set to transmit on 433 Mhz
  9.  
  10.    Sketch 2-2-20 Used to send test text "Testing 123" to TTGO Receiver Module
  11.  
  12.  
  13.    Modified 12-9-19 By Adolfo Mondragon added both an Analog Input & digital Input
  14.    
  15. **********************     Sender/ Transmit Unit set For 433 Mhz Band     *********
  16.  
  17.              TTGO V2.1_1.6 T3                --  Sender Sketch --
  18.              Version 2-2-20
  19.              
  20.              Notes:  ** LoRa RF parameters for the receiver MUST BE set the same as the SENDER **
  21.              
  22.              Modified by Bob Rader 1-22-20 added LoRa RF Parameters, internal green
  23.              LED and an external output for a LED on pin 12 to verify receipt of packet.
  24.              Added to the display the analog reading & digital status sent from sender
  25.              Mod of 1-30-20 -- added call sign
  26.                                modified for signal range test without the Digital or Analog
  27.              Mod of 2-5-20 --  Removed call sign, digital I/O, Analog & other mods for Random Nurds
  28.          
  29.          Two very good articles explaining the LoRa RF parameters:
  30.          
  31.          "A Study of LoRa: Long Range & Low Power Networks for the Internet of Things"
  32.          explaining the LoRa parameters can be found at:
  33.          https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5038744/
  34.                            &
  35.          Decoding Lora
  36.          https://revspace.nl/DecodingLora
  37.  
  38.  
  39. **************************************.............. SET LoRa Modulation & RF Parameters
  40.                                                      
  41.                            Band          Band or exact Freq 433E6 for Asia, 866E6 Europe, 915E6 America
  42.                                                  ie: 915E6 or 922350000 or another specific frequency
  43.                            Power         Tx Power 2 to 20  default 17
  44.                            SF            Spreading Factor 6 to 12  default 7
  45.                            BW            Bandwith 7.8E3, 10.4E3, 15.6E3, 20.8E3, 31.25E3,
  46.                                                   41.7E3, 62.5E3, 125E3, & 250E3 default 125E3
  47.                            CR            Coding Rate 5 or 8 default 5
  48.                            Preamble      Preamble 6 to 65535 default 8 -- Longer = longer transmission time
  49.                            SyncWd        Sync Word byte val default 0x12            
  50. ********************************************************************************************
  51. */
  52.                                                          
  53.     #define Band 433E6   // Set Module Frequency
  54.     #define Power 5      // Set Power (2 to 20)
  55.     #define SF 10        // Set Spreading Factor (6 to 12)
  56.     #define BW 125E3     // Set Bandwidth (see above)
  57.     #define CR 5         // Set Coding Rate (5 or 8)
  58.     #define Preamble 255 // Set Preamble (6 to 65535)
  59.     #define SyncWd 0x12  // Set Sync Word ( default 0x12)
  60.    
  61. //********************.............. Libraries for LoRa.........******************
  62.     #include <SPI.h>
  63.     #include <LoRa.h>
  64.  
  65. //*******************.............. Libraries for OLED Display ..............**********
  66.     #include <Wire.h>
  67.     #include <Adafruit_GFX.h>
  68.     #include <Adafruit_SSD1306.h>
  69.  
  70. //******************............. Define pins used by LoRa SX1276 module..............***
  71.     #define SCK 5
  72.     #define MISO 19
  73.     #define MOSI 27
  74.     #define SS 18
  75.     #define RST 23
  76.     #define DIO0 26
  77.  
  78.   const int ledPin =  25;     // Ues Pin 25 for internal Grn LED to indicate transmission made
  79.                          
  80. //*********************...............Define pins & Parameters used by OLED Display..............
  81.     #define OLED_SDA 21
  82.     #define OLED_SCL 22
  83.     #define OLED_RST 16
  84.     #define SCREEN_WIDTH 128 // OLED display width, in pixels
  85.     #define SCREEN_HEIGHT 64 // OLED display height, in pixels
  86.         Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, & Wire, OLED_RST);
  87.  
  88. //********************.............. Define Sensors..............**********
  89.  
  90.         byte sensor_D ;            //  This will be the Digital I/O Input on pin 14
  91.         int sensor_A  ;            //  This will be the Analog Input on pin 12
  92.         int count=0;
  93.        
  94.  //*******************..............  initialize and set-up ESp32 Pins & Serial Monitor ..............
  95.      
  96.     void setup() {
  97.     Serial.begin(9600);            // set baud rate for serial monitor
  98.        
  99.   pinMode(14, INPUT_PULLUP);       // Use pin 14 for Digital Input SENSOR with pull-up
  100.   pinMode(12, INPUT);              // Use pin 12 for Analog Input SENSOR, see below
  101.   pinMode(ledPin, OUTPUT);         // Use pin 25 For internal Led -- On when in Tx mode
  102.                                
  103.  
  104. //***************************.............. Reset OLED display..............**********        
  105.   pinMode(OLED_RST, OUTPUT);
  106.   digitalWrite(OLED_RST, LOW);
  107.   delay(20);
  108.   digitalWrite(OLED_RST, HIGH);
  109.  
  110. //************************************.... Initialize OLED at address 0x3C..............
  111.   Wire.begin(OLED_SDA, OLED_SCL);
  112.   if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) {
  113.     for(;;);                       // .......... Don't proceed, loop forever..............
  114.   }
  115. //*************************........Set-Up & Write To Display..............****************  
  116.   display.clearDisplay();
  117.   display.setTextColor(WHITE);
  118.   display.setTextSize(1);
  119.   display.setCursor(10,0);
  120.   display.print("LoRa Sender Module");
  121.   display.setCursor(30,10);
  122.   display.print("initalized OK!");
  123.   display.display();
  124.  
  125. //************************************  LoRa SPI pins..............**********
  126.   SPI.begin(SCK, MISO, MOSI, SS);
  127.  
  128. //********************************..............Set & test LoRa transmit frequency..............
  129.   LoRa.setPins(SS, RST, DIO0);
  130.   if (!LoRa.begin(Band)) {
  131.     while (true);
  132.   }
  133.  
  134. //************************.....Setup LoRa Transmission & Modulation Parameters..............
  135.  
  136.      LoRa.setTxPower(Power);               // 2 to 20
  137.      LoRa.setSpreadingFactor(SF);          // 6-12
  138.      LoRa.setSignalBandwidth(BW);          // 7.8E3, 10.4E3, 15.6E3, 20.8E3, 31.25E3,
  139.                                            // 41.7E3, 62.5E3, 125E3, & 250E3
  140.      LoRa.setCodingRate4(CR);              // 5 or 8
  141.      LoRa.setPreambleLength(Preamble);     // 5 to 65535
  142.      LoRa.setSyncWord(SyncWd);             // byte val to use as sync word 0x12
  143.   delay(2000);
  144. }
  145.  
  146. //*****************    START LOOPING     **********************************
  147. //*************************************************************************
  148. //*****************    Start Looping      *********************************
  149.  
  150. void loop() {
  151. //****************************......... Read Sensors..............**********
  152.  
  153.    sensor_A = analogRead(12);           // Analog Data Attached To Pin 12
  154.                                         // If using a Test Pot > connect +3.3V -- Pin 12 -- GND
  155.    sensor_D = digitalRead(14);          // Digital Input Attached To Pin 14, Hi or Low
  156.                                
  157.    digitalWrite(ledPin, HIGH);          // Turn ESP 32 on-board green LED (attached to pin 25) on
  158.                                         // to indicate a transmission in progress
  159.    Serial.print("Analog = ");
  160.    Serial.print(sensor_A);              // Print Analog value to serial monitor
  161.    Serial.print("   Digital = ");            
  162.    Serial.print(sensor_D);            // Print Digital value to serial monitor
  163.    Serial.print("  ");
  164.    Serial.print("Count = ");
  165.    Serial.println(count);
  166.    
  167.    
  168.    
  169.    
  170. //**************************.... Send the LoRa packets..............**********
  171.  
  172.   LoRa.beginPacket();
  173.   LoRa.print("Test 123 ");
  174.  
  175. /*  
  176.     LoRa.print(count);
  177.     LoRa.print(sensor_D);
  178.     LoRa.println("");
  179.     LoRa.print("A = ");
  180.     LoRa.print(sensor_A);
  181. */
  182.   LoRa.endPacket();
  183.  
  184. // ***********************.............. Write to local Display On ESP 32..............
  185.   display.setTextSize(2);
  186.   display.clearDisplay();
  187.   display.setCursor(0,0);
  188.   display.println("LORA 433TX");
  189.   display.setCursor(0,20);
  190.   //display.print(count);
  191.   //display.setCursor(55,20);
  192.   //display.print(sensor_D);
  193.   //display.setCursor(0,40);
  194.   display.print("Test 123  ");
  195.   //display.print(count);
  196.   //display.setCursor(55,40);
  197.   //display.print(sensor_A);      
  198.   display.display();
  199.  
  200.   digitalWrite(ledPin, LOW);               // turn ESP green LED off
  201.   count++;
  202.  
  203.   delay(3000);
  204. }
  205.  
  206. //  **************              END     ******************
  207. //
  208. //
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top