Setting Lora Parameters Lora.h library

Hello, I have TTGO's setup with the Lora.h library(Sandeep). Works fine but I wish to alter some of the default parameters. I have had no luck searching for how to do this so I copied a parameters list from the library and copied them into my code just after Lora.begin. I commented out all but spread factor for both tx and rx sketches. The rx no longer receives so I reverted back to my original sketches and it works again. I have included some copied text from Lora.h api.
Can anyone enlighten me on how to do this?

/*********
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/ttgo-lora32-sx1276-arduino-ide/
*********/

//Libraries for LoRa
#include <SPI.h>
#include <LoRa.h>

//Libraries for OLED Display
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

//define the pins used by the LoRa transceiver module
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 23
#define DIO0 26

//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define BAND 915E6

//OLED pins
#define OLED_SDA 21
#define OLED_SCL 22 
#define OLED_RST -1
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define SCREEN_ADDRESS 0x3c
//packet counter
int counter = 0;

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST);



//////////////////////////////////////SETUP////////////////////////////////////////////////////////
void setup() {
  //initialize Serial Monitor
  Serial.begin(115200);

  //reset OLED display via software
  pinMode(OLED_RST, OUTPUT);
  digitalWrite(OLED_RST, LOW);
  delay(20);
  digitalWrite(OLED_RST, HIGH);

  //initialize OLED
  Wire.begin(OLED_SDA, OLED_SCL);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0,0);
  display.print("LORA SENDER ");
  display.display();
  
  Serial.println("LoRa Sender Test");

  //SPI LoRa pins
  SPI.begin(SCK, MISO, MOSI, SS);
  //setup LoRa transceiver module
  LoRa.setPins(SS, RST, DIO0);
  
  if (!LoRa.begin(BAND)) {
    Serial.println("Starting LoRa failed!");
    while (1);
    // Set Lora parameters  
  //LoRa.setTxPower(17, PA_OUTPUT_PA_BOOST_PIN);//Supported values are between 2 and 17 for PA_OUTPUT_PA_BOOST_PIN
  LoRa.setSpreadingFactor(10);
  //LoRa.setSignalBandwidth(62.5E3);
  //LoRa.setCodingRate4(7); //min 5- max 8
  //setPreambleLength(long length);
  //setSyncWord(int sw);
  //LoRa.enableCrc();
  // LoRa.disableCrc();
  //enableInvertIQ();
  //disableInvertIQ()  
  }
  
  Serial.println("LoRa Initializing OK!");
  display.setCursor(0,10);
  display.print("LoRa Initializing OK!");
  display.display();
  delay(2000);
}
///////////////////////////LOOP//////////////////////////////////////////////
void loop() {
   
  Serial.print("Sending packet: ");
  Serial.println(counter);

  //Send LoRa packet to receiver
  LoRa.beginPacket();
  LoRa.print("hello ");
  LoRa.print(counter);
  LoRa.endPacket();
  
  display.clearDisplay();
  display.setCursor(0,0);
  display.println("LORA SENDER");
  display.setCursor(0,20);
  display.setTextSize(1);
  display.print("LoRa packet sent.");
  display.setCursor(0,30);
  display.print("Counter:");
  display.setCursor(50,30);
  display.print(counter);      
  display.display();

  counter++;
  
  delay(10000);
}

From Lora.h api

Radio parameters
TX Power
Change the TX power of the radio.

LoRa.setTxPower(txPower);

LoRa.setTxPower(txPower, outputPin);
txPower - TX power in dB, defaults to 17
outputPin - (optional) PA output pin, supported values are PA_OUTPUT_RFO_PIN and PA_OUTPUT_PA_BOOST_PIN, defaults to PA_OUTPUT_PA_BOOST_PIN.
Supported values are 2 to 20 for PA_OUTPUT_PA_BOOST_PIN, and 0 to 14 for PA_OUTPUT_RFO_PIN.

Most modules have the PA output pin connected to PA BOOST,

Frequency
Change the frequency of the radio.

LoRa.setFrequency(frequency);
frequency - frequency in Hz (433E6, 868E6, 915E6)
Spreading Factor
Change the spreading factor of the radio.

LoRa.setSpreadingFactor(spreadingFactor);
spreadingFactor - spreading factor, defaults to 7
Supported values are between 6 and 12. If a spreading factor of 6 is set, implicit header mode must be used to transmit and receive packets.
1 Like

When looking at problems like this, simplify the code. Go back to the basic sender and receiver examples, you dont need the confusion of writing to an OLED display etc.

If you change the spreading factor (or bandwidth, or frequency) then you need to make the same change in the receiver.

I have played with it some more, basically using parameters like " LoRa.setSpreadingFactor(10)" have no effect. To verify I changed spread factor on the transmit device only and the radios still worked so I know they have no effect as the receiver would not work if the spread factors were not matched as was stated.

If the test was done at close range, that is probably not meaningful.

The critical differences show up with weak signals.

In your original post you said you made changes and the "rx no longer receives" but now you are saying you can make changes and the RX does receive.

Did you simplify the sketch as suggested or start with the library example sender and receiver sketches ?

Sorry for the conflicting info. I had a problem with my oled not refreshing so lets forget about my original post.
In my second post I changed spread factor on my tx to 12 and left my rx at default 7. Radios still worked at 2km at similar rssi to original tests so I just assumed that changing spread factor didnot take effect on the tx.
I am using original examples. Maybe I need to go farther away but I thought the radios should not talk to each other with different sf's.

Ok, I uncommented the spread factor print statement to try and verify the setting. I got this:
int LoRaClass::getSpreadingFactor()' is private within this context.

Then clearly the TX is still using SF7.

The original examples have pin assignments for UNO\Nano as I recall, so you must be making some changes for the TTGO....

Correct, getSpreadingFactor() is not a public function in that library, check the code.

Hi, yes I am modifying the 5 SPI parameters and setting -1 to the I2C reset pin.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.