TTGO LoRa32 SX1276 OLED Board: Getting Started with Arduino IDE

The TTGO LoRa32 SX1276 OLED is an ESP32 development board with a built-in LoRa chip and an SSD1306 0.96 inch OLED display. In this guide, we’ll show you how to: send and receive LoRa packets (point to point communication) and use the OLED display with Arduino IDE.

TTGO LoRa32 OLED SX1276 Board: Getting Started with Arduino IDE

For an introduction to LoRa communication, read: ESP32 with LoRa using Arduino IDE.

TTGO LoRa32 SX1276 OLED Overview

The TTGO LoRa32 SX1276 OLED is a development board with an ESP32, a built-in LoRa chip and an SSD1306 OLED display. This is the OLED model display we use in most of our electronics projects (Guide for OLED display with ESP32).

 TTGO LoRa32 OLED SX1276 Overview

The board also features several GPIOs to connect peripherals, PRG (BOOT) and RST buttons, and a lithium battery connector. For a more in-depth overview of this board, read: TTGO LoRa32 SX1276 OLED Review.

Where to buy?

You can go to the TTGO LoRa32 SX1276 OLED page on Maker Advisor to find the best price at different stores. To complete this tutorial, you’ll need two TTGO LoRa32 boards.

TTGO LoRa32 OLED SX1276

TTGO LoRa32 SX1276 OLED

The following figure shows the TTGO LoRa32 OLED board pinout.

 TTGO LoRa32 OLED SX1276 Pinout Diagram

The OLED displays communicates using I2C communication protocol. It is internally connected to the ESP32 on the following pins:

OLED (built-in)ESP32
SDAGPIO 4
SCLGPIO 15
RSTGPIO 16

The SX1276 LoRa chip communicates via SPI communication protocol, and it is internally connected to the ESP32 on the following GPIOs:

SX1276 LoRaESP32
MISOGPIO 19
MOSIGPIO 27
SCKGPIO 5
CSGPIO 18
IRQGPIO 26
RSTGPIO 14

Recommended reading: ESP32 Pinout Reference Guide

Install ESP32 Boards on Arduino IDE

To program the TTGO LoRa32 board, we’ll use Arduino IDE. So, you must have Arduino IDE installed as well as the ESP32 add-on. Follow the next guide to install the ESP32 package on Arduino IDE, if you haven’t already:

Installing OLED Libraries

There are several libraries available to control the OLED display with the ESP32. In this tutorial we’ll use two Adafruit libraries: Adafruit_SSD1306 library and Adafruit_GFX library.

Follow the next steps to install those libraries.

1. Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open.

2. Type “SSD1306” in the search box and install the SSD1306 library from Adafruit.

Installing the Adafruit SSD1306 library for OLED display Arduino IDE

3. After installing the SSD1306 library from Adafruit, type “GFX” in the search box and install the library.

Installing GFX Library for ESP32 Arduino IDE

Installing LoRa Library

There are several libraries available to easily send and receive LoRa packets with the ESP32. In this example we’ll be using the arduino-LoRa library by sandeep mistry.

Open your Arduino IDE, and go to Sketch > Include Library > Manage Libraries and search for “LoRa“. Select the LoRa library highlighted in the figure below, and install it.

Installing LoRa Library for ESP32 Arduino IDE

After installing the libraries, restart your Arduino IDE.

LoRa Sender Sketch

Copy the following code to your Arduino IDE. This code sends a “hello” message followed by a counter via LoRa every 10 seconds. It also displays the counter on the OLED display.

