TTGO LoRa32 SX1276 OLED Board: Getting Started with Arduino IDE
The TTGO LoRa32 SX1276 is an ESP32 development board with a built-in LoRa chip and OLED display. Learn how to send and receive LoRa packets using Arduino IDE.
- Suitable forB.Tech/Diploma IoT/ESP32 students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
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.
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
).
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 SX1276 OLED
The following figure shows the TTGO LoRa32 OLED board pinout.
The OLED displays communicates using
I2C communication protocol
. It is internally connected to the ESP32 on the following pins:
OLED
(built-in)
ESP32
SDA
GPIO 4
SCL
GPIO 15
RST
GPIO 16
The SX1276 LoRa chip communicates via SPI communication protocol, and it is internally connected to the ESP32 on the following GPIOs:
SX1276 LoRa
ESP32
MISO
GPIO 19
MOSI
GPIO 27
SCK
GPIO 5
CS
GPIO 18
IRQ
GPIO 26
RST
GPIO 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 the ESP32 Board in Arduino IDE (Windows, Mac OS X, Linux)
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.
3. After installing the SSD1306 library from Adafruit, type “
GFX
” in the search box and install the library.
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.
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.
//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() {
//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);
}
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);
}
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
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.
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
).
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 SX1276 OLED
The following figure shows the TTGO LoRa32 OLED board pinout.
The OLED displays communicates using
I2C communication protocol
. It is internally connected to the ESP32 on the following pins:
OLED
(built-in)
ESP32
SDA
GPIO 4
SCL
GPIO 15
RST
GPIO 16
The SX1276 LoRa chip communicates via SPI communication protocol, and it is internally connected to the ESP32 on the following GPIOs:
SX1276 LoRa
ESP32
MISO
GPIO 19
MOSI
GPIO 27
SCK
GPIO 5
CS
GPIO 18
IRQ
GPIO 26
RST
GPIO 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 the ESP32 Board in Arduino IDE (Windows, Mac OS X, Linux)
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.
3. After installing the SSD1306 library from Adafruit, type “
GFX
” in the search box and install the library.
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.
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.
//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() {
//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);
}
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);
}
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
Technologies used
Hardware components
- ESP32
- Arduino
- SSD1306
- OLED
- SX1276
Software & tools
- Arduino IDE
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.