/*********
  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 14
#define DIO0 26

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

//OLED pins
#define OLED_SDA 4
#define OLED_SCL 15 
#define OLED_RST 16
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

//packet counter
int counter = 0;

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

void setup() {

  //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();
  
  //initialize Serial Monitor
  Serial.begin(115200);
  
  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);
  }
  Serial.println("LoRa Initializing OK!");
  display.setCursor(0,10);
  display.print("LoRa Initializing OK!");
  display.display();
  delay(2000);
}

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);
}

View raw code

How the code works

Start by including the libraries to interact with the LoRa chip.

#include <SPI.h>
#include <LoRa.h>

Then, include the libraries to interface with the I2C 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 14
#define DIO0 26

Select the LoRa frequency:

#define BAND 866E6

Define the OLED pins.

#define OLED_SDA 4
#define OLED_SCL 15 
#define OLED_RST 16

Define the OLED size.

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

Create a counter variable to keep track of the number of LoRa packets sent.

int counter = 0;

Create an Adafruit_SSD1306 object called display.

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

setup()

In the setup(), to start using the OLED you need to do a manual reset via software using the RST pin. To do this reset, you need to declare the RST pin as an output, set it to LOW for a few milliseconds and then, set it to HIGH again.

pinMode(OLED_RST, OUTPUT);
digitalWrite(OLED_RST, LOW);
delay(20);
digitalWrite(OLED_RST, HIGH);

Start an I2C communication using the defined OLED_SDA and OLED_SCL pins using Wire.begin().

Wire.begin(OLED_SDA, OLED_SCL);

After that, initialize the display with the following parameters. The parameters set as false ensure that the library doesn’t use the default I2C pins and use the pins defined in the code (GPIO 4 and GPIO 15).

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { // Address 0x3C for 128x32
  Serial.println(F("SSD1306 allocation failed"));
  for(;;); // Don't proceed, loop forever
}

Then, you can use the methods from the Adafruit library to interact with the OLED display. To learn more you can read our tutorial about the I2C OLED display with the ESP32.

Write the message “LORA SENDER” to the display.

display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0,0);
display.print("LORA SENDER ");
display.display();

Initialize the serial monitor for debugging purposes.

Serial.begin(115200);
Serial.println("LoRa Sender Test");

Define the SPI pins used by the LoRa chip.

SPI.begin(SCK, MISO, MOSI, SS);

And set up the LoRa transceiver module.

LoRa.setPins(SS, RST, DIO0);

Finally, initialize the LoRa transceiver module using the begin() method on the LoRa object and pass the frequency as argument.

if (!LoRa.begin(BAND)) {
  Serial.println("Starting LoRa failed!");
  while (1);
}

If we succeed in initializing the display, we write a success message on the OLED display.

display.setCursor(0,10);
display.print("LoRa Initializing OK!");
display.display();

loop()

In the loop() is where we’ll send the packets. You initialize a packet with the beginPacket() method.

LoRa.beginPacket();

You write data into the packet using the print() method. As you can see in the following two lines, we’re sending a hello message followed by the counter.

LoRa.print("hello ");
LoRa.print(counter);

Then, close the packet with the endPacket() method.

LoRa.endPacket();

Next, write the counter on the OLED display

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();

After this, the counter message is incremented by one in every loop, which happens every 10 seconds.

counter++;
delay(10000);

Testing the LoRa Sender

Upload the code to your board. You need to select the right board and COM port you’re using.

To select the board, in the Arduino IDE, go to Tools > Board and select the TTGO LoRa32-OLED V1 board.

Select TTGO LoRa32 OLED V1 in Arduino IDE

After uploading the code to your board, it should start sending LoRa packets.

TTGO LoRa ESP32 Dev Board Sender

LoRa Receiver Sketch

Now, upload the receiver sketch to another TTGO LoRa32 OLED board. This sketch listens for LoRa packets within its range and prints the content of the packets on the OLED, as well as the RSSI (relative received signal strength).

/*********
  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 14
#define DIO0 26

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

//OLED pins
#define OLED_SDA 4
#define OLED_SCL 15 
#define OLED_RST 16
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

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

String LoRaData;

void setup() { 
  
  //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 RECEIVER ");
  display.display();
  
  //initialize Serial Monitor
  Serial.begin(115200);

  Serial.println("LoRa Receiver 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);
  }
  Serial.println("LoRa Initializing OK!");
  display.setCursor(0,10);
  display.println("LoRa Initializing OK!");
  display.display();  
}

void loop() {

  //try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    //received a packet
    Serial.print("Received packet ");

    //read packet
    while (LoRa.available()) {
      LoRaData = LoRa.readString();
      Serial.print(LoRaData);
    }

    //print RSSI of packet
    int rssi = LoRa.packetRssi();
    Serial.print(" with RSSI ");    
    Serial.println(rssi);

   // Dsiplay information
   display.clearDisplay();
   display.setCursor(0,0);
   display.print("LORA RECEIVER");
   display.setCursor(0,20);
   display.print("Received packet:");
   display.setCursor(0,30);
   display.print(LoRaData);
   display.setCursor(0,40);
   display.print("RSSI:");
   display.setCursor(30,40);
   display.print(rssi);
   display.display();   
  }
}

View raw code

This sketch is very similar with the previous one. We just need to modify some lines to receive LoRa packets instead of sending.

In the loop(), we check if there are new packets to receive using the parsePacket() method.

int packetSize = LoRa.parsePacket();

If there’s a new packet, we’ll read its content. To read the incoming data, use the readString() method. The data received is saved on the LoRaData variable.

if (packetSize) {
  //received a packet
  Serial.print("Received packet ");

  //read packet
  while (LoRa.available()) {
    LoRaData = LoRa.readString();
    Serial.print(LoRaData);
  }

We also get the RSSI of the received packet by using the packetRSSI() method.

int rssi = LoRa.packetRssi();

Finally, display the received message, as well as the RSSI.

display.clearDisplay();
display.setCursor(0,0);
display.print("LORA RECEIVER");
display.setCursor(0,20);
display.print("Received packet:");
display.setCursor(0,30);
display.print(LoRaData);
display.setCursor(0,40);
display.print("RSSI:");
display.setCursor(30,40);
display.print(rssi);
display.display();

Testing the LoRa Receiver

Upload the code to your board. Don’t forget you need to select the TTGO LoRa32-OLED V1 in the Boards menu.

After uploading the code, it should start receiving the LoRa packets from the other board.

TTGO LoRa ESP32 Dev Board Receiver

Wrapping Up

This article was a quick getting started guide for the TTGO LoRa32 board how to: send LoRa packets in point to point communication and use the OLED display.

Now, the idea is to combine what you’ve learned here to build IoT projects. LoRa can be specially useful if you want to receive sensor readings that are not covered by your wi-fi network and are several meters apart. Additionally, you can also connect your board to the TTN (The Things Network).

We hope you’ve found this tutorial useful. Learn more about the ESP32 with our resources:

Thanks for reading.



Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »


Enjoyed this project? Stay updated by subscribing our weekly newsletter!

72 thoughts on “TTGO LoRa32 SX1276 OLED Board: Getting Started with Arduino IDE”

  1. How i can transfer from this board using UART the data to a pic18.
    I would like to have a Pic18 + Lora+ ESP and be able to send 30 bytes to a second Pic18, or receive from other PIC18 a group of 30 bytes.

    Reply
  2. The TTGO series of boards are great, they have loads of really odd ones too, like esp32 + a camera, or SIM card, or GPS, or DHT sensor, just about any project you want, there is a TTGO board for it.
    Only thing I’ve found is the range of the TTGO LoRa is pretty poor, I’m only getting a couple 100m in clear open countryside, rather than the 1000s of m it should really be.

    Reply
  3. Hello Rui and Sara.
    I can send and receive text via Lora.
    But I would like to send an analog value and an on / or switch command to a receiver. I have not yet succeeded. Have you already done something with it? It seems very nice to be able to read something from a greater distance and to switch than just to transfer text.
    I just have no idea how to handle that and I need a hint. The Text distance that I have already covered here is not that great yet. About 1000 Meters, but that is also sufficient for me.
    Greetings from bert from (cold) Netherlands.

    Reply
    • Hi Bert.
      You just need to send your sensor readings as a String.
      For example, the following snipet sends several sensor readings on the same message. Note that each reading is separated by a special character. This way, on the receiver side, you know how to split the message.

      void sendReadings() {
      // Send packet data
      // Send temperature in Celsius
      message = String(readingID) + “/” + String(tempC) + “&” +
      String(soilMoisture) + “#” + String(batteryLevel);
      // Uncomment to send temperature in Fahrenheit
      //message = String(readingID) + “/” + String(tempF) + “&” +
      // String(soilMoisture) + “#” + String(batteryLevel);
      delay(1000);
      LoRa.beginPacket();
      LoRa.print(message);
      LoRa.endPacket();
      }

      This works the same way if you want to sendo commands to turn something on or off.
      On the receiver side, we use the following to read and split the data:

      void getLoRaData() {
      Serial.print(“Lora packet received: “);
      // Read packet
      while (LoRa.available()) {
      String LoRaData = LoRa.readString();
      // LoRaData format: readingID/temperature&soilMoisture#batterylevel
      // String example: 1/27.43&654#95.34
      Serial.print(LoRaData);

      // Get readingID, temperature and soil moisture
      int pos1 = LoRaData.indexOf(‘/’);
      int pos2 = LoRaData.indexOf(‘&’);
      int pos3 = LoRaData.indexOf(‘#’);
      readingID = LoRaData.substring(0, pos1);
      temperature = LoRaData.substring(pos1 +1, pos2);
      soilMoisture = LoRaData.substring(pos2+1, pos3);
      batteryLevel = LoRaData.substring(pos3+1, LoRaData.length());
      }

      Now, feel free to modify these functions to use in your project.
      REgards,
      Sara

      Reply
      • Hi Sara,
        thank you for this piece of code. It’s very interesting since I try to send temperature and soil moisture sensor values with these boards.
        I was wondering if I can still use I2C to connect a BME280.
        I2C is already used by the oled display, but I think it is possible to have both device on the same “line” with different I2C adresses.
        Am I right ?
        Many thanks to you and Ruis for your work and nice tutos ^^

        Reply
  4. Hi
    I have used these boards to control my outdoor light etc.
    i have connected them with solar cells and 18650 battery with charger module as instructed in Learn ESP32 for Arduino.

    everything has been working perfectly for a month until the battery runs out of power.
    after that I cannot contact the board over USB

    the first time it happened I thought it was a bad board
    but today it happened again with two boards running out of power
    no sun in DanmarK 🙁

    it may be a problem that they get power through the lithium battery. Connecting even if they write is ok?

    Regards
    Aage

    Reply
  5. Hi,

    Great article. I got myself a pair of these to see what I could do.
    They came already programmed as a pair but did not have the signal strength displayed so I re-programmed them using the code in the article which worked flawlessly, thank you.
    I do have a problem though, the range is extremely poor. Although I am only using the antennas that were supplied, I expected much more range. I am getting barely 10m away and the signal is lost.
    I tried disconnecting the antennas on both transmit and receive ends to see if there was a drop in signal which would indicate the antennas were working, (no drop in signal would show one or both antennas were faulty in some way).
    For example, with about 50cm between the two units I get an RSSI of -85 and just moving to the next room (5m away and through just a stud wall) the RSSI drops to -104.
    Is there something wrong do you think?

    Thanks
    Martin

    Reply
    • I’ve had the same problem. But now I checked my failure: I did not select the proper frequency. One has to pay attention to the built in different frequencies of the LoRa transceivers. So I changed “LoRa.begin(866E6)” to “LoRa.begin(433E6)” and the range grew up to more than 1 kilometer.

      Reply
      • How can we check that? I bought two units as the ones on the tutorial, and I’m also getting too short of a range. Is there any problem in setting the frequency to 443MHz?

        Reply
  6. November 28, 2019   —
    Now that we have this board working, I would like to know if the TTGO Model LoRa32 V2.1_1.6 T3 can be programmed using the Arduino IDE?  If Yes, Under the tools tab of the IDE, what board do I select, what upload speed do I select, what programmer do I select, etc.?  Also, do I need to do other things to the board during the upload process ( for instance, as with the TTGO LoRa32-OLED V1 it was required to push and hold the \”prog\” button)?   Bob Rader  

    Reply
  7. This is cool. Great tutorial! I have a problem, using the TTGO devices. The sender goes forever, but the webserver stops after 50- 250 packets. I switched the sender and receiver and the same thing happens. The webserver/receiver stops responding. No idea why. Was going to put the sender in my observatory to keep track of conditions, but it it quits, won’t be of use. Ideas?

    Thanks,
    Joe

    Reply
  8. Thank you for these examples. The pin assignments for the SPI interface to the SX1276 chip were what I needed to get things working. You’ve provided more information than LilyGo about their own TTGO product. Please note that your code also works with the version that does NOT have the built-in display, just by taking out the OLED code.

    Reply
  9. Hello
    A great tuto as usual !

    I have implemented this LoRa send and LoRa recieve codes on ESP LoRa OLED from TTGO.
    I have combined this tuto with the tuto on BM280 data so that LoRA can relay weather data to a host site for display over the web.
    This can work for hours ( some 8000 packets ) and suddenly the receiver stops receiving packets without any reasons. I need to reset the ESP to restart. When it stucks all Serial.prints are stopped on the serial console, no more IRQ signal are available on IRQ/DiO0 pin.
    I am investigating the following problems: CRC error on reception, unexpected LoRA chip reset on RST pin, LoRa chip loosing LoRa Begin configuration, SPI interrupt conflicting with the OLED display, idle mode ?
    Have you any ideas to solve the problem?

    Reply
    • Hi Alain.
      You can check for that in your code and when something wrong happens like: fail to init LoRa, drop internet connection or something, restart the board with: ESP.restart();

      I hope this helps.
      Regards,
      Sara

      Reply
      • Hi Sara

        Thank you for your prompt answer.
        Today, my workaround was to include a LoRa.begin(BAND) command after each sucessfully received packet .
        This looks to solve the problem for now more than 23 000 packets received.
        I hope this could also help other members in the ESP/LoRa community.
        Besr regards

        Alain

        Reply
        • I tried this and it’s the receiver that quits. Restarting the receiver gets it going again??? Dies at somewhere around 70 packets.

          Reply
          • Instead of restarting the receiver I have schedule the receiver to go in deep sleep modefor 10 secondes after every sucessful reception of the LoRa packet. This greatly increased the robustness of the service. A Longer test period is necessary to conclude.
            Note : the idea of reprogramming with LoRa begin after reception was not 100% satisfactory for me. The receiver still stuck after some 12000 packets.

          • I wonder it it is related to the frequency. I’m in the US so am using the 915 band. I am sampling every 60 sec.

    • After experiencing the receiver stall problem mentioned several time in these comments, and trying all the mentioned fixes with no satisfaction, I checked the API and found the following: LoRa.receive(); which according to the docs sets the chip to continuous receive. Has worked well for several days now with 100ms updates of the received data (a counter). so I’m guessing the chip goes to sleep on its own for some reason. I will dig into the 1276 data sheet for more info as time permits. For now the following code works:

      void initLora() {
      //SPI LoRa pins
      SPI.begin(SCK, MISO, MOSI, SS);
      //setup LoRa transceiver module
      LoRa.setPins(SS, RST, DIO0);
      LoRa.begin(BAND);
      LoRa.receive(); // Sets continuous receive

      Reply
  10. Hello

    I have sucessfully implemented this brillant tutotrial to deliver BME 280 data to a web server accessible over WiFi.
    I am periodically experiencing the LoRa receiver that stops delivering packets after some 1000’s of perfect data transmission.
    No more IRQ signals are visible from the LoRa chip. The ESP is still looping correctly.
    With full ESP restart, the receiver resumes its task. Also with a single LoRa.begin(BAND) command (without ESP reset) the receiver also resumes its task.
    Can we suspect conflicts between functions/librairies : OLED, LoRa, WiFi, http?

    Reply
  11. January 12, 2020
    Hi Sara,

    The TTGO LoRa project is going well for me and thanks a million for all your tutorials, posts and the E-Books.
    Using a pair of TTGO V2.1 – 1.6 T3 modules I have been able to transmit & receive the transmitted signal more than 5km. I like Using this module because it allows me to connect the module directly to a vertically polarized dipole antenna at both the Tx & Rx ends. For this distance test the signal path was line-of-sight with no interfering obstructions.
    Now, my next project will be to see how far I can actually transmit the LoRa signal. To do this I will need to play with some of the LoRa SX1276 parameters which effect the range such as coding factor, bandwidth, Tx power, etc…

    One issue I have NOT been able to successfully resolve is changing these LoRa RF parameters on the SX1276 using the LoRa library. For instance, I recently attempted to adjust the transmit power parameter without success. Note, I am using a spectrum analyzer to view and characterize the short burst of RF output signal from the TTGO module.

    I also would like to play with some of the other LoRa parameters like coding factor, bandwidth, spreading factor and other such parameters. However, I am unable to find the correct syntax nor any documentation as to how to set and use such parameters.

    Can you help???

    Regards,
    Bob Rader

    Reply
  12. I’m using the heltec board and my program pauses within this if statement. What would the issue be with this?

    if (!LoRa.begin(BAND)) {
    Serial.println(“Starting LoRa failed!”);
    while (1);
    }

    Reply
    • Hi Harry.
      It probably means that LoRa is not initializing properly.
      What LoRa boards are you using? Your board might be using a different pinout than ours.
      Regards,
      Sara

      Reply
        • Hi again.
          I just checked and the Heltec LoRa boards with oled have the same pinout as the TTGO LoRa32. So, the code should work straight away (unless you have a “weird” version of an heltec board).
          So, without more information, it is very difficult to find out what might be wrong :/
          Regards,
          Sara

          Reply
  13. Hello Sara Santos, how are you? I hope fine.

    I have two modules TTGO LORA_V1_0_OLED and they working normally, however I using the standard Send/Receive LoRa examples, I would like to know if its possible to improve the RSSI value by adjusting some parameters on the code like for an example the TxPower on the Sender? Have you tried this and could you share the part of your code?

    Thank you!

    Reply
      • Hi Sara,
        I am responding to Cassio Lucas’ post of February 2, 2020 and your reply to him. I am providing a copy of my Sender & Receiver sketches allowing for and utilizing the LoRa RF & Modulation parameters.
        I have also done distance testing and have so far been able to send a LoRa message more than 5 km. To do this I am using the TTGO V2.1 -1.6 T3 with a home made ground plane antenna at each end. My signal path also is “line-of-sight” with NO intervening obstructions. I have found that the external antennas are very very important to get good range.
        Further please note that this testing was done on the 433 Mhz band here in the US running under amateur radio authorization. I have also used the same sketches on 915 Mhz making the appropriate frequency changes in the sketches, LoRa module & antenna.
        I also would like to suggest 2 articles I found very helpful to help understand the LoRa Modulation parameters.
        Two very good articles explaining the LoRa RF parameters are:
        “A Study of LoRa: Long Range & Low Power Networks for the Internet of Things”
        explaining the LoRa parameters can be found at https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5038744/
        &
        Decoding Lora https://revspace.nl/DecodingLora

        Here are my two sketches (please note it appears that the copy did not preserve the exact/ correct formatting):

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

        ********************************** Receive Unit set For 433 Mhz Band *********

        TTGO V2.1_1.6 T3 — Receiver Sketch —
        Version 1-30-20

        Notes: ** LoRa RF parameters for the receiver MUST BE set the same as the SENDER **

        Modified by Bob Rader 1-22-20 added LoRa RF Parameters, internal green
        LED and an external output for an LED on pin 12 to verify receipt of packet.
        Added to the display the analog reading & digital status sent from sender
        Mod of 1-30-20 — added call sign
        2-2-20 modified for signal range test without the Digital or Analog, Removed Call Sign

        Two very good articles explaining the LoRa RF parameters:

        “A Study of LoRa: Long Range & Low Power Networks for the Internet of Things”
        explaining the LoRa parameters can be found at https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5038744/
        &
        Decoding Lora https://revspace.nl/DecodingLora

        *********/

        //433E6 for Asia
        //866E6 for Europe
        //915E6 for North America

        /**************************** SET LoRa RF & Modilation Parameters *******************************
        *
        Define parameters to be used by LoRa module
        Band Band or Freq — 433E6 for Asia, 866E6 Europe, 915E6 North America
        ie: 915E6 or 922350000 or any specific frequency
        Power Tx Power 2 to 20 default 17
        SF Spreading Factor 6 to 12 default 7
        BW Bandwith 7.8E3, 10.4E3, 15.6E3, 20.8E3, 31.25E3,
        41.7E3, 62.5E3, 125E3, & 250E3 default 125E3
        CR Coding Rate 5 or 8 default 5
        Preamble Preamble 6 to 65535 default 8
        SyncWd Sync Word byte val to use as sync word default 0x12

        **************************************************************************************************
        */

        #define Band 433E6 // Set Band or Frequency in Hz
        #define SF 10 // Set Spreading Factor
        #define BW 125E3 // Set Bandwidth
        #define CR 5 // Set Coding Rate
        #define Preamble 255 // Set Preamble
        #define SyncWd 0x12 // Set Sync Word

        //************************************………….. Libraries for LoRa

        #include
        #include

        //************************************………….. Libraries for OLED Display

        #include
        #include
        #include

        //************************************………….. Define pins used by LoRa module

        #define SCK 5
        #define MISO 19
        #define MOSI 27
        #define SS 18
        #define RST 23
        #define DIO0 26

        //************************************……………Define pins & Parameters used by OLED Display
        // and variables

        #define OLED_SDA 21
        #define OLED_SCL 22
        #define OLED_RST 16
        #define SCREEN_WIDTH 128 // OLED display width, in pixels
        #define SCREEN_HEIGHT 64 // OLED display height, in pixels

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

        String LoRaData;
        const int ledPin = 25; //Use pin 25 for Led
        const int ledPin1 = 12; //Use pin 12 for External Led

        void setup() {

        pinMode(ledPin, OUTPUT); //Define ledPin as output
        pinMode(ledPin1, OUTPUT);//Define ledPin as output
        //reset OLED display via software
        pinMode(OLED_RST, OUTPUT);
        digitalWrite(OLED_RST, LOW);
        delay(20);
        digitalWrite(OLED_RST, HIGH);

        digitalWrite(ledPin, HIGH);

        //************************************…. Initialize OLED ……. Address 0x3C

        Wire.begin(OLED_SDA, OLED_SCL);
        if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { // Address 0x3C
        Serial.println(F(“SSD1306 allocation failed”));
        for(;;); // Don’t proceed, loop forever
        }
        //***********************************…..Set-Up Display

        display.clearDisplay();
        display.setTextColor(WHITE);
        display.setTextSize(1);
        display.setCursor(0,0);
        display.print(“LORA RECEIVER “);
        display.display();

        // initialize Serial Monitor
        Serial.begin(115200);

        Serial.println(“LoRa Receiver Test”);

        //************************************ LoRa SPI pins

        SPI.begin(SCK, MISO, MOSI, SS);
        //************************************ setup LoRa transceiver module & Frequency

        LoRa.setPins(SS, RST, DIO0);

        if (!LoRa.begin(Band)) { // Please Set Correct Frequency/ Band above
        Serial.println(“Starting LoRa failed!”);
        while (1);
        }

        //************************************ Setup LoRa Transmission Parameters
        LoRa.setSpreadingFactor(SF); // 6-12
        LoRa.setSignalBandwidth(BW); // 7.8E3, 10.4E3, 15.6E3, 20.8E3, 31.25E3,
        // 41.7E3, 62.5E3, 125E3, & 250E3
        LoRa.setCodingRate4(CR); // 5 or 8
        LoRa.setPreambleLength(Preamble); // 5 to 65535
        LoRa.setSyncWord(SyncWd); // byte val to use as sync word

        Serial.println(“LoRa Initializing OK!”);
        display.setCursor(0,10);
        display.println(“LoRa Initializing OK!”);
        display.display();
        }
        //************************** START LOOP **********************************
        //*******************************************************************************

        void loop() {

        //*****************************……… parse data from packet
        int packetSize = LoRa.parsePacket();
        if (packetSize) { // when no more data in packet — end
        //received a packet
        Serial.print(“Received packet “);

        //*****************************……….read packet data
        while (LoRa.available()) { // while data is in packet
        LoRaData = LoRa.readString(); // read data
        Serial.print(LoRaData); // continue until all packet
        } // data has been read

        //*****************************……….print RSSI
        int rssi = LoRa.packetRssi(); // read the transceiver RSSI value
        Serial.print(” with RSSI “);
        Serial.println(rssi);

        //*****************************……….display information on Oled Display
        display.clearDisplay();
        display.setCursor(0,0); // Set cursor to col 0 line 0
        display.setTextSize(2);
        display.print(“LoRa 433Rx”); // Send “LORA RECEIVER” to top line of display
        display.setCursor(10,18); // Set cursor to col 10 line 18
        display.print(LoRaData);
        display.setCursor(0,54); // Set cursor to col 0 line 54
        display.setTextSize(1);
        display.print(“RSSI = “);
        display.setTextSize(2);
        display.setCursor(48,50); // Set cursor to col 48 line 50
        display.print(rssi);
        display.display();

        if (LoRaData == “Test 123”) // test to see if data received is
        { // same as data sent — if yes,
        for (int i = 0; i < 3; i++) // blink ledPin 3 times
        {
        digitalWrite(ledPin, HIGH);
        digitalWrite(ledPin1, HIGH);
        delay(200);
        digitalWrite(ledPin, LOW);
        digitalWrite(ledPin1, LOW);
        delay(200);
        }
        }

        //*****************************……….blink external & internal green LED
        // 3 times to verify receipt of packets
        /* for (int i = 0; i < 3; i++){
        digitalWrite(ledPin, HIGH);
        digitalWrite(ledPin1, HIGH);
        delay(300);
        digitalWrite(ledPin, LOW);
        digitalWrite(ledPin1, LOW);
        delay(300);
        }
        */
        }
        }

        //**************** END ****************
        //
        //

        /*
        **************………. TTGO V2.1-1.6 T3 Transmit/ Sender Sketch……….***********
        Original sketch from
        Rui Santos
        Complete original project details at https://RandomNerdTutorials.com/ttgo-lora32-sx1276-arduino-ide/

        Set for transmittion on 433 Mhz

        Sketch 2-2-20 Used to send test text "Testing 123" to TTGO Receiver Module

        Modified 12-9-19 By Adolfo Mondragon added both an Analog Input & digital Input

        ********************************** Sender/ Transmit Unit set For 433 Mhz Band *********

        TTGO V2.1_1.6 T3 — Sender Sketch —
        Version 2-2-20

        Notes: ** LoRa RF parameters for the receiver MUST BE set the same as the SENDER **

        Modified by Bob Rader 1-22-20 added LoRa RF Parameters, internal green Led

        Added to the display the analog reading & digital status sent from sender
        Mod of 1-30-20 — added call sign
        modified for signal range test without the Digital or Analog, Removed Call Sign

        Two very good articles explaining the LoRa RF parameters:

        "A Study of LoRa: Long Range & Low Power Networks for the Internet of Things"
        explaining the LoRa parameters can be found at https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5038744/
        &
        Decoding Lora https://revspace.nl/DecodingLora

        **************************************………….. SET LoRa Modulation & RF Parameters

        Band Band or exact Freq 433E6 for Asia, 866E6 Europe, 915E6 America
        ie: 915E6 or 922350000 or another specific frequency
        Power Tx Power 2 to 20 default 17
        SF Spreading Factor 6 to 12 default 7
        BW Bandwith 7.8E3, 10.4E3, 15.6E3, 20.8E3, 31.25E3,
        41.7E3, 62.5E3, 125E3, & 250E3 default 125E3
        CR Coding Rate 5 or 8 default 5
        Preamble Preamble 6 to 65535 default 8
        SyncWd Sync Word byte val default 0x12
        ********************************************************************************************
        */

        #define Band 433E6 // Set Module Frequency
        #define Power 17 // Set Power (2 to 20)
        #define SF 10 // Set Spreading Factor (6 to 12)
        #define BW 125E3 // Set Bandwidth (see above)
        #define CR 5 // Set Coding Rate (5 or 8)
        #define Preamble 8 // Set Preamble (6 to 65535)
        #define SyncWd 0x12 // Set Sync Word ( default 0x12)

        //********************………….. Libraries for LoRa………******************
        #include
        #include

        //*******************………….. Libraries for OLED Display …………..**********
        #include
        #include
        #include

        //******************…………. Define pins used by LoRa SX1276 module…………..***
        #define SCK 5
        #define MISO 19
        #define MOSI 27
        #define SS 18
        #define RST 23
        #define DIO0 26

        const int ledPin = 25; // Uses Pin 25 for internal Grn LED to indicate transmission made

        //*********************……………Define pins & Parameters used by OLED Display…………..
        #define OLED_SDA 21
        #define OLED_SCL 22
        #define OLED_RST 16
        #define SCREEN_WIDTH 128 // OLED display width, in pixels
        #define SCREEN_HEIGHT 64 // OLED display height, in pixels
        Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, & Wire, OLED_RST);

        //********************………….. Define Sensors…………..**********

        byte sensor_D ; // This will be the Digital I/O Input on pin 14
        int sensor_A ; // This will be the Analog Input on pin 12

        //*******************………….. initialize and set-up ESp32 Pins & Serial Monitor …………..

        void setup() {
        Serial.begin(9600); // set baud rate for serial monitor

        pinMode(14, INPUT_PULLUP); // Use pin 14 for Digital Input SENSOR with pull-up
        pinMode(12, INPUT); // Use pin 12 for Analog Input SENSOR, see below
        pinMode(ledPin, OUTPUT); // Use pin 25 For internal Led — On when in Tx mode

        //***************************………….. Reset OLED display…………..**********
        pinMode(OLED_RST, OUTPUT);
        digitalWrite(OLED_RST, LOW);
        delay(20);
        digitalWrite(OLED_RST, HIGH);

        //************************************…. Initialize OLED at address 0x3C…………..
        Wire.begin(OLED_SDA, OLED_SCL);
        if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) {
        for(;;); // ………. Don’t proceed, loop forever…………..
        }
        //*************************……..Set-Up & Write To Display…………..****************
        display.clearDisplay();
        display.setTextColor(WHITE);
        display.setTextSize(1);
        display.setCursor(10,0);
        display.print(“LoRa Sender Module”);
        display.setCursor(30,10);
        display.print(“initalized OK!”);
        display.display();

        //************************************ LoRa SPI pins…………..**********
        SPI.begin(SCK, MISO, MOSI, SS);

        //********************************…………..Set & test LoRa transmit frequency…………..
        LoRa.setPins(SS, RST, DIO0);
        if (!LoRa.begin(Band)) {
        while (1);
        }

        //************************…..Setup LoRa Transmission & Modulation Parameters…………..

        LoRa.setTxPower(Power); // 2 to 20
        LoRa.setSpreadingFactor(SF); // 6-12
        LoRa.setSignalBandwidth(BW); // 7.8E3, 10.4E3, 15.6E3, 20.8E3, 31.25E3,
        // 41.7E3, 62.5E3, 125E3, & 250E3
        LoRa.setCodingRate4(CR); // 5 or 8
        LoRa.setPreambleLength(Preamble); // 5 to 65535
        LoRa.setSyncWord(SyncWd); // byte val to use as sync word 0x12
        delay(2000);
        }

        //***************** START LOOPING **********************************
        //*************************************************************************
        //***************** Start Looping *********************************

        void loop() {
        //****************************……… Read Sensors…………..**********

        sensor_A = analogRead(12); // Analog Data Attached To Pin 12
        // If using a Test Pot > connect +3.3V — Pin 12 — GND
        sensor_D = digitalRead(14); // Digital Input Attached To Pin 14, Hi or Low

        digitalWrite(ledPin, HIGH); // Turn ESP 32 on-board green LED (attached to pin 25) on
        // to indicate a transmission in progress
        Serial.print(sensor_A); // Print Analog value to serial monitor
        Serial.print(” “); //
        Serial.println(sensor_D); // Print Digital value to serial monitor

        //**************************…. Send the LoRa packets…………..**********

        LoRa.beginPacket();
        LoRa.print(“Test 123”);
        /*
        LoRa.print(sensor_D);
        LoRa.println(“”);
        LoRa.print(“A = “);
        LoRa.print(sensor_A);
        */
        LoRa.endPacket();

        // ***********************………….. Write to local Display On ESP 32…………..
        display.setTextSize(2);
        display.clearDisplay();
        display.setCursor(0,0);
        display.println(“LORA 433TX”);
        display.setCursor(0,40);
        display.print(“”);
        //display.setCursor(55,20);
        //display.print(sensor_D);
        //display.setCursor(0,40);
        display.print(“Test 123”);
        //display.setCursor(55,40);
        //display.print(sensor_A);
        display.display();

        digitalWrite(ledPin, LOW); // turn ESP green LED off

        delay(3000);
        }

        // ************** END ******************
        //
        //

        Reply
        • Hi Bob.
          Thank you so much for sharing this valuable information.
          Can you please share your codes using pastebin? When you paste the code here, some sections are automatically cut and it doesn’t preserve formatting.
          Regards,
          Sara

          Reply
          • Sara,

            Yes! I would be happy to share my code. Please give me the detailed specifics about sharing the code on pastebin . I am not familiar with this process and as such don’t know how to start or do it. Also, I would like to share some pictures of the, simple to make, home made antennas and perhaps a spectrum analyzer output of the RF signal. How to do this?

            Just need the details & specifics how to proceed…

            Bob Rader

          • Feb 4, 2020

            Sara,

            Hopefully I have been able to successfully drop my .ino code for the TTGO Receiver Sketch to paste.bin. As I have never used this feature I hope all went OK.
            Upon your conformation that all is OK, I will work to upload the Transmit/ Sender sketch…

            The title is: TTGO_V2_1-1_6_T3_Receiver_Sketch_From_Bob_Rader_Feb4_2020

            Please confirm if you are able to get it…

            Regards,
            Bob Rader

          • Sara,

            GREAT! Now that I know how pastebin works I will soon send off the sender/ transmit sketch.

            Regards,

            Bob

          • Sara,

            Here is the link to the sender sketch: https://pastebin.com/qVqJbQYt

            I am also planning in the future to do some fotos of the homemade antennas & a spectrum analyzer screen capture of the RF output. Hope you find these sketches helpful…

            Regards,

            Bob

          • Thank you for sharing.
            What was the communication range that you get with these new LoRa parameters?
            Regards,
            Sara

          • Feb. 6, 2020

            Sara,

            Yes! The communications range is effected by the the modulation parameters, however, there are some other factors that more SIGNIFICANTLY effect the communications range and they have little to do with the modulation parameters. Specifically, the antenna, coax and an unobstructed line-of-sight path between sender & receiver.

            I am getting more than 6 km here in southern New Mexico and feel I can get even longer range by looking at the system from an RF standpoint.

            First let me give you the theoretical stuff:
            The TTGO V2.1 – 1.6 T3 ESP32 LoRa system with modulation parameters of, SF=10; BW=125 KHz and a coding rate of 5. Semtech says that the SX1276 with these parameters should have a receiver sensitivity of -132 dBm. With a transmitter power setting of 17 (+17dBm) yields a total ‘link budget’ of (132 + 17) or 149 dB.
            Now calculating the link losses in free air, (37 dB + 20* (log of freq MHz) + 20* (log of distance miles)), 37dB + 20(log915)=59.2 +20 (log40)=32 (0 dB of antenna gain and 0 dB of coax losses are assumed) or a total link loss of 129 dB. If one wanted to have a 20dB signal margin then these numbers work for a theoretical distance of 65 km. Looking at these numbers, it can be seen that a 3 dB increase in the link budget yields a theoretical distance of almost 90 km.

            My testing to date was only to verify that I could communicate 6 km to a farm field. The distance was line-of-sight with no intervening obstructions. I used external home made ground plane antennas at both ends, with the receive system (antenna & TTGO) about 7 meters above ground and the sender system about 1.5 meters above ground. The TTGO systems and antennas were connected directly to the SMA connector provided on the TTGO (this was the main reason for selecting this ESP32 module). The receiving TTGO said the RSSI was -117 for this test and it should be noted here that the RSSI number does not directly relate to dBm.
            Pictures of this set-up, I hope, will be forth coming in the near future.

            It is hopped this helps you and others working with the LoRa technology. I find the LoRa quite fascinating and functional for battery powered low speed data transfers with very long expected battery life.

            Also, I wish to thank you and Rui for all your help with the ESP32 programming end of things. Your help and assistance was invaluable in getting this project up and running.

            Regards,

            Bob Rader

  14. #Bob Rader

    I’am trying to change Signal BandWidth.
    But no matter what I set. SBW stays at 125khz.
    I’ve tried these methods:

    #define BW 62.5E3 // Set Bandwidth

    and…

    LoRa.setSignalBandwidth(62.5E3);

    Can anyone please clarify !

    Reply
    • March 2, 2020

      Hi AuLeeFor,

      A few things come to mind in trying to help with your issue:

      First, I use the TTGO LoRa32 V2.1_1.6 T3 module due to the SMA connector attached directly on the board. For me it makes the antenna mounting easier and less signal loss in the antenna feed line circuit.

      Second, I am using the Sandeepmistry LoRa Library with the
      #include LoRa.h statement at the beginning of my sketch.

      Third, The sender and receiver NEED TO HAVE the exact same parameters, ie, BW, etc defined for both unit’s sketches.

      Forth, If you are wanting to set the BW at 62.5 KHz I would do it as: #define BW 62500 Then later in your sketch ( I did it at in the void setup() { )
      using the statement LoRa.setSignalBandwidth(BW);

      Please note that the LoRa.h library requires statements like LoRa.setxxxxxxxxxx(xx); to be used if you intend to modify the modulation parameters beyond the defaults. I have played with many of these modulation parameters and found them all working as expected.

      Hope this helps…

      Regards,
      Bob Rader

      Reply
  15. I’m also seeing the sender failing with the “Starting LoRa failed!” message. (TTGO LoRa OLED version 1 module.

    I have other code that uses this radio, and it has also stopped working when I rebuild it with the current ESP-IDF / arduino-esp32 environment. I’ve traced it to the low-level SPI communication with the radio chip failing. I wonder if something in the development environment has changed recently?

    Can anyone who has this working with a current build please post the versions of the tools you’re using? Thanks.

    Reply
    • Hi.
      Are you sure that your board is the same as ours?
      If you have a slightly different board, it may use different pins to connect to the LoRa chip. So, if you don’t initialize SPI properly on the right pins, it won’t be able to initialize LoRa.
      Make sure you define the right pins on the next lines:
      //define the pins used by the LoRa transceiver module
      #define SCK 5
      #define MISO 19
      #define MOSI 27
      #define SS 18
      #define RST 14
      #define DIO0 26

      Regards,
      Sara

      Reply
  16. Hi everyone,

    I m trying to use TTGO LoRa 32 OLED V1 and NodeMCU (ESP-12E) modules for my work. I want to send data via UART, from ESP-12E to TTGO LoRa module. However I am unable to implement the receive part on the TTGO LoRa module.

    Can someone suggest how this can be done?

    Thanks in advance,

    -Chandrasekhar DVS

    Reply
    • Hi.
      Basically, you need to instantiate an hardware serial communication – this uses GPIO 17(TX) and GPIO 16 (RX):
      HardwareSerial ss(2);

      in the setup():
      ss.begin(115200); //or change for another baud rate
      Serial.begin(115200); //Serial monitor

      than, to read the information:

      if (ss.available() > 0) {
      // read the incoming byte:
      incomingByte = ss.read();

      // say what you got:
      Serial.print(“I received: “);
      Serial.println(incomingByte, DEC);
      }
      }

      As shown in this example: https://www.arduino.cc/reference/en/language/functions/communication/serial/read/
      I hope this helps.

      Regards,
      Sara

      Reply
      • Hi Sara,

        Thanks for the quick response, I think the default 16 and 17 pins weren’t working right on my board. Referring to the code snippet of yours and some others, I was able to solve the problem. Also I remapped the UART pins. Following is the code snippet I used.

        HardwareSerial ss(2);

        #define RXD2 23
        #define TXD2 18

        String inputString = “”;
        char inChar;

        void setup() {
        // put your setup code here, to run once:
        Serial.begin(9600);
        ss.begin(9600,SERIAL_8N1, RXD2, TXD2);

        inputString.reserve(50);
        }

        void loop() {
        while(ss.available()>0)
        {
        inChar = (char)ss.read();
        inputString+=inChar;

        if(inChar == ‘!’)
        {
        Serial.println(inputString);
        inputString = “”;
        }
        }
        }

        Thanks for your reply.

        -Chandrasekhar DVS

        Reply
        • Hi again.
          I’m glad it is working 😀
          Thanks for sharing your solution. It might be helpful for others.
          Regards,
          Sara

          Reply
  17. Hi, thank you for this great tutorial. At first I didn’t see anything on the oled screen. I did not have any errors during uploading the sketch. In Serial monitor I could see the packets being send so it must be the oled pinout. It turns out that with the TTGO LoRa V2.1_1.6, oled SDA = 21 and oled SCL = 22. after changing that it works great!

    Reply
    • Great!
      You should always look at your board pinout, so that you have the right pin assignment on the code.
      Regards,
      Sara

      Reply
  18. Hi Sara, great ‘TTGO LoRa32 SX1276 OLED’ tutorial.
    I’m working with your code on a TTGO LoRa 32 OLED V1, but I didn’t see anything on the oled screen (like ‘ulco’ said), …any idea?, could you share a sketch/code in order to check only the oled screen?
    I suspect that my oled is damaged becouse the code uploaled is the exactaly same as yours in this tutorial.

    Thanks so much in advance !!

    Reply
    • Hi.
      To test the OLED, you can use the code in this tutorial: https://randomnerdtutorials.com/esp32-built-in-oled-ssd1306/
      But change the following line with the pins used by the OLED in your board:
      So, instead of
      Wire.begin(5, 4);

      You should have
      Wire.begin(4, 15);

      You also need to add the following lines right after the setup()
      pinMode(OLED_RST, OUTPUT);
      digitalWrite(16, LOW);
      delay(20);
      digitalWrite(16, HIGH);

      I hope this helps.
      Regards,
      Sara

      Reply
  19. Hello Sara,
    thank you very much for this excellent tutorial. I am a new user of the Arduino platform, the LoRa protocol has also fascinated me a lot. I’m trying to get my 11-year-old son Gabriel interested. By doing various searches on several sites to find out about LoRa I landed here. I was wondering if you were going to do some tutorials also on LoRaWan, because the literature on the web is very poor and I think the need to be able to read multiple sensors in different positions becomes more and more interesting. Alternatively if you can recommend me some tutorials on LoRaWan and how to connect the same sensors as your tutorial.
    Thanks
    Tiziano

    Reply
    • Hi.
      Thank you for following our work.
      Yes, I intend to do some tutorials about LoraWan and connecting the board to The Things Network (TTN).
      However, I don’t think I’ll be doing it soon. I have other projects on the “waiting list”.
      One of our followers built a very interesting project in which he connects the ESP32 to TTN.
      Here’s a link for his project: https://marcoroda.com/2020/04/12/TTGO-LORA-TTN.html
      I hope this is helpful.
      Regards,
      Sara

      Reply
  20. Hi Sara and team,
    I completed this project and it worked very well. Thanks for all the work you have done.
    However, I hooked up a accelerometer (MPU6050) using the I2C bus (Using the default pins 21, 22) . The MPU6050 works okay on its own but when I integrate the code into the sketch with the Lora/Oled I get a debug or exception error on the monitor.

    If I comment out the following lines from the setup , the 6050 works okay. Any ideas you may have which could help me in this regard ? I am trying to have the Accel/Gyro data transmitted via LOra.

    Thanks,
    Carl

    //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 128×32
    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();

    //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);
    }
    Serial.println(“LoRa Initializing OK!”);
    display.setCursor(0,10);
    display.print(“LoRa Initializing OK!”);
    display.display();
    delay(2000);

    Reply
      • Thanks for your prompt response. I am trying to figure out the I2C communications but in the meantime I disconnected the 6050 and did a I2C port scan and it did not show the integrated OLED device. It is not faulty because it works with test sketches.

        Could you explain the reason why this device does not show up on the port scan ? Btw, when I reconnect the 6050, it’s I2C address shows up with the scan.

        Reply
  21. Hello and thanks for this article!

    I have some questions about this kind ob ESP32 and LoRa board:
    – is it possible to set the ESP & LoRa module to sleep and only wake up the ESP at some kind of intervall for some measuring and then activate the LoRa module if the value changed (for example the temperature) to send the data?
    – what is the current consumption of the whole board when all components are active or in sleep mode?
    – is it possible with the LoRaWAN protocoll on this chip to use the adaptive data rate, for example automatically to change the spreading factor if the end devices moves far away?

    Last question is, why does all the LoRa chips on the market use the older Semtech SX127x and not the newer SX126x versions?

    Reply

Leave a Reply to Alain BERTOUT Cancel reply

Download our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.